1KEYCTL_READ(3) Linux Key Management Calls KEYCTL_READ(3)
2
3
4
6 keyctl_read - read a key
7
9 #include <keyutils.h>
10
11 long keyctl_read(key_serial_t key, char *buffer,
12 size_tbuflen);
13
14 long keyctl_read_alloc(key_serial_t key, void **_buffer);
15
17 keyctl_read() reads the payload of a key if the key type supports it.
18
19 The caller must have read permission on a key to be able to read it.
20
21 buffer and buflen specify the buffer into which the payload data will
22 be placed. If the buffer is too small, then the full size of the pay‐
23 load will be returned, and the contents of the buffer may be overwrit‐
24 ten in some undefined way.
25
26 keyctl_read_alloc() is similar to keyctl_read() except that it allo‐
27 cates a buffer big enough to hold the payload data and places the data
28 in it. If successful, a pointer to the buffer is placed in *_buffer.
29 The caller must free the buffer.
30
31 keyctl_read_alloc() adds a NUL character after the data it retrieves,
32 though this is not counted in the size value it returns.
33
35 This call can be used to list the contents of a keyring. The data is
36 presented to the user as an array of key_serial_t values, each of which
37 corresponds to a key to which the keyring holds a link.
38
39 The size of the keyring will be sizeof(key_serial_t) multiplied by the
40 number of keys. The size of key_serial_t is invariant across different
41 word sizes, though the byte-ordering is as appropriate for the kernel.
42
44 On success keyctl_read() returns the amount of data placed into the
45 buffer. If the buffer was too small, then the size of buffer required
46 will be returned, and the contents of the buffer may have been over‐
47 written in some undefined way.
48
49 On success keyctl_read_alloc() returns the amount of data in the buf‐
50 fer.
51
52 On error, both functions set errno to an appropriate code and return
53 the value -1.
54
56 ENOKEY The key specified is invalid.
57
58 EKEYEXPIRED
59 The key specified has expired.
60
61 EKEYREVOKED
62 The key specified had been revoked.
63
64 EACCES The key exists, but is not readable by the calling process.
65
66 EOPNOTSUPP
67 The key type does not support reading of the payload data.
68
70 This is a library function that can be found in libkeyutils. When
71 linking, -lkeyutils should be specified to the linker.
72
74 keyctl(1), add_key(2), keyctl(2), request_key(2), keyctl(3),
75 keyrings(7), keyutils(7)
76
77
78
79Linux 21 Feb 2014 KEYCTL_READ(3)