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