text
stringlengths
0
234
int
main(int argc, char *argv[])
{
file *fp;
time_t t;
char *operation;
key_serial_t key_to_instantiate, dest_keyring;
key_serial_t thread_keyring, process_keyring, session_keyring;
uid_t uid;
gid_t gid;
char dbuf[256];
char auth_key_payload[256];
int akp_size; /* size of auth_key_payload */
int auth_key;
fp = fopen("/tmp/key_instantiate.log", "w");
if (fp == null)
exit(exit_failure);
setbuf(fp, null);
t = time(null);
fprintf(fp, "time: %s\en", ctime(&t));
/*
* the kernel passes a fixed set of arguments to the program
* that it execs; fetch them.
*/
operation = argv[1];
key_to_instantiate = atoi(argv[2]);
uid = atoi(argv[3]);
gid = atoi(argv[4]);
thread_keyring = atoi(argv[5]);
process_keyring = atoi(argv[6]);
session_keyring = atoi(argv[7]);
fprintf(fp, "command line arguments:\en");
fprintf(fp, " argv[0]: %s\en", argv[0]);
fprintf(fp, " operation: %s\en", operation);
fprintf(fp, " key_to_instantiate: %jx\en",
(uintmax_t) key_to_instantiate);
fprintf(fp, " uid: %jd\en", (intmax_t) uid);
fprintf(fp, " gid: %jd\en", (intmax_t) gid);
fprintf(fp, " thread_keyring: %jx\en",
(uintmax_t) thread_keyring);
fprintf(fp, " process_keyring: %jx\en",
(uintmax_t) process_keyring);
fprintf(fp, " session_keyring: %jx\en",
(uintmax_t) session_keyring);
fprintf(fp, "\en");
/*
* assume the authority to instantiate the key named in argv[2].
*/
if (keyctl(keyctl_assume_authority, key_to_instantiate) == \-1) {
fprintf(fp, "keyctl_assume_authority failed: %s\en",
strerror(errno));
exit(exit_failure);
}
/*
* fetch the description of the key that is to be instantiated.
*/
if (keyctl(keyctl_describe, key_to_instantiate,
dbuf, sizeof(dbuf)) == \-1) {
fprintf(fp, "keyctl_describe failed: %s\en", strerror(errno));
exit(exit_failure);
}
fprintf(fp, "key description: %s\en", dbuf);
/*
* fetch the payload of the authorization key, which is
* actually the callout data given to request_key().
*/
akp_size = keyctl(keyctl_read, key_spec_reqkey_auth_key,
auth_key_payload, sizeof(auth_key_payload));
if (akp_size == \-1) {
fprintf(fp, "keyctl_read failed: %s\en", strerror(errno));
exit(exit_failure);
}
auth_key_payload[akp_size] = \(aq\e0\(aq;
fprintf(fp, "auth key payload: %s\en", auth_key_payload);
/*
* for interest, get the id of the authorization key and
* display it.
*/
auth_key = keyctl(keyctl_get_keyring_id,
key_spec_reqkey_auth_key);
if (auth_key == \-1) {
fprintf(fp, "keyctl_get_keyring_id failed: %s\en",
strerror(errno));
exit(exit_failure);
}
fprintf(fp, "auth key id: %jx\en", (uintmax_t) auth_key);
/*