1 .\" Copyright (C) 2006 Red Hat, Inc. All Rights Reserved.
2 .\" Written by David Howells (dhowells@redhat.com)
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.
11 .TH ADD_KEY 2 2016-07-17 Linux "Linux Key Management Calls"
13 add_key \- add a key to the kernel's key management facility
16 .B #include <keyutils.h>
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 ");"
23 No glibc wrapper is provided for this system call; see NOTES.
26 creates or updates a key of the given
30 instantiates it with the
34 attaches it to the nominated
36 and return the key's serial number.
38 The key type may reject the data if it is in the wrong format or
39 is in some other way invalid.
43 already contains a key that matches the specified
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.
53 serial number may be that of a valid keyring for which the caller has
55 permission, or it may be one of the following special keyring IDs:
57 .B KEY_SPEC_THREAD_KEYRING
58 This specifies the caller's thread-specific keyring.
60 .B KEY_SPEC_PROCESS_KEYRING
61 This specifies the caller's process-specific keyring.
63 .B KEY_SPEC_SESSION_KEYRING
64 This specifies the caller's session-specific keyring.
66 .B KEY_SPEC_USER_KEYRING
67 This specifies the caller's UID-specific keyring.
69 .B KEY_SPEC_USER_SESSION_KEYRING
70 This specifies the caller's UID-session keyring.
72 There are a number of key types available in the core key management code, and
73 these can be specified to this function:
76 Keys of the user-defined key type may contain a blob of arbitrary data, and the
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).
84 Keyrings are special key types that may contain links to sequences of other
86 If this interface is used to create a keyring, then a NULL
88 should be specified, and
94 returns the serial number of the key it created or updated.
95 On error, \-1 is returned and
97 is set to indicate the cause of the error.
101 The keyring wasn't available for modification by the user.
104 The payload data was invalid.
107 The keyring has expired.
110 The keyring has been revoked.
113 The keyring doesn't exist.
116 Insufficient memory to create a key.
119 The key quota for this user would be exceeded by creating this key or linking
122 This system call first appeared in Linux 2.6.11.
124 This system call is a nonstandard Linux extension.
126 No wrapper for this system call is provided in glibc.
127 A wrapper is provided in the
130 When employing the wrapper in that library, link with
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)
146 The kernel source files
147 .IR Documentation/security/keys.txt
149 .IR Documentation/security/keys-request-key.txt .