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, key_serial_t keyring);
13

DESCRIPTION

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

RETURN VALUE

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

ERRORS

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

LINKING

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

SEE ALSO

96       keyctl(1), add_key(2), keyctl(2), request-key(8)
97
98
99
100Linux                             4 May 2006                    REQUEST_KEY(2)
Impressum