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