OSDN Git Service

(split) LDP man-pages の original/ を v3.29 に更新。
[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 ", key_serial_t " keyring ");"
19 .SH DESCRIPTION
20 .BR request_key ()
21 asks the kernel to find a key of the given
22 .I type
23 that matches the specified
24 .I description
25 and, if successful, to attach it to the nominated
26 .I keyring
27 and to return its serial number.
28 .P
29 .BR request_key ()
30 first recursively searches all the keyrings attached to the calling process in
31 the order thread-specific keyring, process-specific keyring and then session
32 keyring for a matching key.
33 .P
34 If
35 .BR request_key ()
36 is called from a program invoked by
37 .BR request_key ()
38 on behalf of some other process to generate a key, then the keyrings of that
39 other process will be searched next, using that other process's UID, GID,
40 groups and security context to control access.
41 .P
42 The keys in each keyring searched are checked for a match before any child
43 keyrings are recursed into.  Only keys that are
44 .B searchable
45 for the caller may be found, and only
46 .B searchable
47 keyrings may be searched.
48 .P
49 If the key is not found then, if
50 .I callout_info
51 is set, this function will attempt to look further afield.  In such a case, the
52 .I callout_info
53 is passed to a userspace service such as
54 .B /sbin/request\-key
55 to generate the key.
56 .P
57 If that is unsuccessful also, then an error will be returned, and a temporary
58 negative key will be installed in the nominated
59 .IR keyring .
60 This will expire after a few seconds, but will cause subsequent
61 calls to
62 .BR request_key ()
63 to fail until it does.
64 .P
65 The
66 .I keyring
67 serial number may be that of a valid keyring to which the caller has write
68 permission, or it may be a special keyring ID:
69 .TP
70 .B KEY_SPEC_THREAD_KEYRING
71 This specifies the caller's thread-specific keyring.
72 .TP
73 .B KEY_SPEC_PROCESS_KEYRING
74 This specifies the caller's process-specific keyring.
75 .TP
76 .B KEY_SPEC_SESSION_KEYRING
77 This specifies the caller's session-specific keyring.
78 .TP
79 .B KEY_SPEC_USER_KEYRING
80 This specifies the caller's UID-specific keyring.
81 .TP
82 .B KEY_SPEC_USER_SESSION_KEYRING
83 This specifies the caller's UID-session keyring.
84 .P
85 If a key is created, no matter whether it's a valid key or a negative key, it
86 will displace any other key of the same type and description from the
87 destination
88 .IR keyring .
89 .SH RETURN VALUE
90 On success
91 .BR request_key ()
92 returns the serial number of the key it found.
93 On error, the value
94 .B -1
95 will be returned and errno will have been set to an appropriate error.
96 .SH ERRORS
97 .TP
98 .B ENOKEY
99 No matching key was found.
100 .TP
101 .B EKEYEXPIRED
102 An expired key was found, but no replacement could be obtained.
103 .TP
104 .B EKEYREVOKED
105 A revoked key was found, but no replacement could be obtained.
106 .TP
107 .B EKEYREJECTED
108 The attempt to generate a new key was rejected.
109 .TP
110 .B ENOMEM
111 Insufficient memory to create a key.
112 .TP
113 .B EINTR
114 The request was interrupted by a signal.
115 .TP
116 .B EDQUOT
117 The key quota for this user would be exceeded by creating this key or linking
118 it to the keyring.
119 .TP
120 .B EACCES
121 The keyring wasn't available for modification by the user.
122 .SH LINKING
123 Although this is a Linux system call, it is not present in
124 .I libc
125 but can be found rather in
126 .IR libkeyutils .
127 When linking,
128 .B -lkeyutils
129 should be specified to the linker.
130 .SH SEE ALSO
131 .BR keyctl (1),
132 .BR add_key (2),
133 .BR keyctl (2),
134 .BR request-key (8)