OSDN Git Service

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