xref: /xnu-11417.140.69/bsd/sys/kauth.h (revision 43a90889846e00bfb5cf1d255cdc0a701a1e05a4)
1*43a90889SApple OSS Distributions /*
2*43a90889SApple OSS Distributions  * Copyright (c) 2004-2010 Apple Inc. All rights reserved.
3*43a90889SApple OSS Distributions  *
4*43a90889SApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5*43a90889SApple OSS Distributions  *
6*43a90889SApple OSS Distributions  * This file contains Original Code and/or Modifications of Original Code
7*43a90889SApple OSS Distributions  * as defined in and that are subject to the Apple Public Source License
8*43a90889SApple OSS Distributions  * Version 2.0 (the 'License'). You may not use this file except in
9*43a90889SApple OSS Distributions  * compliance with the License. The rights granted to you under the License
10*43a90889SApple OSS Distributions  * may not be used to create, or enable the creation or redistribution of,
11*43a90889SApple OSS Distributions  * unlawful or unlicensed copies of an Apple operating system, or to
12*43a90889SApple OSS Distributions  * circumvent, violate, or enable the circumvention or violation of, any
13*43a90889SApple OSS Distributions  * terms of an Apple operating system software license agreement.
14*43a90889SApple OSS Distributions  *
15*43a90889SApple OSS Distributions  * Please obtain a copy of the License at
16*43a90889SApple OSS Distributions  * http://www.opensource.apple.com/apsl/ and read it before using this file.
17*43a90889SApple OSS Distributions  *
18*43a90889SApple OSS Distributions  * The Original Code and all software distributed under the License are
19*43a90889SApple OSS Distributions  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20*43a90889SApple OSS Distributions  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21*43a90889SApple OSS Distributions  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22*43a90889SApple OSS Distributions  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23*43a90889SApple OSS Distributions  * Please see the License for the specific language governing rights and
24*43a90889SApple OSS Distributions  * limitations under the License.
25*43a90889SApple OSS Distributions  *
26*43a90889SApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27*43a90889SApple OSS Distributions  */
28*43a90889SApple OSS Distributions /*
29*43a90889SApple OSS Distributions  * NOTICE: This file was modified by SPARTA, Inc. in 2005 to introduce
30*43a90889SApple OSS Distributions  * support for mandatory and extensible security protections.  This notice
31*43a90889SApple OSS Distributions  * is included in support of clause 2.2 (b) of the Apple Public License,
32*43a90889SApple OSS Distributions  * Version 2.0.
33*43a90889SApple OSS Distributions  */
34*43a90889SApple OSS Distributions 
35*43a90889SApple OSS Distributions #ifndef _SYS_KAUTH_H
36*43a90889SApple OSS Distributions #define _SYS_KAUTH_H
37*43a90889SApple OSS Distributions 
38*43a90889SApple OSS Distributions #include <sys/appleapiopts.h>
39*43a90889SApple OSS Distributions #include <sys/cdefs.h>
40*43a90889SApple OSS Distributions #include <mach/boolean.h>
41*43a90889SApple OSS Distributions #include <machine/types.h>      /* u_int8_t, etc. */
42*43a90889SApple OSS Distributions #include <sys/_types.h>         /* __offsetof() */
43*43a90889SApple OSS Distributions #include <sys/_types/_uid_t.h>  /* uid_t */
44*43a90889SApple OSS Distributions #include <sys/_types/_gid_t.h>     /* gid_t */
45*43a90889SApple OSS Distributions #include <sys/_types/_guid_t.h>
46*43a90889SApple OSS Distributions #include <sys/syslimits.h>      /* NGROUPS_MAX */
47*43a90889SApple OSS Distributions #ifdef KERNEL
48*43a90889SApple OSS Distributions #include <stdbool.h>
49*43a90889SApple OSS Distributions #include <sys/ucred.h>
50*43a90889SApple OSS Distributions #include <sys/lock.h>   /* lck_grp_t */
51*43a90889SApple OSS Distributions #endif /* KERNEL */
52*43a90889SApple OSS Distributions #if KERNEL_PRIVATE
53*43a90889SApple OSS Distributions #include <kern/smr_types.h>
54*43a90889SApple OSS Distributions #endif
55*43a90889SApple OSS Distributions 
56*43a90889SApple OSS Distributions __BEGIN_DECLS
57*43a90889SApple OSS Distributions 
58*43a90889SApple OSS Distributions #ifdef __APPLE_API_EVOLVING
59*43a90889SApple OSS Distributions 
60*43a90889SApple OSS Distributions /*
61*43a90889SApple OSS Distributions  * Identities.
62*43a90889SApple OSS Distributions  */
63*43a90889SApple OSS Distributions 
64*43a90889SApple OSS Distributions #define KAUTH_UID_NONE  (~(uid_t)0 - 100)       /* not a valid UID */
65*43a90889SApple OSS Distributions #define KAUTH_GID_NONE  (~(gid_t)0 - 100)       /* not a valid GID */
66*43a90889SApple OSS Distributions 
67*43a90889SApple OSS Distributions /* NT Security Identifier, structure as defined by Microsoft */
68*43a90889SApple OSS Distributions #pragma pack(1)    /* push packing of 1 byte */
69*43a90889SApple OSS Distributions typedef struct {
70*43a90889SApple OSS Distributions 	u_int8_t                sid_kind;
71*43a90889SApple OSS Distributions 	u_int8_t                sid_authcount;
72*43a90889SApple OSS Distributions 	u_int8_t                sid_authority[6];
73*43a90889SApple OSS Distributions #define KAUTH_NTSID_MAX_AUTHORITIES 16
74*43a90889SApple OSS Distributions 	u_int32_t       sid_authorities[KAUTH_NTSID_MAX_AUTHORITIES];
75*43a90889SApple OSS Distributions } ntsid_t;
76*43a90889SApple OSS Distributions #pragma pack()    /* pop packing to previous packing level */
77*43a90889SApple OSS Distributions #define _NTSID_T
78*43a90889SApple OSS Distributions 
79*43a90889SApple OSS Distributions /* valid byte count inside a SID structure */
80*43a90889SApple OSS Distributions #define KAUTH_NTSID_HDRSIZE     (8)
81*43a90889SApple OSS Distributions #define KAUTH_NTSID_SIZE(_s)    (KAUTH_NTSID_HDRSIZE + ((_s)->sid_authcount * sizeof(u_int32_t)))
82*43a90889SApple OSS Distributions 
83*43a90889SApple OSS Distributions /*
84*43a90889SApple OSS Distributions  * External lookup message payload; this structure is shared between the
85*43a90889SApple OSS Distributions  * kernel group membership resolver, and the user space group membership
86*43a90889SApple OSS Distributions  * resolver daemon, and is use to communicate resolution requests from the
87*43a90889SApple OSS Distributions  * kernel to user space, and the result of that request from user space to
88*43a90889SApple OSS Distributions  * the kernel.
89*43a90889SApple OSS Distributions  */
90*43a90889SApple OSS Distributions struct kauth_identity_extlookup {
91*43a90889SApple OSS Distributions 	u_int32_t       el_seqno;       /* request sequence number */
92*43a90889SApple OSS Distributions 	u_int32_t       el_result;      /* lookup result */
93*43a90889SApple OSS Distributions #define KAUTH_EXTLOOKUP_SUCCESS         0       /* results here are good */
94*43a90889SApple OSS Distributions #define KAUTH_EXTLOOKUP_BADRQ           1       /* request badly formatted */
95*43a90889SApple OSS Distributions #define KAUTH_EXTLOOKUP_FAILURE         2       /* transient failure during lookup */
96*43a90889SApple OSS Distributions #define KAUTH_EXTLOOKUP_FATAL           3       /* permanent failure during lookup */
97*43a90889SApple OSS Distributions #define KAUTH_EXTLOOKUP_INPROG          100     /* request in progress */
98*43a90889SApple OSS Distributions 	u_int32_t       el_flags;
99*43a90889SApple OSS Distributions #define KAUTH_EXTLOOKUP_VALID_UID       (1<<0)
100*43a90889SApple OSS Distributions #define KAUTH_EXTLOOKUP_VALID_UGUID     (1<<1)
101*43a90889SApple OSS Distributions #define KAUTH_EXTLOOKUP_VALID_USID      (1<<2)
102*43a90889SApple OSS Distributions #define KAUTH_EXTLOOKUP_VALID_GID       (1<<3)
103*43a90889SApple OSS Distributions #define KAUTH_EXTLOOKUP_VALID_GGUID     (1<<4)
104*43a90889SApple OSS Distributions #define KAUTH_EXTLOOKUP_VALID_GSID      (1<<5)
105*43a90889SApple OSS Distributions #define KAUTH_EXTLOOKUP_WANT_UID        (1<<6)
106*43a90889SApple OSS Distributions #define KAUTH_EXTLOOKUP_WANT_UGUID      (1<<7)
107*43a90889SApple OSS Distributions #define KAUTH_EXTLOOKUP_WANT_USID       (1<<8)
108*43a90889SApple OSS Distributions #define KAUTH_EXTLOOKUP_WANT_GID        (1<<9)
109*43a90889SApple OSS Distributions #define KAUTH_EXTLOOKUP_WANT_GGUID      (1<<10)
110*43a90889SApple OSS Distributions #define KAUTH_EXTLOOKUP_WANT_GSID       (1<<11)
111*43a90889SApple OSS Distributions #define KAUTH_EXTLOOKUP_WANT_MEMBERSHIP (1<<12)
112*43a90889SApple OSS Distributions #define KAUTH_EXTLOOKUP_VALID_MEMBERSHIP (1<<13)
113*43a90889SApple OSS Distributions #define KAUTH_EXTLOOKUP_ISMEMBER        (1<<14)
114*43a90889SApple OSS Distributions #define KAUTH_EXTLOOKUP_VALID_PWNAM     (1<<15)
115*43a90889SApple OSS Distributions #define KAUTH_EXTLOOKUP_WANT_PWNAM      (1<<16)
116*43a90889SApple OSS Distributions #define KAUTH_EXTLOOKUP_VALID_GRNAM     (1<<17)
117*43a90889SApple OSS Distributions #define KAUTH_EXTLOOKUP_WANT_GRNAM      (1<<18)
118*43a90889SApple OSS Distributions #define KAUTH_EXTLOOKUP_VALID_SUPGRPS   (1<<19)
119*43a90889SApple OSS Distributions #define KAUTH_EXTLOOKUP_WANT_SUPGRPS    (1<<20)
120*43a90889SApple OSS Distributions 
121*43a90889SApple OSS Distributions 	__darwin_pid_t  el_info_pid;            /* request on behalf of PID */
122*43a90889SApple OSS Distributions 	u_int64_t       el_extend;              /* extension field */
123*43a90889SApple OSS Distributions 	u_int32_t       el_info_reserved_1;     /* reserved (APPLE) */
124*43a90889SApple OSS Distributions 
125*43a90889SApple OSS Distributions 	uid_t           el_uid;         /* user ID */
126*43a90889SApple OSS Distributions 	guid_t          el_uguid;       /* user GUID */
127*43a90889SApple OSS Distributions 	u_int32_t       el_uguid_valid; /* TTL on translation result (seconds) */
128*43a90889SApple OSS Distributions 	ntsid_t         el_usid;        /* user NT SID */
129*43a90889SApple OSS Distributions 	u_int32_t       el_usid_valid;  /* TTL on translation result (seconds) */
130*43a90889SApple OSS Distributions 	gid_t           el_gid;         /* group ID */
131*43a90889SApple OSS Distributions 	guid_t          el_gguid;       /* group GUID */
132*43a90889SApple OSS Distributions 	u_int32_t       el_gguid_valid; /* TTL on translation result (seconds) */
133*43a90889SApple OSS Distributions 	ntsid_t         el_gsid;        /* group SID */
134*43a90889SApple OSS Distributions 	u_int32_t       el_gsid_valid;  /* TTL on translation result (seconds) */
135*43a90889SApple OSS Distributions 	u_int32_t       el_member_valid; /* TTL on group lookup result */
136*43a90889SApple OSS Distributions 	u_int32_t       el_sup_grp_cnt;  /* count of supplemental groups up to NGROUPS */
137*43a90889SApple OSS Distributions 	gid_t           el_sup_groups[NGROUPS_MAX];     /* supplemental group list */
138*43a90889SApple OSS Distributions };
139*43a90889SApple OSS Distributions 
140*43a90889SApple OSS Distributions struct kauth_cache_sizes {
141*43a90889SApple OSS Distributions 	u_int32_t kcs_group_size;
142*43a90889SApple OSS Distributions 	u_int32_t kcs_id_size;
143*43a90889SApple OSS Distributions };
144*43a90889SApple OSS Distributions 
145*43a90889SApple OSS Distributions #define KAUTH_EXTLOOKUP_REGISTER        (0)
146*43a90889SApple OSS Distributions #define KAUTH_EXTLOOKUP_RESULT          (1<<0)
147*43a90889SApple OSS Distributions #define KAUTH_EXTLOOKUP_WORKER          (1<<1)
148*43a90889SApple OSS Distributions #define KAUTH_EXTLOOKUP_DEREGISTER      (1<<2)
149*43a90889SApple OSS Distributions #define KAUTH_GET_CACHE_SIZES           (1<<3)
150*43a90889SApple OSS Distributions #define KAUTH_SET_CACHE_SIZES           (1<<4)
151*43a90889SApple OSS Distributions #define KAUTH_CLEAR_CACHES              (1<<5)
152*43a90889SApple OSS Distributions 
153*43a90889SApple OSS Distributions #define IDENTITYSVC_ENTITLEMENT         "com.apple.private.identitysvc"
154*43a90889SApple OSS Distributions 
155*43a90889SApple OSS Distributions #ifdef KERNEL
156*43a90889SApple OSS Distributions #pragma mark - kauth_cred
157*43a90889SApple OSS Distributions 
158*43a90889SApple OSS Distributions /*!
159*43a90889SApple OSS Distributions  * @brief
160*43a90889SApple OSS Distributions  * Retains a credential data structure.
161*43a90889SApple OSS Distributions  *
162*43a90889SApple OSS Distributions  * @Description
163*43a90889SApple OSS Distributions  * The reference returned must be released with @c kauth_cred_unref().
164*43a90889SApple OSS Distributions  */
165*43a90889SApple OSS Distributions extern void         kauth_cred_ref(kauth_cred_t cred);
166*43a90889SApple OSS Distributions 
167*43a90889SApple OSS Distributions /*!
168*43a90889SApple OSS Distributions  * @brief
169*43a90889SApple OSS Distributions  * Releases a credential data structure, and nils out the pointer.
170*43a90889SApple OSS Distributions  *
171*43a90889SApple OSS Distributions  * @Description
172*43a90889SApple OSS Distributions  * @c credp must be non NULL, but can point to a NULL/NOCRED credential.
173*43a90889SApple OSS Distributions  */
174*43a90889SApple OSS Distributions extern void         kauth_cred_unref(kauth_cred_t *credp);
175*43a90889SApple OSS Distributions 
176*43a90889SApple OSS Distributions 
177*43a90889SApple OSS Distributions /*!
178*43a90889SApple OSS Distributions  * @brief
179*43a90889SApple OSS Distributions  * Returns the current thread assumed credentials.
180*43a90889SApple OSS Distributions  *
181*43a90889SApple OSS Distributions  * @discussion
182*43a90889SApple OSS Distributions  * These might differ from the proc's credential if settid() has been called.
183*43a90889SApple OSS Distributions  * This never returns NULL/NOCRED.
184*43a90889SApple OSS Distributions  *
185*43a90889SApple OSS Distributions  * This function doesn't take a reference, and the returned pointer is valid
186*43a90889SApple OSS Distributions  * for the duration of the current syscall.
187*43a90889SApple OSS Distributions  *
188*43a90889SApple OSS Distributions  * This function returns cached credentials without a reference which are valid
189*43a90889SApple OSS Distributions  * for the duration of a MACF hook.  If a copy of this pointer has to be stashed,
190*43a90889SApple OSS Distributions  * the credentials must be retained with kauth_cred_ref().
191*43a90889SApple OSS Distributions  *
192*43a90889SApple OSS Distributions  * (this function should really be called @c current_thread_cred())
193*43a90889SApple OSS Distributions  */
194*43a90889SApple OSS Distributions extern kauth_cred_t kauth_cred_get(void) __pure2;
195*43a90889SApple OSS Distributions #define current_thread_cred()           kauth_cred_get()
196*43a90889SApple OSS Distributions 
197*43a90889SApple OSS Distributions /*!
198*43a90889SApple OSS Distributions  * @brief
199*43a90889SApple OSS Distributions  * Returns the current MAC label slot value for the thread assumed credentials.
200*43a90889SApple OSS Distributions  *
201*43a90889SApple OSS Distributions  * @discussion
202*43a90889SApple OSS Distributions  * These might differ from the proc's credential if settid() has been called.
203*43a90889SApple OSS Distributions  */
204*43a90889SApple OSS Distributions extern intptr_t current_thread_cred_label_get(int slot) __pure2;
205*43a90889SApple OSS Distributions 
206*43a90889SApple OSS Distributions /*!
207*43a90889SApple OSS Distributions  * @brief
208*43a90889SApple OSS Distributions  * Returns the current thread assumed credentials, with a reference.
209*43a90889SApple OSS Distributions  *
210*43a90889SApple OSS Distributions  * @discussion
211*43a90889SApple OSS Distributions  * These might differ from the proc's credential if settid() has been called.
212*43a90889SApple OSS Distributions  * This never returns NULL/NOCRED.
213*43a90889SApple OSS Distributions  *
214*43a90889SApple OSS Distributions  * The caller must call kauth_cred_unref() to dispose of the returned value.
215*43a90889SApple OSS Distributions  *
216*43a90889SApple OSS Distributions  * This is equivalent to @c kauth_cred_ref(kauth_cred_get())
217*43a90889SApple OSS Distributions  *
218*43a90889SApple OSS Distributions  * (this function should really be called @c current_thread_cred_ref())
219*43a90889SApple OSS Distributions  */
220*43a90889SApple OSS Distributions extern kauth_cred_t kauth_cred_get_with_ref(void);
221*43a90889SApple OSS Distributions #define current_thread_cred_ref()       kauth_cred_get_with_ref()
222*43a90889SApple OSS Distributions 
223*43a90889SApple OSS Distributions /*!
224*43a90889SApple OSS Distributions  * @brief
225*43a90889SApple OSS Distributions  * Returns the current cached proc credentials.
226*43a90889SApple OSS Distributions  *
227*43a90889SApple OSS Distributions  * @discussion
228*43a90889SApple OSS Distributions  * This function will panic if its argument is neither PROC_NULL nor
229*43a90889SApple OSS Distributions  * current_proc() (this can be used to protect against programming mistakes
230*43a90889SApple OSS Distributions  * assuming the incorrect context).
231*43a90889SApple OSS Distributions  *
232*43a90889SApple OSS Distributions  * Note that this function returns the credential the proc had
233*43a90889SApple OSS Distributions  * at the time of the last syscall this thread performed.
234*43a90889SApple OSS Distributions  *
235*43a90889SApple OSS Distributions  * This function returns cached credentials without a reference which are valid
236*43a90889SApple OSS Distributions  * for the duration of a syscall only. If a copy of this pointer has to be
237*43a90889SApple OSS Distributions  * stashed, the credentials must be retained with kauth_cred_ref().
238*43a90889SApple OSS Distributions  *
239*43a90889SApple OSS Distributions  * For the freshest credentials, kauth_cred_proc_ref()
240*43a90889SApple OSS Distributions  * must be used against @c current_proc().
241*43a90889SApple OSS Distributions  *
242*43a90889SApple OSS Distributions  * This never returns NULL/NOCRED.
243*43a90889SApple OSS Distributions  */
244*43a90889SApple OSS Distributions extern kauth_cred_t current_cached_proc_cred(proc_t) __pure2;
245*43a90889SApple OSS Distributions 
246*43a90889SApple OSS Distributions /*!
247*43a90889SApple OSS Distributions  * @brief
248*43a90889SApple OSS Distributions  * Returns the current MAC label slot value for the cached proc credentials.
249*43a90889SApple OSS Distributions  */
250*43a90889SApple OSS Distributions extern intptr_t current_cached_proc_label_get(int slot) __pure2;
251*43a90889SApple OSS Distributions 
252*43a90889SApple OSS Distributions /*!
253*43a90889SApple OSS Distributions  * @brief
254*43a90889SApple OSS Distributions  * Returns the current cached proc credentials, with a reference.
255*43a90889SApple OSS Distributions  *
256*43a90889SApple OSS Distributions  * @discussion
257*43a90889SApple OSS Distributions  * This function will panic if its argument is neither PROC_NULL nor
258*43a90889SApple OSS Distributions  * current_proc() (this can be used to protect against programming mistakes
259*43a90889SApple OSS Distributions  * assuming the incorrect context).
260*43a90889SApple OSS Distributions  *
261*43a90889SApple OSS Distributions  * Note that this function returns the credential the proc had
262*43a90889SApple OSS Distributions  * at the time of the last syscall this thread performed.
263*43a90889SApple OSS Distributions  *
264*43a90889SApple OSS Distributions  * For the freshest credentials, kauth_cred_proc_ref()
265*43a90889SApple OSS Distributions  * must be used against @c current_proc().
266*43a90889SApple OSS Distributions  *
267*43a90889SApple OSS Distributions  * The caller must call kauth_cred_unref() to dispose of the returned value.
268*43a90889SApple OSS Distributions  *
269*43a90889SApple OSS Distributions  * This never returns NULL/NOCRED.
270*43a90889SApple OSS Distributions  */
271*43a90889SApple OSS Distributions extern kauth_cred_t current_cached_proc_cred_ref(proc_t);
272*43a90889SApple OSS Distributions 
273*43a90889SApple OSS Distributions /*!
274*43a90889SApple OSS Distributions  * @brief
275*43a90889SApple OSS Distributions  * Returns the specified proc credentials, with a reference.
276*43a90889SApple OSS Distributions  *
277*43a90889SApple OSS Distributions  * @discussion
278*43a90889SApple OSS Distributions  * The caller must call kauth_cred_unref() to dispose of the returned value.
279*43a90889SApple OSS Distributions  * This never returns NULL/NOCRED.
280*43a90889SApple OSS Distributions  *
281*43a90889SApple OSS Distributions  * The caller must call kauth_cred_unref() to dispose of the returned value.
282*43a90889SApple OSS Distributions  */
283*43a90889SApple OSS Distributions extern kauth_cred_t kauth_cred_proc_ref(proc_t procp);
284*43a90889SApple OSS Distributions 
285*43a90889SApple OSS Distributions /*!
286*43a90889SApple OSS Distributions  * @brief
287*43a90889SApple OSS Distributions  * Returns the specified proc credentials, with a reference, or NOCRED.
288*43a90889SApple OSS Distributions  *
289*43a90889SApple OSS Distributions  * @discussion
290*43a90889SApple OSS Distributions  * The caller must call kauth_cred_unref() to dispose of the returned value.
291*43a90889SApple OSS Distributions  */
292*43a90889SApple OSS Distributions extern kauth_cred_t kauth_cred_proc_ref_for_pid(pid_t pid);
293*43a90889SApple OSS Distributions 
294*43a90889SApple OSS Distributions /*!
295*43a90889SApple OSS Distributions  * @brief
296*43a90889SApple OSS Distributions  * Returns the specified proc credentials, with a reference, or NOCRED.
297*43a90889SApple OSS Distributions  *
298*43a90889SApple OSS Distributions  * @discussion
299*43a90889SApple OSS Distributions  * The caller must call kauth_cred_unref() to dispose of the returned value.
300*43a90889SApple OSS Distributions  */
301*43a90889SApple OSS Distributions extern kauth_cred_t kauth_cred_proc_ref_for_pidversion(pid_t pid, uint32_t version);
302*43a90889SApple OSS Distributions 
303*43a90889SApple OSS Distributions 
304*43a90889SApple OSS Distributions /*!
305*43a90889SApple OSS Distributions  * @brief
306*43a90889SApple OSS Distributions  * Obsolete way to create a valid posix-only credential structure out of
307*43a90889SApple OSS Distributions  * a model, DO NOT USE.
308*43a90889SApple OSS Distributions  */
309*43a90889SApple OSS Distributions extern kauth_cred_t kauth_cred_create(kauth_cred_t cred);
310*43a90889SApple OSS Distributions 
311*43a90889SApple OSS Distributions 
312*43a90889SApple OSS Distributions #pragma mark kauth_cred: accessors
313*43a90889SApple OSS Distributions 
314*43a90889SApple OSS Distributions /*!
315*43a90889SApple OSS Distributions  * @brief
316*43a90889SApple OSS Distributions  * Returns the effective user ID for the specified @c kauth_cred_t.
317*43a90889SApple OSS Distributions  */
318*43a90889SApple OSS Distributions extern uid_t        kauth_cred_getuid(kauth_cred_t _cred);
319*43a90889SApple OSS Distributions 
320*43a90889SApple OSS Distributions /*!
321*43a90889SApple OSS Distributions  * @brief
322*43a90889SApple OSS Distributions  * Returns the real user ID for the specified @c kauth_cred_t.
323*43a90889SApple OSS Distributions  */
324*43a90889SApple OSS Distributions extern uid_t        kauth_cred_getruid(kauth_cred_t _cred);
325*43a90889SApple OSS Distributions 
326*43a90889SApple OSS Distributions /*!
327*43a90889SApple OSS Distributions  * @brief
328*43a90889SApple OSS Distributions  * Returns the saved user ID for the specified @c kauth_cred_t.
329*43a90889SApple OSS Distributions  */
330*43a90889SApple OSS Distributions extern uid_t        kauth_cred_getsvuid(kauth_cred_t _cred);
331*43a90889SApple OSS Distributions 
332*43a90889SApple OSS Distributions /*!
333*43a90889SApple OSS Distributions  * @brief
334*43a90889SApple OSS Distributions  * Returns whether the current credential effective user ID is the super user.
335*43a90889SApple OSS Distributions  */
336*43a90889SApple OSS Distributions extern int          kauth_cred_issuser(kauth_cred_t _cred);
337*43a90889SApple OSS Distributions 
338*43a90889SApple OSS Distributions /*!
339*43a90889SApple OSS Distributions  * @brief
340*43a90889SApple OSS Distributions  * Returns the effective group ID for the specified @c kauth_cred_t.
341*43a90889SApple OSS Distributions  */
342*43a90889SApple OSS Distributions extern gid_t        kauth_cred_getgid(kauth_cred_t _cred);
343*43a90889SApple OSS Distributions 
344*43a90889SApple OSS Distributions /*!
345*43a90889SApple OSS Distributions  * @brief
346*43a90889SApple OSS Distributions  * Returns the real group ID for the specified @c kauth_cred_t.
347*43a90889SApple OSS Distributions  */
348*43a90889SApple OSS Distributions extern gid_t        kauth_cred_getrgid(kauth_cred_t _cred);
349*43a90889SApple OSS Distributions 
350*43a90889SApple OSS Distributions /*!
351*43a90889SApple OSS Distributions  * @brief
352*43a90889SApple OSS Distributions  * Returns the saved group ID for the specified @c kauth_cred_t.
353*43a90889SApple OSS Distributions  */
354*43a90889SApple OSS Distributions extern gid_t        kauth_cred_getsvgid(kauth_cred_t _cred);
355*43a90889SApple OSS Distributions 
356*43a90889SApple OSS Distributions /*!
357*43a90889SApple OSS Distributions  * @brief
358*43a90889SApple OSS Distributions  * Returns the effective user ID for the current thread.
359*43a90889SApple OSS Distributions  *
360*43a90889SApple OSS Distributions  * @Description
361*43a90889SApple OSS Distributions  * Equivalent to @c kauth_getuid(kauth_cred_get())
362*43a90889SApple OSS Distributions  */
363*43a90889SApple OSS Distributions extern uid_t        kauth_getuid(void);
364*43a90889SApple OSS Distributions 
365*43a90889SApple OSS Distributions /*!
366*43a90889SApple OSS Distributions  * @brief
367*43a90889SApple OSS Distributions  * Returns the real user ID for the current thread.
368*43a90889SApple OSS Distributions  *
369*43a90889SApple OSS Distributions  * @Description
370*43a90889SApple OSS Distributions  * Equivalent to @c kauth_getruid(kauth_cred_get())
371*43a90889SApple OSS Distributions  */
372*43a90889SApple OSS Distributions extern uid_t        kauth_getruid(void);
373*43a90889SApple OSS Distributions 
374*43a90889SApple OSS Distributions /*!
375*43a90889SApple OSS Distributions  * @brief
376*43a90889SApple OSS Distributions  * Returns the effective group ID for the current thread.
377*43a90889SApple OSS Distributions  *
378*43a90889SApple OSS Distributions  * @Description
379*43a90889SApple OSS Distributions  * Equivalent to @c kauth_getgid(kauth_cred_get())
380*43a90889SApple OSS Distributions  */
381*43a90889SApple OSS Distributions extern gid_t        kauth_getgid(void);
382*43a90889SApple OSS Distributions 
383*43a90889SApple OSS Distributions /*!
384*43a90889SApple OSS Distributions  * @brief
385*43a90889SApple OSS Distributions  * Returns the real group ID for the current thread.
386*43a90889SApple OSS Distributions  *
387*43a90889SApple OSS Distributions  * @Description
388*43a90889SApple OSS Distributions  * Equivalent to @c kauth_getrgid(kauth_cred_get())
389*43a90889SApple OSS Distributions  */
390*43a90889SApple OSS Distributions extern gid_t        kauth_getrgid(void);
391*43a90889SApple OSS Distributions 
392*43a90889SApple OSS Distributions 
393*43a90889SApple OSS Distributions #pragma mark kauth_cred: MACF label updates
394*43a90889SApple OSS Distributions 
395*43a90889SApple OSS Distributions struct label;
396*43a90889SApple OSS Distributions 
397*43a90889SApple OSS Distributions /*!
398*43a90889SApple OSS Distributions  * @brief
399*43a90889SApple OSS Distributions  * Updates the MAC label associated with a credential.
400*43a90889SApple OSS Distributions  *
401*43a90889SApple OSS Distributions  * @discussion
402*43a90889SApple OSS Distributions  * This function returns a new credential where the passed
403*43a90889SApple OSS Distributions  * in label is updated with the specified one.
404*43a90889SApple OSS Distributions  *
405*43a90889SApple OSS Distributions  * This will cause the @c cred_label_associate() MAC hook to be invoked
406*43a90889SApple OSS Distributions  * first (so that all MAC policies have a chance to make the newly formed
407*43a90889SApple OSS Distributions  * credential inherit labels) then the @c cred_label_update() hook
408*43a90889SApple OSS Distributions  * (which will allow the newly made credential labels to be overridden).
409*43a90889SApple OSS Distributions  *
410*43a90889SApple OSS Distributions  * This never returns NULL/NOCRED.
411*43a90889SApple OSS Distributions  *
412*43a90889SApple OSS Distributions  * @param cred          (ref consumed) the credentials to use as a model.
413*43a90889SApple OSS Distributions  * @param label         the model label to copy from.
414*43a90889SApple OSS Distributions  */
415*43a90889SApple OSS Distributions extern kauth_cred_t kauth_cred_label_update(
416*43a90889SApple OSS Distributions 	kauth_cred_t            cred,
417*43a90889SApple OSS Distributions 	struct label           *label);
418*43a90889SApple OSS Distributions 
419*43a90889SApple OSS Distributions 
420*43a90889SApple OSS Distributions /*!
421*43a90889SApple OSS Distributions  * @brief
422*43a90889SApple OSS Distributions  * Updates the MAC label insde the proc's credentials.
423*43a90889SApple OSS Distributions  *
424*43a90889SApple OSS Distributions  * @discussion
425*43a90889SApple OSS Distributions  * This function applies @c kauth_cred_label_update() to the specified
426*43a90889SApple OSS Distributions  * process's credntials, and updates the process's credentials
427*43a90889SApple OSS Distributions  * with the outcome.
428*43a90889SApple OSS Distributions  *
429*43a90889SApple OSS Distributions  * This function never fails (returns 0 all the time).
430*43a90889SApple OSS Distributions  *
431*43a90889SApple OSS Distributions  * @param proc          the process which creedntials must be updated.
432*43a90889SApple OSS Distributions  * @param label         the model label to copy from.
433*43a90889SApple OSS Distributions  */
434*43a90889SApple OSS Distributions extern int          kauth_proc_label_update(
435*43a90889SApple OSS Distributions 	struct proc            *proc,
436*43a90889SApple OSS Distributions 	struct label           *label);
437*43a90889SApple OSS Distributions 
438*43a90889SApple OSS Distributions 
439*43a90889SApple OSS Distributions #pragma mark kauth_cred: group membership (private API)
440*43a90889SApple OSS Distributions /*
441*43a90889SApple OSS Distributions  * This part of the kernel is considered private and prototypes
442*43a90889SApple OSS Distributions  * will be eventually be removed from the public headers.
443*43a90889SApple OSS Distributions  */
444*43a90889SApple OSS Distributions 
445*43a90889SApple OSS Distributions extern int          kauth_cred_pwnam2guid(char *pwnam, guid_t *guidp);
446*43a90889SApple OSS Distributions extern int          kauth_cred_grnam2guid(char *grnam, guid_t *guidp);
447*43a90889SApple OSS Distributions extern int          kauth_cred_guid2pwnam(guid_t *guidp, char *pwnam);
448*43a90889SApple OSS Distributions extern int          kauth_cred_guid2grnam(guid_t *guidp, char *grnam);
449*43a90889SApple OSS Distributions extern int          kauth_cred_guid2uid(guid_t *_guid, uid_t *_uidp);
450*43a90889SApple OSS Distributions extern int          kauth_cred_guid2gid(guid_t *_guid, gid_t *_gidp);
451*43a90889SApple OSS Distributions extern int          kauth_cred_ntsid2uid(ntsid_t *_sid, uid_t *_uidp);
452*43a90889SApple OSS Distributions extern int          kauth_cred_ntsid2gid(ntsid_t *_sid, gid_t *_gidp);
453*43a90889SApple OSS Distributions extern int          kauth_cred_ntsid2guid(ntsid_t *_sid, guid_t *_guidp);
454*43a90889SApple OSS Distributions extern int          kauth_cred_uid2guid(uid_t _uid, guid_t *_guidp);
455*43a90889SApple OSS Distributions extern int          kauth_cred_getguid(kauth_cred_t _cred, guid_t *_guidp);
456*43a90889SApple OSS Distributions extern int          kauth_cred_gid2guid(gid_t _gid, guid_t *_guidp);
457*43a90889SApple OSS Distributions extern int          kauth_cred_uid2ntsid(uid_t _uid, ntsid_t *_sidp);
458*43a90889SApple OSS Distributions extern int          kauth_cred_getntsid(kauth_cred_t _cred, ntsid_t *_sidp);
459*43a90889SApple OSS Distributions extern int          kauth_cred_gid2ntsid(gid_t _gid, ntsid_t *_sidp);
460*43a90889SApple OSS Distributions extern int          kauth_cred_guid2ntsid(guid_t *_guid, ntsid_t *_sidp);
461*43a90889SApple OSS Distributions extern int          kauth_cred_ismember_gid(kauth_cred_t _cred, gid_t _gid, int *_resultp);
462*43a90889SApple OSS Distributions extern int          kauth_cred_ismember_guid(kauth_cred_t _cred, guid_t *_guidp, int *_resultp);
463*43a90889SApple OSS Distributions extern int          kauth_cred_nfs4domain2dsnode(char *nfs4domain, char *dsnode);
464*43a90889SApple OSS Distributions extern int          kauth_cred_dsnode2nfs4domain(char *dsnode, char *nfs4domain);
465*43a90889SApple OSS Distributions 
466*43a90889SApple OSS Distributions extern int          groupmember(gid_t gid, kauth_cred_t cred);
467*43a90889SApple OSS Distributions 
468*43a90889SApple OSS Distributions 
469*43a90889SApple OSS Distributions #ifdef KERNEL_PRIVATE
470*43a90889SApple OSS Distributions #pragma mark kauth_cred: private KPI
471*43a90889SApple OSS Distributions 
472*43a90889SApple OSS Distributions extern int          kauth_cred_getgroups(kauth_cred_t _cred, gid_t *_groups, size_t *_groupcount);
473*43a90889SApple OSS Distributions 
474*43a90889SApple OSS Distributions #endif /* KERNEL_PRIVATE */
475*43a90889SApple OSS Distributions #ifdef XNU_KERNEL_PRIVATE
476*43a90889SApple OSS Distributions #pragma mark kauth_cred: XNU only
477*43a90889SApple OSS Distributions #pragma GCC visibility push(hidden)
478*43a90889SApple OSS Distributions 
479*43a90889SApple OSS Distributions extern lck_grp_t    kauth_lck_grp;
480*43a90889SApple OSS Distributions 
481*43a90889SApple OSS Distributions extern void         kauth_init(void);
482*43a90889SApple OSS Distributions 
483*43a90889SApple OSS Distributions #pragma mark XNU only: kauth_cred interfaces
484*43a90889SApple OSS Distributions 
485*43a90889SApple OSS Distributions extern kauth_cred_t posix_cred_create(posix_cred_t pcred);
486*43a90889SApple OSS Distributions extern posix_cred_t posix_cred_get(kauth_cred_t cred) __pure2;
487*43a90889SApple OSS Distributions extern int          posix_cred_access(kauth_cred_t cred, id_t object_uid, id_t object_gid, mode_t object_mode, mode_t mode_req);
488*43a90889SApple OSS Distributions 
489*43a90889SApple OSS Distributions extern int          cantrace(proc_t cur_procp, kauth_cred_t creds, proc_t traced_procp, int *errp);
490*43a90889SApple OSS Distributions extern kauth_cred_t kauth_cred_copy_real(kauth_cred_t cred);
491*43a90889SApple OSS Distributions 
492*43a90889SApple OSS Distributions 
493*43a90889SApple OSS Distributions /*!
494*43a90889SApple OSS Distributions  * @brief
495*43a90889SApple OSS Distributions  * Type of functions used to derive credentials from an original one.
496*43a90889SApple OSS Distributions  *
497*43a90889SApple OSS Distributions  * @description
498*43a90889SApple OSS Distributions  * The @c model argument is an on-stack template that is to be mutated
499*43a90889SApple OSS Distributions  * in place, and that will be used to make the derived credential.
500*43a90889SApple OSS Distributions  *
501*43a90889SApple OSS Distributions  * The function should return false if it made no modifications,
502*43a90889SApple OSS Distributions  * and true if it did (it is OK to return true incorrectly,
503*43a90889SApple OSS Distributions  * it is just a little less efficient).
504*43a90889SApple OSS Distributions  */
505*43a90889SApple OSS Distributions typedef bool (^kauth_cred_derive_t)(kauth_cred_t parent, kauth_cred_t model);
506*43a90889SApple OSS Distributions 
507*43a90889SApple OSS Distributions /*!
508*43a90889SApple OSS Distributions  * @brief
509*43a90889SApple OSS Distributions  * Derive a credential from a given cred.
510*43a90889SApple OSS Distributions  *
511*43a90889SApple OSS Distributions  * @description
512*43a90889SApple OSS Distributions  * This function never returns NULL.
513*43a90889SApple OSS Distributions  */
514*43a90889SApple OSS Distributions extern kauth_cred_t kauth_cred_derive(kauth_cred_t cred, kauth_cred_derive_t fn);
515*43a90889SApple OSS Distributions 
516*43a90889SApple OSS Distributions __enum_decl(proc_settoken_t, uint32_t, {
517*43a90889SApple OSS Distributions 	PROC_SETTOKEN_NONE       = 0x0000,
518*43a90889SApple OSS Distributions 	PROC_SETTOKEN_LAZY       = 0x0001, /* set the security token on change */
519*43a90889SApple OSS Distributions 	PROC_SETTOKEN_ALWAYS     = 0x0002, /* set the security token all the time */
520*43a90889SApple OSS Distributions 	PROC_SETTOKEN_SETUGID    = 0x0003, /* PROC_SETTOKEN_LAZY + set P_SUGID */
521*43a90889SApple OSS Distributions });
522*43a90889SApple OSS Distributions 
523*43a90889SApple OSS Distributions /*!
524*43a90889SApple OSS Distributions  * @brief
525*43a90889SApple OSS Distributions  * Update the credential on the specified proc.
526*43a90889SApple OSS Distributions  *
527*43a90889SApple OSS Distributions  * @description
528*43a90889SApple OSS Distributions  * The function returns true if an update took place.
529*43a90889SApple OSS Distributions  */
530*43a90889SApple OSS Distributions extern bool         kauth_cred_proc_update(proc_t p, proc_settoken_t action, kauth_cred_derive_t fn);
531*43a90889SApple OSS Distributions 
532*43a90889SApple OSS Distributions extern bool         kauth_cred_model_setresuid(kauth_cred_t model, uid_t ruid, uid_t euid, uid_t svuid, uid_t gmuid);
533*43a90889SApple OSS Distributions extern bool         kauth_cred_model_setresgid(kauth_cred_t model, gid_t rgid, gid_t egid, gid_t svgid);
534*43a90889SApple OSS Distributions extern bool         kauth_cred_model_setuidgid(kauth_cred_t model, uid_t uid, gid_t gid);
535*43a90889SApple OSS Distributions extern bool         kauth_cred_model_setgroups(kauth_cred_t model, gid_t *groups, size_t groupcount, uid_t gmuid);
536*43a90889SApple OSS Distributions extern bool         kauth_cred_model_setauditinfo(kauth_cred_t model, au_session_t *);
537*43a90889SApple OSS Distributions 
538*43a90889SApple OSS Distributions extern void         kauth_cred_thread_update(struct thread *, proc_t);
539*43a90889SApple OSS Distributions #ifdef CONFIG_MACF
540*43a90889SApple OSS Distributions extern void         kauth_proc_label_update_execve(struct proc *p, struct vfs_context *ctx, struct vnode *vp, off_t offset, struct vnode *scriptvp, struct label *scriptlabel, struct label *execlabel, unsigned int *csflags, void *psattr, int *disjoint, int *update_return);
541*43a90889SApple OSS Distributions #endif
542*43a90889SApple OSS Distributions extern int          kauth_cred_gid_subset(kauth_cred_t _cred1, kauth_cred_t _cred2, int *_resultp);
543*43a90889SApple OSS Distributions 
544*43a90889SApple OSS Distributions extern kauth_cred_t kauth_cred_require(kauth_cred_t cred) __pure2;
545*43a90889SApple OSS Distributions 
546*43a90889SApple OSS Distributions extern void         kauth_cred_set(kauth_cred_t *credp, kauth_cred_t new_cred);
547*43a90889SApple OSS Distributions #if CONFIG_EXT_RESOLVER
548*43a90889SApple OSS Distributions extern void         kauth_resolver_identity_reset(void);
549*43a90889SApple OSS Distributions #endif
550*43a90889SApple OSS Distributions 
551*43a90889SApple OSS Distributions /* update the thread's proc cred cache, called on syscall entry */
552*43a90889SApple OSS Distributions extern void         current_cached_proc_cred_update(void);
553*43a90889SApple OSS Distributions 
554*43a90889SApple OSS Distributions /*
555*43a90889SApple OSS Distributions  * `kauth_cred_set` and `kauth_cred_unref` take pointers to a
556*43a90889SApple OSS Distributions  * `kauth_cred_t`, which the compiler considers strictly different from a
557*43a90889SApple OSS Distributions  * pointer to a signed `kauth_cred_t` (as it should do).  These macros
558*43a90889SApple OSS Distributions  * therefore authenticate the arguments into naked locals, pass them to the
559*43a90889SApple OSS Distributions  * function and then write back the results, signing them in the process.
560*43a90889SApple OSS Distributions  */
561*43a90889SApple OSS Distributions #define kauth_cred_set(credp, new_cred) \
562*43a90889SApple OSS Distributions     do { \
563*43a90889SApple OSS Distributions 	    kauth_cred_t _cred __single = *(credp); \
564*43a90889SApple OSS Distributions 	    (kauth_cred_set)(&_cred, (new_cred)); \
565*43a90889SApple OSS Distributions 	    *(credp) = _cred; \
566*43a90889SApple OSS Distributions     } while (0)
567*43a90889SApple OSS Distributions 
568*43a90889SApple OSS Distributions #define kauth_cred_unref(credp) \
569*43a90889SApple OSS Distributions     do { \
570*43a90889SApple OSS Distributions 	    kauth_cred_t _credp __single = *(credp); \
571*43a90889SApple OSS Distributions 	    (kauth_cred_unref)(&_credp); \
572*43a90889SApple OSS Distributions 	    *(credp) = _credp; \
573*43a90889SApple OSS Distributions     } while (0)
574*43a90889SApple OSS Distributions 
575*43a90889SApple OSS Distributions #pragma GCC visibility pop
576*43a90889SApple OSS Distributions #endif /* XNU_KERNEL_PRIVATE */
577*43a90889SApple OSS Distributions #endif /* KERNEL */
578*43a90889SApple OSS Distributions #if defined(KERNEL) || defined (_SYS_ACL_H)
579*43a90889SApple OSS Distributions #pragma mark - kauth
580*43a90889SApple OSS Distributions #pragma mark kauth: Generic Access Control Lists.
581*43a90889SApple OSS Distributions 
582*43a90889SApple OSS Distributions typedef u_int32_t kauth_ace_rights_t;
583*43a90889SApple OSS Distributions 
584*43a90889SApple OSS Distributions /* Access Control List Entry (ACE) */
585*43a90889SApple OSS Distributions struct kauth_ace {
586*43a90889SApple OSS Distributions 	guid_t          ace_applicable;
587*43a90889SApple OSS Distributions 	u_int32_t       ace_flags;
588*43a90889SApple OSS Distributions #define KAUTH_ACE_KINDMASK              0xf
589*43a90889SApple OSS Distributions #define KAUTH_ACE_PERMIT                1
590*43a90889SApple OSS Distributions #define KAUTH_ACE_DENY                  2
591*43a90889SApple OSS Distributions #define KAUTH_ACE_AUDIT                 3       /* not implemented */
592*43a90889SApple OSS Distributions #define KAUTH_ACE_ALARM                 4       /* not implemented */
593*43a90889SApple OSS Distributions #define KAUTH_ACE_INHERITED             (1<<4)
594*43a90889SApple OSS Distributions #define KAUTH_ACE_FILE_INHERIT          (1<<5)
595*43a90889SApple OSS Distributions #define KAUTH_ACE_DIRECTORY_INHERIT     (1<<6)
596*43a90889SApple OSS Distributions #define KAUTH_ACE_LIMIT_INHERIT         (1<<7)
597*43a90889SApple OSS Distributions #define KAUTH_ACE_ONLY_INHERIT          (1<<8)
598*43a90889SApple OSS Distributions #define KAUTH_ACE_SUCCESS               (1<<9)  /* not implemented (AUDIT/ALARM) */
599*43a90889SApple OSS Distributions #define KAUTH_ACE_FAILURE               (1<<10) /* not implemented (AUDIT/ALARM) */
600*43a90889SApple OSS Distributions /* All flag bits controlling ACE inheritance */
601*43a90889SApple OSS Distributions #define KAUTH_ACE_INHERIT_CONTROL_FLAGS         \
602*43a90889SApple OSS Distributions 	        (KAUTH_ACE_FILE_INHERIT |       \
603*43a90889SApple OSS Distributions 	         KAUTH_ACE_DIRECTORY_INHERIT |  \
604*43a90889SApple OSS Distributions 	         KAUTH_ACE_LIMIT_INHERIT |      \
605*43a90889SApple OSS Distributions 	         KAUTH_ACE_ONLY_INHERIT)
606*43a90889SApple OSS Distributions 	kauth_ace_rights_t ace_rights;          /* scope specific */
607*43a90889SApple OSS Distributions 	/* These rights are never tested, but may be present in an ACL */
608*43a90889SApple OSS Distributions #define KAUTH_ACE_GENERIC_ALL           (1<<21)
609*43a90889SApple OSS Distributions #define KAUTH_ACE_GENERIC_EXECUTE       (1<<22)
610*43a90889SApple OSS Distributions #define KAUTH_ACE_GENERIC_WRITE         (1<<23)
611*43a90889SApple OSS Distributions #define KAUTH_ACE_GENERIC_READ          (1<<24)
612*43a90889SApple OSS Distributions };
613*43a90889SApple OSS Distributions 
614*43a90889SApple OSS Distributions #ifndef _KAUTH_ACE
615*43a90889SApple OSS Distributions #define _KAUTH_ACE
616*43a90889SApple OSS Distributions typedef struct kauth_ace *kauth_ace_t;
617*43a90889SApple OSS Distributions #endif
618*43a90889SApple OSS Distributions 
619*43a90889SApple OSS Distributions 
620*43a90889SApple OSS Distributions /* Access Control List */
621*43a90889SApple OSS Distributions struct kauth_acl {
622*43a90889SApple OSS Distributions 	u_int32_t       acl_entrycount;
623*43a90889SApple OSS Distributions 	u_int32_t       acl_flags;
624*43a90889SApple OSS Distributions 
625*43a90889SApple OSS Distributions 	struct kauth_ace acl_ace[1];
626*43a90889SApple OSS Distributions };
627*43a90889SApple OSS Distributions 
628*43a90889SApple OSS Distributions /*
629*43a90889SApple OSS Distributions  * XXX this value needs to be raised - 3893388
630*43a90889SApple OSS Distributions  */
631*43a90889SApple OSS Distributions #define KAUTH_ACL_MAX_ENTRIES           128
632*43a90889SApple OSS Distributions 
633*43a90889SApple OSS Distributions /*
634*43a90889SApple OSS Distributions  * The low 16 bits of the flags field are reserved for filesystem
635*43a90889SApple OSS Distributions  * internal use and must be preserved by all APIs.  This includes
636*43a90889SApple OSS Distributions  * round-tripping flags through user-space interfaces.
637*43a90889SApple OSS Distributions  */
638*43a90889SApple OSS Distributions #define KAUTH_ACL_FLAGS_PRIVATE (0xffff)
639*43a90889SApple OSS Distributions 
640*43a90889SApple OSS Distributions /*
641*43a90889SApple OSS Distributions  * The high 16 bits of the flags are used to store attributes and
642*43a90889SApple OSS Distributions  * to request specific handling of the ACL.
643*43a90889SApple OSS Distributions  */
644*43a90889SApple OSS Distributions 
645*43a90889SApple OSS Distributions /* inheritance will be deferred until the first rename operation */
646*43a90889SApple OSS Distributions #define KAUTH_ACL_DEFER_INHERIT (1<<16)
647*43a90889SApple OSS Distributions /* this ACL must not be overwritten as part of an inheritance operation */
648*43a90889SApple OSS Distributions #define KAUTH_ACL_NO_INHERIT    (1<<17)
649*43a90889SApple OSS Distributions 
650*43a90889SApple OSS Distributions /* acl_entrycount that tells us the ACL is not valid */
651*43a90889SApple OSS Distributions #define KAUTH_FILESEC_NOACL ((u_int32_t)(-1))
652*43a90889SApple OSS Distributions 
653*43a90889SApple OSS Distributions /*
654*43a90889SApple OSS Distributions  * If the acl_entrycount field is KAUTH_FILESEC_NOACL, then the size is the
655*43a90889SApple OSS Distributions  * same as a kauth_acl structure; the intent is to put an actual entrycount of
656*43a90889SApple OSS Distributions  * KAUTH_FILESEC_NOACL on disk to distinguish a kauth_filesec_t with an empty
657*43a90889SApple OSS Distributions  * entry (Windows treats this as "deny all") from one that merely indicates a
658*43a90889SApple OSS Distributions  * file group and/or owner guid values.
659*43a90889SApple OSS Distributions  */
660*43a90889SApple OSS Distributions #define KAUTH_ACL_SIZE(c)       (__offsetof(struct kauth_acl, acl_ace) + ((u_int32_t)(c) != KAUTH_FILESEC_NOACL ? ((c) * sizeof(struct kauth_ace)) : 0))
661*43a90889SApple OSS Distributions #define KAUTH_ACL_COPYSIZE(p)   KAUTH_ACL_SIZE((p)->acl_entrycount)
662*43a90889SApple OSS Distributions 
663*43a90889SApple OSS Distributions 
664*43a90889SApple OSS Distributions #ifndef _KAUTH_ACL
665*43a90889SApple OSS Distributions #define _KAUTH_ACL
666*43a90889SApple OSS Distributions typedef struct kauth_acl *kauth_acl_t;
667*43a90889SApple OSS Distributions #endif
668*43a90889SApple OSS Distributions 
669*43a90889SApple OSS Distributions #ifdef KERNEL
670*43a90889SApple OSS Distributions kauth_acl_t     kauth_acl_alloc(int size);
671*43a90889SApple OSS Distributions void            kauth_acl_free(kauth_acl_t fsp);
672*43a90889SApple OSS Distributions #endif
673*43a90889SApple OSS Distributions 
674*43a90889SApple OSS Distributions 
675*43a90889SApple OSS Distributions /*
676*43a90889SApple OSS Distributions  * Extended File Security.
677*43a90889SApple OSS Distributions  */
678*43a90889SApple OSS Distributions 
679*43a90889SApple OSS Distributions /* File Security information */
680*43a90889SApple OSS Distributions struct kauth_filesec {
681*43a90889SApple OSS Distributions 	u_int32_t       fsec_magic;
682*43a90889SApple OSS Distributions #define KAUTH_FILESEC_MAGIC     0x012cc16d
683*43a90889SApple OSS Distributions 	guid_t          fsec_owner;
684*43a90889SApple OSS Distributions 	guid_t          fsec_group;
685*43a90889SApple OSS Distributions 
686*43a90889SApple OSS Distributions 	struct kauth_acl fsec_acl;
687*43a90889SApple OSS Distributions };
688*43a90889SApple OSS Distributions 
689*43a90889SApple OSS Distributions /* backwards compatibility */
690*43a90889SApple OSS Distributions #define fsec_entrycount fsec_acl.acl_entrycount
691*43a90889SApple OSS Distributions #define fsec_flags      fsec_acl.acl_flags
692*43a90889SApple OSS Distributions #define fsec_ace        fsec_acl.acl_ace
693*43a90889SApple OSS Distributions #define KAUTH_FILESEC_FLAGS_PRIVATE     KAUTH_ACL_FLAGS_PRIVATE
694*43a90889SApple OSS Distributions #define KAUTH_FILESEC_DEFER_INHERIT     KAUTH_ACL_DEFER_INHERIT
695*43a90889SApple OSS Distributions #define KAUTH_FILESEC_NO_INHERIT        KAUTH_ACL_NO_INHERIT
696*43a90889SApple OSS Distributions #define KAUTH_FILESEC_NONE      ((kauth_filesec_t)0)
697*43a90889SApple OSS Distributions #define KAUTH_FILESEC_WANTED    ((kauth_filesec_t)1)
698*43a90889SApple OSS Distributions 
699*43a90889SApple OSS Distributions #ifndef _KAUTH_FILESEC
700*43a90889SApple OSS Distributions #define _KAUTH_FILESEC
701*43a90889SApple OSS Distributions typedef struct kauth_filesec *kauth_filesec_t;
702*43a90889SApple OSS Distributions #endif
703*43a90889SApple OSS Distributions 
704*43a90889SApple OSS Distributions #define KAUTH_FILESEC_SIZE(c)           (__offsetof(struct kauth_filesec, fsec_acl) + __offsetof(struct kauth_acl, acl_ace) + (c) * sizeof(struct kauth_ace))
705*43a90889SApple OSS Distributions #define KAUTH_FILESEC_COPYSIZE(p)       KAUTH_FILESEC_SIZE(((p)->fsec_entrycount == KAUTH_FILESEC_NOACL) ? 0 : (p)->fsec_entrycount)
706*43a90889SApple OSS Distributions #define KAUTH_FILESEC_COUNT(s)          (((s)  - KAUTH_FILESEC_SIZE(0)) / sizeof(struct kauth_ace))
707*43a90889SApple OSS Distributions #define KAUTH_FILESEC_VALID(s)          ((s) >= KAUTH_FILESEC_SIZE(0) && (((s) - KAUTH_FILESEC_SIZE(0)) % sizeof(struct kauth_ace)) == 0)
708*43a90889SApple OSS Distributions 
709*43a90889SApple OSS Distributions #define KAUTH_FILESEC_XATTR     "com.apple.system.Security"
710*43a90889SApple OSS Distributions 
711*43a90889SApple OSS Distributions /* Allowable first arguments to kauth_filesec_acl_setendian() */
712*43a90889SApple OSS Distributions #define KAUTH_ENDIAN_HOST       0x00000001      /* set host endianness */
713*43a90889SApple OSS Distributions #define KAUTH_ENDIAN_DISK       0x00000002      /* set disk endianness */
714*43a90889SApple OSS Distributions 
715*43a90889SApple OSS Distributions #endif /* KERNEL || <sys/acl.h> */
716*43a90889SApple OSS Distributions #ifdef KERNEL
717*43a90889SApple OSS Distributions #pragma mark kauth: Scope management
718*43a90889SApple OSS Distributions 
719*43a90889SApple OSS Distributions struct kauth_scope;
720*43a90889SApple OSS Distributions typedef struct kauth_scope *kauth_scope_t;
721*43a90889SApple OSS Distributions struct kauth_listener;
722*43a90889SApple OSS Distributions typedef struct kauth_listener *kauth_listener_t;
723*43a90889SApple OSS Distributions #ifndef _KAUTH_ACTION_T
724*43a90889SApple OSS Distributions typedef int kauth_action_t;
725*43a90889SApple OSS Distributions # define _KAUTH_ACTION_T
726*43a90889SApple OSS Distributions #endif
727*43a90889SApple OSS Distributions 
728*43a90889SApple OSS Distributions typedef int (* kauth_scope_callback_t)(kauth_cred_t _credential,
729*43a90889SApple OSS Distributions     void *_idata,
730*43a90889SApple OSS Distributions     kauth_action_t _action,
731*43a90889SApple OSS Distributions     uintptr_t _arg0,
732*43a90889SApple OSS Distributions     uintptr_t _arg1,
733*43a90889SApple OSS Distributions     uintptr_t _arg2,
734*43a90889SApple OSS Distributions     uintptr_t _arg3);
735*43a90889SApple OSS Distributions 
736*43a90889SApple OSS Distributions #define KAUTH_RESULT_ALLOW      (1)
737*43a90889SApple OSS Distributions #define KAUTH_RESULT_DENY       (2)
738*43a90889SApple OSS Distributions #define KAUTH_RESULT_DEFER      (3)
739*43a90889SApple OSS Distributions 
740*43a90889SApple OSS Distributions struct kauth_acl_eval {
741*43a90889SApple OSS Distributions 	kauth_ace_t             ae_acl;
742*43a90889SApple OSS Distributions 	int                     ae_count;
743*43a90889SApple OSS Distributions 	kauth_ace_rights_t      ae_requested;
744*43a90889SApple OSS Distributions 	kauth_ace_rights_t      ae_residual;
745*43a90889SApple OSS Distributions 	int                     ae_result;
746*43a90889SApple OSS Distributions 	boolean_t               ae_found_deny;
747*43a90889SApple OSS Distributions 	int                     ae_options;
748*43a90889SApple OSS Distributions #define KAUTH_AEVAL_IS_OWNER    (1<<0)          /* authorizing operation for owner */
749*43a90889SApple OSS Distributions #define KAUTH_AEVAL_IN_GROUP    (1<<1)          /* authorizing operation for groupmember */
750*43a90889SApple OSS Distributions #define KAUTH_AEVAL_IN_GROUP_UNKNOWN    (1<<2)          /* authorizing operation for unknown group membership */
751*43a90889SApple OSS Distributions 	/* expansions for 'generic' rights bits */
752*43a90889SApple OSS Distributions 	kauth_ace_rights_t      ae_exp_gall;
753*43a90889SApple OSS Distributions 	kauth_ace_rights_t      ae_exp_gread;
754*43a90889SApple OSS Distributions 	kauth_ace_rights_t      ae_exp_gwrite;
755*43a90889SApple OSS Distributions 	kauth_ace_rights_t      ae_exp_gexec;
756*43a90889SApple OSS Distributions };
757*43a90889SApple OSS Distributions 
758*43a90889SApple OSS Distributions typedef struct kauth_acl_eval *kauth_acl_eval_t;
759*43a90889SApple OSS Distributions 
760*43a90889SApple OSS Distributions kauth_filesec_t kauth_filesec_alloc(int size);
761*43a90889SApple OSS Distributions void            kauth_filesec_free(kauth_filesec_t fsp);
762*43a90889SApple OSS Distributions extern kauth_scope_t kauth_register_scope(const char *_identifier, kauth_scope_callback_t _callback, void *_idata);
763*43a90889SApple OSS Distributions extern void     kauth_deregister_scope(kauth_scope_t _scope);
764*43a90889SApple OSS Distributions __kpi_deprecated("Use EndpointSecurity instead")
765*43a90889SApple OSS Distributions extern kauth_listener_t kauth_listen_scope(const char *_identifier, kauth_scope_callback_t _callback, void *_idata);
766*43a90889SApple OSS Distributions __kpi_deprecated("Use EndpointSecurity instead")
767*43a90889SApple OSS Distributions extern void     kauth_unlisten_scope(kauth_listener_t _scope);
768*43a90889SApple OSS Distributions extern int      kauth_authorize_action(kauth_scope_t _scope, kauth_cred_t _credential, kauth_action_t _action,
769*43a90889SApple OSS Distributions     uintptr_t _arg0, uintptr_t _arg1, uintptr_t _arg2, uintptr_t _arg3);
770*43a90889SApple OSS Distributions 
771*43a90889SApple OSS Distributions /*
772*43a90889SApple OSS Distributions  * Generic scope.
773*43a90889SApple OSS Distributions  */
774*43a90889SApple OSS Distributions #define KAUTH_SCOPE_GENERIC     "com.apple.kauth.generic"
775*43a90889SApple OSS Distributions 
776*43a90889SApple OSS Distributions /* Actions */
777*43a90889SApple OSS Distributions #define KAUTH_GENERIC_ISSUSER                   1
778*43a90889SApple OSS Distributions 
779*43a90889SApple OSS Distributions /*
780*43a90889SApple OSS Distributions  * Process/task scope.
781*43a90889SApple OSS Distributions  */
782*43a90889SApple OSS Distributions #define KAUTH_SCOPE_PROCESS     "com.apple.kauth.process"
783*43a90889SApple OSS Distributions 
784*43a90889SApple OSS Distributions /* Actions */
785*43a90889SApple OSS Distributions #define KAUTH_PROCESS_CANSIGNAL                 1
786*43a90889SApple OSS Distributions #define KAUTH_PROCESS_CANTRACE                  2
787*43a90889SApple OSS Distributions 
788*43a90889SApple OSS Distributions extern int      kauth_authorize_process(kauth_cred_t _credential, kauth_action_t _action,
789*43a90889SApple OSS Distributions     struct proc *_process, uintptr_t _arg1, uintptr_t _arg2, uintptr_t _arg3);
790*43a90889SApple OSS Distributions 
791*43a90889SApple OSS Distributions /*
792*43a90889SApple OSS Distributions  * Vnode operation scope.
793*43a90889SApple OSS Distributions  *
794*43a90889SApple OSS Distributions  * Prototype for vnode_authorize is in vnode.h
795*43a90889SApple OSS Distributions  */
796*43a90889SApple OSS Distributions #define KAUTH_SCOPE_VNODE       "com.apple.kauth.vnode"
797*43a90889SApple OSS Distributions 
798*43a90889SApple OSS Distributions /*
799*43a90889SApple OSS Distributions  * File system operation scope.
800*43a90889SApple OSS Distributions  *
801*43a90889SApple OSS Distributions  */
802*43a90889SApple OSS Distributions #define KAUTH_SCOPE_FILEOP      "com.apple.kauth.fileop"
803*43a90889SApple OSS Distributions 
804*43a90889SApple OSS Distributions /* Actions */
805*43a90889SApple OSS Distributions #define KAUTH_FILEOP_OPEN                       1
806*43a90889SApple OSS Distributions #define KAUTH_FILEOP_CLOSE                      2
807*43a90889SApple OSS Distributions #define KAUTH_FILEOP_RENAME                     3
808*43a90889SApple OSS Distributions #define KAUTH_FILEOP_EXCHANGE                   4
809*43a90889SApple OSS Distributions #define KAUTH_FILEOP_LINK                       5
810*43a90889SApple OSS Distributions #define KAUTH_FILEOP_EXEC                       6
811*43a90889SApple OSS Distributions #define KAUTH_FILEOP_DELETE                     7
812*43a90889SApple OSS Distributions #define KAUTH_FILEOP_WILL_RENAME                8
813*43a90889SApple OSS Distributions 
814*43a90889SApple OSS Distributions /*
815*43a90889SApple OSS Distributions  * arguments passed to KAUTH_FILEOP_OPEN listeners
816*43a90889SApple OSS Distributions  *		arg0 is pointer to vnode (vnode *) for given user path.
817*43a90889SApple OSS Distributions  *		arg1 is pointer to path (char *) passed in to open.
818*43a90889SApple OSS Distributions  * arguments passed to KAUTH_FILEOP_CLOSE listeners
819*43a90889SApple OSS Distributions  *		arg0 is pointer to vnode (vnode *) for file to be closed.
820*43a90889SApple OSS Distributions  *		arg1 is pointer to path (char *) of file to be closed.
821*43a90889SApple OSS Distributions  *		arg2 is close flags.
822*43a90889SApple OSS Distributions  * arguments passed to KAUTH_FILEOP_WILL_RENAME listeners
823*43a90889SApple OSS Distributions  *		arg0 is pointer to vnode (vnode *) of the file being renamed
824*43a90889SApple OSS Distributions  *		arg1 is pointer to the "from" path (char *)
825*43a90889SApple OSS Distributions  *		arg2 is pointer to the "to" path (char *)
826*43a90889SApple OSS Distributions  * arguments passed to KAUTH_FILEOP_RENAME listeners
827*43a90889SApple OSS Distributions  *		arg0 is pointer to "from" path (char *).
828*43a90889SApple OSS Distributions  *		arg1 is pointer to "to" path (char *).
829*43a90889SApple OSS Distributions  * arguments passed to KAUTH_FILEOP_EXCHANGE listeners
830*43a90889SApple OSS Distributions  *		arg0 is pointer to file 1 path (char *).
831*43a90889SApple OSS Distributions  *		arg1 is pointer to file 2 path (char *).
832*43a90889SApple OSS Distributions  * arguments passed to KAUTH_FILEOP_LINK listeners
833*43a90889SApple OSS Distributions  *		arg0 is pointer to path to file we are linking to (char *).
834*43a90889SApple OSS Distributions  *		arg1 is pointer to path to the new link file (char *).
835*43a90889SApple OSS Distributions  * arguments passed to KAUTH_FILEOP_EXEC listeners
836*43a90889SApple OSS Distributions  *		arg0 is pointer to vnode (vnode *) for executable.
837*43a90889SApple OSS Distributions  *		arg1 is pointer to path (char *) to executable.
838*43a90889SApple OSS Distributions  * arguments passed to KAUTH_FILEOP_DELETE listeners
839*43a90889SApple OSS Distributions  *		arg0 is pointer to vnode (vnode *) of file/dir that was deleted.
840*43a90889SApple OSS Distributions  *		arg1 is pointer to path (char *) of file/dir that was deleted.
841*43a90889SApple OSS Distributions  */
842*43a90889SApple OSS Distributions 
843*43a90889SApple OSS Distributions /* Flag values returned to close listeners. */
844*43a90889SApple OSS Distributions #define KAUTH_FILEOP_CLOSE_MODIFIED                     (1<<1)
845*43a90889SApple OSS Distributions 
846*43a90889SApple OSS Distributions /* GUID, NTSID helpers */
847*43a90889SApple OSS Distributions extern guid_t   kauth_null_guid;
848*43a90889SApple OSS Distributions extern int      kauth_guid_equal(guid_t *_guid1, guid_t *_guid2);
849*43a90889SApple OSS Distributions 
850*43a90889SApple OSS Distributions #ifdef KERNEL_PRIVATE
851*43a90889SApple OSS Distributions 
852*43a90889SApple OSS Distributions extern int      kauth_acl_evaluate(kauth_cred_t _credential, kauth_acl_eval_t _eval);
853*43a90889SApple OSS Distributions 
854*43a90889SApple OSS Distributions #endif /* KERNEL_PRIVATE */
855*43a90889SApple OSS Distributions #ifdef XNU_KERNEL_PRIVATE
856*43a90889SApple OSS Distributions #pragma mark kauth: XNU only
857*43a90889SApple OSS Distributions #pragma GCC visibility push(hidden)
858*43a90889SApple OSS Distributions 
859*43a90889SApple OSS Distributions void            kauth_filesec_acl_setendian(int, kauth_filesec_t, kauth_acl_t);
860*43a90889SApple OSS Distributions int             kauth_copyinfilesec(user_addr_t xsecurity, kauth_filesec_t *xsecdestpp);
861*43a90889SApple OSS Distributions extern int      kauth_acl_inherit(vnode_t _dvp, kauth_acl_t _initial, kauth_acl_t *_product, int _isdir, vfs_context_t _ctx);
862*43a90889SApple OSS Distributions 
863*43a90889SApple OSS Distributions extern int      kauth_authorize_allow(kauth_cred_t _credential, void *_idata, kauth_action_t _action,
864*43a90889SApple OSS Distributions     uintptr_t _arg0, uintptr_t _arg1, uintptr_t _arg2, uintptr_t _arg3);
865*43a90889SApple OSS Distributions 
866*43a90889SApple OSS Distributions extern int      kauth_authorize_generic(kauth_cred_t credential, kauth_action_t action);
867*43a90889SApple OSS Distributions 
868*43a90889SApple OSS Distributions extern int      kauth_authorize_fileop_has_listeners(void);
869*43a90889SApple OSS Distributions 
870*43a90889SApple OSS Distributions extern int      kauth_authorize_fileop(kauth_cred_t _credential, kauth_action_t _action,
871*43a90889SApple OSS Distributions     uintptr_t _arg0, uintptr_t _arg1);
872*43a90889SApple OSS Distributions 
873*43a90889SApple OSS Distributions extern int      kauth_ntsid_equal(ntsid_t *_sid1, ntsid_t *_sid2);
874*43a90889SApple OSS Distributions 
875*43a90889SApple OSS Distributions extern int      kauth_wellknown_guid(guid_t *_guid);
876*43a90889SApple OSS Distributions #define KAUTH_WKG_NOT           0       /* not a well-known GUID */
877*43a90889SApple OSS Distributions #define KAUTH_WKG_OWNER         1
878*43a90889SApple OSS Distributions #define KAUTH_WKG_GROUP         2
879*43a90889SApple OSS Distributions #define KAUTH_WKG_NOBODY        3
880*43a90889SApple OSS Distributions #define KAUTH_WKG_EVERYBODY     4
881*43a90889SApple OSS Distributions 
882*43a90889SApple OSS Distributions #pragma GCC visibility pop
883*43a90889SApple OSS Distributions #endif /* XNU_KERNEL_PRIVATE */
884*43a90889SApple OSS Distributions #endif /* KERNEL */
885*43a90889SApple OSS Distributions 
886*43a90889SApple OSS Distributions /* Actions, also rights bits in an ACE */
887*43a90889SApple OSS Distributions 
888*43a90889SApple OSS Distributions #if defined(KERNEL) || defined (_SYS_ACL_H)
889*43a90889SApple OSS Distributions #define KAUTH_VNODE_READ_DATA                   (1U<<1)
890*43a90889SApple OSS Distributions #define KAUTH_VNODE_LIST_DIRECTORY              KAUTH_VNODE_READ_DATA
891*43a90889SApple OSS Distributions #define KAUTH_VNODE_WRITE_DATA                  (1U<<2)
892*43a90889SApple OSS Distributions #define KAUTH_VNODE_ADD_FILE                    KAUTH_VNODE_WRITE_DATA
893*43a90889SApple OSS Distributions #define KAUTH_VNODE_EXECUTE                     (1U<<3)
894*43a90889SApple OSS Distributions #define KAUTH_VNODE_SEARCH                      KAUTH_VNODE_EXECUTE
895*43a90889SApple OSS Distributions #define KAUTH_VNODE_DELETE                      (1U<<4)
896*43a90889SApple OSS Distributions #define KAUTH_VNODE_APPEND_DATA                 (1U<<5)
897*43a90889SApple OSS Distributions #define KAUTH_VNODE_ADD_SUBDIRECTORY            KAUTH_VNODE_APPEND_DATA
898*43a90889SApple OSS Distributions #define KAUTH_VNODE_DELETE_CHILD                (1U<<6)
899*43a90889SApple OSS Distributions #define KAUTH_VNODE_READ_ATTRIBUTES             (1U<<7)
900*43a90889SApple OSS Distributions #define KAUTH_VNODE_WRITE_ATTRIBUTES            (1U<<8)
901*43a90889SApple OSS Distributions #define KAUTH_VNODE_READ_EXTATTRIBUTES          (1U<<9)
902*43a90889SApple OSS Distributions #define KAUTH_VNODE_WRITE_EXTATTRIBUTES         (1U<<10)
903*43a90889SApple OSS Distributions #define KAUTH_VNODE_READ_SECURITY               (1U<<11)
904*43a90889SApple OSS Distributions #define KAUTH_VNODE_WRITE_SECURITY              (1U<<12)
905*43a90889SApple OSS Distributions #define KAUTH_VNODE_TAKE_OWNERSHIP              (1U<<13)
906*43a90889SApple OSS Distributions 
907*43a90889SApple OSS Distributions /* backwards compatibility only */
908*43a90889SApple OSS Distributions #define KAUTH_VNODE_CHANGE_OWNER                KAUTH_VNODE_TAKE_OWNERSHIP
909*43a90889SApple OSS Distributions 
910*43a90889SApple OSS Distributions /* For Windows interoperability only */
911*43a90889SApple OSS Distributions #define KAUTH_VNODE_SYNCHRONIZE                 (1U<<20)
912*43a90889SApple OSS Distributions 
913*43a90889SApple OSS Distributions /* (1<<21) - (1<<24) are reserved for generic rights bits */
914*43a90889SApple OSS Distributions 
915*43a90889SApple OSS Distributions /* Actions not expressed as rights bits */
916*43a90889SApple OSS Distributions /*
917*43a90889SApple OSS Distributions  * Authorizes the vnode as the target of a hard link.
918*43a90889SApple OSS Distributions  */
919*43a90889SApple OSS Distributions #define KAUTH_VNODE_LINKTARGET                  (1U<<25)
920*43a90889SApple OSS Distributions 
921*43a90889SApple OSS Distributions /*
922*43a90889SApple OSS Distributions  * Indicates that other steps have been taken to authorise the action,
923*43a90889SApple OSS Distributions  * but authorisation should be denied for immutable objects.
924*43a90889SApple OSS Distributions  */
925*43a90889SApple OSS Distributions #define KAUTH_VNODE_CHECKIMMUTABLE              (1U<<26)
926*43a90889SApple OSS Distributions 
927*43a90889SApple OSS Distributions /* Action modifiers */
928*43a90889SApple OSS Distributions /*
929*43a90889SApple OSS Distributions  * The KAUTH_VNODE_ACCESS bit is passed to the callback if the authorisation
930*43a90889SApple OSS Distributions  * request in progress is advisory, rather than authoritative.  Listeners
931*43a90889SApple OSS Distributions  * performing consequential work (i.e. not strictly checking authorisation)
932*43a90889SApple OSS Distributions  * may test this flag to avoid performing unnecessary work.
933*43a90889SApple OSS Distributions  *
934*43a90889SApple OSS Distributions  * This bit will never be present in an ACE.
935*43a90889SApple OSS Distributions  */
936*43a90889SApple OSS Distributions #define KAUTH_VNODE_ACCESS                      (1U<<31)
937*43a90889SApple OSS Distributions 
938*43a90889SApple OSS Distributions /*
939*43a90889SApple OSS Distributions  * The KAUTH_VNODE_NOIMMUTABLE bit is passed to the callback along with the
940*43a90889SApple OSS Distributions  * KAUTH_VNODE_WRITE_SECURITY bit (and no others) to indicate that the
941*43a90889SApple OSS Distributions  * caller wishes to change one or more of the immutable flags, and the
942*43a90889SApple OSS Distributions  * state of these flags should not be considered when authorizing the request.
943*43a90889SApple OSS Distributions  * The system immutable flags are only ignored when the system securelevel
944*43a90889SApple OSS Distributions  * is low enough to allow their removal.
945*43a90889SApple OSS Distributions  */
946*43a90889SApple OSS Distributions #define KAUTH_VNODE_NOIMMUTABLE                 (1U<<30)
947*43a90889SApple OSS Distributions 
948*43a90889SApple OSS Distributions 
949*43a90889SApple OSS Distributions /*
950*43a90889SApple OSS Distributions  * fake right that is composed by the following...
951*43a90889SApple OSS Distributions  * vnode must have search for owner, group and world allowed
952*43a90889SApple OSS Distributions  * plus there must be no deny modes present for SEARCH... this fake
953*43a90889SApple OSS Distributions  * right is used by the fast lookup path to avoid checking
954*43a90889SApple OSS Distributions  * for an exact match on the last credential to lookup
955*43a90889SApple OSS Distributions  * the component being acted on
956*43a90889SApple OSS Distributions  */
957*43a90889SApple OSS Distributions #define KAUTH_VNODE_SEARCHBYANYONE              (1U<<29)
958*43a90889SApple OSS Distributions 
959*43a90889SApple OSS Distributions 
960*43a90889SApple OSS Distributions /*
961*43a90889SApple OSS Distributions  * when passed as an 'action' to "vnode_uncache_authorized_actions"
962*43a90889SApple OSS Distributions  * it indicates that all of the cached authorizations for that
963*43a90889SApple OSS Distributions  * vnode should be invalidated
964*43a90889SApple OSS Distributions  */
965*43a90889SApple OSS Distributions #define KAUTH_INVALIDATE_CACHED_RIGHTS          ((kauth_action_t)~0)
966*43a90889SApple OSS Distributions 
967*43a90889SApple OSS Distributions 
968*43a90889SApple OSS Distributions 
969*43a90889SApple OSS Distributions /* The expansions of the GENERIC bits at evaluation time */
970*43a90889SApple OSS Distributions #define KAUTH_VNODE_GENERIC_READ_BITS   (KAUTH_VNODE_READ_DATA |                \
971*43a90889SApple OSS Distributions 	                                KAUTH_VNODE_READ_ATTRIBUTES |           \
972*43a90889SApple OSS Distributions 	                                KAUTH_VNODE_READ_EXTATTRIBUTES |        \
973*43a90889SApple OSS Distributions 	                                KAUTH_VNODE_READ_SECURITY)
974*43a90889SApple OSS Distributions 
975*43a90889SApple OSS Distributions #define KAUTH_VNODE_GENERIC_WRITE_BITS  (KAUTH_VNODE_WRITE_DATA |               \
976*43a90889SApple OSS Distributions 	                                KAUTH_VNODE_APPEND_DATA |               \
977*43a90889SApple OSS Distributions 	                                KAUTH_VNODE_DELETE |                    \
978*43a90889SApple OSS Distributions 	                                KAUTH_VNODE_DELETE_CHILD |              \
979*43a90889SApple OSS Distributions 	                                KAUTH_VNODE_WRITE_ATTRIBUTES |          \
980*43a90889SApple OSS Distributions 	                                KAUTH_VNODE_WRITE_EXTATTRIBUTES |       \
981*43a90889SApple OSS Distributions 	                                KAUTH_VNODE_WRITE_SECURITY)
982*43a90889SApple OSS Distributions 
983*43a90889SApple OSS Distributions #define KAUTH_VNODE_GENERIC_EXECUTE_BITS (KAUTH_VNODE_EXECUTE)
984*43a90889SApple OSS Distributions 
985*43a90889SApple OSS Distributions #define KAUTH_VNODE_GENERIC_ALL_BITS    (KAUTH_VNODE_GENERIC_READ_BITS |        \
986*43a90889SApple OSS Distributions 	                                KAUTH_VNODE_GENERIC_WRITE_BITS |        \
987*43a90889SApple OSS Distributions 	                                KAUTH_VNODE_GENERIC_EXECUTE_BITS)
988*43a90889SApple OSS Distributions 
989*43a90889SApple OSS Distributions /*
990*43a90889SApple OSS Distributions  * Some sets of bits, defined here for convenience.
991*43a90889SApple OSS Distributions  */
992*43a90889SApple OSS Distributions #define KAUTH_VNODE_WRITE_RIGHTS        (KAUTH_VNODE_ADD_FILE |                         \
993*43a90889SApple OSS Distributions 	                                KAUTH_VNODE_ADD_SUBDIRECTORY |                  \
994*43a90889SApple OSS Distributions 	                                KAUTH_VNODE_DELETE_CHILD |                      \
995*43a90889SApple OSS Distributions 	                                KAUTH_VNODE_WRITE_DATA |                        \
996*43a90889SApple OSS Distributions 	                                KAUTH_VNODE_APPEND_DATA |                       \
997*43a90889SApple OSS Distributions 	                                KAUTH_VNODE_DELETE |                            \
998*43a90889SApple OSS Distributions 	                                KAUTH_VNODE_WRITE_ATTRIBUTES |                  \
999*43a90889SApple OSS Distributions 	                                KAUTH_VNODE_WRITE_EXTATTRIBUTES |               \
1000*43a90889SApple OSS Distributions 	                                KAUTH_VNODE_WRITE_SECURITY |                    \
1001*43a90889SApple OSS Distributions 	                                KAUTH_VNODE_TAKE_OWNERSHIP |                    \
1002*43a90889SApple OSS Distributions 	                                KAUTH_VNODE_LINKTARGET |                        \
1003*43a90889SApple OSS Distributions 	                                KAUTH_VNODE_CHECKIMMUTABLE)
1004*43a90889SApple OSS Distributions 
1005*43a90889SApple OSS Distributions 
1006*43a90889SApple OSS Distributions #endif /* KERNEL || <sys/acl.h> */
1007*43a90889SApple OSS Distributions 
1008*43a90889SApple OSS Distributions #ifdef KERNEL
1009*43a90889SApple OSS Distributions /*
1010*43a90889SApple OSS Distributions  * Debugging
1011*43a90889SApple OSS Distributions  *
1012*43a90889SApple OSS Distributions  * XXX this wouldn't be necessary if we had a *real* debug-logging system.
1013*43a90889SApple OSS Distributions  */
1014*43a90889SApple OSS Distributions #if 0
1015*43a90889SApple OSS Distributions # ifndef _FN_KPRINTF
1016*43a90889SApple OSS Distributions #  define       _FN_KPRINTF
1017*43a90889SApple OSS Distributions void kprintf(const char *fmt, ...) __printflike(1, 2);
1018*43a90889SApple OSS Distributions # endif /* !_FN_KPRINTF */
1019*43a90889SApple OSS Distributions # define KAUTH_DEBUG_ENABLE
1020*43a90889SApple OSS Distributions # define K_UUID_FMT "%08x:%08x:%08x:%08x"
1021*43a90889SApple OSS Distributions # define K_UUID_ARG(_u) &_u.g_guid_asint[0],&_u.g_guid_asint[1],&_u.g_guid_asint[2],&_u.g_guid_asint[3]
1022*43a90889SApple OSS Distributions # define KAUTH_DEBUG(fmt, args...)      do { kprintf("%s:%d: " fmt "\n", __PRETTY_FUNCTION__, __LINE__ , ##args); } while (0)
1023*43a90889SApple OSS Distributions # define KAUTH_DEBUG_CTX(_c)            KAUTH_DEBUG("p = %p c = %p", _c->vc_proc, _c->vc_ucred)
1024*43a90889SApple OSS Distributions # define VFS_DEBUG(_ctx, _vp, fmt, args...)                                             \
1025*43a90889SApple OSS Distributions 	do {                                                                            \
1026*43a90889SApple OSS Distributions 	        kprintf("%p '%s' %s:%d " fmt "\n",                                      \
1027*43a90889SApple OSS Distributions 	            _ctx,                                                               \
1028*43a90889SApple OSS Distributions 	            (_vp != NULL && _vp->v_name != NULL) ? _vp->v_name : "????",        \
1029*43a90889SApple OSS Distributions 	            __PRETTY_FUNCTION__, __LINE__ ,                                     \
1030*43a90889SApple OSS Distributions 	            ##args);                                                            \
1031*43a90889SApple OSS Distributions 	} while(0)
1032*43a90889SApple OSS Distributions #else   /* !0 */
1033*43a90889SApple OSS Distributions # define KAUTH_DEBUG(fmt, args...)              do { } while (0)
1034*43a90889SApple OSS Distributions # define VFS_DEBUG(ctx, vp, fmt, args...)       do { } while(0)
1035*43a90889SApple OSS Distributions #endif  /* !0 */
1036*43a90889SApple OSS Distributions #endif  /* KERNEL */
1037*43a90889SApple OSS Distributions 
1038*43a90889SApple OSS Distributions #endif /* __APPLE_API_EVOLVING */
1039*43a90889SApple OSS Distributions 
1040*43a90889SApple OSS Distributions __END_DECLS
1041*43a90889SApple OSS Distributions 
1042*43a90889SApple OSS Distributions #endif /* _SYS_KAUTH_H */
1043