2 .\" Copyright (C) 2006 Red Hat, Inc. All Rights Reserved.
3 .\" Written by David Howells (dhowells@redhat.com)
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.
10 .TH REQUEST_KEY 2 2010-02-25 Linux "Linux Key Management Calls"
12 request_key \- Request a key from the kernel's key management facility
15 .B #include <keyutils.h>
17 .BI "key_serial_t request_key(const char *" type ", const char *" description ,
18 .BI "const char *" callout_info ", key_serial_t " keyring ");"
21 asks the kernel to find a key of the given
23 that matches the specified
25 and, if successful, to attach it to the nominated
27 and to return its serial number.
30 first recursively searches all the keyrings attached to the calling process in
31 the order thread-specific keyring, process-specific keyring and then session
32 keyring for a matching key.
36 is called from a program invoked by
38 on behalf of some other process to generate a key, then the keyrings of that
39 other process will be searched next, using that other process's UID, GID,
40 groups and security context to control access.
42 The keys in each keyring searched are checked for a match before any child
43 keyrings are recursed into. Only keys that are
45 for the caller may be found, and only
47 keyrings may be searched.
49 If the key is not found then, if
51 is set, this function will attempt to look further afield. In such a case, the
53 is passed to a userspace service such as
57 If that is unsuccessful also, then an error will be returned, and a temporary
58 negative key will be installed in the nominated
60 This will expire after a few seconds, but will cause subsequent
63 to fail until it does.
67 serial number may be that of a valid keyring to which the caller has write
68 permission, or it may be a special keyring ID:
70 .B KEY_SPEC_THREAD_KEYRING
71 This specifies the caller's thread-specific keyring.
73 .B KEY_SPEC_PROCESS_KEYRING
74 This specifies the caller's process-specific keyring.
76 .B KEY_SPEC_SESSION_KEYRING
77 This specifies the caller's session-specific keyring.
79 .B KEY_SPEC_USER_KEYRING
80 This specifies the caller's UID-specific keyring.
82 .B KEY_SPEC_USER_SESSION_KEYRING
83 This specifies the caller's UID-session keyring.
85 If a key is created, no matter whether it's a valid key or a negative key, it
86 will displace any other key of the same type and description from the
92 returns the serial number of the key it found.
95 will be returned and errno will have been set to an appropriate error.
99 No matching key was found.
102 An expired key was found, but no replacement could be obtained.
105 A revoked key was found, but no replacement could be obtained.
108 The attempt to generate a new key was rejected.
111 Insufficient memory to create a key.
114 The request was interrupted by a signal.
117 The key quota for this user would be exceeded by creating this key or linking
121 The keyring wasn't available for modification by the user.
123 Although this is a Linux system call, it is not present in
125 but can be found rather in
129 should be specified to the linker.