man-pages/man2/capget.2

209 lines
5.7 KiB
Groff
Raw Normal View History

.\" written by Andrew Morgan <morgan@kernel.org>
2004-11-03 13:51:07 +00:00
.\" may be distributed as per GPL
.\" Modified by David A. Wheeler <dwheeler@ida.org>
.\" Modified 2004-05-27, mtk
.\" Modified 2004-06-21, aeb
.\" Modified 2008-04-28, morgan of kernel.org
.\" Update in line with addition of file capabilities and
.\" 64-bit capability sets in kernel 2.6.2[45].
2004-11-03 13:51:07 +00:00
.\"
.TH CAPGET 2 2008-07-14 "Linux" "Linux Programmer's Manual"
2004-11-03 13:51:07 +00:00
.SH NAME
capget, capset \- set/get capabilities of thread(s)
2004-11-03 13:51:07 +00:00
.SH SYNOPSIS
.B #undef _POSIX_SOURCE
.br
.B #include <sys/capability.h>
.sp
.BI "int capget(cap_user_header_t " hdrp ", cap_user_data_t " datap );
.sp
.BI "int capset(cap_user_header_t " hdrp ", const cap_user_data_t " datap );
.SH DESCRIPTION
As of Linux 2.2,
the power of the superuser (root) has been partitioned into
2004-11-03 13:51:07 +00:00
a set of discrete capabilities.
Each thread has a set of effective capabilities identifying
2004-11-03 13:51:07 +00:00
which capabilities (if any) it may currently exercise.
Each thread also has a set of inheritable capabilities that may be
2004-11-03 13:51:07 +00:00
passed through an
.BR execve (2)
call, and a set of permitted capabilities
that it can make effective or inheritable.
.PP
These two functions are the raw kernel interface for getting and
setting thread capabilities.
Not only are these system calls specific to Linux,
2004-11-03 13:51:07 +00:00
but the kernel API is likely to change and use of
these functions (in particular the format of the
2007-12-24 22:25:11 +00:00
.I cap_user_*_t
2004-11-03 13:51:07 +00:00
types) is subject to change with each kernel revision.
.sp
The portable interfaces are
.BR cap_set_proc (3)
2004-11-03 13:51:07 +00:00
and
.BR cap_get_proc (3);
2004-11-03 13:51:07 +00:00
if possible you should use those interfaces in applications.
If you wish to use the Linux extensions in applications, you should
use the easier-to-use interfaces
.BR capsetp (3)
and
.BR capgetp (3).
2004-11-03 13:51:07 +00:00
.SS "Current details"
Now that you have been warned, some current kernel details.
The structures are defined as follows.
2004-11-03 13:51:07 +00:00
.sp
.nf
.in +4n
#define _LINUX_CAPABILITY_VERSION_1 0x19980330
#define _LINUX_CAPABILITY_U32S_1 1
#define _LINUX_CAPABILITY_VERSION_2 0x20071026
#define _LINUX_CAPABILITY_U32S_2 2
2004-11-03 13:51:07 +00:00
typedef struct __user_cap_header_struct {
__u32 version;
int pid;
2004-11-03 13:51:07 +00:00
} *cap_user_header_t;
typedef struct __user_cap_data_struct {
__u32 effective;
__u32 permitted;
__u32 inheritable;
2004-11-03 13:51:07 +00:00
} *cap_user_data_t;
.fi
.in -4n
.sp
The calls will fail with the error
2007-06-22 17:16:20 +00:00
.BR EINVAL ,
and set the
.I version
field of
2007-10-16 19:18:17 +00:00
.I hdrp
to the kernel preferred value of
.B _LINUX_CAPABILITY_VERSION_?
when an unsupported
.I version
value is specified.
In this way, one can probe what the current
preferred capability revision is.
Kernels prior to 2.6.25 prefer
32-bit capabilities with version
.BR _LINUX_CAPABILITY_VERSION_1 ,
and kernels 2.6.25+ prefer 64-bit capabilities with version
.BR _LINUX_CAPABILITY_VERSION_2 .
Note, 64-bit capabilities use
.IR datap [0]
and
.IR datap [1],
whereas 32-bit capabilities only use
.IR datap [0].
.sp
Another change affecting the behavior of these system calls is kernel
support for file capabilities (VFS capability support).
This support is currently a compile time option (added in kernel 2.6.24).
.sp
For
.BR capget ()
calls, one can probe the capabilities of any process by specifying its
process ID with the
.I hdrp->pid
field value.
.SS With VFS Capability Support
VFS Capability support creates a file-attribute method for adding
capabilities to privileged executables.
This privilege model obsoletes kernel support for one process
asynchronously setting the capabilities of another.
That is, with VFS support, for
.BR capset ()
calls the only permitted values for
.I hdrp->pid
are 0 or
.BR getpid (2),
which are equivalent.
.SS Without VFS Capability Support
When the kernel does not support VFS capabilities,
.BR capset ()
calls can operate on the capabilities of the thread specified by the
.I pid
field of
2007-10-16 19:18:17 +00:00
.I hdrp
2008-03-19 13:16:39 +00:00
when that is non-zero, or on the capabilities of the calling thread if
.I pid
is 0.
If
.I pid
refers to a single-threaded process, then
.I pid
can be specified as a traditional process ID;
operating on a thread of a multithreaded process requires a thread ID
of the type returned by
.BR gettid (2).
For
.BR capset (),
.I pid
2006-08-08 16:34:16 +00:00
can also be: \-1, meaning perform the change on all threads except the
caller and
2007-05-14 20:39:44 +00:00
.BR init (8);
or a value less than \-1, in which case the change is applied
to all members of the process group whose ID is \-\fIpid\fP.
2004-11-03 13:51:07 +00:00
For details on the data, see
.BR capabilities (7).
.SH "RETURN VALUE"
On success, zero is returned.
On error, \-1 is returned, and
2004-11-03 13:51:07 +00:00
.I errno
is set appropriately.
.SH ERRORS
.TP
.B EFAULT
Bad memory address.
2004-11-03 13:51:07 +00:00
.I hdrp
must not be NULL.
2004-11-03 13:51:07 +00:00
.I datap
may only be NULL when the user is trying to determine the preferred
capability version format supported by the kernel.
2004-11-03 13:51:07 +00:00
.TP
.B EINVAL
One of the arguments was invalid.
.TP
.B EPERM
An attempt was made to add a capability to the Permitted set, or to set
a capability in the Effective or Inheritable sets that is not in the
Permitted set.
.TP
.B EPERM
The caller attempted to use
2004-11-03 13:51:07 +00:00
.BR capset ()
to modify the capabilities of a thread other than itself,
but lacked sufficient privilege.
For kernels supporting VFS
capabilities, this is never permitted.
For kernels lacking VFS
support, the
2004-11-03 13:51:07 +00:00
.B CAP_SETPCAP
capability is required.
(A bug in kernels before 2.6.11 meant that this error could also
occur if a thread without this capability tried to change its
own capabilities by specifying the
.I pid
2008-03-19 13:16:39 +00:00
field as a non-zero value (i.e., the value returned by
.BR getpid (2))
instead of 0.)
2004-11-03 13:51:07 +00:00
.TP
.B ESRCH
No such thread.
.SH "CONFORMING TO"
2007-12-25 21:28:09 +00:00
These system calls are Linux-specific.
2007-05-16 02:25:26 +00:00
.SH NOTES
2004-11-03 13:51:07 +00:00
The portable interface to the capability querying and setting
functions is provided by the
2007-06-23 07:19:07 +00:00
.I libcap
2007-06-23 08:17:33 +00:00
library and is available here:
2004-11-03 13:51:07 +00:00
.br
http://www.kernel.org/pub/linux/libs/security/linux-privs
2004-11-03 13:51:07 +00:00
.SH "SEE ALSO"
2006-08-08 16:34:16 +00:00
.BR clone (2),
.BR gettid (2),
2004-11-03 13:51:07 +00:00
.BR capabilities (7)