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 2010-02-25 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 ");"
24 asks the kernel to create or update a key of the given
28 instantiate it with the
32 and to attach it to the nominated
34 and to return its serial number.
36 The key type may reject the data if it's in the wrong format or in some other
41 already contains a key that matches the specified
42 .IR type " and " description,
43 then, if the key type supports it, that key will be updated rather than a new
44 key being created; if not, a new key will be created and it will displace the
45 link to the extant key from the keyring.
49 serial number may be that of a valid keyring to which the caller has write
50 permission, or it may be a special keyring ID:
52 .B KEY_SPEC_THREAD_KEYRING
53 This specifies the caller's thread-specific keyring.
55 .B KEY_SPEC_PROCESS_KEYRING
56 This specifies the caller's process-specific keyring.
58 .B KEY_SPEC_SESSION_KEYRING
59 This specifies the caller's session-specific keyring.
61 .B KEY_SPEC_USER_KEYRING
62 This specifies the caller's UID-specific keyring.
64 .B KEY_SPEC_USER_SESSION_KEYRING
65 This specifies the caller's UID-session keyring.
67 There are a number of key types available in the core key management code, and
68 these can be specified to this function:
71 Keys of the user-defined key type may contain a blob of arbitrary data, and the
73 may be any valid string, though it is preferred that the description be
74 prefixed with a string representing the service to which the key is of interest
75 and a colon (for instance
76 .RB \*(lq afs:mykey \*(rq).
79 may be empty or NULL for keys of this type.
82 Keyrings are special key types that may contain links to sequences of other
84 If this interface is used to create a keyring, then a NULL
86 should be specified, and
92 returns the serial number of the key it created or updated.
93 On error, the value \-1
94 will be returned and errno will have been set to an appropriate error.
98 The keyring doesn't exist.
101 The keyring has expired.
104 The keyring has been revoked.
107 The payload data was invalid.
110 Insufficient memory to create a key.
113 The key quota for this user would be exceeded by creating this key or linking
117 The keyring wasn't available for modification by the user.
119 Although this is a Linux system call, it is not present in
121 but can be found rather in
125 should be specified to the linker.