]> git.saurik.com Git - apple/xnu.git/blob - bsd/sys/kauth.h
1514999207f33d32160d2eec72767cf99c7e115f
[apple/xnu.git] / bsd / sys / kauth.h
1 /*
2 * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_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 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
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
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);
188 extern void kauth_cred_unref(kauth_cred_t _cred);
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
310 #define KAUTH_ACL_SIZE(c) (sizeof(struct kauth_acl) + (c) * sizeof(struct kauth_ace))
311 #define KAUTH_ACL_COPYSIZE(p) KAUTH_ACL_SIZE((p)->acl_entrycount)
312
313
314 #ifndef _KAUTH_ACL
315 #define _KAUTH_ACL
316 typedef struct kauth_acl *kauth_acl_t;
317 #endif
318
319 #ifdef KERNEL
320 __BEGIN_DECLS
321 kauth_acl_t kauth_acl_alloc(int size);
322 void kauth_acl_free(kauth_acl_t fsp);
323 __END_DECLS
324 #endif
325
326
327 /*
328 * Extended File Security.
329 */
330
331 /* File Security information */
332 struct kauth_filesec {
333 u_int32_t fsec_magic;
334 #define KAUTH_FILESEC_MAGIC 0x012cc16d
335 guid_t fsec_owner;
336 guid_t fsec_group;
337
338 struct kauth_acl fsec_acl;
339 /* acl_entrycount that tells us the ACL is not valid */
340 #define KAUTH_FILESEC_NOACL ((u_int32_t)(-1))
341 };
342
343 /* backwards compatibility */
344 #define fsec_entrycount fsec_acl.acl_entrycount
345 #define fsec_flags fsec_acl.acl_flags
346 #define fsec_ace fsec_acl.acl_ace
347 #define KAUTH_FILESEC_FLAGS_PRIVATE KAUTH_ACL_FLAGS_PRIVATE
348 #define KAUTH_FILESEC_DEFER_INHERIT KAUTH_ACL_DEFER_INHERIT
349 #define KAUTH_FILESEC_NO_INHERIT KAUTH_ACL_NO_INHERIT
350 #define KAUTH_FILESEC_NONE ((kauth_filesec_t)0)
351 #define KAUTH_FILESEC_WANTED ((kauth_filesec_t)1)
352
353 #ifndef _KAUTH_FILESEC
354 #define _KAUTH_FILESEC
355 typedef struct kauth_filesec *kauth_filesec_t;
356 #endif
357
358 #define KAUTH_FILESEC_SIZE(c) (sizeof(struct kauth_filesec) + (c) * sizeof(struct kauth_ace))
359 #define KAUTH_FILESEC_COPYSIZE(p) KAUTH_FILESEC_SIZE(((p)->fsec_entrycount == KAUTH_FILESEC_NOACL) ? 0 : (p)->fsec_entrycount)
360 #define KAUTH_FILESEC_COUNT(s) ((s - sizeof(struct kauth_filesec)) / sizeof(struct kauth_ace))
361
362 #define KAUTH_FILESEC_XATTR "com.apple.system.Security"
363
364 __BEGIN_DECLS
365 kauth_filesec_t kauth_filesec_alloc(int size);
366 void kauth_filesec_free(kauth_filesec_t fsp);
367 int kauth_copyinfilesec(user_addr_t xsecurity, kauth_filesec_t *xsecdestpp);
368 __END_DECLS
369
370 #endif /* KERNEL || <sys/acl.h> */
371
372
373 #ifdef KERNEL
374 /*
375 * Scope management.
376 */
377 struct kauth_scope;
378 typedef struct kauth_scope *kauth_scope_t;
379 struct kauth_listener;
380 typedef struct kauth_listener *kauth_listener_t;
381 #ifndef _KAUTH_ACTION_T
382 typedef int kauth_action_t;
383 # define _KAUTH_ACTION_T
384 #endif
385
386 typedef int (* kauth_scope_callback_t)(kauth_cred_t _credential,
387 void *_idata,
388 kauth_action_t _action,
389 uintptr_t _arg0,
390 uintptr_t _arg1,
391 uintptr_t _arg2,
392 uintptr_t _arg3);
393
394 #define KAUTH_RESULT_ALLOW (1)
395 #define KAUTH_RESULT_DENY (2)
396 #define KAUTH_RESULT_DEFER (3)
397
398 struct kauth_acl_eval {
399 kauth_ace_t ae_acl;
400 int ae_count;
401 kauth_ace_rights_t ae_requested;
402 kauth_ace_rights_t ae_residual;
403 int ae_result;
404 int ae_options;
405 #define KAUTH_AEVAL_IS_OWNER (1<<0) /* authorizing operation for owner */
406 #define KAUTH_AEVAL_IN_GROUP (1<<1) /* authorizing operation for groupmember */
407 /* expansions for 'generic' rights bits */
408 kauth_ace_rights_t ae_exp_gall;
409 kauth_ace_rights_t ae_exp_gread;
410 kauth_ace_rights_t ae_exp_gwrite;
411 kauth_ace_rights_t ae_exp_gexec;
412 };
413
414 typedef struct kauth_acl_eval *kauth_acl_eval_t;
415
416 __BEGIN_DECLS
417 extern kauth_scope_t kauth_register_scope(const char *_identifier, kauth_scope_callback_t _callback, void *_idata);
418 extern void kauth_deregister_scope(kauth_scope_t _scope);
419 extern kauth_listener_t kauth_listen_scope(const char *_identifier, kauth_scope_callback_t _callback, void *_idata);
420 extern void kauth_unlisten_scope(kauth_listener_t _scope);
421 extern int kauth_authorize_action(kauth_scope_t _scope, kauth_cred_t _credential, kauth_action_t _action,
422 uintptr_t _arg0, uintptr_t _arg1, uintptr_t _arg2, uintptr_t _arg3);
423 extern int kauth_acl_evaluate(kauth_cred_t _credential, kauth_acl_eval_t _eval);
424 extern int kauth_acl_inherit(vnode_t _dvp, kauth_acl_t _initial, kauth_acl_t *_product, int _isdir, vfs_context_t _ctx);
425
426 /* default scope handlers */
427 extern int kauth_authorize_allow(kauth_cred_t _credential, void *_idata, kauth_action_t _action,
428 uintptr_t _arg0, uintptr_t _arg1, uintptr_t _arg2, uintptr_t _arg3);
429 __END_DECLS
430
431 /*
432 * Generic scope.
433 */
434 #define KAUTH_SCOPE_GENERIC "com.apple.kauth.generic"
435
436 /* Actions */
437 #define KAUTH_GENERIC_ISSUSER 1
438
439 __BEGIN_DECLS
440 extern int kauth_authorize_generic(kauth_cred_t credential, kauth_action_t action);
441 __END_DECLS
442
443 /*
444 * Process/task scope.
445 */
446 #define KAUTH_SCOPE_PROCESS "com.apple.kauth.process"
447
448 /* Actions */
449 #define KAUTH_PROCESS_CANSIGNAL 1
450 #define KAUTH_PROCESS_CANTRACE 2
451
452 __BEGIN_DECLS
453 extern int kauth_authorize_process(kauth_cred_t _credential, kauth_action_t _action,
454 struct proc *_process, uintptr_t _arg1, uintptr_t _arg2, uintptr_t _arg3);
455 __END_DECLS
456
457 /*
458 * Vnode operation scope.
459 *
460 * Prototype for vnode_authorize is in vnode.h
461 */
462 #define KAUTH_SCOPE_VNODE "com.apple.kauth.vnode"
463
464 /*
465 * File system operation scope.
466 *
467 */
468 #define KAUTH_SCOPE_FILEOP "com.apple.kauth.fileop"
469
470 /* Actions */
471 #define KAUTH_FILEOP_OPEN 1
472 #define KAUTH_FILEOP_CLOSE 2
473 #define KAUTH_FILEOP_RENAME 3
474 #define KAUTH_FILEOP_EXCHANGE 4
475 #define KAUTH_FILEOP_LINK 5
476 #define KAUTH_FILEOP_EXEC 6
477
478 /*
479 * arguments passed to KAUTH_FILEOP_OPEN listeners
480 * arg0 is pointer to vnode (vnode *) for given user path.
481 * arg1 is pointer to path (char *) passed in to open.
482 * arguments passed to KAUTH_FILEOP_CLOSE listeners
483 * arg0 is pointer to vnode (vnode *) for file to be closed.
484 * arg1 is pointer to path (char *) of file to be closed.
485 * arg2 is close flags.
486 * arguments passed to KAUTH_FILEOP_RENAME listeners
487 * arg0 is pointer to "from" path (char *).
488 * arg1 is pointer to "to" path (char *).
489 * arguments passed to KAUTH_FILEOP_EXCHANGE listeners
490 * arg0 is pointer to file 1 path (char *).
491 * arg1 is pointer to file 2 path (char *).
492 * arguments passed to KAUTH_FILEOP_LINK listeners
493 * arg0 is pointer to path to file we are linking to (char *).
494 * arg1 is pointer to path to the new link file (char *).
495 * arguments passed to KAUTH_FILEOP_EXEC listeners
496 * arg0 is pointer to vnode (vnode *) for executable.
497 * arg1 is pointer to path (char *) to executable.
498 */
499
500 /* Flag values returned to close listeners. */
501 #define KAUTH_FILEOP_CLOSE_MODIFIED (1<<1)
502
503 __BEGIN_DECLS
504 extern int kauth_authorize_fileop_has_listeners(void);
505 extern int kauth_authorize_fileop(kauth_cred_t _credential, kauth_action_t _action,
506 uintptr_t _arg0, uintptr_t _arg1);
507 __END_DECLS
508
509 #endif /* KERNEL */
510
511 /* Actions, also rights bits in an ACE */
512
513 #if defined(KERNEL) || defined (_SYS_ACL_H)
514 #define KAUTH_VNODE_READ_DATA (1<<1)
515 #define KAUTH_VNODE_LIST_DIRECTORY KAUTH_VNODE_READ_DATA
516 #define KAUTH_VNODE_WRITE_DATA (1<<2)
517 #define KAUTH_VNODE_ADD_FILE KAUTH_VNODE_WRITE_DATA
518 #define KAUTH_VNODE_EXECUTE (1<<3)
519 #define KAUTH_VNODE_SEARCH KAUTH_VNODE_EXECUTE
520 #define KAUTH_VNODE_DELETE (1<<4)
521 #define KAUTH_VNODE_APPEND_DATA (1<<5)
522 #define KAUTH_VNODE_ADD_SUBDIRECTORY KAUTH_VNODE_APPEND_DATA
523 #define KAUTH_VNODE_DELETE_CHILD (1<<6)
524 #define KAUTH_VNODE_READ_ATTRIBUTES (1<<7)
525 #define KAUTH_VNODE_WRITE_ATTRIBUTES (1<<8)
526 #define KAUTH_VNODE_READ_EXTATTRIBUTES (1<<9)
527 #define KAUTH_VNODE_WRITE_EXTATTRIBUTES (1<<10)
528 #define KAUTH_VNODE_READ_SECURITY (1<<11)
529 #define KAUTH_VNODE_WRITE_SECURITY (1<<12)
530 #define KAUTH_VNODE_TAKE_OWNERSHIP (1<<13)
531
532 /* backwards compatibility only */
533 #define KAUTH_VNODE_CHANGE_OWNER KAUTH_VNODE_TAKE_OWNERSHIP
534
535 /* For Windows interoperability only */
536 #define KAUTH_VNODE_SYNCHRONIZE (1<<20)
537
538 /* (1<<21) - (1<<24) are reserved for generic rights bits */
539
540 /* Actions not expressed as rights bits */
541 /*
542 * Authorizes the vnode as the target of a hard link.
543 */
544 #define KAUTH_VNODE_LINKTARGET (1<<25)
545
546 /*
547 * Indicates that other steps have been taken to authorise the action,
548 * but authorisation should be denied for immutable objects.
549 */
550 #define KAUTH_VNODE_CHECKIMMUTABLE (1<<26)
551
552 /* Action modifiers */
553 /*
554 * The KAUTH_VNODE_ACCESS bit is passed to the callback if the authorisation
555 * request in progress is advisory, rather than authoritative. Listeners
556 * performing consequential work (i.e. not strictly checking authorisation)
557 * may test this flag to avoid performing unnecessary work.
558 *
559 * This bit will never be present in an ACE.
560 */
561 #define KAUTH_VNODE_ACCESS (1<<31)
562
563 /*
564 * The KAUTH_VNODE_NOIMMUTABLE bit is passed to the callback along with the
565 * KAUTH_VNODE_WRITE_SECURITY bit (and no others) to indicate that the
566 * caller wishes to change one or more of the immutable flags, and the
567 * state of these flags should not be considered when authorizing the request.
568 * The system immutable flags are only ignored when the system securelevel
569 * is low enough to allow their removal.
570 */
571 #define KAUTH_VNODE_NOIMMUTABLE (1<<30)
572
573 /* The expansions of the GENERIC bits at evaluation time */
574 #define KAUTH_VNODE_GENERIC_READ_BITS (KAUTH_VNODE_READ_DATA | \
575 KAUTH_VNODE_READ_ATTRIBUTES | \
576 KAUTH_VNODE_READ_EXTATTRIBUTES | \
577 KAUTH_VNODE_READ_SECURITY)
578
579 #define KAUTH_VNODE_GENERIC_WRITE_BITS (KAUTH_VNODE_WRITE_DATA | \
580 KAUTH_VNODE_APPEND_DATA | \
581 KAUTH_VNODE_DELETE | \
582 KAUTH_VNODE_DELETE_CHILD | \
583 KAUTH_VNODE_WRITE_ATTRIBUTES | \
584 KAUTH_VNODE_WRITE_EXTATTRIBUTES | \
585 KAUTH_VNODE_WRITE_SECURITY)
586
587 #define KAUTH_VNODE_GENERIC_EXECUTE_BITS (KAUTH_VNODE_EXECUTE)
588
589 #define KAUTH_VNODE_GENERIC_ALL_BITS (KAUTH_VNODE_GENERIC_READ_BITS | \
590 KAUTH_VNODE_GENERIC_WRITE_BITS | \
591 KAUTH_VNODE_GENERIC_EXECUTE_BITS)
592
593 /*
594 * Some sets of bits, defined here for convenience.
595 */
596 #define KAUTH_VNODE_WRITE_RIGHTS (KAUTH_VNODE_ADD_FILE | \
597 KAUTH_VNODE_ADD_SUBDIRECTORY | \
598 KAUTH_VNODE_DELETE_CHILD | \
599 KAUTH_VNODE_WRITE_DATA | \
600 KAUTH_VNODE_APPEND_DATA | \
601 KAUTH_VNODE_DELETE | \
602 KAUTH_VNODE_WRITE_ATTRIBUTES | \
603 KAUTH_VNODE_WRITE_EXTATTRIBUTES | \
604 KAUTH_VNODE_WRITE_SECURITY | \
605 KAUTH_VNODE_TAKE_OWNERSHIP | \
606 KAUTH_VNODE_LINKTARGET | \
607 KAUTH_VNODE_CHECKIMMUTABLE)
608
609
610 #endif /* KERNEL || <sys/acl.h> */
611
612 #ifdef KERNEL
613 #include <sys/lock.h> /* lck_grp_t */
614
615 /*
616 * Debugging
617 *
618 * XXX this wouldn't be necessary if we had a *real* debug-logging system.
619 */
620 #if 0
621 # ifndef _FN_KPRINTF
622 # define _FN_KPRINTF
623 void kprintf(const char *fmt, ...);
624 # endif
625 # define KAUTH_DEBUG_ENABLE
626 # define K_UUID_FMT "%08x:%08x:%08x:%08x"
627 # 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]
628 # define KAUTH_DEBUG(fmt, args...) do { kprintf("%s:%d: " fmt "\n", __PRETTY_FUNCTION__, __LINE__ , ##args); } while (0)
629 # define KAUTH_DEBUG_CTX(_c) KAUTH_DEBUG("p = %p c = %p", _c->vc_proc, _c->vc_ucred)
630 # define VFS_DEBUG(_ctx, _vp, fmt, args...) \
631 do { \
632 kprintf("%p '%s' %s:%d " fmt "\n", \
633 _ctx, \
634 (_vp != NULL && _vp->v_name != NULL) ? _vp->v_name : "????", \
635 __PRETTY_FUNCTION__, __LINE__ , \
636 ##args); \
637 } while(0)
638 #else
639 # define KAUTH_DEBUG(fmt, args...) do { } while (0)
640 # define VFS_DEBUG(ctx, vp, fmt, args...) do { } while(0)
641 #endif
642
643 /*
644 * Initialisation.
645 */
646 extern lck_grp_t *kauth_lck_grp;
647 __BEGIN_DECLS
648 extern void kauth_init(void);
649 extern void kauth_identity_init(void);
650 extern void kauth_groups_init(void);
651 extern void kauth_cred_init(void);
652 extern void kauth_resolver_init(void);
653 __END_DECLS
654 #endif
655
656 #endif /* __APPLE_API_EVOLVING */
657 #endif /* _SYS_KAUTH_H */
658