]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man2/keyctl.2
keyctl.2: Various wording fixes
[thirdparty/man-pages.git] / man2 / keyctl.2
CommitLineData
4509c62e
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)
4509c62e
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
4509c62e 10.\"
67d2c687 11.TH KEYCTL 2 2015-05-07 Linux "Linux Key Management Calls"
4509c62e 12.SH NAME
f68512e9 13keyctl \- manipulate the kernel's key management facility
4509c62e
MK
14.SH SYNOPSIS
15.nf
16.B #include <keyutils.h>
17.sp
fa76da80
ES
18.BI "long keyctl(int " cmd ", ...)"
19.sp
60fc9e95 20.B "/* For direct call via syscall(2): */"
fa76da80
ES
21.B #include <asm/unistd.h>
22.B #include <linux/keyctl.h>
23.B #include <unistd.h>
24.sp
9a9febc8
MK
25.BI "long syscall(__NR_keyctl, int " option ", __kernel_ulong_t " arg2 ,
26.BI " __kernel_ulong_t " arg3 ", __kernel_ulong_t " arg4 ,
27.BI " __kernel_ulong_t " arg5 );
6030f2d8 28.fi
4509c62e
MK
29.SH DESCRIPTION
30.BR keyctl ()
60fc9e95
MK
31allows user-space programs to perform key manipulation.
32
33The operation performed by
fa76da80 34.BR keyctl ()
60fc9e95
MK
35is determined by the value of the
36.I option
37argument.
38Each of these operations is wrapped by
39.B libkeyutils
40into individual functions (listed under SEE ALSO)
41to permit the compiler to check types.
42
43The permitted values for
fa76da80 44.I option
60fc9e95 45are:
4509c62e 46.TP
a92d3bb4 47.B KEYCTL_GET_KEYRING_ID
60fc9e95 48Ask for a keyring whose ID is provided in
fa76da80
ES
49.I arg2
50(converted to
51.IR key_serial_t ).
52If the
53.I arg3
60fc9e95
MK
54argument contains a non-zero value, a new keyring is created.
55
56The caller must have
fa76da80 57.I search
60fc9e95
MK
58permission on a keyring in order for it to be found.
59
60The arguments
61.IR arg4
62and
63.IR arg5
fa76da80 64are ignored.
4509c62e 65.TP
a92d3bb4 66.B KEYCTL_JOIN_SESSION_KEYRING
60fc9e95 67Create a new anonymous session keyring (in case
fa76da80
ES
68.I arg2
69is
70.BR NULL )
60fc9e95 71or join an existing named session keyring
fa76da80 72.RI ( arg2
60fc9e95
MK
73should be a pointer to a string containing session name in this case).
74
75The caller must have
fa76da80 76.I search
60fc9e95 77permission on the keyring name which is provided in order
461a8ce5 78to successfully join.
60fc9e95
MK
79
80The arguments
81.IR arg3 ,
82.IR arg4 ,
83and
84.IR arg5
fa76da80 85are ignored.
4509c62e 86.TP
a92d3bb4 87.B KEYCTL_UPDATE
60fc9e95 88Update a key's data payload.
461a8ce5 89The
fa76da80
ES
90.I arg2
91argument (converted to
92.IR key_serial_t )
60fc9e95
MK
93should contain the key ID.
94The
fa76da80
ES
95.I arg3
96argument is interpreted as a pointer to the new payload and
97.I arg4
98(converted to
99.IR size_t )
60fc9e95
MK
100should contain the payload size in bytes.
101
102The caller must have
fa76da80 103.I write
60fc9e95
MK
104permission on the key specified and the key type must support updating.
105A negative key can be positively instantiated with this call.
106
461a8ce5 107The
fa76da80
ES
108.I arg5
109argument is ignored.
4509c62e 110.TP
a92d3bb4 111.B KEYCTL_REVOKE
60fc9e95 112Revoke the key with the ID provided in
fa76da80
ES
113.I arg2
114(converted to
115.IR key_serial_t ).
60fc9e95
MK
116
117The caller must have
fa76da80 118.IR write " or " setattr
60fc9e95
MK
119permission on they key.
120
121The arguments
122.IR arg3 ,
123.IR arg4 ,
124and
125.IR arg5
fa76da80 126are ignored.
4509c62e 127.TP
a92d3bb4 128.B KEYCTL_CHOWN
60fc9e95 129Set the ownership of a key.
461a8ce5 130The
fa76da80
ES
131.I arg2
132argument (converted to
133.IR key_serial_t )
60fc9e95
MK
134contains the key ID.
135The
fa76da80
ES
136.I arg3
137argument (converted to
138.IR uid_t )
60fc9e95
MK
139contains the new user ID (or \-1 in case the user ID shouldn't be changed).
140The
fa76da80
ES
141.I arg4
142argument (converted to
143.IR gid_t )
60fc9e95 144contains the new group ID (or \-1 in case the group ID shouldn't be changed).
fa76da80
ES
145The key must grant the caller
146.I setattr
461a8ce5
MK
147permission.
148For the UID to be changed, or for the GID to be changed to a group
60fc9e95
MK
149the caller is not a member of, the caller must have the
150.B CAP_SYS_ADMIN
fa76da80 151capability (see
60fc9e95 152.BR capabilities (7)).
461a8ce5
MK
153If the UID is to be changed, the new user must have sufficient
154quota to accept the key.
155The quota deduction will be removed from the old user
156to the new user should the attribute be changed.
60fc9e95 157
461a8ce5 158The
fa76da80
ES
159.I arg5
160argument is ignored.
4509c62e 161.TP
a92d3bb4 162.B KEYCTL_SETPERM
60fc9e95 163Change the permissions of the key with the ID provided in the
fa76da80
ES
164.I arg2
165argument (converted to
166.IR key_serial_t )
60fc9e95 167to the permissions provided in the
fa76da80
ES
168.I arg3
169argument (converted to
170.IR key_perms_t ).
171The key must grant
172.I setattr
461a8ce5
MK
173permission to the caller.
174If the caller doesn't have
60fc9e95
MK
175.B CAP_SYS_ADMIN
176capability, it can change permissions only for the keys it owns.
177Permissions contains a mask of available operations for possessor
461a8ce5 178(since Linux 2.6.14), user, group, other.
60fc9e95 179Each mask is eight bits in size, with only six bits currently used.
461a8ce5 180The available permissions are:
fa76da80
ES
181.RS
182.IP \(bu 3
183.BR View .
461a8ce5
MK
184Allows reading attributes of a key.
185Needed for
60fc9e95 186.BR KEYCTL_DESCRIBE .
fa76da80
ES
187.IP \(bu
188.BR Read .
60fc9e95 189Allows reading a key's payload.
461a8ce5 190Needed for
60fc9e95 191.BR KEYCTL_READ .
fa76da80
ES
192.IP \(bu
193.BR Write .
60fc9e95
MK
194Allows update or instantiation of a key's payload.
195For a keyring, it enables addition and removal of keys to a keyring.
461a8ce5 196Needed for
60fc9e95
MK
197.BR KEYCTL_UPDATE ,
198.BR KEYCTL_REVOKE ,
199.BR KEYCTL_CLEAR ,
200.BR KEYCTL_LINK ,
201and
202.BR KEYCTL_UNLINK .
fa76da80
ES
203.IP \(bu
204.BR Search .
461a8ce5
MK
205This permits keyrings to be searched and keys to be found.
206Searches can only recurse into nested keyrings
207that have search permission set.
208Needed for
60fc9e95
MK
209.BR KEYCTL_GET_KEYRING_ID ,
210.BR KEYCTL_JOIN_SESSION_KEYRING ,
211.BR KEYCTL_SEARCH ,
212and
213.BR KEYCTL_INVALIDATE .
fa76da80
ES
214.IP \(bu
215.BR Link .
461a8ce5
MK
216This permits a key or keyring to be linked to.
217Needed for
60fc9e95
MK
218.BR KEYCTL_LINK
219and
220.BR KEYCTL_SESSION_TO_PARENT .
fa76da80 221.IP \(bu
60fc9e95
MK
222.BR "Set attribute" " (since Linux 2.6.15)."
223This permits a key's UID, GID, and permissions mask to be changed.
461a8ce5 224Needed for
60fc9e95
MK
225.BR KEYCTL_REVOKE ,
226.BR KEYCTL_CHOWN ,
227and
228.BR KEYCTL_SETPERM .
fa76da80
ES
229.RE
230.IP
231The
232.IR arg4 " and " arg5
233arguments are ignored.
4509c62e 234.TP
a92d3bb4 235.B KEYCTL_DESCRIBE
461a8ce5 236Describe a key.
60fc9e95 237The ID of the key to be described should be provided in the
fa76da80
ES
238.I arg2
239argument (converted to
60fc9e95
MK
240.IR key_serial_t ).
241The
fa76da80 242.I arg3
60fc9e95 243argument should point to the destination buffer (of type
fa76da80
ES
244.IR "char *" ),
245and the
246.I arg4
247argument should contain size of the buffer (of kernel's
248.I size_t
461a8ce5
MK
249type).
250The key must grant the caller
fa76da80 251.I view
461a8ce5 252permission.
60fc9e95 253Writing to the buffer is attempted only when the buffer is non-NULL and
fa76da80
ES
254has enough space to accept the description.
255'\" Function commentary says it copies up to buflen bytes, bu see the
256'\" (buffer && buflen >= ret) condition in keyctl_describe_key() in
257'\" security/keyctl.c
60fc9e95 258The description itself is provided in the format:
fa76da80
ES
259.RS
260.IP
261.IR type ; uid ; gid ; perm ; description "<NUL>"
262.RE
263.IP
461a8ce5 264The
fa76da80
ES
265.I arg5
266argument is ignored.
4509c62e 267.TP
a92d3bb4 268.B KEYCTL_CLEAR
60fc9e95 269Clear the contents of the keyring with the ID provided in the
fa76da80
ES
270.I arg2
271argument (converted to
272.IR key_serial_t ).
60fc9e95
MK
273
274The caller must have
fa76da80 275.I write
461a8ce5 276permission.
60fc9e95
MK
277
278The arguments
279.IR arg3 ,
280.IR arg4 ,
281and
282.IR arg5
fa76da80 283are ignored.
4509c62e 284.TP
a92d3bb4 285.B KEYCTL_LINK
fa76da80
ES
286Link a key (provided in the
287.I arg2
288argument converted to
289.I key_serial_t
290type) to a keyring (provided in the
291.I arg3
292argument converted to
293.I key_serial_t
294type) of there is no matching key in the keyring, or replace the link
461a8ce5 295to the matching key with a link to the new key.
60fc9e95
MK
296
297The caller must have
fa76da80
ES
298.I link
299permission on the key being added and
300.I write
461a8ce5 301permission on the keyring to which key being added to.
60fc9e95
MK
302
303The arguments
304.IR arg4
305and
306.IR arg5
fa76da80 307are ignored.
4509c62e 308.TP
a92d3bb4 309.B KEYCTL_UNLINK
fa76da80
ES
310Unlink a key (provided in the
311.I arg2
312argument converted to
313.I key_serial_t
314type) from a keyring (provided in the
315.I arg3
316argument converted to
317.I key_serial_t
461a8ce5 318type).
60fc9e95
MK
319
320The caller must have
fa76da80 321.I write
60fc9e95
MK
322permission on the keyring from which the key is being removed.
323
461a8ce5 324If the last link
60fc9e95
MK
325to a key is removed, then that key will be scheduled for destruction.
326
327The arguments
328.IR arg4
329and
330.IR arg5
fa76da80 331are ignored.
4509c62e 332.TP
a92d3bb4 333.B KEYCTL_SEARCH
60fc9e95 334Search for a key in a keyring with the ID provided in the
fa76da80
ES
335.I arg2
336argument (converted to
337.I key_serial_t
461a8ce5
MK
338type).
339The
fa76da80
ES
340.I arg3
341argument should be a
342.I char *
60fc9e95
MK
343pointing to the name of the type of the key being searched for
344(NUL-terminated character string up to 32 bytes in size), and the
fa76da80
ES
345.I arg4
346argument should be a
347.I char *
60fc9e95
MK
348pointing to a NUL-terminated character string (up to 4096 bytes in size)
349with the description of the key being searched for.
461a8ce5 350The search is performed recursively
60fc9e95 351starting from the keyring with the ID provided in
fa76da80
ES
352.IR arg2 .
353Only keyrings that grant the caller
354.I search
355permission will be searched (this includes the starting keyring).
356Only keys with
357.I search
461a8ce5 358permission can be found.
60fc9e95 359
461a8ce5 360If the
fa76da80
ES
361.I arg5
362argument (converted to
363.I key_serial_t
60fc9e95 364type) contains a non-zero value, it is interpreted as a keyring ID to which
fa76da80 365the found key should be linked.
4509c62e 366.TP
a92d3bb4 367.B KEYCTL_READ
60fc9e95 368Read the payload of the key whose ID is provided in the
fa76da80
ES
369.I arg2
370argument (converted to
371.I key_serial_t
60fc9e95
MK
372type).
373The payload is placed in the buffer pointed by the
fa76da80
ES
374.I arg3
375argument (converted to
376.I char *
60fc9e95
MK
377type);
378the size of that buffer must be provided in the
fa76da80
ES
379.I arg4
380argument (converted to kernel's
381.I size_t
461a8ce5
MK
382type).
383The key must either grant the caller
fa76da80
ES
384.I read
385permission, or it must grant the caller
386.I search
461a8ce5 387permission when searched for from the process keyrings.
60fc9e95 388
461a8ce5 389The
fa76da80
ES
390.I arg5
391argument is ignored.
4509c62e 392.TP
a92d3bb4 393.B KEYCTL_INSTANTIATE
60fc9e95 394Instantiate a partially constructed key whose ID is provided in the
fa76da80
ES
395.I arg2
396argument (converted to
397.I key_serial_t
398type) with a payload pointed by the
399.I arg3
400argument (converted to
401.I char *
402type) of size provided in the
403.I arg4
404argument (converted to kernel's
405.I size_t
461a8ce5 406type).
60fc9e95 407The instantiated key will be linked to the keyring ID which is provided in the
fa76da80
ES
408.I arg5
409argument (converted to
410.I key_serial_t
461a8ce5
MK
411type).
412The caller must have the appropriate instantiation permit set (auth key).
60fc9e95 413
4509c62e 414.TP
a92d3bb4 415.B KEYCTL_NEGATE
60fc9e95 416Negatively instantiate a partially constructed key with the ID provided in the
fa76da80
ES
417.I arg2
418argument (converted to
419.I key_serial_t
60fc9e95 420type), setting the timeout (in seconds) to the value provided in the
fa76da80
ES
421.I arg3
422argument (converted to
423.I unsigned int
461a8ce5 424type).
60fc9e95 425The instantiated key will be linked to the keyring ID which is provided in the
fa76da80
ES
426.I arg4
427argument (converted to
428.I key_serial_t
461a8ce5 429type).
60fc9e95 430
461a8ce5 431The caller must have the appropriate instantiation permit set
60fc9e95
MK
432(authorization key, see
433.B KEYCTL_ASSUME_AUTHORITY
461a8ce5 434command).
60fc9e95 435
461a8ce5 436Negative keys are used to rate limit repeated
60fc9e95
MK
437.BR request_key (2)
438calls by causing them to fail with the error
439.B ENOKEY
461a8ce5 440until the negative key expires.
60fc9e95
MK
441
442This is equivalent to the call
443
444 keyctl(KEYCTL_REJECT, arg2, arg3, ENOKEY, arg4);
445
fa76da80
ES
446The
447.I arg5
448argument is ignored.
8ec6a211 449.TP
fa76da80 450.BR KEYCTL_SET_REQKEY_KEYRING " (since Linux 2.6.13)"
60fc9e95
MK
451Read or set the default keyring in which
452.BR request_key (2)
461a8ce5
MK
453will cache keys.
454The
fa76da80
ES
455.I arg2
456argument (converted to
457.I int
458type) should contain one of the following values, defined in
459.IR <linux/keyring.h> :
d1d5839d
MK
460.RS
461.TP 33
462.BR KEY_REQKEY_DEFL_NO_CHANGE
463No change.
464.TP
465.BR KEY_REQKEY_DEFL_DEFAULT
466Default keyring.
467.TP
468.BR KEY_REQKEY_DEFL_THREAD_KEYRING
469Thread-specific keyring.
470.TP
471.BR KEY_REQKEY_DEFL_PROCESS_KEYRING
472Process-specific keyring.
473.TP
474.BR KEY_REQKEY_DEFL_SESSION_KEYRING
475Session-specific keyring.
476.TP
477.BR KEY_REQKEY_DEFL_USER_KEYRING
478UID-specific keyring.
479.TP
480.BR KEY_REQKEY_DEFL_USER_SESSION_KEYRING 5
481Session keyring of UID.
482.TP
483.BR KEY_REQKEY_DEFL_REQUESTOR_KEYRING " (since Linux 2.6.29)"
fa76da80 484'\" 8bbf4976b59fc9fc2861e79cab7beb3f6d647640
d1d5839d
MK
485Requestor keyring.
486.RE
487.IP
60fc9e95
MK
488All other values are invalid (including the as-yet-unsupported
489.BR KEY_REQKEY_DEFL_GROUP_KEYRING ).
490
491The arguments
492.IR arg3 ,
493.IR arg4 ,
494and
495.IR arg5
fa76da80 496are ignored.
8ec6a211 497.TP
fa76da80 498.BR KEYCTL_SET_TIMEOUT " (since Linux 2.6.16)"
461a8ce5
MK
499Set timeout on a key.
500ID of a key provided in the
fa76da80
ES
501.I arg2
502argument (converted to
503.I key_serial_t
504type), timeout value (in seconds from current time) provided in the
505.I arg3
506argument (converted to
507.I unsigned int
461a8ce5 508type).
60fc9e95
MK
509
510The caller must either have the
fa76da80 511.I setattr
60fc9e95
MK
512permission or hold an instantiation authorization token for the key.
513
514A timeout value of 0 clears the timeout.
461a8ce5
MK
515The key and any links to the key will be
516automatically garbage collected after the timeout expires.
60fc9e95
MK
517
518The arguments
519.IR arg4
520and
521.IR arg5
fa76da80 522are ignored.
8ec6a211 523.TP
fa76da80 524.BR KEYCTL_ASSUME_AUTHORITY " (since Linux 2.6.16)"
461a8ce5 525Assume (or clear) the authority for the key instantiation.
60fc9e95 526The ID of the authorization key provided in the
fa76da80
ES
527.I arg2
528argument (converted to
529.I key_serial_t
461a8ce5 530type).
60fc9e95 531
461a8ce5 532The caller must have the instantiation key in their process keyrings
fa76da80
ES
533with a
534.I search
461a8ce5 535permission grant available to the caller.
60fc9e95 536
461a8ce5 537If the ID given in the
fa76da80 538.I arg2
461a8ce5 539argument is 0, then the setting will be cleared.
60fc9e95
MK
540
541The arguments
542.IR arg3 ,
543.IR arg4 ,
544and
545.IR arg5
fa76da80
ES
546are ignored.
547.TP
548.BR KEYCTL_GET_SECURITY " (since Linux 2.6.26)"
60fc9e95 549Get the LSM security label of the specified key.
461a8ce5 550The ID of the key should be provided in the
fa76da80
ES
551.I arg2
552argument (converted to
553.I key_serial_t
461a8ce5 554type).
60fc9e95 555The buffer where the security label should be stored is provided in the
fa76da80
ES
556.I arg3
557argument (converted to
558.I char *
559type) with its size provided in the
560.I arg4
561argument (converted to kernel's
562.I size_t
461a8ce5 563type).
60fc9e95 564
461a8ce5 565The
fa76da80
ES
566.I arg5
567argument is ignored.
568.TP
569.BR KEYCTL_SESSION_TO_PARENT " (since Linux 2.6.32)"
570Apply session keyring to parent process.
571.IP
461a8ce5
MK
572Attempt to install the calling process's session keyring
573on the process's parent process.
574The keyring must exist and must grant the caller
fa76da80 575.I link
60fc9e95
MK
576permission, and the parent process must be single-threaded and have
577the same effective ownership as this process
578and must not be be set-user-ID or set-group-ID.
fa76da80
ES
579.IP
580The keyring will be emplaced on the parent when it next resumes userspace.
60fc9e95
MK
581
582The arguments
583.IR arg2 ,
584.IR arg3 ,
585.IR arg4 ,
586and
587.IR arg5
fa76da80
ES
588are ignored.
589.TP
590.BR KEYCTL_REJECT " (since Linux 2.6.39)"
60fc9e95 591Negatively instantiate a partially constructed key with the ID provided in the
fa76da80
ES
592.I arg2
593argument (converted to
594.I key_serial_t
595type), setting timeout (in seconds) to the value provided in the
596.I arg3
597argument (converted to
598.I unsigned int
599type) and instantiation error to the value provided in the
600.I arg4
601argument (converted to
602.I unsigned int
461a8ce5 603type).
60fc9e95 604The instantiated key will be linked to the keyring ID which is provided in the
fa76da80
ES
605.I arg5
606argument (converted to
607.I key_serial_t
461a8ce5 608type).
60fc9e95 609
461a8ce5 610The caller must have the appropriate instantiation permit set
60fc9e95
MK
611(authorization key, see
612.B KEYCTL_ASSUME_AUTHORITY
461a8ce5
MK
613command).
614Negative keys are used to rate limit repeated
60fc9e95 615.BR request_key (2)
fa76da80
ES
616calls by causing them to return the error specified until the negative key
617expires.
618.TP
619.BR KEYCTL_INSTANTIATE_IOV " (since Linux 2.6.39)"
60fc9e95 620Instantiate a key (with the ID specified in the
fa76da80
ES
621.I arg2
622argument of type
623.IR key_serial_t )
624with the specified (in the
625.I arg3
626argument of type
627.IR "const struct iovec *" )
628multipart payload and link the key into
60fc9e95 629the destination keyring (whose ID is provided in the
fa76da80
ES
630.I arg4
631argument of type
632.IR key_serial_t )
461a8ce5 633if non-zero one is given.
60fc9e95 634
461a8ce5 635The caller must have the appropriate instantiation
60fc9e95
MK
636permit (authorization key, see
637.B KEYCTL_ASSUME_AUTHORITY
461a8ce5
MK
638command) set for this to work.
639No other permissions are required.
60fc9e95 640
461a8ce5 641The
fa76da80
ES
642.I arg5
643argument is ignored.
644.TP
645.BR KEYCTL_INVALIDATE " (since Linux 3.5)"
60fc9e95 646Invalidate a key with the ID provided in the
fa76da80
ES
647.I arg2
648argument (converted to
649.I key_serial_t
461a8ce5 650type).
60fc9e95 651
461a8ce5 652The caller must have
fa76da80 653.I search
461a8ce5 654permission in order to perform invalidation.
60fc9e95 655
461a8ce5
MK
656The key and any links to the key
657will be automatically garbage collected immediately.
60fc9e95
MK
658
659The arguments
660.IR arg3 ,
661.IR arg4 ,
662and
663.IR arg5
fa76da80
ES
664are ignored.
665.TP
666.BR KEYCTL_GET_PERSISTENT " (since Linux 3.13)"
667Get the persistent keyring of the user specified in the
668.I arg2
669(converted to
670.I uid_t
60fc9e95 671type) and link it to the keyring with the ID provided in the
fa76da80
ES
672.I arg3
673argument (converted to
674.I key_serial_t
461a8ce5 675type).
60fc9e95
MK
676If \-1 is provided as UID, current user's ID is used.
677
678The arguments
679.IR arg4
680and
681.IR arg5
fa76da80
ES
682are ignored.
683.TP
684.BR KEYCTL_DH_COMPUTE " (since Linux 4.7)"
461a8ce5
MK
685Compute Diffie-Hellman values.
686The
fa76da80
ES
687.I arg2
688argument is a pointer to
60fc9e95 689.I struct keyctl_dh_params
fa76da80
ES
690which is defined in
691.I <linux/keyctl.h>
692as follows:
693
694.nf
695.in +4n
696struct keyctl_dh_params {
697 int32_t private;
698 int32_t prime;
699 int32_t base;
700};
701.in
702.fi
703
60fc9e95 704The
fa76da80 705.IR private ", " prime " and " base
60fc9e95 706fields are IDs of the keys, payload of which would be used for DH values
461a8ce5 707calculation.
60fc9e95 708The result is calculated as
fa76da80 709.IR "base^private mod prime" .
60fc9e95 710
fa76da80
ES
711The
712.I arg3
713argument (converted to
714.I char *
60fc9e95 715type) should point to an output buffer whose size is passed in the
fa76da80
ES
716.I arg4
717argument (converted to kernel's
718.I size_t
461a8ce5 719type).
60fc9e95
MK
720The buffer should be big enough in order to accommodate the output data,
721otherwise an error is returned.
722A NULL pointer can be provided as buffer in order
723to obtain the required buffer size.
724
461a8ce5 725The
fa76da80 726.I arg5
60fc9e95 727argument is reserved and must be 0.
4509c62e 728.SH RETURN VALUE
fa76da80
ES
729For a successful call, the return value depends on the operation:
730.TP
731.B KEYCTL_GET_KEYRING_ID
732The ID of the requested keyring.
733.TP
734.B KEYCTL_JOIN_SESSION_KEYRING
735The ID of the joined session keyring.
736.TP
737.B KEYCTL_DESCRIBE
60fc9e95 738The size of description (including the terminating null byte), irrespective
fa76da80
ES
739of the provided buffer size.
740.TP
741.B KEYCTL_SEARCH
742The found key ID.
743.TP
744.B KEYCTL_READ
745The amount of data that is available in the key, irrespective of the provided
746buffer size.
747.TP
748.B KEYCTL_SET_REQKEY_KEYRING
749Old setting (one of
60fc9e95 750.BR KEY_REQKEY_DEFL_USER_* )
fa76da80
ES
751.TP
752.B KEYCTL_ASSUME_AUTHORITY
461a8ce5 7530, if the ID given is 0.
60fc9e95 754ID of the authorization key matching key with the given
fa76da80
ES
755ID if non-zero key ID provided.
756.TP
757.B KEYCTL_GET_SECURITY
60fc9e95 758The amount of information available (including the terminating null byte),
fa76da80
ES
759irrespective of the provided buffer size.
760.TP
761.B KEYCTL_GET_PERSISTENT
762ID of the persistent keyring.
763.TP
764.B KEYCTL_DH_COMPUTE
765Amount of bytes being copied.
766.TP
767All other commands
768Zero.
769.PP
770On error, \-1 is returned, and
771.I errno
772is set appropriately to indicate the error.
4509c62e
MK
773.SH ERRORS
774.TP
27807c32 775.B EACCES
60fc9e95 776The requested operation wasn't permitted.
27807c32
MK
777.TP
778.B EDQUOT
779The key quota for the caller's user would be exceeded by creating a key or
780linking it to the keyring.
4509c62e
MK
781.TP
782.B EKEYEXPIRED
783An expired key was found or specified.
784.TP
4509c62e
MK
785.B EKEYREJECTED
786A rejected key was found or specified.
787.TP
27807c32
MK
788.B EKEYREVOKED
789A revoked key was found or specified.
4509c62e 790.TP
27807c32
MK
791.B ENOKEY
792No matching key was found or an invalid key was specified.
fa76da80
ES
793.TP
794.B ENOTSUPP
795.I option
796is
797.B KEYCTL_UPDATE
60fc9e95 798and the key type does not support updating.
fa76da80
ES
799.TP
800.B ENOTDIR
801Key of keyring type is expected but ID of a key with a different type provided.
802.TP
803.B ENFILE
804Keyring is full.
805.TP
806.B ENOENT
807.I option
808is
809.B KEYCTL_UNLINK
810and the key requested for unlinking isn't linked to the keyring.
811.TP
812.B EINVAL
813.I option
814is
815.B KEYCTL_DH_COMPUTE
60fc9e95 816and the buffer size provided is not enough for the result to fit in.
461a8ce5 817Provide 0 as
fa76da80 818a buffer size in order to obtain minimum buffer size first.
60fc9e95 819.SH NOTES
4509c62e
MK
820Although this is a Linux system call, it is not present in
821.I libc
822but can be found rather in
823.IR libkeyutils .
824When linking,
60fc9e95 825.B \-lkeyutils
4509c62e 826should be specified to the linker.
4509c62e 827.SH SEE ALSO
e264f024
MK
828.ad l
829.nh
4509c62e 830.BR keyctl (1),
4509c62e 831.BR add_key (2),
4509c62e 832.BR request_key (2),
4509c62e 833.BR keyctl_chown (3),
4509c62e 834.BR keyctl_clear (3),
cf4d4361
DP
835.BR keyctl_describe (3),
836.BR keyctl_describe_alloc (3),
837.BR keyctl_get_keyring_ID (3),
4509c62e 838.BR keyctl_instantiate (3),
cf4d4361
DP
839.BR keyctl_join_session_keyring (3),
840.BR keyctl_link (3),
4509c62e 841.BR keyctl_negate (3),
d8f1a35c
MK
842.BR keyctl_read (3),
843.BR keyctl_read_alloc (3),
cf4d4361
DP
844.BR keyctl_revoke (3),
845.BR keyctl_search (3),
4509c62e 846.BR keyctl_set_reqkey_keyring (3),
4509c62e 847.BR keyctl_set_timeout (3),
d8f1a35c 848.BR keyctl_setperm (3),
cf4d4361
DP
849.BR keyctl_unlink (3),
850.BR keyctl_update (3),
32fc2407 851.BR keyrings (7),
4509c62e 852.BR request-key (8)
7e7454ef
MK
853
854The kernel source file
855.IR Documentation/security/keys.txt .