]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man2/add_key.2
add_key.2: Expand SEE ALSO list
[thirdparty/man-pages.git] / man2 / add_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 ADD_KEY 2 2016-07-17 Linux "Linux Key Management Calls"
12 .SH NAME
13 add_key \- add a key to the kernel's key management facility
14 .SH SYNOPSIS
15 .nf
16 .B #include <keyutils.h>
17 .sp
18 .BI "key_serial_t add_key(const char *" type ", const char *" description ,
19 .BI " const void *" payload ", size_t " plen ,
20 .BI " key_serial_t " keyring ");"
21 .fi
22
23 No glibc wrapper is provided for this system call; see NOTES.
24 .SH DESCRIPTION
25 .BR add_key ()
26 creates or updates a key of the given
27 .I type
28 and
29 .IR description ,
30 instantiates it with the
31 .I payload
32 of length
33 .IR plen ,
34 attaches it to the nominated
35 .IR keyring ,
36 and return the key's serial number.
37 .P
38 The key type may reject the data if it is in the wrong format or
39 is in some other way invalid.
40 .P
41 If the destination
42 .I keyring
43 already contains a key that matches the specified
44 .IR type
45 and
46 .IR description ,
47 then, if the key type supports it, that key will be updated rather than a new
48 key being created; if not, a new key will be created and it will displace the
49 link to the extant key from the keyring.
50 .P
51 The destination
52 .I keyring
53 serial number may be that of a valid keyring for which the caller has
54 .I write
55 permission, or it may be one of the following special keyring IDs:
56 .TP
57 .B KEY_SPEC_THREAD_KEYRING
58 This specifies the caller's thread-specific keyring.
59 .TP
60 .B KEY_SPEC_PROCESS_KEYRING
61 This specifies the caller's process-specific keyring.
62 .TP
63 .B KEY_SPEC_SESSION_KEYRING
64 This specifies the caller's session-specific keyring.
65 .TP
66 .B KEY_SPEC_USER_KEYRING
67 This specifies the caller's UID-specific keyring.
68 .TP
69 .B KEY_SPEC_USER_SESSION_KEYRING
70 This specifies the caller's UID-session keyring.
71 .SS Key types
72 There are a number of key types available in the core key management code, and
73 these can be specified to this function:
74 .TP
75 .B \*(lquser\*(rq
76 Keys of the user-defined key type may contain a blob of arbitrary data, and the
77 .I description
78 may be any valid string, though it is preferred that the description be
79 prefixed with a string representing the service to which the key is of interest
80 and a colon (for instance
81 .RB \*(lq afs:mykey \*(rq).
82 .TP
83 .B \*(lqkeyring\*(rq
84 Keyrings are special key types that may contain links to sequences of other
85 keys of any type.
86 If this interface is used to create a keyring, then a NULL
87 .I payload
88 should be specified, and
89 .I plen
90 should be zero.
91 .SH RETURN VALUE
92 On success,
93 .BR add_key ()
94 returns the serial number of the key it created or updated.
95 On error, \-1 is returned and
96 .I errno
97 is set to indicate the cause of the error.
98 .SH ERRORS
99 .TP
100 .B EACCES
101 The keyring wasn't available for modification by the user.
102 .TP
103 .B EINVAL
104 The payload data was invalid.
105 .TP
106 .B EKEYEXPIRED
107 The keyring has expired.
108 .TP
109 .B EKEYREVOKED
110 The keyring has been revoked.
111 .TP
112 .B ENOKEY
113 The keyring doesn't exist.
114 .TP
115 .B ENOMEM
116 Insufficient memory to create a key.
117 .TP
118 .B EDQUOT
119 The key quota for this user would be exceeded by creating this key or linking
120 it to the keyring.
121 .SH VERSIONS
122 This system call first appeared in Linux 2.6.11.
123 .SH CONFORMING TO
124 This system call is a nonstandard Linux extension.
125 .SH NOTES
126 No wrapper for this system call is provided in glibc.
127 A wrapper is provided in the
128 .IR libkeyutils
129 package.
130 When employing the wrapper in that library, link with
131 .IR \-lkeyutils .
132 .SH SEE ALSO
133 .BR keyctl (1),
134 .BR keyctl (2),
135 .BR request_key (2),
136 .BR keyctl (3),
137 .BR keyutils (7),
138 .BR keyrings (7),
139 .BR persistent-keyring (7),
140 .BR process-keyring (7),
141 .BR session-keyring (7),
142 .BR thread-keyring (7),
143 .BR user-keyring (7),
144 .BR user-session-keyring (7)
145
146 The kernel source files
147 .IR Documentation/security/keys.txt
148 and
149 .IR Documentation/security/keys-request-key.txt .