]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/sys/capability.h
Make dynamic sysctl entries start at 0x100, not decimal 100 - there are
[FreeBSD/FreeBSD.git] / sys / sys / capability.h
1 /*-
2  * Copyright (c) 2000, 2001 Robert N. M. Watson
3  * All rights reserved.
4  *
5  * Copyright (c) 1999 Ilmar S. Habibulin
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  * $FreeBSD$
30  */
31 /*
32  * Developed by the TrustedBSD Project.
33  * Support for POSIX.1e process capabilities.
34  */
35
36 #ifndef _SYS_CAPABILITY_H
37 #define _SYS_CAPABILITY_H
38
39 #define POSIX1E_CAPABILITY_EXTATTR_NAMESPACE    EXTATTR_NAMESPACE_SYSTEM
40 #define POSIX1E_CAPABILITY_EXTATTR_NAME         "posix1e.cap"
41
42 typedef int     cap_flag_t;
43 typedef int     cap_flag_value_t;
44 typedef u_int64_t       cap_value_t;
45
46 struct cap {
47         u_int64_t       c_effective;
48         u_int64_t       c_permitted;
49         u_int64_t       c_inheritable;
50 };
51 typedef struct cap      *cap_t;
52
53 #define SET_CAPABILITY(mask, cap) do { \
54         (mask) |= cap; \
55         } while (0)
56
57 #define UNSET_CAPABILITY(mask, cap) do { \
58         (mask) &= ~(cap); \
59         } while (0)
60
61 #define IS_CAP_SET(mask, cap) \
62         ((mask) & (cap))
63
64 /*
65  * Is (tcap) a logical subset of (scap)?
66  */
67 #define CAP_SUBSET(scap,tcap) \
68         (((scap).c_permitted | (tcap).c_permitted == (scap).c_permitted) && \
69         ((scap).c_effective | (tcap).c_effective == (scap).c_effective) && \
70         ((scap).c_inheritable | (tcap).c_inheritable == (scap).c_inheritable))
71
72 /*
73  * Possible flags for a particular capability.
74  */
75 #define CAP_EFFECTIVE           0x01
76 #define CAP_INHERITABLE         0x02
77 #define CAP_PERMITTED           0x04
78
79 /*
80  * Possible values for each capability flag.
81  */
82 #define CAP_CLEAR               0
83 #define CAP_SET                 1
84
85 /*
86  * Possible capability values, both BSD/LINUX and POSIX.1e.
87  */
88 #define CAP_CHOWN               (0x0000000000000001)
89 #define CAP_DAC_EXECUTE         (0x0000000000000002)
90 #define CAP_DAC_WRITE           (0x0000000000000004)
91 #define CAP_DAC_READ_SEARCH     (0x0000000000000008)
92 #define CAP_FOWNER              (0x0000000000000010)
93 #define CAP_FSETID              (0x0000000000000020)
94 #define CAP_KILL                (0x0000000000000040)
95 #define CAP_LINK_DIR            (0x0000000000000080)
96 #define CAP_SETFCAP             (0x0000000000000100)
97 #define CAP_SETGID              (0x0000000000000200)
98 #define CAP_SETUID              (0x0000000000000400)
99 #define CAP_MAC_DOWNGRADE       (0x0000000000000800)
100 #define CAP_MAC_READ            (0x0000000000001000)
101 #define CAP_MAC_RELABEL_SUBJ    (0x0000000000002000)
102 #define CAP_MAC_UPGRADE         (0x0000000000004000)
103 #define CAP_MAC_WRITE           (0x0000000000008000)
104 #define CAP_INF_NOFLOAT_OBJ     (0x0000000000010000)
105 #define CAP_INF_NOFLOAT_SUBJ    (0x0000000000020000)
106 #define CAP_INF_RELABEL_OBJ     (0x0000000000040000)
107 #define CAP_INF_RELABEL_SUBJ    (0x0000000000080000)
108 #define CAP_AUDIT_CONTROL       (0x0000000000100000)
109 #define CAP_AUDIT_WRITE         (0x0000000000200000)
110
111 /*
112  * The following capability, borrowed from Linux, is unsafe
113  */
114 #define CAP_SETPCAP             (0x0000000000400000)
115 /* This is unallocated: */
116 #define CAP_XXX_INVALID1        (0x0000000000800000)
117 #define CAP_SYS_SETFFLAG        (0x0000000001000000)
118 /*
119  * The CAP_LINUX_IMMUTABLE flag approximately maps into the
120  * general file flag setting capability in BSD.  Therfore, for
121  * compatibility, map the constants.
122  */
123 #define CAP_LINUX_IMMUTABLE     CAP_SYS_SETFFLAG
124 #define CAP_NET_BIND_SERVICE    (0x0000000002000000)
125 #define CAP_NET_BROADCAST       (0x0000000004000000)
126 #define CAP_NET_ADMIN           (0x0000000008000000)
127 #define CAP_NET_RAW             (0x0000000010000000)
128 #define CAP_IPC_LOCK            (0x0000000020000000)
129 #define CAP_IPC_OWNER           (0x0000000040000000)
130 /*
131  * The following capabilities, borrowed from Linux, are unsafe in a
132  * secure environment.
133  *
134  */
135 #define CAP_SYS_MODULE          (0x0000000080000000)
136 #define CAP_SYS_RAWIO           (0x0000000100000000)
137 #define CAP_SYS_CHROOT          (0x0000000200000000)
138 #define CAP_SYS_PTRACE          (0x0000000400000000)
139 #define CAP_SYS_PACCT           (0x0000000800000000)
140 #define CAP_SYS_ADMIN           (0x0000001000000000)
141 /*
142  * Back to the safe ones, again
143  */
144 #define CAP_SYS_BOOT            (0x0000002000000000)
145 #define CAP_SYS_NICE            (0x0000004000000000)
146 #define CAP_SYS_RESOURCE        (0x0000008000000000)
147 #define CAP_SYS_TIME            (0x0000010000000000)
148 #define CAP_SYS_TTY_CONFIG      (0x0000020000000000)
149 #define CAP_MKNOD               (0x0000040000000000)
150 #define CAP_MAX_ID              CAP_MKNOD
151
152 #define CAP_ALL_ON      (CAP_CHOWN | CAP_DAC_EXECUTE | CAP_DAC_WRITE | \
153     CAP_DAC_READ_SEARCH | CAP_FOWNER | CAP_FSETID | CAP_KILL | CAP_LINK_DIR | \
154     CAP_SETFCAP | CAP_SETGID | CAP_SETUID | CAP_MAC_DOWNGRADE | \
155     CAP_MAC_READ | CAP_MAC_RELABEL_SUBJ | CAP_MAC_UPGRADE | \
156     CAP_MAC_WRITE | CAP_INF_NOFLOAT_OBJ | CAP_INF_NOFLOAT_SUBJ | \
157     CAP_INF_RELABEL_OBJ | CAP_INF_RELABEL_SUBJ | CAP_AUDIT_CONTROL | \
158     CAP_AUDIT_WRITE | CAP_SETPCAP | CAP_SYS_SETFFLAG | CAP_NET_BIND_SERVICE | \
159     CAP_NET_BROADCAST | CAP_NET_ADMIN | CAP_NET_RAW | CAP_IPC_LOCK | \
160     CAP_IPC_OWNER | CAP_SYS_MODULE | CAP_SYS_RAWIO | CAP_SYS_CHROOT | \
161     CAP_SYS_PTRACE | CAP_SYS_PACCT | CAP_SYS_ADMIN | CAP_SYS_BOOT | \
162     CAP_SYS_NICE | CAP_SYS_RESOURCE | CAP_SYS_TIME | CAP_SYS_TTY_CONFIG | \
163     CAP_MKNOD)
164 #define CAP_ALL_OFF     (0)
165
166 #ifdef _KERNEL
167
168 struct proc;
169 struct ucred;
170 struct vnode;
171 int     cap_check(struct ucred *, struct proc *, cap_value_t, int);
172 int     cap_change_on_inherit(struct cap *cap_p);
173 int     cap_inherit(struct vnode *vp, struct proc *p);
174 void    cap_init_proc0(struct cap *);
175 void    cap_init_proc1(struct cap *);
176
177 #else /* !_KERNEL */
178
179 #define _POSIX_CAP
180
181 #ifdef  _BSD_SSIZE_T_
182 typedef _BSD_SSIZE_T_   ssize_t;
183 #undef  _BSD_SSIZE_T_
184 #endif
185
186 int     __cap_get_proc(struct cap *);
187 int     __cap_set_proc(struct cap *);
188 int     __cap_get_fd(int, struct cap *);
189 int     __cap_get_file(const char *, struct cap *);
190 int     __cap_set_fd(int, struct cap *);
191 int     __cap_set_file(const char *, struct cap *);
192
193 int     cap_clear(cap_t);
194 ssize_t cap_copy_ext(void *, cap_t, ssize_t);
195 cap_t   cap_copy_int(const void *);
196 cap_t   cap_dup(cap_t);
197 int     cap_free(void *);
198 cap_t   cap_from_text(const char *);
199 cap_t   cap_get_fd(int);
200 cap_t   cap_get_file(const char *);
201 int     cap_get_flag(cap_t, cap_value_t, cap_flag_t, cap_flag_value_t *);
202 cap_t   cap_get_proc(void);
203 cap_t   cap_init(void);
204 int     cap_set_fd(int, cap_t);
205 int     cap_set_file(const char *, cap_t);
206 int     cap_set_flag(cap_t, cap_flag_t, int, cap_value_t[] , cap_flag_value_t);
207 int     cap_set_proc(cap_t);
208 ssize_t cap_size(cap_t);
209 char    *cap_to_text(cap_t, ssize_t *);
210
211 #endif /* !_KERNEL */
212
213 #endif /* !_SYS_CAPABILITY_H */