]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man2/add_key.2
_syscall.2, add_key.2, epoll_create.2, epoll_ctl.2, epoll_wait.2, getxattr.2, inotify...
[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 .\" This program is free software; you can redistribute it and/or
5 .\" modify it under the terms of the GNU General Public License
6 .\" as published by the Free Software Foundation; either version
7 .\" 2 of the License, or (at your option) any later version.
8 .\"
9 .TH ADD_KEY 2 2010-02-25 Linux "Linux Key Management Calls"
10 .SH NAME
11 add_key \- add a key to the kernel's key management facility
12 .SH SYNOPSIS
13 .nf
14 .B #include <keyutils.h>
15 .sp
16 .BI "key_serial_t add_key(const char *" type ", const char *" description ,
17 .BI " const void *" payload ", size_t " plen ,
18 .BI " key_serial_t " keyring ");"
19 .fi
20 .SH DESCRIPTION
21 .BR add_key ()
22 asks the kernel to create or update a key of the given
23 .I type
24 and
25 .IR description ,
26 instantiate it with the
27 .I payload
28 of length
29 .IR plen ,
30 and to attach it to the nominated
31 .I keyring
32 and to return its serial number.
33 .P
34 The key type may reject the data if it's in the wrong format or in some other
35 way invalid.
36 .P
37 If the destination
38 .I keyring
39 already contains a key that matches the specified
40 .IR type " and " description
41 then, if the key type supports it, that key will be updated rather than a new
42 key being created; if not, a new key will be created and it will displace the
43 link to the extant key from the keyring.
44 .P
45 The destination
46 .I keyring
47 serial number may be that of a valid keyring to which the caller has write
48 permission, or it may be a special keyring ID:
49 .TP
50 .B KEY_SPEC_THREAD_KEYRING
51 This specifies the caller's thread-specific keyring.
52 .TP
53 .B KEY_SPEC_PROCESS_KEYRING
54 This specifies the caller's process-specific keyring.
55 .TP
56 .B KEY_SPEC_SESSION_KEYRING
57 This specifies the caller's session-specific keyring.
58 .TP
59 .B KEY_SPEC_USER_KEYRING
60 This specifies the caller's UID-specific keyring.
61 .TP
62 .B KEY_SPEC_USER_SESSION_KEYRING
63 This specifies the caller's UID-session keyring.
64 .SH KEY TYPES
65 There are a number of key types available in the core key management code, and
66 these can be specified to this function:
67 .TP
68 .B \*(lquser\*(rq
69 Keys of the user-defined key type may contain a blob of arbitrary data, and the
70 .I description
71 may be any valid string, though it is preferred that the description be
72 prefixed with a string representing the service to which the key is of interest
73 and a colon (for instance
74 .RB \*(lq afs:mykey \*(rq).
75 The
76 .I payload
77 may be empty or NULL for keys of this type.
78 .TP
79 .B \*(lqkeyring\*(rq
80 Keyrings are special key types that may contain links to sequences of other
81 keys of any type.
82 If this interface is used to create a keyring, then a NULL
83 .I payload
84 should be specified, and
85 .I plen
86 should be zero.
87 .SH RETURN VALUE
88 On success
89 .BR add_key ()
90 returns the serial number of the key it created or updated.
91 On error, the value \-1
92 will be returned and errno will have been set to an appropriate error.
93 .SH ERRORS
94 .TP
95 .B ENOKEY
96 The keyring doesn't exist.
97 .TP
98 .B EKEYEXPIRED
99 The keyring has expired.
100 .TP
101 .B EKEYREVOKED
102 The keyring has been revoked.
103 .TP
104 .B EINVAL
105 The payload data was invalid.
106 .TP
107 .B ENOMEM
108 Insufficient memory to create a key.
109 .TP
110 .B EDQUOT
111 The key quota for this user would be exceeded by creating this key or linking
112 it to the keyring.
113 .TP
114 .B EACCES
115 The keyring wasn't available for modification by the user.
116 .SH LINKING
117 Although this is a Linux system call, it is not present in
118 .I libc
119 but can be found rather in
120 .IR libkeyutils .
121 When linking,
122 .B -lkeyutils
123 should be specified to the linker.
124 .SH SEE ALSO
125 .BR keyctl (1),
126 .BR keyctl (2),
127 .BR request_key (2)