]>
Commit | Line | Data |
---|---|---|
91447636 | 1 | /* |
5d5c5d0d A |
2 | * Copyright (c) 2004 Apple Computer, Inc. All rights reserved. |
3 | * | |
8f6c56a5 | 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
91447636 | 5 | * |
8f6c56a5 A |
6 | * This file contains Original Code and/or Modifications of Original Code |
7 | * as defined in and that are subject to the Apple Public Source License | |
8 | * Version 2.0 (the 'License'). You may not use this file except in | |
9 | * compliance with the License. The rights granted to you under the License | |
10 | * may not be used to create, or enable the creation or redistribution of, | |
11 | * unlawful or unlicensed copies of an Apple operating system, or to | |
12 | * circumvent, violate, or enable the circumvention or violation of, any | |
13 | * terms of an Apple operating system software license agreement. | |
14 | * | |
15 | * Please obtain a copy of the License at | |
16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. | |
17 | * | |
18 | * The Original Code and all software distributed under the License are | |
19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. | |
23 | * Please see the License for the specific language governing rights and | |
8ad349bb | 24 | * limitations under the License. |
8f6c56a5 A |
25 | * |
26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ | |
91447636 A |
27 | */ |
28 | ||
29 | #ifndef _SYS_KAUTH_H | |
30 | #define _SYS_KAUTH_H | |
31 | ||
32 | #include <sys/appleapiopts.h> | |
33 | #include <sys/cdefs.h> | |
34 | ||
35 | #ifdef __APPLE_API_EVOLVING | |
36 | ||
37 | /* | |
38 | * Identities. | |
39 | */ | |
40 | ||
41 | #define KAUTH_UID_NONE (~(uid_t)0 - 100) /* not a valid UID */ | |
42 | #define KAUTH_GID_NONE (~(gid_t)0 - 100) /* not a valid GID */ | |
43 | ||
44 | #ifndef _KAUTH_GUID | |
45 | #define _KAUTH_GUID | |
46 | /* Apple-style globally unique identifier */ | |
47 | typedef struct { | |
48 | #define KAUTH_GUID_SIZE 16 /* 128-bit identifier */ | |
49 | unsigned char g_guid[KAUTH_GUID_SIZE]; | |
50 | } guid_t; | |
51 | #define _GUID_T | |
52 | #endif /* _KAUTH_GUID */ | |
53 | ||
54 | /* NT Security Identifier, structure as defined by Microsoft */ | |
55 | #pragma pack(1) /* push packing of 1 byte */ | |
56 | typedef struct { | |
57 | u_int8_t sid_kind; | |
58 | u_int8_t sid_authcount; | |
59 | u_int8_t sid_authority[6]; | |
60 | #define KAUTH_NTSID_MAX_AUTHORITIES 16 | |
61 | u_int32_t sid_authorities[KAUTH_NTSID_MAX_AUTHORITIES]; | |
62 | } ntsid_t; | |
63 | #pragma pack() /* pop packing to previous packing level */ | |
64 | #define _NTSID_T | |
65 | ||
66 | /* valid byte count inside a SID structure */ | |
67 | #define KAUTH_NTSID_HDRSIZE (8) | |
68 | #define KAUTH_NTSID_SIZE(_s) (KAUTH_NTSID_HDRSIZE + ((_s)->sid_authcount * sizeof(u_int32_t))) | |
69 | ||
70 | /* | |
71 | * External lookup message payload | |
72 | */ | |
73 | struct kauth_identity_extlookup { | |
74 | u_int32_t el_seqno; /* request sequence number */ | |
75 | u_int32_t el_result; /* lookup result */ | |
76 | #define KAUTH_EXTLOOKUP_SUCCESS 0 /* results here are good */ | |
77 | #define KAUTH_EXTLOOKUP_BADRQ 1 /* request badly formatted */ | |
78 | #define KAUTH_EXTLOOKUP_FAILURE 2 /* transient failure during lookup */ | |
79 | #define KAUTH_EXTLOOKUP_FATAL 3 /* permanent failure during lookup */ | |
80 | #define KAUTH_EXTLOOKUP_INPROG 100 /* request in progress */ | |
81 | u_int32_t el_flags; | |
82 | #define KAUTH_EXTLOOKUP_VALID_UID (1<<0) | |
83 | #define KAUTH_EXTLOOKUP_VALID_UGUID (1<<1) | |
84 | #define KAUTH_EXTLOOKUP_VALID_USID (1<<2) | |
85 | #define KAUTH_EXTLOOKUP_VALID_GID (1<<3) | |
86 | #define KAUTH_EXTLOOKUP_VALID_GGUID (1<<4) | |
87 | #define KAUTH_EXTLOOKUP_VALID_GSID (1<<5) | |
88 | #define KAUTH_EXTLOOKUP_WANT_UID (1<<6) | |
89 | #define KAUTH_EXTLOOKUP_WANT_UGUID (1<<7) | |
90 | #define KAUTH_EXTLOOKUP_WANT_USID (1<<8) | |
91 | #define KAUTH_EXTLOOKUP_WANT_GID (1<<9) | |
92 | #define KAUTH_EXTLOOKUP_WANT_GGUID (1<<10) | |
93 | #define KAUTH_EXTLOOKUP_WANT_GSID (1<<11) | |
94 | #define KAUTH_EXTLOOKUP_WANT_MEMBERSHIP (1<<12) | |
95 | #define KAUTH_EXTLOOKUP_VALID_MEMBERSHIP (1<<13) | |
96 | #define KAUTH_EXTLOOKUP_ISMEMBER (1<<14) | |
97 | uid_t el_uid; /* user ID */ | |
98 | guid_t el_uguid; /* user GUID */ | |
99 | u_int32_t el_uguid_valid; /* TTL on translation result (seconds) */ | |
100 | ntsid_t el_usid; /* user NT SID */ | |
101 | u_int32_t el_usid_valid; /* TTL on translation result (seconds) */ | |
102 | gid_t el_gid; /* group ID */ | |
103 | guid_t el_gguid; /* group GUID */ | |
104 | u_int32_t el_gguid_valid; /* TTL on translation result (seconds) */ | |
105 | ntsid_t el_gsid; /* group SID */ | |
106 | u_int32_t el_gsid_valid; /* TTL on translation result (seconds) */ | |
107 | u_int32_t el_member_valid; /* TTL on group lookup result */ | |
108 | }; | |
109 | ||
110 | #define KAUTH_EXTLOOKUP_REGISTER (0) | |
111 | #define KAUTH_EXTLOOKUP_RESULT (1<<0) | |
112 | #define KAUTH_EXTLOOKUP_WORKER (1<<1) | |
113 | ||
114 | ||
115 | #ifdef KERNEL | |
116 | /* | |
117 | * Credentials. | |
118 | */ | |
119 | ||
120 | #if 0 | |
121 | /* | |
122 | * Supplemental credential data. | |
123 | * | |
124 | * This interface allows us to associate arbitrary data with a credential. | |
125 | * As with the credential, the data is considered immutable. | |
126 | */ | |
127 | struct kauth_cred_supplement { | |
128 | TAILQ_ENTRY(kauth_cred_supplement) kcs_link; | |
129 | ||
130 | int kcs_ref; /* reference count */ | |
131 | int kcs_id; /* vended identifier */ | |
132 | size_t kcs_size; /* size of data field */ | |
133 | char kcs_data[0]; | |
134 | }; | |
135 | ||
136 | typedef struct kauth_cred_supplement *kauth_cred_supplement_t; | |
137 | ||
138 | struct kauth_cred { | |
139 | TAILQ_ENTRY(kauth_cred) kc_link; | |
140 | ||
141 | int kc_ref; /* reference count */ | |
142 | uid_t kc_uid; /* effective user id */ | |
143 | uid_t kc_ruid; /* real user id */ | |
144 | uid_t kc_svuid; /* saved user id */ | |
145 | gid_t kc_gid; /* effective group id */ | |
146 | gid_t kc_rgid; /* real group id */ | |
147 | gid_t kc_svgid; /* saved group id */ | |
148 | ||
149 | int kc_flags; | |
150 | #define KAUTH_CRED_GRPOVERRIDE (1<<0) /* private group list is authoritative */ | |
151 | ||
152 | int kc_npvtgroups; /* private group list, advisory or authoritative */ | |
153 | gid_t kc_pvtgroups[NGROUPS]; /* based on KAUTH_CRED_GRPOVERRIDE flag */ | |
154 | ||
155 | int kc_nsuppgroups; /* supplementary group list */ | |
156 | gid_t *kc_suppgroups; | |
157 | ||
158 | int kc_nwhtgroups; /* whiteout group list */ | |
159 | gid_t *kc_whtgroups; | |
160 | ||
161 | struct auditinfo cr_au; /* user auditing data */ | |
162 | ||
163 | int kc_nsupplement; /* entry count in supplemental data pointer array */ | |
164 | kauth_cred_supplement_t *kc_supplement; | |
165 | }; | |
166 | #else | |
167 | ||
168 | /* XXX just for now */ | |
169 | #include <sys/ucred.h> | |
170 | // typedef struct ucred *kauth_cred_t; | |
171 | #endif | |
172 | ||
173 | /* Kernel SPI for now */ | |
174 | __BEGIN_DECLS | |
175 | extern uid_t kauth_getuid(void); | |
176 | extern uid_t kauth_getruid(void); | |
177 | extern gid_t kauth_getgid(void); | |
178 | extern gid_t kauth_getrgid(void); | |
179 | extern kauth_cred_t kauth_cred_get(void); | |
180 | extern kauth_cred_t kauth_cred_get_with_ref(void); | |
181 | extern kauth_cred_t kauth_cred_proc_ref(proc_t procp); | |
182 | extern kauth_cred_t kauth_cred_alloc(void); | |
183 | extern kauth_cred_t kauth_cred_create(kauth_cred_t cred); | |
184 | extern void kauth_cred_ref(kauth_cred_t _cred); | |
185 | extern void kauth_cred_rele(kauth_cred_t _cred); | |
186 | extern kauth_cred_t kauth_cred_dup(kauth_cred_t cred); | |
187 | extern kauth_cred_t kauth_cred_copy_real(kauth_cred_t cred); | |
4452a7af | 188 | extern void kauth_cred_unref(kauth_cred_t *_cred); |
91447636 A |
189 | extern kauth_cred_t kauth_cred_setuid(kauth_cred_t cred, uid_t uid); |
190 | extern kauth_cred_t kauth_cred_seteuid(kauth_cred_t cred, uid_t euid); | |
191 | extern kauth_cred_t kauth_cred_setgid(kauth_cred_t cred, gid_t gid); | |
192 | extern kauth_cred_t kauth_cred_setegid(kauth_cred_t cred, gid_t egid); | |
193 | extern kauth_cred_t kauth_cred_setuidgid(kauth_cred_t cred, uid_t uid, gid_t gid); | |
194 | extern kauth_cred_t kauth_cred_setsvuidgid(kauth_cred_t cred, uid_t uid, gid_t gid); | |
195 | extern kauth_cred_t kauth_cred_setgroups(kauth_cred_t cred, gid_t *groups, int groupcount, uid_t gmuid); | |
196 | extern kauth_cred_t kauth_cred_find(kauth_cred_t cred); | |
197 | extern int kauth_cred_getgroups(gid_t *_groups, int *_groupcount); | |
198 | extern int kauth_cred_assume(uid_t _uid); | |
199 | extern uid_t kauth_cred_getuid(kauth_cred_t _cred); | |
200 | extern gid_t kauth_cred_getgid(kauth_cred_t _cred); | |
201 | extern int kauth_cred_guid2uid(guid_t *_guid, uid_t *_uidp); | |
202 | extern int kauth_cred_guid2gid(guid_t *_guid, gid_t *_gidp); | |
203 | extern int kauth_cred_ntsid2uid(ntsid_t *_sid, uid_t *_uidp); | |
204 | extern int kauth_cred_ntsid2gid(ntsid_t *_sid, gid_t *_gidp); | |
205 | extern int kauth_cred_ntsid2guid(ntsid_t *_sid, guid_t *_guidp); | |
206 | extern int kauth_cred_uid2guid(uid_t _uid, guid_t *_guidp); | |
207 | extern int kauth_cred_getguid(kauth_cred_t _cred, guid_t *_guidp); | |
208 | extern int kauth_cred_gid2guid(gid_t _gid, guid_t *_guidp); | |
209 | extern int kauth_cred_uid2ntsid(uid_t _uid, ntsid_t *_sidp); | |
210 | extern int kauth_cred_getntsid(kauth_cred_t _cred, ntsid_t *_sidp); | |
211 | extern int kauth_cred_gid2ntsid(gid_t _gid, ntsid_t *_sidp); | |
212 | extern int kauth_cred_guid2ntsid(guid_t *_guid, ntsid_t *_sidp); | |
213 | extern int kauth_cred_ismember_gid(kauth_cred_t _cred, gid_t _gid, int *_resultp); | |
214 | extern int kauth_cred_ismember_guid(kauth_cred_t _cred, guid_t *_guidp, int *_resultp); | |
215 | ||
216 | extern int kauth_cred_supplementary_register(const char *name, int *ident); | |
217 | extern int kauth_cred_supplementary_add(kauth_cred_t cred, int ident, const void *data, size_t datasize); | |
218 | extern int kauth_cred_supplementary_remove(kauth_cred_t cred, int ident); | |
219 | ||
220 | /* NOT KPI - fast path for in-kernel code only */ | |
221 | extern int kauth_cred_issuser(kauth_cred_t _cred); | |
222 | ||
223 | ||
224 | /* GUID, NTSID helpers */ | |
225 | extern guid_t kauth_null_guid; | |
226 | extern int kauth_guid_equal(guid_t *_guid1, guid_t *_guid2); | |
227 | extern int kauth_ntsid_equal(ntsid_t *_sid1, ntsid_t *_sid2); | |
228 | ||
229 | extern int kauth_wellknown_guid(guid_t *_guid); | |
230 | #define KAUTH_WKG_NOT 0 /* not a well-known GUID */ | |
231 | #define KAUTH_WKG_OWNER 1 | |
232 | #define KAUTH_WKG_GROUP 2 | |
233 | #define KAUTH_WKG_NOBODY 3 | |
234 | #define KAUTH_WKG_EVERYBODY 4 | |
235 | ||
236 | extern int cantrace(proc_t cur_procp, kauth_cred_t creds, proc_t traced_procp, int *errp); | |
237 | ||
238 | __END_DECLS | |
239 | ||
240 | #endif /* KERNEL */ | |
241 | ||
242 | /* | |
243 | * Generic Access Control Lists. | |
244 | */ | |
245 | #if defined(KERNEL) || defined (_SYS_ACL_H) | |
246 | ||
247 | typedef u_int32_t kauth_ace_rights_t; | |
248 | ||
249 | /* Access Control List Entry (ACE) */ | |
250 | struct kauth_ace { | |
251 | guid_t ace_applicable; | |
252 | u_int32_t ace_flags; | |
253 | #define KAUTH_ACE_KINDMASK 0xf | |
254 | #define KAUTH_ACE_PERMIT 1 | |
255 | #define KAUTH_ACE_DENY 2 | |
256 | #define KAUTH_ACE_AUDIT 3 /* not implemented */ | |
257 | #define KAUTH_ACE_ALARM 4 /* not implemented */ | |
258 | #define KAUTH_ACE_INHERITED (1<<4) | |
259 | #define KAUTH_ACE_FILE_INHERIT (1<<5) | |
260 | #define KAUTH_ACE_DIRECTORY_INHERIT (1<<6) | |
261 | #define KAUTH_ACE_LIMIT_INHERIT (1<<7) | |
262 | #define KAUTH_ACE_ONLY_INHERIT (1<<8) | |
263 | #define KAUTH_ACE_SUCCESS (1<<9) /* not implemented (AUDIT/ALARM) */ | |
264 | #define KAUTH_ACE_FAILURE (1<<10) /* not implemented (AUDIT/ALARM) */ | |
265 | kauth_ace_rights_t ace_rights; /* scope specific */ | |
266 | /* These rights are never tested, but may be present in an ACL */ | |
267 | #define KAUTH_ACE_GENERIC_ALL (1<<21) | |
268 | #define KAUTH_ACE_GENERIC_EXECUTE (1<<22) | |
269 | #define KAUTH_ACE_GENERIC_WRITE (1<<23) | |
270 | #define KAUTH_ACE_GENERIC_READ (1<<24) | |
271 | ||
272 | }; | |
273 | ||
274 | #ifndef _KAUTH_ACE | |
275 | #define _KAUTH_ACE | |
276 | typedef struct kauth_ace *kauth_ace_t; | |
277 | #endif | |
278 | ||
279 | ||
280 | /* Access Control List */ | |
281 | struct kauth_acl { | |
282 | u_int32_t acl_entrycount; | |
283 | u_int32_t acl_flags; | |
284 | ||
285 | struct kauth_ace acl_ace[]; | |
286 | }; | |
287 | ||
288 | /* | |
289 | * XXX this value needs to be raised - 3893388 | |
290 | */ | |
291 | #define KAUTH_ACL_MAX_ENTRIES 128 | |
292 | ||
293 | /* | |
294 | * The low 16 bits of the flags field are reserved for filesystem | |
295 | * internal use and must be preserved by all APIs. This includes | |
296 | * round-tripping flags through user-space interfaces. | |
297 | */ | |
298 | #define KAUTH_ACL_FLAGS_PRIVATE (0xffff) | |
299 | ||
300 | /* | |
301 | * The high 16 bits of the flags are used to store attributes and | |
302 | * to request specific handling of the ACL. | |
303 | */ | |
304 | ||
305 | /* inheritance will be deferred until the first rename operation */ | |
306 | #define KAUTH_ACL_DEFER_INHERIT (1<<16) | |
307 | /* this ACL must not be overwritten as part of an inheritance operation */ | |
308 | #define KAUTH_ACL_NO_INHERIT (1<<17) | |
309 | ||
4452a7af A |
310 | /* acl_entrycount that tells us the ACL is not valid */ |
311 | #define KAUTH_FILESEC_NOACL ((u_int32_t)(-1)) | |
312 | ||
313 | /* | |
314 | * If the acl_entrycount field is KAUTH_FILESEC_NOACL, then the size is the | |
315 | * same as a kauth_acl structure; the intent is to put an actual entrycount of | |
316 | * KAUTH_FILESEC_NOACL on disk to distinguish a kauth_filesec_t with an empty | |
317 | * entry (Windows treats this as "deny all") from one that merely indicates a | |
318 | * file group and/or owner guid values. | |
319 | */ | |
320 | #define KAUTH_ACL_SIZE(c) (sizeof(struct kauth_acl) + ((u_int32_t)(c) != KAUTH_FILESEC_NOACL ? ((c) * sizeof(struct kauth_ace)) : 0)) | |
91447636 A |
321 | #define KAUTH_ACL_COPYSIZE(p) KAUTH_ACL_SIZE((p)->acl_entrycount) |
322 | ||
323 | ||
324 | #ifndef _KAUTH_ACL | |
325 | #define _KAUTH_ACL | |
326 | typedef struct kauth_acl *kauth_acl_t; | |
327 | #endif | |
328 | ||
329 | #ifdef KERNEL | |
330 | __BEGIN_DECLS | |
331 | kauth_acl_t kauth_acl_alloc(int size); | |
332 | void kauth_acl_free(kauth_acl_t fsp); | |
333 | __END_DECLS | |
334 | #endif | |
335 | ||
336 | ||
337 | /* | |
338 | * Extended File Security. | |
339 | */ | |
340 | ||
341 | /* File Security information */ | |
342 | struct kauth_filesec { | |
343 | u_int32_t fsec_magic; | |
344 | #define KAUTH_FILESEC_MAGIC 0x012cc16d | |
345 | guid_t fsec_owner; | |
346 | guid_t fsec_group; | |
347 | ||
348 | struct kauth_acl fsec_acl; | |
91447636 A |
349 | }; |
350 | ||
351 | /* backwards compatibility */ | |
352 | #define fsec_entrycount fsec_acl.acl_entrycount | |
353 | #define fsec_flags fsec_acl.acl_flags | |
354 | #define fsec_ace fsec_acl.acl_ace | |
355 | #define KAUTH_FILESEC_FLAGS_PRIVATE KAUTH_ACL_FLAGS_PRIVATE | |
356 | #define KAUTH_FILESEC_DEFER_INHERIT KAUTH_ACL_DEFER_INHERIT | |
357 | #define KAUTH_FILESEC_NO_INHERIT KAUTH_ACL_NO_INHERIT | |
358 | #define KAUTH_FILESEC_NONE ((kauth_filesec_t)0) | |
359 | #define KAUTH_FILESEC_WANTED ((kauth_filesec_t)1) | |
360 | ||
361 | #ifndef _KAUTH_FILESEC | |
362 | #define _KAUTH_FILESEC | |
363 | typedef struct kauth_filesec *kauth_filesec_t; | |
364 | #endif | |
365 | ||
366 | #define KAUTH_FILESEC_SIZE(c) (sizeof(struct kauth_filesec) + (c) * sizeof(struct kauth_ace)) | |
367 | #define KAUTH_FILESEC_COPYSIZE(p) KAUTH_FILESEC_SIZE(((p)->fsec_entrycount == KAUTH_FILESEC_NOACL) ? 0 : (p)->fsec_entrycount) | |
368 | #define KAUTH_FILESEC_COUNT(s) ((s - sizeof(struct kauth_filesec)) / sizeof(struct kauth_ace)) | |
4452a7af | 369 | #define KAUTH_FILESEC_VALID(s) ((s) >= sizeof(struct kauth_filesec) && (((s) - sizeof(struct kauth_filesec)) % sizeof(struct kauth_ace)) == 0) |
91447636 A |
370 | |
371 | #define KAUTH_FILESEC_XATTR "com.apple.system.Security" | |
372 | ||
4452a7af A |
373 | /* Allowable first arguments to kauth_filesec_acl_setendian() */ |
374 | #define KAUTH_ENDIAN_HOST 0x00000001 /* set host endianness */ | |
375 | #define KAUTH_ENDIAN_DISK 0x00000002 /* set disk endianness */ | |
376 | ||
91447636 A |
377 | __BEGIN_DECLS |
378 | kauth_filesec_t kauth_filesec_alloc(int size); | |
379 | void kauth_filesec_free(kauth_filesec_t fsp); | |
380 | int kauth_copyinfilesec(user_addr_t xsecurity, kauth_filesec_t *xsecdestpp); | |
4452a7af | 381 | void kauth_filesec_acl_setendian(int, kauth_filesec_t, kauth_acl_t); |
91447636 A |
382 | __END_DECLS |
383 | ||
384 | #endif /* KERNEL || <sys/acl.h> */ | |
385 | ||
386 | ||
387 | #ifdef KERNEL | |
388 | /* | |
389 | * Scope management. | |
390 | */ | |
391 | struct kauth_scope; | |
392 | typedef struct kauth_scope *kauth_scope_t; | |
393 | struct kauth_listener; | |
394 | typedef struct kauth_listener *kauth_listener_t; | |
395 | #ifndef _KAUTH_ACTION_T | |
396 | typedef int kauth_action_t; | |
397 | # define _KAUTH_ACTION_T | |
398 | #endif | |
399 | ||
400 | typedef int (* kauth_scope_callback_t)(kauth_cred_t _credential, | |
401 | void *_idata, | |
402 | kauth_action_t _action, | |
403 | uintptr_t _arg0, | |
404 | uintptr_t _arg1, | |
405 | uintptr_t _arg2, | |
406 | uintptr_t _arg3); | |
407 | ||
408 | #define KAUTH_RESULT_ALLOW (1) | |
409 | #define KAUTH_RESULT_DENY (2) | |
410 | #define KAUTH_RESULT_DEFER (3) | |
411 | ||
412 | struct kauth_acl_eval { | |
413 | kauth_ace_t ae_acl; | |
414 | int ae_count; | |
415 | kauth_ace_rights_t ae_requested; | |
416 | kauth_ace_rights_t ae_residual; | |
417 | int ae_result; | |
418 | int ae_options; | |
419 | #define KAUTH_AEVAL_IS_OWNER (1<<0) /* authorizing operation for owner */ | |
420 | #define KAUTH_AEVAL_IN_GROUP (1<<1) /* authorizing operation for groupmember */ | |
421 | /* expansions for 'generic' rights bits */ | |
422 | kauth_ace_rights_t ae_exp_gall; | |
423 | kauth_ace_rights_t ae_exp_gread; | |
424 | kauth_ace_rights_t ae_exp_gwrite; | |
425 | kauth_ace_rights_t ae_exp_gexec; | |
426 | }; | |
427 | ||
428 | typedef struct kauth_acl_eval *kauth_acl_eval_t; | |
429 | ||
430 | __BEGIN_DECLS | |
431 | extern kauth_scope_t kauth_register_scope(const char *_identifier, kauth_scope_callback_t _callback, void *_idata); | |
432 | extern void kauth_deregister_scope(kauth_scope_t _scope); | |
433 | extern kauth_listener_t kauth_listen_scope(const char *_identifier, kauth_scope_callback_t _callback, void *_idata); | |
434 | extern void kauth_unlisten_scope(kauth_listener_t _scope); | |
435 | extern int kauth_authorize_action(kauth_scope_t _scope, kauth_cred_t _credential, kauth_action_t _action, | |
436 | uintptr_t _arg0, uintptr_t _arg1, uintptr_t _arg2, uintptr_t _arg3); | |
437 | extern int kauth_acl_evaluate(kauth_cred_t _credential, kauth_acl_eval_t _eval); | |
438 | extern int kauth_acl_inherit(vnode_t _dvp, kauth_acl_t _initial, kauth_acl_t *_product, int _isdir, vfs_context_t _ctx); | |
439 | ||
440 | /* default scope handlers */ | |
441 | extern int kauth_authorize_allow(kauth_cred_t _credential, void *_idata, kauth_action_t _action, | |
442 | uintptr_t _arg0, uintptr_t _arg1, uintptr_t _arg2, uintptr_t _arg3); | |
443 | __END_DECLS | |
444 | ||
445 | /* | |
446 | * Generic scope. | |
447 | */ | |
448 | #define KAUTH_SCOPE_GENERIC "com.apple.kauth.generic" | |
449 | ||
450 | /* Actions */ | |
451 | #define KAUTH_GENERIC_ISSUSER 1 | |
452 | ||
453 | __BEGIN_DECLS | |
454 | extern int kauth_authorize_generic(kauth_cred_t credential, kauth_action_t action); | |
455 | __END_DECLS | |
456 | ||
457 | /* | |
458 | * Process/task scope. | |
459 | */ | |
460 | #define KAUTH_SCOPE_PROCESS "com.apple.kauth.process" | |
461 | ||
462 | /* Actions */ | |
463 | #define KAUTH_PROCESS_CANSIGNAL 1 | |
464 | #define KAUTH_PROCESS_CANTRACE 2 | |
465 | ||
466 | __BEGIN_DECLS | |
467 | extern int kauth_authorize_process(kauth_cred_t _credential, kauth_action_t _action, | |
468 | struct proc *_process, uintptr_t _arg1, uintptr_t _arg2, uintptr_t _arg3); | |
469 | __END_DECLS | |
470 | ||
471 | /* | |
472 | * Vnode operation scope. | |
473 | * | |
474 | * Prototype for vnode_authorize is in vnode.h | |
475 | */ | |
476 | #define KAUTH_SCOPE_VNODE "com.apple.kauth.vnode" | |
477 | ||
478 | /* | |
479 | * File system operation scope. | |
480 | * | |
481 | */ | |
482 | #define KAUTH_SCOPE_FILEOP "com.apple.kauth.fileop" | |
483 | ||
484 | /* Actions */ | |
485 | #define KAUTH_FILEOP_OPEN 1 | |
486 | #define KAUTH_FILEOP_CLOSE 2 | |
487 | #define KAUTH_FILEOP_RENAME 3 | |
488 | #define KAUTH_FILEOP_EXCHANGE 4 | |
489 | #define KAUTH_FILEOP_LINK 5 | |
490 | #define KAUTH_FILEOP_EXEC 6 | |
491 | ||
492 | /* | |
493 | * arguments passed to KAUTH_FILEOP_OPEN listeners | |
494 | * arg0 is pointer to vnode (vnode *) for given user path. | |
495 | * arg1 is pointer to path (char *) passed in to open. | |
496 | * arguments passed to KAUTH_FILEOP_CLOSE listeners | |
497 | * arg0 is pointer to vnode (vnode *) for file to be closed. | |
498 | * arg1 is pointer to path (char *) of file to be closed. | |
499 | * arg2 is close flags. | |
500 | * arguments passed to KAUTH_FILEOP_RENAME listeners | |
501 | * arg0 is pointer to "from" path (char *). | |
502 | * arg1 is pointer to "to" path (char *). | |
503 | * arguments passed to KAUTH_FILEOP_EXCHANGE listeners | |
504 | * arg0 is pointer to file 1 path (char *). | |
505 | * arg1 is pointer to file 2 path (char *). | |
506 | * arguments passed to KAUTH_FILEOP_LINK listeners | |
507 | * arg0 is pointer to path to file we are linking to (char *). | |
508 | * arg1 is pointer to path to the new link file (char *). | |
509 | * arguments passed to KAUTH_FILEOP_EXEC listeners | |
510 | * arg0 is pointer to vnode (vnode *) for executable. | |
511 | * arg1 is pointer to path (char *) to executable. | |
512 | */ | |
513 | ||
514 | /* Flag values returned to close listeners. */ | |
515 | #define KAUTH_FILEOP_CLOSE_MODIFIED (1<<1) | |
516 | ||
517 | __BEGIN_DECLS | |
518 | extern int kauth_authorize_fileop_has_listeners(void); | |
519 | extern int kauth_authorize_fileop(kauth_cred_t _credential, kauth_action_t _action, | |
520 | uintptr_t _arg0, uintptr_t _arg1); | |
521 | __END_DECLS | |
522 | ||
523 | #endif /* KERNEL */ | |
524 | ||
525 | /* Actions, also rights bits in an ACE */ | |
526 | ||
527 | #if defined(KERNEL) || defined (_SYS_ACL_H) | |
528 | #define KAUTH_VNODE_READ_DATA (1<<1) | |
529 | #define KAUTH_VNODE_LIST_DIRECTORY KAUTH_VNODE_READ_DATA | |
530 | #define KAUTH_VNODE_WRITE_DATA (1<<2) | |
531 | #define KAUTH_VNODE_ADD_FILE KAUTH_VNODE_WRITE_DATA | |
532 | #define KAUTH_VNODE_EXECUTE (1<<3) | |
533 | #define KAUTH_VNODE_SEARCH KAUTH_VNODE_EXECUTE | |
534 | #define KAUTH_VNODE_DELETE (1<<4) | |
535 | #define KAUTH_VNODE_APPEND_DATA (1<<5) | |
536 | #define KAUTH_VNODE_ADD_SUBDIRECTORY KAUTH_VNODE_APPEND_DATA | |
537 | #define KAUTH_VNODE_DELETE_CHILD (1<<6) | |
538 | #define KAUTH_VNODE_READ_ATTRIBUTES (1<<7) | |
539 | #define KAUTH_VNODE_WRITE_ATTRIBUTES (1<<8) | |
540 | #define KAUTH_VNODE_READ_EXTATTRIBUTES (1<<9) | |
541 | #define KAUTH_VNODE_WRITE_EXTATTRIBUTES (1<<10) | |
542 | #define KAUTH_VNODE_READ_SECURITY (1<<11) | |
543 | #define KAUTH_VNODE_WRITE_SECURITY (1<<12) | |
544 | #define KAUTH_VNODE_TAKE_OWNERSHIP (1<<13) | |
545 | ||
546 | /* backwards compatibility only */ | |
547 | #define KAUTH_VNODE_CHANGE_OWNER KAUTH_VNODE_TAKE_OWNERSHIP | |
548 | ||
549 | /* For Windows interoperability only */ | |
550 | #define KAUTH_VNODE_SYNCHRONIZE (1<<20) | |
551 | ||
552 | /* (1<<21) - (1<<24) are reserved for generic rights bits */ | |
553 | ||
554 | /* Actions not expressed as rights bits */ | |
555 | /* | |
556 | * Authorizes the vnode as the target of a hard link. | |
557 | */ | |
558 | #define KAUTH_VNODE_LINKTARGET (1<<25) | |
559 | ||
560 | /* | |
561 | * Indicates that other steps have been taken to authorise the action, | |
562 | * but authorisation should be denied for immutable objects. | |
563 | */ | |
564 | #define KAUTH_VNODE_CHECKIMMUTABLE (1<<26) | |
565 | ||
566 | /* Action modifiers */ | |
567 | /* | |
568 | * The KAUTH_VNODE_ACCESS bit is passed to the callback if the authorisation | |
569 | * request in progress is advisory, rather than authoritative. Listeners | |
570 | * performing consequential work (i.e. not strictly checking authorisation) | |
571 | * may test this flag to avoid performing unnecessary work. | |
572 | * | |
573 | * This bit will never be present in an ACE. | |
574 | */ | |
575 | #define KAUTH_VNODE_ACCESS (1<<31) | |
576 | ||
577 | /* | |
578 | * The KAUTH_VNODE_NOIMMUTABLE bit is passed to the callback along with the | |
579 | * KAUTH_VNODE_WRITE_SECURITY bit (and no others) to indicate that the | |
580 | * caller wishes to change one or more of the immutable flags, and the | |
581 | * state of these flags should not be considered when authorizing the request. | |
582 | * The system immutable flags are only ignored when the system securelevel | |
583 | * is low enough to allow their removal. | |
584 | */ | |
585 | #define KAUTH_VNODE_NOIMMUTABLE (1<<30) | |
586 | ||
587 | /* The expansions of the GENERIC bits at evaluation time */ | |
588 | #define KAUTH_VNODE_GENERIC_READ_BITS (KAUTH_VNODE_READ_DATA | \ | |
589 | KAUTH_VNODE_READ_ATTRIBUTES | \ | |
590 | KAUTH_VNODE_READ_EXTATTRIBUTES | \ | |
591 | KAUTH_VNODE_READ_SECURITY) | |
592 | ||
593 | #define KAUTH_VNODE_GENERIC_WRITE_BITS (KAUTH_VNODE_WRITE_DATA | \ | |
594 | KAUTH_VNODE_APPEND_DATA | \ | |
595 | KAUTH_VNODE_DELETE | \ | |
596 | KAUTH_VNODE_DELETE_CHILD | \ | |
597 | KAUTH_VNODE_WRITE_ATTRIBUTES | \ | |
598 | KAUTH_VNODE_WRITE_EXTATTRIBUTES | \ | |
599 | KAUTH_VNODE_WRITE_SECURITY) | |
600 | ||
601 | #define KAUTH_VNODE_GENERIC_EXECUTE_BITS (KAUTH_VNODE_EXECUTE) | |
602 | ||
603 | #define KAUTH_VNODE_GENERIC_ALL_BITS (KAUTH_VNODE_GENERIC_READ_BITS | \ | |
604 | KAUTH_VNODE_GENERIC_WRITE_BITS | \ | |
605 | KAUTH_VNODE_GENERIC_EXECUTE_BITS) | |
606 | ||
607 | /* | |
608 | * Some sets of bits, defined here for convenience. | |
609 | */ | |
610 | #define KAUTH_VNODE_WRITE_RIGHTS (KAUTH_VNODE_ADD_FILE | \ | |
611 | KAUTH_VNODE_ADD_SUBDIRECTORY | \ | |
612 | KAUTH_VNODE_DELETE_CHILD | \ | |
613 | KAUTH_VNODE_WRITE_DATA | \ | |
614 | KAUTH_VNODE_APPEND_DATA | \ | |
615 | KAUTH_VNODE_DELETE | \ | |
616 | KAUTH_VNODE_WRITE_ATTRIBUTES | \ | |
617 | KAUTH_VNODE_WRITE_EXTATTRIBUTES | \ | |
618 | KAUTH_VNODE_WRITE_SECURITY | \ | |
619 | KAUTH_VNODE_TAKE_OWNERSHIP | \ | |
620 | KAUTH_VNODE_LINKTARGET | \ | |
621 | KAUTH_VNODE_CHECKIMMUTABLE) | |
622 | ||
623 | ||
624 | #endif /* KERNEL || <sys/acl.h> */ | |
625 | ||
626 | #ifdef KERNEL | |
627 | #include <sys/lock.h> /* lck_grp_t */ | |
628 | ||
629 | /* | |
630 | * Debugging | |
631 | * | |
632 | * XXX this wouldn't be necessary if we had a *real* debug-logging system. | |
633 | */ | |
634 | #if 0 | |
635 | # ifndef _FN_KPRINTF | |
636 | # define _FN_KPRINTF | |
637 | void kprintf(const char *fmt, ...); | |
638 | # endif | |
639 | # define KAUTH_DEBUG_ENABLE | |
640 | # define K_UUID_FMT "%08x:%08x:%08x:%08x" | |
641 | # define K_UUID_ARG(_u) *(int *)&_u.g_guid[0],*(int *)&_u.g_guid[4],*(int *)&_u.g_guid[8],*(int *)&_u.g_guid[12] | |
642 | # define KAUTH_DEBUG(fmt, args...) do { kprintf("%s:%d: " fmt "\n", __PRETTY_FUNCTION__, __LINE__ , ##args); } while (0) | |
643 | # define KAUTH_DEBUG_CTX(_c) KAUTH_DEBUG("p = %p c = %p", _c->vc_proc, _c->vc_ucred) | |
644 | # define VFS_DEBUG(_ctx, _vp, fmt, args...) \ | |
645 | do { \ | |
646 | kprintf("%p '%s' %s:%d " fmt "\n", \ | |
647 | _ctx, \ | |
648 | (_vp != NULL && _vp->v_name != NULL) ? _vp->v_name : "????", \ | |
649 | __PRETTY_FUNCTION__, __LINE__ , \ | |
650 | ##args); \ | |
651 | } while(0) | |
652 | #else | |
653 | # define KAUTH_DEBUG(fmt, args...) do { } while (0) | |
654 | # define VFS_DEBUG(ctx, vp, fmt, args...) do { } while(0) | |
655 | #endif | |
656 | ||
657 | /* | |
658 | * Initialisation. | |
659 | */ | |
660 | extern lck_grp_t *kauth_lck_grp; | |
661 | __BEGIN_DECLS | |
662 | extern void kauth_init(void); | |
663 | extern void kauth_identity_init(void); | |
664 | extern void kauth_groups_init(void); | |
665 | extern void kauth_cred_init(void); | |
666 | extern void kauth_resolver_init(void); | |
667 | __END_DECLS | |
668 | #endif | |
669 | ||
670 | #endif /* __APPLE_API_EVOLVING */ | |
671 | #endif /* _SYS_KAUTH_H */ | |
672 |