OSDN Git Service

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