1 .\" written by Andrew Morgan <morgan@kernel.org>
2 .\" may be distributed as per GPL
3 .\" Modified by David A. Wheeler <dwheeler@ida.org>
4 .\" Modified 2004-05-27, mtk
5 .\" Modified 2004-06-21, aeb
6 .\" Modified 2008-04-28, morgan of kernel.org
7 .\" Update in line with addition of file capabilities and
8 .\" 64-bit capability sets in kernel 2.6.2[45].
9 .\" Modified 2009-01-26, andi kleen
11 .TH CAPGET 2 2010-09-20 "Linux" "Linux Programmer's Manual"
13 capget, capset \- set/get capabilities of thread(s)
15 .B #include <sys/capability.h>
17 .BI "int capget(cap_user_header_t " hdrp ", cap_user_data_t " datap );
19 .BI "int capset(cap_user_header_t " hdrp ", const cap_user_data_t " datap );
22 the power of the superuser (root) has been partitioned into
23 a set of discrete capabilities.
24 Each thread has a set of effective capabilities identifying
25 which capabilities (if any) it may currently exercise.
26 Each thread also has a set of inheritable capabilities that may be
29 call, and a set of permitted capabilities
30 that it can make effective or inheritable.
32 These two functions are the raw kernel interface for getting and
33 setting thread capabilities.
34 Not only are these system calls specific to Linux,
35 but the kernel API is likely to change and use of
36 these functions (in particular the format of the
38 types) is subject to extension with each kernel revision,
39 but old programs will keep working.
41 The portable interfaces are
45 if possible you should use those interfaces in applications.
46 If you wish to use the Linux extensions in applications, you should
47 use the easier-to-use interfaces
52 Now that you have been warned, some current kernel details.
53 The structures are defined as follows.
57 #define _LINUX_CAPABILITY_VERSION_1 0x19980330
58 #define _LINUX_CAPABILITY_U32S_1 1
60 #define _LINUX_CAPABILITY_VERSION_2 0x20071026
61 #define _LINUX_CAPABILITY_U32S_2 2
63 typedef struct __user_cap_header_struct {
68 typedef struct __user_cap_data_struct {
76 .I effective, permitted, inheritable
77 are bitmasks of the capabilities defined in
81 values are bit indexes and need to be bit-shifted before ORing into
83 To define the structures for passing to the system call you have to use the
84 .I struct __user_cap_header_struct
86 .I struct __user_cap_data_struct
87 names because the typedefs are only pointers.
89 Kernels prior to 2.6.25 prefer
90 32-bit capabilities with version
91 .BR _LINUX_CAPABILITY_VERSION_1 ,
92 and kernels 2.6.25+ prefer 64-bit capabilities with version
93 .BR _LINUX_CAPABILITY_VERSION_2 .
94 Note, 64-bit capabilities use
98 whereas 32-bit capabilities only use
101 Another change affecting the behavior of these system calls is kernel
102 support for file capabilities (VFS capability support).
103 This support is currently a compile time option (added in kernel 2.6.24).
107 calls, one can probe the capabilities of any process by specifying its
111 .SS With VFS Capability Support
112 VFS Capability support creates a file-attribute method for adding
113 capabilities to privileged executables.
114 This privilege model obsoletes kernel support for one process
115 asynchronously setting the capabilities of another.
116 That is, with VFS support, for
118 calls the only permitted values for
122 which are equivalent.
123 .SS Without VFS Capability Support
124 When the kernel does not support VFS capabilities,
126 calls can operate on the capabilities of the thread specified by the
130 when that is nonzero, or on the capabilities of the calling thread if
135 refers to a single-threaded process, then
137 can be specified as a traditional process ID;
138 operating on a thread of a multithreaded process requires a thread ID
139 of the type returned by
144 can also be: \-1, meaning perform the change on all threads except the
147 or a value less than \-1, in which case the change is applied
148 to all members of the process group whose ID is \-\fIpid\fP.
150 For details on the data, see
151 .BR capabilities (7).
153 On success, zero is returned.
154 On error, \-1 is returned, and
156 is set appropriately.
158 The calls will fail with the error
164 to the kernel preferred value of
165 .B _LINUX_CAPABILITY_VERSION_?
169 In this way, one can probe what the current
170 preferred capability revision is.
178 may only be NULL when the user is trying to determine the preferred
179 capability version format supported by the kernel.
182 One of the arguments was invalid.
185 An attempt was made to add a capability to the Permitted set, or to set
186 a capability in the Effective or Inheritable sets that is not in the
190 The caller attempted to use
192 to modify the capabilities of a thread other than itself,
193 but lacked sufficient privilege.
194 For kernels supporting VFS
195 capabilities, this is never permitted.
196 For kernels lacking VFS
199 capability is required.
200 (A bug in kernels before 2.6.11 meant that this error could also
201 occur if a thread without this capability tried to change its
202 own capabilities by specifying the
204 field as a nonzero value (i.e., the value returned by
211 These system calls are Linux-specific.
213 The portable interface to the capability querying and setting
214 functions is provided by the
216 library and is available here:
218 http://www.kernel.org/pub/linux/libs/security/linux-privs