1CAPGET(2)                  Linux Programmer's Manual                 CAPGET(2)
2
3
4

NAME

6       capget, capset - set/get capabilities of thread(s)
7

SYNOPSIS

9       #undef _POSIX_SOURCE
10       #include <sys/capability.h>
11
12       int capget(cap_user_header_t hdrp, cap_user_data_t datap);
13
14       int capset(cap_user_header_t hdrp, const cap_user_data_t datap);
15

DESCRIPTION

17       As of Linux 2.2, the power of the superuser (root) has been partitioned
18       into a set of discrete capabilities.  Each thread has a set  of  effec‐
19       tive  capabilities  identifying which capabilities (if any) it may cur‐
20       rently exercise.  Each thread also has a set of  inheritable  capabili‐
21       ties that may be passed through an execve(2) call, and a set of permit‐
22       ted capabilities that it can make effective or inheritable.
23
24       These two functions are the raw kernel interface for getting  and  set‐
25       ting  thread capabilities.  Not only are these system calls specific to
26       Linux, but the kernel API is likely to change and use  of  these  func‐
27       tions  (in  particular the format of the cap_user_*_t types) is subject
28       to extension with each kernel revision,  but  old  programs  will  keep
29       working.
30
31       The  portable  interfaces  are  cap_set_proc(3) and cap_get_proc(3); if
32       possible you should use those interfaces in applications.  If you  wish
33       to use the Linux extensions in applications, you should use the easier-
34       to-use interfaces capsetp(3) and capgetp(3).
35
36   Current details
37       Now that you have been warned, some current kernel details.  The struc‐
38       tures are defined as follows.
39
40           #define _LINUX_CAPABILITY_VERSION_1  0x19980330
41           #define _LINUX_CAPABILITY_U32S_1     1
42
43           #define _LINUX_CAPABILITY_VERSION_2  0x20071026
44           #define _LINUX_CAPABILITY_U32S_2     2
45
46           typedef struct __user_cap_header_struct {
47              __u32 version;
48              int pid;
49           } *cap_user_header_t;
50
51           typedef struct __user_cap_data_struct {
52              __u32 effective;
53              __u32 permitted;
54              __u32 inheritable;
55           } *cap_user_data_t;
56
57       effective,  permitted,  inheritable  are  bitmasks  of the capabilities
58       defined in capability(7).  Note the CAP_* values are  bit  indexes  and
59       need to be bit-shifted before ORing into the bit fields.  To define the
60       structures for passing to the system call you have to  use  the  struct
61       __user_cap_header_struct   and   struct   __user_cap_data_struct  names
62       because the typedefs are only pointers.
63
64       Kernels  prior  to  2.6.25  prefer  32-bit  capabilities  with  version
65       _LINUX_CAPABILITY_VERSION_1, and kernels 2.6.25+ prefer 64-bit capabil‐
66       ities with version _LINUX_CAPABILITY_VERSION_2.  Note, 64-bit capabili‐
67       ties  use  datap[0]  and datap[1], whereas 32-bit capabilities only use
68       datap[0].
69
70       Another change affecting the behavior of these system calls  is  kernel
71       support  for  file capabilities (VFS capability support).  This support
72       is currently a compile time option (added in kernel 2.6.24).
73
74       For capget() calls, one can probe the capabilities of  any  process  by
75       specifying its process ID with the hdrp->pid field value.
76
77   With VFS Capability Support
78       VFS Capability support creates a file-attribute method for adding capa‐
79       bilities to privileged executables.   This  privilege  model  obsoletes
80       kernel  support for one process asynchronously setting the capabilities
81       of another.  That is, with VFS support, for  capset()  calls  the  only
82       permitted  values  for  hdrp->pid are 0 or getpid(2), which are equiva‐
83       lent.
84
85   Without VFS Capability Support
86       When the kernel does not support VFS capabilities, capset()  calls  can
87       operate on the capabilities of the thread specified by the pid field of
88       hdrp when that is non-zero, or  on  the  capabilities  of  the  calling
89       thread  if  pid is 0.  If pid refers to a single-threaded process, then
90       pid can be specified as a traditional process ID; operating on a thread
91       of a multithreaded process requires a thread ID of the type returned by
92       gettid(2).  For capset(), pid can also  be:  -1,  meaning  perform  the
93       change  on  all  threads except the caller and init(8); or a value less
94       than -1, in which case the change is applied  to  all  members  of  the
95       process group whose ID is -pid.
96
97       For details on the data, see capabilities(7).
98

RETURN VALUE

100       On  success,  zero is returned.  On error, -1 is returned, and errno is
101       set appropriately.
102
103       The calls will fail with the error EINVAL, and set the version field of
104       hdrp to the kernel preferred value of _LINUX_CAPABILITY_VERSION_?  when
105       an unsupported version value is specified.  In this way, one can  probe
106       what the current preferred capability revision is.
107

ERRORS

109       EFAULT Bad  memory  address.  hdrp must not be NULL.  datap may only be
110              NULL when the user is trying to determine the preferred capabil‐
111              ity version format supported by the kernel.
112
113       EINVAL One of the arguments was invalid.
114
115       EPERM  An attempt was made to add a capability to the Permitted set, or
116              to set a capability in the Effective or Inheritable sets that is
117              not in the Permitted set.
118
119       EPERM  The  caller attempted to use capset() to modify the capabilities
120              of a thread other than itself, but lacked sufficient  privilege.
121              For  kernels  supporting VFS capabilities, this is never permit‐
122              ted.  For kernels lacking VFS support, the CAP_SETPCAP  capabil‐
123              ity  is  required.   (A  bug in kernels before 2.6.11 meant that
124              this error could also occur if a thread without this  capability
125              tried to change its own capabilities by specifying the pid field
126              as a non-zero value (i.e.,  the  value  returned  by  getpid(2))
127              instead of 0.)
128
129       ESRCH  No such thread.
130

CONFORMING TO

132       These system calls are Linux-specific.
133

NOTES

135       The portable interface to the capability querying and setting functions
136       is provided by the libcap library and is available here:
137       http://www.kernel.org/pub/linux/libs/security/linux-privs
138

SEE ALSO

140       clone(2), gettid(2), capabilities(7)
141

COLOPHON

143       This page is part of release 3.22 of the Linux  man-pages  project.   A
144       description  of  the project, and information about reporting bugs, can
145       be found at http://www.kernel.org/doc/man-pages/.
146
147
148
149Linux                             2009-01-26                         CAPGET(2)
Impressum