102 lines
3.1 KiB
Diff
102 lines
3.1 KiB
Diff
commit 91252c4e97c19cb6a4cfd2b62980402274cef607
|
|
Author: David Howells <dhowells@redhat.com>
|
|
Date: Thu Aug 1 15:12:30 2013 +0100
|
|
|
|
Add per-UID get-persistent keyring function
|
|
|
|
diff --git a/keyctl.c b/keyctl.c
|
|
index a137e08..dd481a4 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(const char *arg)
|
|
diff --git a/keyutils.c b/keyutils.c
|
|
index 329bfae..060674e 100644
|
|
--- a/keyutils.c
|
|
+++ b/keyutils.c
|
|
@@ -229,6 +229,11 @@ long keyctl_invalidate(key_serial_t id)
|
|
return keyctl(KEYCTL_INVALIDATE, id);
|
|
}
|
|
|
|
+long keyctl_get_persistent(uid_t uid, key_serial_t id)
|
|
+{
|
|
+ return keyctl(KEYCTL_GET_PERSISTENT, uid, id);
|
|
+}
|
|
+
|
|
/*****************************************************************************/
|
|
/*
|
|
* fetch key description into an allocated buffer
|
|
diff --git a/keyutils.h b/keyutils.h
|
|
index 3ddaeae..49126f7 100644
|
|
--- a/keyutils.h
|
|
+++ b/keyutils.h
|
|
@@ -97,6 +97,7 @@ typedef uint32_t key_perm_t;
|
|
#define KEYCTL_REJECT 19 /* reject a partially constructed key */
|
|
#define KEYCTL_INSTANTIATE_IOV 20 /* instantiate a partially constructed key */
|
|
#define KEYCTL_INVALIDATE 21 /* invalidate a key */
|
|
+#define KEYCTL_GET_PERSISTENT 22 /* get a user's persistent keyring */
|
|
|
|
/*
|
|
* syscall wrappers
|
|
@@ -150,6 +151,7 @@ extern long keyctl_instantiate_iov(key_serial_t id,
|
|
unsigned ioc,
|
|
key_serial_t ringid);
|
|
extern long keyctl_invalidate(key_serial_t id);
|
|
+extern long keyctl_get_persistent(uid_t uid, key_serial_t id);
|
|
|
|
/*
|
|
* utilities
|