1REQUEST_KEY(2)            Linux Key Management Calls            REQUEST_KEY(2)
2
3
4

NAME

6       request_key - request a key from the kernel's key management facility
7

SYNOPSIS

9       #include <keyutils.h>
10
11       key_serial_t request_key(const char *type, const char *description,
12                                const char *callout_info,
13                                key_serial_t keyring);
14

DESCRIPTION

16       request_key()  asks  the  kernel  to  find a key of the given type that
17       matches the specified description and, if successful, to attach  it  to
18       the nominated keyring and to return its serial number.
19
20       request_key()  first  recursively searches all the keyrings attached to
21       the calling process in the order thread-specific keyring,  process-spe‐
22       cific keyring and then session keyring for a matching key.
23
24       If  request_key()  is called from a program invoked by request_key() on
25       behalf of some other process to generate a key, then  the  keyrings  of
26       that  other  process  will be searched next, using that other process's
27       UID, GID, groups and security context to control access.
28
29       The keys in each keyring searched are checked for a  match  before  any
30       child  keyrings  are  recursed into.  Only keys that are searchable for
31       the caller may be found, and only searchable keyrings may be searched.
32
33       If the key is not found then, if callout_info  is  set,  this  function
34       will  attempt to look further afield.  In such a case, the callout_info
35       is passed to a user-space service such as /sbin/request-key to generate
36       the key.
37
38       If  that  is  unsuccessful  also, then an error will be returned, and a
39       temporary negative key will be  installed  in  the  nominated  keyring.
40       This  will  expire after a few seconds, but will cause subsequent calls
41       to request_key() to fail until it does.
42
43       The keyring serial number may be that of a valid keyring to  which  the
44       caller has write permission, or it may be a special keyring ID:
45
46       KEY_SPEC_THREAD_KEYRING
47              This specifies the caller's thread-specific keyring.
48
49       KEY_SPEC_PROCESS_KEYRING
50              This specifies the caller's process-specific keyring.
51
52       KEY_SPEC_SESSION_KEYRING
53              This specifies the caller's session-specific keyring.
54
55       KEY_SPEC_USER_KEYRING
56              This specifies the caller's UID-specific keyring.
57
58       KEY_SPEC_USER_SESSION_KEYRING
59              This specifies the caller's UID-session keyring.
60
61       If  a  key is created, no matter whether it's a valid key or a negative
62       key, it will displace any other key of the same  type  and  description
63       from the destination keyring.
64

RETURN VALUE

66       On success request_key() returns the serial number of the key it found.
67       On error, the value -1 will be returned and errno will have been set to
68       an appropriate error.
69

ERRORS

71       EACCES The keyring wasn't available for modification by the user.
72
73       EINTR  The request was interrupted by a signal.
74
75       EDQUOT The  key  quota for this user would be exceeded by creating this
76              key or linking it to the keyring.
77
78       EKEYEXPIRED
79              An expired key was found, but no replacement could be obtained.
80
81       EKEYREJECTED
82              The attempt to generate a new key was rejected.
83
84       EKEYREVOKED
85              A revoked key was found, but no replacement could be obtained.
86
87       ENOMEM Insufficient memory to create a key.
88
89       ENOKEY No matching key was found.
90

LINKING

92       Although this is a Linux system call, it is not present in libc but can
93       be  found  rather  in  libkeyutils.  When linking, -lkeyutils should be
94       specified to the linker.
95

SEE ALSO

97       keyctl(1), add_key(2), keyctl(2), request-key(8)
98

COLOPHON

100       This page is part of release 3.53 of the Linux  man-pages  project.   A
101       description  of  the project, and information about reporting bugs, can
102       be found at http://www.kernel.org/doc/man-pages/.
103
104
105
106Linux                             2010-02-25                    REQUEST_KEY(2)
Impressum