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