2010-02-25 07:29:02 +00:00
|
|
|
.\" Copyright (C) 2006 Red Hat, Inc. All Rights Reserved.
|
2016-10-27 10:01:33 +00:00
|
|
|
.\" Written by David Howells (dhowells@redhat.com)
|
|
|
|
.\" and Copyright (C) 2016 Michael Kerrisk <mtk.man-pages@gmail.com>
|
2010-02-25 07:29:02 +00:00
|
|
|
.\"
|
2013-03-10 09:29:47 +00:00
|
|
|
.\" %%%LICENSE_START(GPLv2+_SW_ONEPARA)
|
2010-02-25 07:29:02 +00:00
|
|
|
.\" This program is free software; you can redistribute it and/or
|
|
|
|
.\" modify it under the terms of the GNU General Public License
|
|
|
|
.\" as published by the Free Software Foundation; either version
|
|
|
|
.\" 2 of the License, or (at your option) any later version.
|
2013-03-10 09:28:55 +00:00
|
|
|
.\" %%%LICENSE_END
|
2010-02-25 07:29:02 +00:00
|
|
|
.\"
|
memusage.1, memusagestat.1, pldd.1, accept.2, adjtimex.2, arch_prctl.2, bdflush.2, bpf.2, close.2, epoll_ctl.2, epoll_wait.2, execve.2, execveat.2, fanotify_init.2, fanotify_mark.2, fcntl.2, fsync.2, get_kernel_syms.2, getdomainname.2, getgroups.2, gethostname.2, getrandom.2, getrlimit.2, getrusage.2, getsid.2, getunwind.2, io_getevents.2, ioctl_fat.2, kexec_load.2, killpg.2, listxattr.2, lseek.2, madvise.2, memfd_create.2, mknod.2, mlock.2, modify_ldt.2, msgctl.2, msgget.2, msgop.2, readlink.2, readv.2, reboot.2, recvmmsg.2, rename.2, request_key.2, restart_syscall.2, sched_setaffinity.2, sched_setattr.2, sched_setparam.2, seccomp.2, select_tut.2, semctl.2, semget.2, semop.2, set_thread_area.2, seteuid.2, setgid.2, setpgid.2, setresuid.2, setreuid.2, setsid.2, setuid.2, shmctl.2, shmget.2, shmop.2, sigaction.2, sigprocmask.2, stat.2, symlink.2, syscall.2, sysctl.2, unlink.2, bindresvport.3, byteorder.3, dlopen.3, endian.3, error.3, ffs.3, fmemopen.3, getcwd.3, getlogin.3, getnetent.3, getprotoent.3, getservent.3, getumask.3, getutent.3, glob.3, isalpha.3, lio_listio.3, login.3, mbsinit.3, mbstowcs.3, mbtowc.3, mkstemp.3, nextup.3, ntp_gettime.3, posix_fallocate.3, posix_spawn.3, pthread_join.3, pthread_rwlockattr_setkind_np.3, random.3, rcmd.3, realpath.3, resolver.3, setjmp.3, setnetgrent.3, sigvec.3, strerror.3, strverscmp.3, system.3, toupper.3, towlower.3, towupper.3, wcstombs.3, wordexp.3, cciss.4, loop.4, mouse.4, random.4, core.5, group.5, hosts.5, resolv.conf.5, ascii.7, environ.7, epoll.7, glob.7, ip.7, mq_overview.7, packet.7, pipe.7, raw.7, sched.7, signal.7, socket.7, symlink.7, ld.so.8, sln.8: tstamp
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2016-10-08 10:53:47 +00:00
|
|
|
.TH REQUEST_KEY 2 2016-10-08 Linux "Linux Key Management Calls"
|
2010-02-25 07:29:02 +00:00
|
|
|
.SH NAME
|
intro.1, add_key.2, get_mempolicy.2, get_thread_area.2, intro.2, keyctl.2, mbind.2, request_key.2, set_thread_area.2, clock.3, cmsg.3, getcwd.3, getpw.3, intro.3, malloc.3, posix_memalign.3, shm_open.3, sleep.3, sysconf.3, intro.4, sd.4, intro.5, locale.5, slabinfo.5, intro.6, boot.7, bootparam.7, futex.7, glob.7, hier.7, intro.7, libc.7, locale.7, mq_overview.7, netlink.7, sem_overview.7, shm_overview.7, unix.7, intro.8: Global fix: Use consistent capitalization in NAME section
The line(s) in the NAME section should only use capitals
where English usage dictates that. Otherwise, use
lowercase throughout.
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2012-10-21 06:29:13 +00:00
|
|
|
request_key \- request a key from the kernel's key management facility
|
2010-02-25 07:29:02 +00:00
|
|
|
.SH SYNOPSIS
|
|
|
|
.nf
|
2016-10-27 07:48:30 +00:00
|
|
|
.B #include <sys/types.h>
|
2010-02-25 07:29:02 +00:00
|
|
|
.B #include <keyutils.h>
|
|
|
|
.sp
|
|
|
|
.BI "key_serial_t request_key(const char *" type ", const char *" description ,
|
2011-11-07 03:46:44 +00:00
|
|
|
.BI " const char *" callout_info ,
|
2016-10-28 15:27:52 +00:00
|
|
|
.BI " key_serial_t " dest_keyring ");"
|
add_key.2, keyctl.2, request_key.2, offsetof.3, pthread_attr_init.3, pthread_attr_setaffinity_np.3, pthread_attr_setdetachstate.3, pthread_attr_setguardsize.3, pthread_attr_setinheritsched.3, pthread_attr_setschedparam.3, pthread_attr_setschedpolicy.3, pthread_attr_setscope.3, pthread_attr_setstackaddr.3, pthread_attr_setstacksize.3, pthread_cancel.3, pthread_cleanup_push.3, pthread_cleanup_push_defer_np.3, pthread_equal.3, pthread_exit.3, pthread_getattr_np.3, pthread_getcpuclockid.3, pthread_self.3, pthread_setaffinity_np.3, pthread_setcancelstate.3, pthread_setconcurrency.3, pthread_setschedparam.3, pthread_setschedprio.3, pthread_testcancel.3: Global formatting fix: balance .nf/.fi pairs
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2012-03-12 15:37:22 +00:00
|
|
|
.fi
|
2016-10-21 07:42:30 +00:00
|
|
|
|
|
|
|
No glibc wrapper is provided for this system call; see NOTES.
|
2010-02-25 07:29:02 +00:00
|
|
|
.SH DESCRIPTION
|
|
|
|
.BR request_key ()
|
2016-10-20 19:41:20 +00:00
|
|
|
attempts to find a key of the given
|
2010-02-25 07:29:02 +00:00
|
|
|
.I type
|
2016-10-20 19:41:20 +00:00
|
|
|
with a description (name) that matches the specified
|
2016-10-26 14:04:41 +00:00
|
|
|
.IR description .
|
2016-10-28 10:32:57 +00:00
|
|
|
If such a key could not be found, then the key is optionally created.
|
|
|
|
If the key is found or created,
|
2016-10-26 14:04:41 +00:00
|
|
|
.BR request_key ()
|
2016-10-28 15:27:52 +00:00
|
|
|
attaches it to the keyring whose ID is specified in
|
|
|
|
.I dest_keyring
|
2016-10-26 14:04:41 +00:00
|
|
|
and returns the key's serial number.
|
2016-10-29 16:52:50 +00:00
|
|
|
.\" FIXME Is 'keyring' allowed to be 0? Reading the source, it appears so.
|
2016-11-02 20:58:06 +00:00
|
|
|
.\" In this case, by default, the key is assigned to the session keyring.
|
|
|
|
.\" But, the KEYCTL_SET_REQKEY_KEYRING also seems to have an influence here.
|
|
|
|
.\" What are the details here?
|
2016-10-29 16:52:50 +00:00
|
|
|
.\"
|
|
|
|
|
2010-02-25 07:29:02 +00:00
|
|
|
.BR request_key ()
|
2016-10-20 19:41:20 +00:00
|
|
|
first recursively searches for a matching key in all of the keyrings
|
|
|
|
attached to the calling process.
|
|
|
|
The keyrings are searched in the order: thread-specific keyring,
|
|
|
|
process-specific keyring, and then session keyring.
|
2010-02-25 07:29:02 +00:00
|
|
|
.P
|
|
|
|
If
|
|
|
|
.BR request_key ()
|
|
|
|
is called from a program invoked by
|
|
|
|
.BR request_key ()
|
|
|
|
on behalf of some other process to generate a key, then the keyrings of that
|
2016-10-20 19:41:20 +00:00
|
|
|
other process will be searched next,
|
|
|
|
using that other process's user ID, group ID,
|
2016-11-02 20:58:06 +00:00
|
|
|
supplementary group IDs, and security context to determine access.
|
|
|
|
.\" FIXME Above, can we then have an arbitrarily long sequence
|
|
|
|
.\" of "recursive" request-key upcalls?
|
2010-02-25 07:29:02 +00:00
|
|
|
.P
|
2016-10-21 11:26:15 +00:00
|
|
|
The search of the keyring tree is breadth-first:
|
|
|
|
the keys in each keyring searched are checked for a match before any child
|
2012-05-05 03:10:16 +00:00
|
|
|
keyrings are recursed into.
|
2016-10-26 14:04:41 +00:00
|
|
|
Only keys for which the caller has
|
|
|
|
.I search
|
|
|
|
permission be found, and only keyrings for which the caller has
|
|
|
|
.I search
|
|
|
|
permission may be searched.
|
2010-02-25 07:29:02 +00:00
|
|
|
.P
|
2016-10-28 10:32:57 +00:00
|
|
|
If the key is not found and
|
|
|
|
.I callout
|
|
|
|
is NULL, then the call fails with the error
|
|
|
|
.BR ENOKEY .
|
|
|
|
|
|
|
|
If the key is not found and
|
|
|
|
.I callout
|
|
|
|
is not NULL, then the kernel attempts to invoke a user-space
|
|
|
|
program to instantiate the key.
|
|
|
|
The details are given below.
|
|
|
|
|
|
|
|
The
|
2016-10-28 15:27:52 +00:00
|
|
|
.I dest_keyring
|
2016-10-28 10:32:57 +00:00
|
|
|
serial number may be that of a valid keyring for which the caller has
|
|
|
|
.I write
|
|
|
|
permission, or it may be one of the following special keyring IDs:
|
|
|
|
.TP
|
|
|
|
.B KEY_SPEC_THREAD_KEYRING
|
|
|
|
This specifies the caller's thread-specific keyring
|
|
|
|
.RB ( thread-keyring (7)).
|
|
|
|
.TP
|
|
|
|
.B KEY_SPEC_PROCESS_KEYRING
|
|
|
|
This specifies the caller's process-specific keyring
|
|
|
|
.RB ( process-keyring (7)).
|
|
|
|
.TP
|
|
|
|
.B KEY_SPEC_SESSION_KEYRING
|
|
|
|
This specifies the caller's session-specific keyring
|
|
|
|
.RB ( session-keyring (7)).
|
|
|
|
.TP
|
|
|
|
.B KEY_SPEC_USER_KEYRING
|
|
|
|
This specifies the caller's UID-specific keyring
|
|
|
|
.RB ( user-keyring (7)).
|
|
|
|
.TP
|
|
|
|
.B KEY_SPEC_USER_SESSION_KEYRING
|
|
|
|
This specifies the caller's UID-session keyring
|
|
|
|
.RB ( user-session-keyring (7)).
|
|
|
|
.\"
|
|
|
|
.SS Requesting user-space instantiation of a key
|
|
|
|
If the kernel cannot find a key matching
|
|
|
|
.IR type
|
|
|
|
and
|
|
|
|
.IR description ,
|
|
|
|
and
|
|
|
|
.I callout
|
|
|
|
is not NULL, then the kernel attempts to invoke a user-space
|
|
|
|
program to instantiate a key with the given
|
|
|
|
.IR type
|
|
|
|
and
|
|
|
|
.IR description .
|
2016-10-26 14:30:36 +00:00
|
|
|
In this case, the following steps are performed:
|
2016-10-28 10:32:57 +00:00
|
|
|
.IP a) 4
|
2016-10-26 14:30:36 +00:00
|
|
|
The kernel creates an uninstantiated key, U, with the requested
|
|
|
|
.I type
|
|
|
|
and
|
|
|
|
.IR description .
|
2016-10-28 10:32:57 +00:00
|
|
|
.IP b)
|
2016-10-26 14:30:36 +00:00
|
|
|
The kernel creates an authorization key, V, that refers to the key U
|
2016-11-02 20:58:06 +00:00
|
|
|
and records the facts that the caller of
|
2016-10-26 14:30:36 +00:00
|
|
|
.BR request_key (2)
|
2016-11-02 20:58:06 +00:00
|
|
|
is:
|
|
|
|
.RS
|
|
|
|
.IP (1) 4
|
|
|
|
the context in which the key U should be instantiated and secured, and
|
|
|
|
.IP (2)
|
|
|
|
the context from which associated key requests may be satisfied.
|
|
|
|
.RE
|
|
|
|
.IP
|
2016-10-28 10:32:57 +00:00
|
|
|
The authorization key is constructed as follows:
|
|
|
|
.RS
|
|
|
|
.IP * 3
|
|
|
|
The key type is
|
|
|
|
.IR """.request_key_auth""" .
|
|
|
|
.IP *
|
|
|
|
The key's UID and GID are the same as the corresponding filesystem IDs
|
|
|
|
of the requesting process.
|
|
|
|
.IP *
|
|
|
|
The key grants
|
|
|
|
.IR view ,
|
|
|
|
.IR read ,
|
|
|
|
and
|
|
|
|
.IR search
|
|
|
|
permissions to the key possessor as well as
|
|
|
|
.IR view
|
|
|
|
permission for the key user.
|
|
|
|
.IP *
|
|
|
|
The description (name) of the key is the hexadecimal
|
|
|
|
string representing the ID of the key that is to be instantiated.
|
|
|
|
.IP *
|
|
|
|
The payload of the key is taken from the data specified in
|
2016-10-26 14:30:36 +00:00
|
|
|
.IR callout_info .
|
2016-10-28 10:32:57 +00:00
|
|
|
.RE
|
|
|
|
.IP c)
|
2016-10-26 14:30:36 +00:00
|
|
|
The kernel creates a process that executes a user-space service such as
|
2016-10-26 14:04:41 +00:00
|
|
|
.BR request-key (8)
|
2016-10-26 14:30:36 +00:00
|
|
|
with a new session keyring that contains a link to the authorization key, V.
|
2016-11-02 20:58:06 +00:00
|
|
|
.\" The request-key(8) program can be invoked in circumstances *other* than
|
|
|
|
.\" when triggered by request_key(2). For example, upcalls from places such
|
|
|
|
.\" as the DNS resolver.
|
2016-10-28 10:32:57 +00:00
|
|
|
|
|
|
|
This program is supplied with the following command-line arguments:
|
|
|
|
.RS
|
|
|
|
.IP [0] 4
|
|
|
|
The string
|
|
|
|
.IR """/sbin/request-key""" .
|
|
|
|
.IP [1]
|
|
|
|
The string
|
|
|
|
.I """create"""
|
|
|
|
(indicating that a key is to be created).
|
|
|
|
.IP [2]
|
|
|
|
The ID of the key that is to be instantiated.
|
|
|
|
.IP [3]
|
|
|
|
The filesystem UID of the caller of
|
|
|
|
.BR request_key ().
|
|
|
|
.IP [4]
|
|
|
|
The filesystem GID of the caller of
|
|
|
|
.BR request_key ().
|
|
|
|
.IP [5]
|
|
|
|
The ID of the thread keyring of the caller of
|
|
|
|
.BR request_key ().
|
|
|
|
This may be zero if that keyring hasn't been created.
|
|
|
|
.IP [6]
|
|
|
|
The ID of the process keyring of the caller of
|
|
|
|
.BR request_key ().
|
|
|
|
This may be zero if that keyring hasn't been created.
|
|
|
|
.IP [7]
|
|
|
|
The ID of the session keyring of the caller of
|
|
|
|
.BR request_key ().
|
|
|
|
.RE
|
|
|
|
.IP
|
|
|
|
.IR Note :
|
2016-11-02 20:58:06 +00:00
|
|
|
each of the command-line arguments that is a key ID is encoded in
|
2016-10-28 10:32:57 +00:00
|
|
|
.IR decimal
|
|
|
|
(unlike the key IDs shown in
|
|
|
|
.IR /proc/keys ,
|
|
|
|
which are shown as hexadecimal values).
|
|
|
|
.IP d)
|
2016-10-26 14:30:36 +00:00
|
|
|
The program spawned in the previous step:
|
|
|
|
.RS
|
|
|
|
.IP * 3
|
|
|
|
Assumes the authority to instantiate the key U using the
|
|
|
|
.BR keyctl (2)
|
|
|
|
.BR KEYCTL_ASSUME_AUTHORITY
|
2016-11-02 20:58:06 +00:00
|
|
|
operation (typically via the
|
|
|
|
.BR keyctl_assume_authority (3)
|
|
|
|
function).
|
2016-10-26 14:30:36 +00:00
|
|
|
.IP *
|
2016-11-02 20:58:06 +00:00
|
|
|
Obtains the callout data from the payload of the authorization key V
|
|
|
|
(using the
|
2016-10-26 14:30:36 +00:00
|
|
|
.BR keyctl (2)
|
|
|
|
.BR KEYCTL_READ
|
2016-11-02 20:58:06 +00:00
|
|
|
operation (or, more commonly, the
|
|
|
|
.BR keyctl_read (3)
|
|
|
|
function) with a key ID value of
|
2016-10-26 14:30:36 +00:00
|
|
|
.BR KEY_SPEC_REQKEY_AUTH_KEY ).
|
|
|
|
.IP *
|
|
|
|
Instantiates the key
|
2016-10-28 10:32:57 +00:00
|
|
|
(or execs another program that performs that task),
|
|
|
|
specifying the payload and destination keyring.
|
|
|
|
(The destination keyring that the requestor specified when calling
|
|
|
|
.BR request_key ()
|
|
|
|
can be accessed using the special key ID
|
|
|
|
.BR KEY_SPEC_REQUESTOR_KEYRING .)
|
2016-11-02 20:58:06 +00:00
|
|
|
.\" Should an instantiating program be using KEY_SPEC_REQUESTOR_KEYRING?
|
2016-10-29 16:52:50 +00:00
|
|
|
.\" I couldn't find a use in the keyutils git repo.
|
2016-11-02 20:58:06 +00:00
|
|
|
.\" According to David Howells:
|
|
|
|
.\" * This feature is provided, but not used at the moment.
|
|
|
|
.\" * A key added to that ring is then owned by the requester
|
|
|
|
Instantiation is performed using the
|
|
|
|
.BR keyctl (2)
|
|
|
|
.BR KEYCTL_INSTANTIATE
|
|
|
|
operation (or, more commonly, the
|
|
|
|
.BR keyctl_instantiate (3)
|
|
|
|
function).
|
|
|
|
At this point, the
|
|
|
|
.BR request_key (2)
|
|
|
|
call completes, and the requesting program can continue execution.
|
2016-10-26 14:30:36 +00:00
|
|
|
.RE
|
2010-02-25 07:29:02 +00:00
|
|
|
.P
|
2016-10-28 10:32:57 +00:00
|
|
|
If these steps are unsuccessful, then an
|
|
|
|
.BR ENOKEY
|
|
|
|
error will be returned to the caller of
|
|
|
|
.BR request_key ()
|
2016-10-28 15:27:52 +00:00
|
|
|
and a temporary negative key will be installed in the keyring specified by
|
|
|
|
.IR dest_keyring .
|
2016-10-28 10:32:57 +00:00
|
|
|
This will expire after a few seconds, but will cause subsequent calls to
|
2010-02-25 07:29:02 +00:00
|
|
|
.BR request_key ()
|
|
|
|
to fail until it does.
|
2016-11-02 20:58:06 +00:00
|
|
|
The purpose of this negatively instantiated key is to prevent
|
|
|
|
(possibly different) processes making repeated requests
|
|
|
|
(that require expensive
|
|
|
|
.BR request-key (8)
|
|
|
|
upcalls) for a key that can't (at the moment) be positively instantiated.
|
|
|
|
|
|
|
|
Once the key has been instantiated, the authorization key
|
|
|
|
.RB ( KEY_SPEC_REQKEY_AUTH_KEY )
|
|
|
|
is revoked, and the destination keyring
|
|
|
|
.RB ( KEY_SPEC_REQUESTOR_KEYRING )
|
|
|
|
is no longer accessible from the
|
|
|
|
.BR request-key (8)
|
|
|
|
program.
|
2016-10-28 10:32:57 +00:00
|
|
|
|
2016-10-26 14:04:41 +00:00
|
|
|
If a key is created, then\(emregardless of whether it is a valid key or
|
|
|
|
a negative key\(emit will displace any other key with
|
2016-10-28 15:27:52 +00:00
|
|
|
the same type and description from the keyring specified in
|
|
|
|
.IR dest_keyring .
|
2010-02-25 07:29:02 +00:00
|
|
|
.SH RETURN VALUE
|
2016-10-20 19:41:20 +00:00
|
|
|
On success,
|
2010-02-25 07:29:02 +00:00
|
|
|
.BR request_key ()
|
2016-10-26 14:04:41 +00:00
|
|
|
returns the serial number of the key it found or caused to be created.
|
2016-10-20 19:41:20 +00:00
|
|
|
On error, \-1 is returned and
|
|
|
|
.I errno
|
|
|
|
is set to indicate the cause of the error.
|
2010-02-25 07:29:02 +00:00
|
|
|
.SH ERRORS
|
|
|
|
.TP
|
2010-11-01 06:18:03 +00:00
|
|
|
.B EACCES
|
|
|
|
The keyring wasn't available for modification by the user.
|
|
|
|
.TP
|
|
|
|
.B EDQUOT
|
|
|
|
The key quota for this user would be exceeded by creating this key or linking
|
|
|
|
it to the keyring.
|
2010-02-25 07:29:02 +00:00
|
|
|
.TP
|
2016-08-07 17:10:00 +00:00
|
|
|
.B EINTR
|
|
|
|
The request was interrupted by a signal; see
|
|
|
|
.BR signal (7).
|
|
|
|
.TP
|
2016-10-27 12:09:04 +00:00
|
|
|
.B EINVAL
|
|
|
|
The size of the string (including the terminating null byte) specified in
|
|
|
|
.I type
|
|
|
|
or
|
|
|
|
.I description
|
|
|
|
exceeded the limit (32 bytes and 4096 bytes respectively).
|
|
|
|
.TP
|
|
|
|
.B EINVAL
|
|
|
|
The size of the string (including the terminating null byte) specified in
|
|
|
|
.I callout_info
|
|
|
|
exceeded the system page size.
|
|
|
|
.TP
|
2010-02-25 07:29:02 +00:00
|
|
|
.B EKEYEXPIRED
|
|
|
|
An expired key was found, but no replacement could be obtained.
|
|
|
|
.TP
|
|
|
|
.B EKEYREJECTED
|
|
|
|
The attempt to generate a new key was rejected.
|
|
|
|
.TP
|
2010-11-01 06:18:03 +00:00
|
|
|
.B EKEYREVOKED
|
|
|
|
A revoked key was found, but no replacement could be obtained.
|
|
|
|
.TP
|
|
|
|
.B ENOKEY
|
|
|
|
No matching key was found.
|
2016-08-07 17:10:00 +00:00
|
|
|
.TP
|
|
|
|
.B ENOMEM
|
|
|
|
Insufficient memory to create a key.
|
2016-10-19 08:30:35 +00:00
|
|
|
.SH VERSIONS
|
2016-11-03 18:05:38 +00:00
|
|
|
This system call first appeared in Linux 2.6.10.
|
2016-10-19 08:30:35 +00:00
|
|
|
.SH CONFORMING TO
|
|
|
|
This system call is a nonstandard Linux extension.
|
2016-10-19 08:29:50 +00:00
|
|
|
.SH NOTES
|
2016-10-21 07:42:30 +00:00
|
|
|
No wrapper for this system call is provided in glibc.
|
|
|
|
A wrapper is provided in the
|
|
|
|
.IR libkeyutils
|
|
|
|
package.
|
|
|
|
When employing the wrapper in that library, link with
|
|
|
|
.IR \-lkeyutils .
|
2016-10-27 10:01:33 +00:00
|
|
|
.SH EXAMPLE
|
|
|
|
The program below demonstrates the use of
|
|
|
|
.BR request_key ().
|
|
|
|
The
|
|
|
|
.IR type ,
|
|
|
|
.IR description ,
|
|
|
|
and
|
|
|
|
.BR callout_info
|
|
|
|
arguments for the system call are taken from the values
|
|
|
|
supplied in the command line arguments.
|
|
|
|
The call specifies the session keyring as the target keyring.
|
|
|
|
|
|
|
|
In order to demonstrate this program,
|
|
|
|
we first create a suitable entry in the file
|
|
|
|
.IR /etc/request-key.conf .
|
|
|
|
|
|
|
|
.in +4n
|
|
|
|
.nf
|
|
|
|
$ sudo sh
|
|
|
|
# \fBecho 'create user mtk:* * /bin/keyctl instantiate %k %c %S' \\\fP
|
|
|
|
\fB> /etc/request-keys.conf\fP
|
|
|
|
# \fBexit\fP
|
|
|
|
.fi
|
|
|
|
.in
|
|
|
|
|
|
|
|
This entry specifies that when a new "user" key with the prefix
|
|
|
|
"mtk:" must be instantiated, that task should be performed via the
|
|
|
|
.BR keyctl (1)
|
|
|
|
command's
|
|
|
|
.B instantiate
|
|
|
|
operation.
|
|
|
|
(The program could
|
|
|
|
The arguments supplied to the
|
|
|
|
.B instantiate
|
|
|
|
operation are:
|
|
|
|
the ID of the uninstantiated key
|
|
|
|
.RI ( %k );
|
|
|
|
the callout data supplied to the
|
|
|
|
.BR request_key ()
|
|
|
|
call
|
|
|
|
.RI ( %c );
|
|
|
|
and the session keyring
|
|
|
|
.RI ( %S )
|
|
|
|
of the requestor (i.e., the caller of
|
|
|
|
.BR request)key ()).
|
|
|
|
i(See
|
|
|
|
.BR request-key.conf (5)
|
|
|
|
for details of these
|
|
|
|
.I %
|
|
|
|
specifiers.)
|
|
|
|
|
|
|
|
Then we run the program and check the contents of
|
|
|
|
.IR /proc/keys
|
|
|
|
to verify that the requested kay has been instantiated:
|
|
|
|
|
|
|
|
.in +4n
|
|
|
|
.nf
|
|
|
|
$ \fB./a.out user mtk:key1 "Payload data"\fP
|
|
|
|
$ \fBgrep \(aq2dddaf50\(aq /proc/keys\fP
|
|
|
|
2dddaf50 I--Q--- 1 perm 3f010000 1000 1000 user mtk:key1: 12
|
|
|
|
.fi
|
|
|
|
.in
|
|
|
|
.SS Program source
|
|
|
|
\&
|
|
|
|
.nf
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <keyutils.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#define errExit(msg) do { perror(msg); exit(EXIT_FAILURE); \\
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
key_serial_t key;
|
|
|
|
|
|
|
|
if (argc != 4) {
|
|
|
|
fprintf(stderr, "Usage: %s type description callout\-data\\n",
|
|
|
|
argv[0]);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
key = request_key(argv[1], argv[2], argv[3],
|
|
|
|
KEY_SPEC_SESSION_KEYRING);
|
|
|
|
if (key == \-1)
|
|
|
|
errExit("request_key");
|
|
|
|
|
|
|
|
printf("Key ID is %lx\\n", (long) key);
|
|
|
|
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
}
|
|
|
|
.fi
|
2010-02-25 07:29:02 +00:00
|
|
|
.SH SEE ALSO
|
2016-11-02 02:59:30 +00:00
|
|
|
.ad l
|
|
|
|
.nh
|
2010-02-25 07:29:02 +00:00
|
|
|
.BR keyctl (1),
|
|
|
|
.BR add_key (2),
|
|
|
|
.BR keyctl (2),
|
2015-04-22 12:06:47 +00:00
|
|
|
.BR keyctl (3),
|
2015-04-22 12:04:54 +00:00
|
|
|
.BR keyrings (7),
|
2016-10-21 08:11:22 +00:00
|
|
|
.BR keyutils (7),
|
2016-11-02 02:59:30 +00:00
|
|
|
.BR persistent\-keyring (7),
|
|
|
|
.BR process\-keyring (7),
|
|
|
|
.BR session\-keyring (7),
|
|
|
|
.BR thread\-keyring (7),
|
|
|
|
.BR user\-keyring (7),
|
|
|
|
.BR user\-session\-keyring (7),
|
|
|
|
.BR request\-key (8)
|
2016-10-20 06:46:46 +00:00
|
|
|
|
|
|
|
The kernel source files
|
|
|
|
.IR Documentation/security/keys.txt
|
|
|
|
and
|
2016-11-02 02:59:30 +00:00
|
|
|
.IR Documentation/security/keys\-request\-key.txt .
|