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