1KEYCTL_READ(3)            Linux Key Management Calls            KEYCTL_READ(3)
2
3
4

NAME

6       keyctl_read - read a key
7

SYNOPSIS

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

DESCRIPTION

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, the full size  of  the  payload
23       will be returned and no copy will take place.
24
25       keyctl_read_alloc()  is  similar  to keyctl_read() except that it allo‐
26       cates a buffer big enough to hold the payload data and places the  data
27       in  it.   If successful, a pointer to the buffer is placed in *_buffer.
28       The caller must free the buffer.
29
30       keyctl_read_alloc() adds a NUL character after the data  it  retrieves,
31       though this is not counted in the size value it returns.
32

READING KEYRINGS

34       This  call  can be used to list the contents of a keyring.  The data is
35       presented to the user as an array of key_serial_t values, each of which
36       corresponds to a key to which the keyring holds a link.
37
38       The  size of the keyring will be sizeof(key_serial_t) multiplied by the
39       number of keys.  The size of key_serial_t is invariant across different
40       word sizes, though the byte-ordering is as appropriate for the kernel.
41

RETURN VALUE

43       On  success  keyctl_read()  returns  the amount of data placed into the
44       buffer.  If the buffer was too small, then the size of buffer  required
45       will be returned, but no data will be transferred.
46
47       On  success  keyctl_read_alloc() returns the amount of data in the buf‐
48       fer.
49
50       On error, both functions set errno to an appropriate  code  and  return
51       the value -1.
52

ERRORS

54       ENOKEY The key specified is invalid.
55
56       EKEYEXPIRED
57              The key specified has expired.
58
59       EKEYREVOKED
60              The key specified had been revoked.
61
62       EACCES The key exists, but is not readable by the calling process.
63
64       EOPNOTSUPP
65              The key type does not support reading of the payload data.
66

LINKING

68       This  is  a  library  function  that can be found in libkeyutils.  When
69       linking, -lkeyutils should be specified to the linker.
70

SEE ALSO

72       keyctl(1), add_key(2), keyctl(2), request_key(2), keyctl(3),
73       keyrings(7), keyutils(7)
74
75
76
77Linux                             21 Feb 2014                   KEYCTL_READ(3)
Impressum