]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * This is <linux/capability.h> | |
3 | * | |
4 | * Andrew G. Morgan <morgan@transmeta.com> | |
5 | * Alexander Kjeldaas <astor@guardian.no> | |
6 | * with help from Aleph1, Roland Buresund and Andrew Main. | |
7 | * | |
8 | * See here for the libcap library ("POSIX draft" compliance): | |
9 | * | |
10 | * ftp://linux.kernel.org/pub/linux/libs/security/linux-privs/kernel-2.2/ | |
11 | */ | |
12 | ||
13 | #ifndef _LINUX_CAPABILITY_H | |
14 | #define _LINUX_CAPABILITY_H | |
15 | ||
16 | #include <linux/types.h> | |
17 | #include <linux/compiler.h> | |
18 | ||
19 | /* User-level do most of the mapping between kernel and user | |
20 | capabilities based on the version tag given by the kernel. The | |
21 | kernel might be somewhat backwards compatible, but don't bet on | |
22 | it. */ | |
23 | ||
24 | /* XXX - Note, cap_t, is defined by POSIX to be an "opaque" pointer to | |
25 | a set of three capability sets. The transposition of 3*the | |
26 | following structure to such a composite is better handled in a user | |
27 | library since the draft standard requires the use of malloc/free | |
28 | etc.. */ | |
29 | ||
30 | #define _LINUX_CAPABILITY_VERSION 0x19980330 | |
31 | ||
32 | typedef struct __user_cap_header_struct { | |
33 | __u32 version; | |
34 | int pid; | |
35 | } __user *cap_user_header_t; | |
36 | ||
37 | typedef struct __user_cap_data_struct { | |
38 | __u32 effective; | |
39 | __u32 permitted; | |
40 | __u32 inheritable; | |
41 | } __user *cap_user_data_t; | |
42 | ||
43 | #ifdef __KERNEL__ | |
44 | ||
45 | #include <linux/spinlock.h> | |
46 | ||
47 | /* #define STRICT_CAP_T_TYPECHECKS */ | |
48 | ||
49 | #ifdef STRICT_CAP_T_TYPECHECKS | |
50 | ||
51 | typedef struct kernel_cap_struct { | |
52 | __u32 cap; | |
53 | } kernel_cap_t; | |
54 | ||
55 | #else | |
56 | ||
57 | typedef __u32 kernel_cap_t; | |
58 | ||
59 | #endif | |
60 | ||
61 | #define _USER_CAP_HEADER_SIZE (2*sizeof(__u32)) | |
62 | #define _KERNEL_CAP_T_SIZE (sizeof(kernel_cap_t)) | |
63 | ||
64 | #endif | |
65 | ||
66 | ||
67 | /** | |
68 | ** POSIX-draft defined capabilities. | |
69 | **/ | |
70 | ||
71 | /* In a system with the [_POSIX_CHOWN_RESTRICTED] option defined, this | |
72 | overrides the restriction of changing file ownership and group | |
73 | ownership. */ | |
74 | ||
75 | #define CAP_CHOWN 0 | |
76 | ||
77 | /* Override all DAC access, including ACL execute access if | |
78 | [_POSIX_ACL] is defined. Excluding DAC access covered by | |
79 | CAP_LINUX_IMMUTABLE. */ | |
80 | ||
81 | #define CAP_DAC_OVERRIDE 1 | |
82 | ||
83 | /* Overrides all DAC restrictions regarding read and search on files | |
84 | and directories, including ACL restrictions if [_POSIX_ACL] is | |
85 | defined. Excluding DAC access covered by CAP_LINUX_IMMUTABLE. */ | |
86 | ||
87 | #define CAP_DAC_READ_SEARCH 2 | |
88 | ||
89 | /* Overrides all restrictions about allowed operations on files, where | |
90 | file owner ID must be equal to the user ID, except where CAP_FSETID | |
91 | is applicable. It doesn't override MAC and DAC restrictions. */ | |
92 | ||
93 | #define CAP_FOWNER 3 | |
94 | ||
95 | /* Overrides the following restrictions that the effective user ID | |
96 | shall match the file owner ID when setting the S_ISUID and S_ISGID | |
97 | bits on that file; that the effective group ID (or one of the | |
98 | supplementary group IDs) shall match the file owner ID when setting | |
99 | the S_ISGID bit on that file; that the S_ISUID and S_ISGID bits are | |
100 | cleared on successful return from chown(2) (not implemented). */ | |
101 | ||
102 | #define CAP_FSETID 4 | |
103 | ||
104 | /* Used to decide between falling back on the old suser() or fsuser(). */ | |
105 | ||
106 | #define CAP_FS_MASK 0x1f | |
107 | ||
108 | /* Overrides the restriction that the real or effective user ID of a | |
109 | process sending a signal must match the real or effective user ID | |
110 | of the process receiving the signal. */ | |
111 | ||
112 | #define CAP_KILL 5 | |
113 | ||
114 | /* Allows setgid(2) manipulation */ | |
115 | /* Allows setgroups(2) */ | |
116 | /* Allows forged gids on socket credentials passing. */ | |
117 | ||
118 | #define CAP_SETGID 6 | |
119 | ||
120 | /* Allows set*uid(2) manipulation (including fsuid). */ | |
121 | /* Allows forged pids on socket credentials passing. */ | |
122 | ||
123 | #define CAP_SETUID 7 | |
124 | ||
125 | ||
126 | /** | |
127 | ** Linux-specific capabilities | |
128 | **/ | |
129 | ||
130 | /* Transfer any capability in your permitted set to any pid, | |
131 | remove any capability in your permitted set from any pid */ | |
132 | ||
133 | #define CAP_SETPCAP 8 | |
134 | ||
135 | /* Allow modification of S_IMMUTABLE and S_APPEND file attributes */ | |
136 | ||
137 | #define CAP_LINUX_IMMUTABLE 9 | |
138 | ||
139 | /* Allows binding to TCP/UDP sockets below 1024 */ | |
140 | /* Allows binding to ATM VCIs below 32 */ | |
141 | ||
142 | #define CAP_NET_BIND_SERVICE 10 | |
143 | ||
144 | /* Allow broadcasting, listen to multicast */ | |
145 | ||
146 | #define CAP_NET_BROADCAST 11 | |
147 | ||
148 | /* Allow interface configuration */ | |
149 | /* Allow administration of IP firewall, masquerading and accounting */ | |
150 | /* Allow setting debug option on sockets */ | |
151 | /* Allow modification of routing tables */ | |
152 | /* Allow setting arbitrary process / process group ownership on | |
153 | sockets */ | |
154 | /* Allow binding to any address for transparent proxying */ | |
155 | /* Allow setting TOS (type of service) */ | |
156 | /* Allow setting promiscuous mode */ | |
157 | /* Allow clearing driver statistics */ | |
158 | /* Allow multicasting */ | |
159 | /* Allow read/write of device-specific registers */ | |
160 | /* Allow activation of ATM control sockets */ | |
161 | ||
162 | #define CAP_NET_ADMIN 12 | |
163 | ||
164 | /* Allow use of RAW sockets */ | |
165 | /* Allow use of PACKET sockets */ | |
166 | ||
167 | #define CAP_NET_RAW 13 | |
168 | ||
169 | /* Allow locking of shared memory segments */ | |
170 | /* Allow mlock and mlockall (which doesn't really have anything to do | |
171 | with IPC) */ | |
172 | ||
173 | #define CAP_IPC_LOCK 14 | |
174 | ||
175 | /* Override IPC ownership checks */ | |
176 | ||
177 | #define CAP_IPC_OWNER 15 | |
178 | ||
179 | /* Insert and remove kernel modules - modify kernel without limit */ | |
180 | /* Modify cap_bset */ | |
181 | #define CAP_SYS_MODULE 16 | |
182 | ||
183 | /* Allow ioperm/iopl access */ | |
184 | /* Allow sending USB messages to any device via /proc/bus/usb */ | |
185 | ||
186 | #define CAP_SYS_RAWIO 17 | |
187 | ||
188 | /* Allow use of chroot() */ | |
189 | ||
190 | #define CAP_SYS_CHROOT 18 | |
191 | ||
192 | /* Allow ptrace() of any process */ | |
193 | ||
194 | #define CAP_SYS_PTRACE 19 | |
195 | ||
196 | /* Allow configuration of process accounting */ | |
197 | ||
198 | #define CAP_SYS_PACCT 20 | |
199 | ||
200 | /* Allow configuration of the secure attention key */ | |
201 | /* Allow administration of the random device */ | |
202 | /* Allow examination and configuration of disk quotas */ | |
203 | /* Allow configuring the kernel's syslog (printk behaviour) */ | |
204 | /* Allow setting the domainname */ | |
205 | /* Allow setting the hostname */ | |
206 | /* Allow calling bdflush() */ | |
207 | /* Allow mount() and umount(), setting up new smb connection */ | |
208 | /* Allow some autofs root ioctls */ | |
209 | /* Allow nfsservctl */ | |
210 | /* Allow VM86_REQUEST_IRQ */ | |
211 | /* Allow to read/write pci config on alpha */ | |
212 | /* Allow irix_prctl on mips (setstacksize) */ | |
213 | /* Allow flushing all cache on m68k (sys_cacheflush) */ | |
214 | /* Allow removing semaphores */ | |
215 | /* Used instead of CAP_CHOWN to "chown" IPC message queues, semaphores | |
216 | and shared memory */ | |
217 | /* Allow locking/unlocking of shared memory segment */ | |
218 | /* Allow turning swap on/off */ | |
219 | /* Allow forged pids on socket credentials passing */ | |
220 | /* Allow setting readahead and flushing buffers on block devices */ | |
221 | /* Allow setting geometry in floppy driver */ | |
222 | /* Allow turning DMA on/off in xd driver */ | |
223 | /* Allow administration of md devices (mostly the above, but some | |
224 | extra ioctls) */ | |
225 | /* Allow tuning the ide driver */ | |
226 | /* Allow access to the nvram device */ | |
227 | /* Allow administration of apm_bios, serial and bttv (TV) device */ | |
228 | /* Allow manufacturer commands in isdn CAPI support driver */ | |
229 | /* Allow reading non-standardized portions of pci configuration space */ | |
230 | /* Allow DDI debug ioctl on sbpcd driver */ | |
231 | /* Allow setting up serial ports */ | |
232 | /* Allow sending raw qic-117 commands */ | |
233 | /* Allow enabling/disabling tagged queuing on SCSI controllers and sending | |
234 | arbitrary SCSI commands */ | |
235 | /* Allow setting encryption key on loopback filesystem */ | |
236 | ||
237 | #define CAP_SYS_ADMIN 21 | |
238 | ||
239 | /* Allow use of reboot() */ | |
240 | ||
241 | #define CAP_SYS_BOOT 22 | |
242 | ||
243 | /* Allow raising priority and setting priority on other (different | |
244 | UID) processes */ | |
245 | /* Allow use of FIFO and round-robin (realtime) scheduling on own | |
246 | processes and setting the scheduling algorithm used by another | |
247 | process. */ | |
248 | /* Allow setting cpu affinity on other processes */ | |
249 | ||
250 | #define CAP_SYS_NICE 23 | |
251 | ||
252 | /* Override resource limits. Set resource limits. */ | |
253 | /* Override quota limits. */ | |
254 | /* Override reserved space on ext2 filesystem */ | |
255 | /* Modify data journaling mode on ext3 filesystem (uses journaling | |
256 | resources) */ | |
257 | /* NOTE: ext2 honors fsuid when checking for resource overrides, so | |
258 | you can override using fsuid too */ | |
259 | /* Override size restrictions on IPC message queues */ | |
260 | /* Allow more than 64hz interrupts from the real-time clock */ | |
261 | /* Override max number of consoles on console allocation */ | |
262 | /* Override max number of keymaps */ | |
263 | ||
264 | #define CAP_SYS_RESOURCE 24 | |
265 | ||
266 | /* Allow manipulation of system clock */ | |
267 | /* Allow irix_stime on mips */ | |
268 | /* Allow setting the real-time clock */ | |
269 | ||
270 | #define CAP_SYS_TIME 25 | |
271 | ||
272 | /* Allow configuration of tty devices */ | |
273 | /* Allow vhangup() of tty */ | |
274 | ||
275 | #define CAP_SYS_TTY_CONFIG 26 | |
276 | ||
277 | /* Allow the privileged aspects of mknod() */ | |
278 | ||
279 | #define CAP_MKNOD 27 | |
280 | ||
281 | /* Allow taking of leases on files */ | |
282 | ||
283 | #define CAP_LEASE 28 | |
284 | ||
285 | #define CAP_AUDIT_WRITE 29 | |
286 | ||
287 | #define CAP_AUDIT_CONTROL 30 | |
288 | ||
289 | #ifdef __KERNEL__ | |
290 | /* | |
291 | * Bounding set | |
292 | */ | |
293 | extern kernel_cap_t cap_bset; | |
294 | ||
295 | /* | |
296 | * Internal kernel functions only | |
297 | */ | |
298 | ||
299 | #ifdef STRICT_CAP_T_TYPECHECKS | |
300 | ||
301 | #define to_cap_t(x) { x } | |
302 | #define cap_t(x) (x).cap | |
303 | ||
304 | #else | |
305 | ||
306 | #define to_cap_t(x) (x) | |
307 | #define cap_t(x) (x) | |
308 | ||
309 | #endif | |
310 | ||
311 | #define CAP_EMPTY_SET to_cap_t(0) | |
312 | #define CAP_FULL_SET to_cap_t(~0) | |
313 | #define CAP_INIT_EFF_SET to_cap_t(~0 & ~CAP_TO_MASK(CAP_SETPCAP)) | |
314 | #define CAP_INIT_INH_SET to_cap_t(0) | |
315 | ||
316 | #define CAP_TO_MASK(x) (1 << (x)) | |
317 | #define cap_raise(c, flag) (cap_t(c) |= CAP_TO_MASK(flag)) | |
318 | #define cap_lower(c, flag) (cap_t(c) &= ~CAP_TO_MASK(flag)) | |
319 | #define cap_raised(c, flag) (cap_t(c) & CAP_TO_MASK(flag)) | |
320 | ||
321 | static inline kernel_cap_t cap_combine(kernel_cap_t a, kernel_cap_t b) | |
322 | { | |
323 | kernel_cap_t dest; | |
324 | cap_t(dest) = cap_t(a) | cap_t(b); | |
325 | return dest; | |
326 | } | |
327 | ||
328 | static inline kernel_cap_t cap_intersect(kernel_cap_t a, kernel_cap_t b) | |
329 | { | |
330 | kernel_cap_t dest; | |
331 | cap_t(dest) = cap_t(a) & cap_t(b); | |
332 | return dest; | |
333 | } | |
334 | ||
335 | static inline kernel_cap_t cap_drop(kernel_cap_t a, kernel_cap_t drop) | |
336 | { | |
337 | kernel_cap_t dest; | |
338 | cap_t(dest) = cap_t(a) & ~cap_t(drop); | |
339 | return dest; | |
340 | } | |
341 | ||
342 | static inline kernel_cap_t cap_invert(kernel_cap_t c) | |
343 | { | |
344 | kernel_cap_t dest; | |
345 | cap_t(dest) = ~cap_t(c); | |
346 | return dest; | |
347 | } | |
348 | ||
349 | #define cap_isclear(c) (!cap_t(c)) | |
350 | #define cap_issubset(a,set) (!(cap_t(a) & ~cap_t(set))) | |
351 | ||
352 | #define cap_clear(c) do { cap_t(c) = 0; } while(0) | |
353 | #define cap_set_full(c) do { cap_t(c) = ~0; } while(0) | |
354 | #define cap_mask(c,mask) do { cap_t(c) &= cap_t(mask); } while(0) | |
355 | ||
356 | #define cap_is_fs_cap(c) (CAP_TO_MASK(c) & CAP_FS_MASK) | |
357 | ||
358 | #endif /* __KERNEL__ */ | |
359 | ||
360 | #endif /* !_LINUX_CAPABILITY_H */ |