diff options
author | David Howells <dhowells@redhat.com> | 2010-02-26 20:28:22 +0000 |
---|---|---|
committer | David Howells <dhowells@redhat.com> | 2010-02-26 20:28:22 +0000 |
commit | 79f87dc5e988dc2744bf40c5b8c6557f0cf58fc8 (patch) | |
tree | 5bcc4126724ff722434a61a149db85d6e2aa0662 /keyctl.c | |
parent | 3a8cc353e0cc88a84f5425bfef1be82933f3646d (diff) | |
download | keyutils-79f87dc5e988dc2744bf40c5b8c6557f0cf58fc8.tar.gz |
Add keyctl command to give the parent process a new keyring
Signed-off-by: David Howells <dhowells@redhat.com>
Diffstat (limited to 'keyctl.c')
-rw-r--r-- | keyctl.c | 28 |
1 files changed, 28 insertions, 0 deletions
@@ -56,6 +56,7 @@ static int act_keyctl_pinstantiate(int argc, char *argv[]); static int act_keyctl_negate(int argc, char *argv[]); static int act_keyctl_timeout(int argc, char *argv[]); static int act_keyctl_security(int argc, char *argv[]); +static int act_keyctl_new_session(int argc, char *argv[]); const struct command commands[] = { { act_keyctl_show, "show", "" }, @@ -90,6 +91,7 @@ const struct command commands[] = { { act_keyctl_negate, "negate", "<key> <timeout> <keyring>" }, { act_keyctl_timeout, "timeout", "<key> <timeout>" }, { act_keyctl_security, "security", "<key>" }, + { act_keyctl_new_session, "new_session", "" }, { NULL, NULL, NULL } }; @@ -1202,6 +1204,32 @@ static int act_keyctl_security(int argc, char *argv[]) /*****************************************************************************/ /* + * install a new session keyring on the parent process + */ +static int act_keyctl_new_session(int argc, char *argv[]) +{ + key_serial_t keyring; + + if (argc != 1) + format(); + + if (keyctl_join_session_keyring(NULL) < 0) + error("keyctl_join_session_keyring"); + + if (keyctl_session_to_parent() < 0) + error("keyctl_session_to_parent"); + + keyring = keyctl_get_keyring_ID(KEY_SPEC_SESSION_KEYRING, 0); + if (keyring < 0) + error("keyctl_get_keyring_ID"); + + /* print the resulting key ID */ + printf("%d\n", keyring); + return 0; +} + +/*****************************************************************************/ +/* * parse a key identifier */ static key_serial_t get_key_id(const char *arg) |