OSDN Git Service

(split) LDP: Update original to LDP v3.38.
[linuxjm/LDP_man-pages.git] / original / man2 / request_key.2
1 .\"
2 .\" Copyright (C) 2006 Red Hat, Inc. All Rights Reserved.
3 .\" Written by David Howells (dhowells@redhat.com)
4 .\"
5 .\" This program is free software; you can redistribute it and/or
6 .\" modify it under the terms of the GNU General Public License
7 .\" as published by the Free Software Foundation; either version
8 .\" 2 of the License, or (at your option) any later version.
9 .\"
10 .TH REQUEST_KEY 2 2010-02-25 Linux "Linux Key Management Calls"
11 .SH NAME
12 request_key \- Request a key from the kernel's key management facility
13 .SH SYNOPSIS
14 .nf
15 .B #include <keyutils.h>
16 .sp
17 .BI "key_serial_t request_key(const char *" type ", const char *" description ,
18 .BI "                         const char *" callout_info ,
19 .BI "                         key_serial_t " keyring ");"
20 .fi
21 .SH DESCRIPTION
22 .BR request_key ()
23 asks the kernel to find a key of the given
24 .I type
25 that matches the specified
26 .I description
27 and, if successful, to attach it to the nominated
28 .I keyring
29 and to return its serial number.
30 .P
31 .BR request_key ()
32 first recursively searches all the keyrings attached to the calling process in
33 the order thread-specific keyring, process-specific keyring and then session
34 keyring for a matching key.
35 .P
36 If
37 .BR request_key ()
38 is called from a program invoked by
39 .BR request_key ()
40 on behalf of some other process to generate a key, then the keyrings of that
41 other process will be searched next, using that other process's UID, GID,
42 groups and security context to control access.
43 .P
44 The keys in each keyring searched are checked for a match before any child
45 keyrings are recursed into.  Only keys that are
46 .B searchable
47 for the caller may be found, and only
48 .B searchable
49 keyrings may be searched.
50 .P
51 If the key is not found then, if
52 .I callout_info
53 is set, this function will attempt to look further afield.  In such a case, the
54 .I callout_info
55 is passed to a userspace service such as
56 .B /sbin/request\-key
57 to generate the key.
58 .P
59 If that is unsuccessful also, then an error will be returned, and a temporary
60 negative key will be installed in the nominated
61 .IR keyring .
62 This will expire after a few seconds, but will cause subsequent
63 calls to
64 .BR request_key ()
65 to fail until it does.
66 .P
67 The
68 .I keyring
69 serial number may be that of a valid keyring to which the caller has write
70 permission, or it may be a special keyring ID:
71 .TP
72 .B KEY_SPEC_THREAD_KEYRING
73 This specifies the caller's thread-specific keyring.
74 .TP
75 .B KEY_SPEC_PROCESS_KEYRING
76 This specifies the caller's process-specific keyring.
77 .TP
78 .B KEY_SPEC_SESSION_KEYRING
79 This specifies the caller's session-specific keyring.
80 .TP
81 .B KEY_SPEC_USER_KEYRING
82 This specifies the caller's UID-specific keyring.
83 .TP
84 .B KEY_SPEC_USER_SESSION_KEYRING
85 This specifies the caller's UID-session keyring.
86 .P
87 If a key is created, no matter whether it's a valid key or a negative key, it
88 will displace any other key of the same type and description from the
89 destination
90 .IR keyring .
91 .SH RETURN VALUE
92 On success
93 .BR request_key ()
94 returns the serial number of the key it found.
95 On error, the value
96 .B -1
97 will be returned and errno will have been set to an appropriate error.
98 .SH ERRORS
99 .TP
100 .B EACCES
101 The keyring wasn't available for modification by the user.
102 .TP
103 .B EINTR
104 The request was interrupted by a signal.
105 .TP
106 .B EDQUOT
107 The key quota for this user would be exceeded by creating this key or linking
108 it to the keyring.
109 .TP
110 .B EKEYEXPIRED
111 An expired key was found, but no replacement could be obtained.
112 .TP
113 .B EKEYREJECTED
114 The attempt to generate a new key was rejected.
115 .TP
116 .B EKEYREVOKED
117 A revoked key was found, but no replacement could be obtained.
118 .TP
119 .B ENOMEM
120 Insufficient memory to create a key.
121 .TP
122 .B ENOKEY
123 No matching key was found.
124 .SH LINKING
125 Although this is a Linux system call, it is not present in
126 .I libc
127 but can be found rather in
128 .IR libkeyutils .
129 When linking,
130 .B -lkeyutils
131 should be specified to the linker.
132 .SH SEE ALSO
133 .BR keyctl (1),
134 .BR add_key (2),
135 .BR keyctl (2),
136 .BR request-key (8)