summaryrefslogtreecommitdiff
path: root/keyctl.c
diff options
context:
space:
mode:
authorDavid Howells <dhowells@redhat.com>2013-10-02 15:59:30 +0100
committerDavid Howells <dhowells@redhat.com>2013-10-02 15:58:10 +0100
commit89e0912913031c6cacbd436aafacfce837b83896 (patch)
treef4a9ffaf1a36ab32a0e2e626df710ac99c7463fa /keyctl.c
parent16a6d435b48b168d3e23673437d488e78deb91fc (diff)
downloadkeyutils-89e0912913031c6cacbd436aafacfce837b83896.tar.gz
Add per-UID get-persistent keyring function
Diffstat (limited to 'keyctl.c')
-rw-r--r--keyctl.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/keyctl.c b/keyctl.c
index e403ead..4cc6097 100644
--- a/keyctl.c
+++ b/keyctl.c
@@ -63,6 +63,7 @@ static int act_keyctl_reject(int argc, char *argv[]);
static int act_keyctl_reap(int argc, char *argv[]);
static int act_keyctl_purge(int argc, char *argv[]);
static int act_keyctl_invalidate(int argc, char *argv[]);
+static int act_keyctl_get_persistent(int argc, char *argv[]);
const struct command commands[] = {
{ act_keyctl___version, "--version", "" },
@@ -73,6 +74,7 @@ const struct command commands[] = {
{ act_keyctl_describe, "describe", "<keyring>" },
{ act_keyctl_instantiate, "instantiate","<key> <data> <keyring>" },
{ act_keyctl_invalidate,"invalidate", "<key>" },
+ { act_keyctl_get_persistent, "get_persistent", "<keyring> [<uid>]" },
{ act_keyctl_link, "link", "<key> <keyring>" },
{ act_keyctl_list, "list", "<keyring>" },
{ act_keyctl_negate, "negate", "<key> <timeout> <keyring>" },
@@ -1575,6 +1577,38 @@ static int act_keyctl_invalidate(int argc, char *argv[])
/*****************************************************************************/
/*
+ * Get the per-UID persistent keyring
+ */
+static int act_keyctl_get_persistent(int argc, char *argv[])
+{
+ key_serial_t dest, ret;
+ uid_t uid = -1;
+ char *q;
+
+ if (argc != 2 && argc != 3)
+ format();
+
+ dest = get_key_id(argv[1]);
+
+ if (argc > 2) {
+ uid = strtoul(argv[2], &q, 0);
+ if (*q) {
+ fprintf(stderr, "Unparsable uid: '%s'\n", argv[2]);
+ exit(2);
+ }
+ }
+
+ ret = keyctl_get_persistent(uid, dest);
+ if (ret < 0)
+ error("keyctl_get_persistent");
+
+ /* print the resulting key ID */
+ printf("%d\n", ret);
+ return 0;
+}
+
+/*****************************************************************************/
+/*
* parse a key identifier
*/
static key_serial_t get_key_id(char *arg)