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