OSDN Git Service

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