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