xref: /xnu-8020.140.41/security/mac_internal.h (revision 27b03b360a988dfd3dfdf34262bb0042026747cc)
1*27b03b36SApple OSS Distributions /*
2*27b03b36SApple OSS Distributions  * Copyright (c) 2007 Apple Inc. All rights reserved.
3*27b03b36SApple OSS Distributions  *
4*27b03b36SApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5*27b03b36SApple OSS Distributions  *
6*27b03b36SApple OSS Distributions  * This file contains Original Code and/or Modifications of Original Code
7*27b03b36SApple OSS Distributions  * as defined in and that are subject to the Apple Public Source License
8*27b03b36SApple OSS Distributions  * Version 2.0 (the 'License'). You may not use this file except in
9*27b03b36SApple OSS Distributions  * compliance with the License. The rights granted to you under the License
10*27b03b36SApple OSS Distributions  * may not be used to create, or enable the creation or redistribution of,
11*27b03b36SApple OSS Distributions  * unlawful or unlicensed copies of an Apple operating system, or to
12*27b03b36SApple OSS Distributions  * circumvent, violate, or enable the circumvention or violation of, any
13*27b03b36SApple OSS Distributions  * terms of an Apple operating system software license agreement.
14*27b03b36SApple OSS Distributions  *
15*27b03b36SApple OSS Distributions  * Please obtain a copy of the License at
16*27b03b36SApple OSS Distributions  * http://www.opensource.apple.com/apsl/ and read it before using this file.
17*27b03b36SApple OSS Distributions  *
18*27b03b36SApple OSS Distributions  * The Original Code and all software distributed under the License are
19*27b03b36SApple OSS Distributions  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20*27b03b36SApple OSS Distributions  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21*27b03b36SApple OSS Distributions  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22*27b03b36SApple OSS Distributions  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23*27b03b36SApple OSS Distributions  * Please see the License for the specific language governing rights and
24*27b03b36SApple OSS Distributions  * limitations under the License.
25*27b03b36SApple OSS Distributions  *
26*27b03b36SApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27*27b03b36SApple OSS Distributions  */
28*27b03b36SApple OSS Distributions 
29*27b03b36SApple OSS Distributions /*-
30*27b03b36SApple OSS Distributions  * Copyright (c) 1999, 2000, 2001, 2002 Robert N. M. Watson
31*27b03b36SApple OSS Distributions  * Copyright (c) 2001 Ilmar S. Habibulin
32*27b03b36SApple OSS Distributions  * Copyright (c) 2001, 2002, 2003, 2004 Networks Associates Technology, Inc.
33*27b03b36SApple OSS Distributions  * Copyright (c) 2005 SPARTA, Inc.
34*27b03b36SApple OSS Distributions  * All rights reserved.
35*27b03b36SApple OSS Distributions  *
36*27b03b36SApple OSS Distributions  * This software was developed by Robert Watson and Ilmar Habibulin for the
37*27b03b36SApple OSS Distributions  * TrustedBSD Project.
38*27b03b36SApple OSS Distributions  *
39*27b03b36SApple OSS Distributions  * This software was developed for the FreeBSD Project in part by Network
40*27b03b36SApple OSS Distributions  * Associates Laboratories, the Security Research Division of Network
41*27b03b36SApple OSS Distributions  * Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"),
42*27b03b36SApple OSS Distributions  * as part of the DARPA CHATS research program.
43*27b03b36SApple OSS Distributions  *
44*27b03b36SApple OSS Distributions  * Redistribution and use in source and binary forms, with or without
45*27b03b36SApple OSS Distributions  * modification, are permitted provided that the following conditions
46*27b03b36SApple OSS Distributions  * are met:
47*27b03b36SApple OSS Distributions  * 1. Redistributions of source code must retain the above copyright
48*27b03b36SApple OSS Distributions  *    notice, this list of conditions and the following disclaimer.
49*27b03b36SApple OSS Distributions  * 2. Redistributions in binary form must reproduce the above copyright
50*27b03b36SApple OSS Distributions  *    notice, this list of conditions and the following disclaimer in the
51*27b03b36SApple OSS Distributions  *    documentation and/or other materials provided with the distribution.
52*27b03b36SApple OSS Distributions  *
53*27b03b36SApple OSS Distributions  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
54*27b03b36SApple OSS Distributions  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
55*27b03b36SApple OSS Distributions  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
56*27b03b36SApple OSS Distributions  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
57*27b03b36SApple OSS Distributions  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
58*27b03b36SApple OSS Distributions  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
59*27b03b36SApple OSS Distributions  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
60*27b03b36SApple OSS Distributions  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
61*27b03b36SApple OSS Distributions  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
62*27b03b36SApple OSS Distributions  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
63*27b03b36SApple OSS Distributions  * SUCH DAMAGE.
64*27b03b36SApple OSS Distributions  *
65*27b03b36SApple OSS Distributions  */
66*27b03b36SApple OSS Distributions 
67*27b03b36SApple OSS Distributions #ifndef _SECURITY_MAC_INTERNAL_H_
68*27b03b36SApple OSS Distributions #define _SECURITY_MAC_INTERNAL_H_
69*27b03b36SApple OSS Distributions 
70*27b03b36SApple OSS Distributions #ifndef PRIVATE
71*27b03b36SApple OSS Distributions #warning "MAC policy is not KPI, see Technical Q&A QA1574, this header will be removed in next version"
72*27b03b36SApple OSS Distributions #endif
73*27b03b36SApple OSS Distributions 
74*27b03b36SApple OSS Distributions #include <string.h>
75*27b03b36SApple OSS Distributions #include <sys/param.h>
76*27b03b36SApple OSS Distributions #include <sys/queue.h>
77*27b03b36SApple OSS Distributions #include <security/mac.h>
78*27b03b36SApple OSS Distributions #include <security/mac_framework.h>
79*27b03b36SApple OSS Distributions #include <security/mac_policy.h>
80*27b03b36SApple OSS Distributions #include <security/mac_data.h>
81*27b03b36SApple OSS Distributions #include <sys/sysctl.h>
82*27b03b36SApple OSS Distributions #include <kern/locks.h>
83*27b03b36SApple OSS Distributions #include <sys/kernel.h>
84*27b03b36SApple OSS Distributions #include <sys/lock.h>
85*27b03b36SApple OSS Distributions #include <sys/malloc.h>
86*27b03b36SApple OSS Distributions #include <sys/sbuf.h>
87*27b03b36SApple OSS Distributions #include <sys/proc.h>
88*27b03b36SApple OSS Distributions #include <sys/systm.h>
89*27b03b36SApple OSS Distributions #include <sys/socket.h>
90*27b03b36SApple OSS Distributions #include <sys/socketvar.h>
91*27b03b36SApple OSS Distributions #include <sys/vnode.h>
92*27b03b36SApple OSS Distributions #include <mach/sdt.h>
93*27b03b36SApple OSS Distributions 
94*27b03b36SApple OSS Distributions /*
95*27b03b36SApple OSS Distributions  * MAC Framework sysctl namespace.
96*27b03b36SApple OSS Distributions  */
97*27b03b36SApple OSS Distributions 
98*27b03b36SApple OSS Distributions SYSCTL_DECL(_security);
99*27b03b36SApple OSS Distributions SYSCTL_DECL(_security_mac);
100*27b03b36SApple OSS Distributions 
101*27b03b36SApple OSS Distributions extern int mac_late;
102*27b03b36SApple OSS Distributions 
103*27b03b36SApple OSS Distributions struct mac_policy_list_element {
104*27b03b36SApple OSS Distributions 	struct mac_policy_conf *mpc;
105*27b03b36SApple OSS Distributions };
106*27b03b36SApple OSS Distributions 
107*27b03b36SApple OSS Distributions struct mac_policy_list {
108*27b03b36SApple OSS Distributions 	u_int                           numloaded;
109*27b03b36SApple OSS Distributions 	u_int                           max;
110*27b03b36SApple OSS Distributions 	u_int                           maxindex;
111*27b03b36SApple OSS Distributions 	u_int                           staticmax;
112*27b03b36SApple OSS Distributions 	u_int                           chunks;
113*27b03b36SApple OSS Distributions 	u_int                           freehint;
114*27b03b36SApple OSS Distributions 	struct mac_policy_list_element  *entries;
115*27b03b36SApple OSS Distributions };
116*27b03b36SApple OSS Distributions 
117*27b03b36SApple OSS Distributions typedef struct mac_policy_list mac_policy_list_t;
118*27b03b36SApple OSS Distributions 
119*27b03b36SApple OSS Distributions 
120*27b03b36SApple OSS Distributions /*
121*27b03b36SApple OSS Distributions  * Policy that has registered with the framework for a specific
122*27b03b36SApple OSS Distributions  * label namespace name.
123*27b03b36SApple OSS Distributions  */
124*27b03b36SApple OSS Distributions struct mac_label_listener {
125*27b03b36SApple OSS Distributions 	mac_policy_handle_t             mll_handle;
126*27b03b36SApple OSS Distributions 	SLIST_ENTRY(mac_label_listener) mll_list;
127*27b03b36SApple OSS Distributions };
128*27b03b36SApple OSS Distributions 
129*27b03b36SApple OSS Distributions SLIST_HEAD(mac_label_listeners_t, mac_label_listener);
130*27b03b36SApple OSS Distributions 
131*27b03b36SApple OSS Distributions /*
132*27b03b36SApple OSS Distributions  * Type of list used to manage label namespace names.
133*27b03b36SApple OSS Distributions  */
134*27b03b36SApple OSS Distributions struct mac_label_element {
135*27b03b36SApple OSS Distributions 	char                            mle_name[MAC_MAX_LABEL_ELEMENT_NAME];
136*27b03b36SApple OSS Distributions 	struct mac_label_listeners_t    mle_listeners;
137*27b03b36SApple OSS Distributions 	SLIST_ENTRY(mac_label_element)  mle_list;
138*27b03b36SApple OSS Distributions };
139*27b03b36SApple OSS Distributions 
140*27b03b36SApple OSS Distributions SLIST_HEAD(mac_label_element_list_t, mac_label_element);
141*27b03b36SApple OSS Distributions 
142*27b03b36SApple OSS Distributions /*
143*27b03b36SApple OSS Distributions  * MAC Framework global variables.
144*27b03b36SApple OSS Distributions  */
145*27b03b36SApple OSS Distributions 
146*27b03b36SApple OSS Distributions extern struct mac_label_element_list_t mac_label_element_list;
147*27b03b36SApple OSS Distributions extern struct mac_label_element_list_t mac_static_label_element_list;
148*27b03b36SApple OSS Distributions 
149*27b03b36SApple OSS Distributions extern struct mac_policy_list mac_policy_list;
150*27b03b36SApple OSS Distributions 
151*27b03b36SApple OSS Distributions /*
152*27b03b36SApple OSS Distributions  * global flags to control whether a MACF subsystem is configured
153*27b03b36SApple OSS Distributions  * at all in the system.
154*27b03b36SApple OSS Distributions  */
155*27b03b36SApple OSS Distributions extern unsigned int mac_device_enforce;
156*27b03b36SApple OSS Distributions extern unsigned int mac_pipe_enforce;
157*27b03b36SApple OSS Distributions extern unsigned int mac_posixsem_enforce;
158*27b03b36SApple OSS Distributions extern unsigned int mac_posixshm_enforce;
159*27b03b36SApple OSS Distributions extern unsigned int mac_proc_enforce;
160*27b03b36SApple OSS Distributions extern unsigned int mac_socket_enforce;
161*27b03b36SApple OSS Distributions extern unsigned int mac_system_enforce;
162*27b03b36SApple OSS Distributions extern unsigned int mac_sysvmsg_enforce;
163*27b03b36SApple OSS Distributions extern unsigned int mac_sysvsem_enforce;
164*27b03b36SApple OSS Distributions extern unsigned int mac_sysvshm_enforce;
165*27b03b36SApple OSS Distributions extern unsigned int mac_vm_enforce;
166*27b03b36SApple OSS Distributions extern unsigned int mac_vnode_enforce;
167*27b03b36SApple OSS Distributions 
168*27b03b36SApple OSS Distributions extern unsigned int mac_label_vnodes;
169*27b03b36SApple OSS Distributions extern unsigned int mac_vnode_label_count;
170*27b03b36SApple OSS Distributions 
171*27b03b36SApple OSS Distributions static bool mac_proc_check_enforce(proc_t p);
172*27b03b36SApple OSS Distributions 
173*27b03b36SApple OSS Distributions static __inline__ bool
mac_proc_check_enforce(proc_t p)174*27b03b36SApple OSS Distributions mac_proc_check_enforce(proc_t p)
175*27b03b36SApple OSS Distributions {
176*27b03b36SApple OSS Distributions #if CONFIG_MACF
177*27b03b36SApple OSS Distributions 	// Don't apply policies to the kernel itself.
178*27b03b36SApple OSS Distributions 	return p != kernproc;
179*27b03b36SApple OSS Distributions #else
180*27b03b36SApple OSS Distributions #pragma unused(p)
181*27b03b36SApple OSS Distributions 	return false;
182*27b03b36SApple OSS Distributions #endif // CONFIG_MACF
183*27b03b36SApple OSS Distributions }
184*27b03b36SApple OSS Distributions 
185*27b03b36SApple OSS Distributions static bool mac_cred_check_enforce(kauth_cred_t cred);
186*27b03b36SApple OSS Distributions 
187*27b03b36SApple OSS Distributions static __inline__ bool
mac_cred_check_enforce(kauth_cred_t cred)188*27b03b36SApple OSS Distributions mac_cred_check_enforce(kauth_cred_t cred)
189*27b03b36SApple OSS Distributions {
190*27b03b36SApple OSS Distributions #if CONFIG_MACF
191*27b03b36SApple OSS Distributions 	return cred != proc_ucred(kernproc);
192*27b03b36SApple OSS Distributions #else
193*27b03b36SApple OSS Distributions #pragma unused(p)
194*27b03b36SApple OSS Distributions 	return false;
195*27b03b36SApple OSS Distributions #endif // CONFIG_MACF
196*27b03b36SApple OSS Distributions }
197*27b03b36SApple OSS Distributions 
198*27b03b36SApple OSS Distributions /*
199*27b03b36SApple OSS Distributions  * MAC Framework infrastructure functions.
200*27b03b36SApple OSS Distributions  */
201*27b03b36SApple OSS Distributions 
202*27b03b36SApple OSS Distributions int mac_error_select(int error1, int error2);
203*27b03b36SApple OSS Distributions 
204*27b03b36SApple OSS Distributions void  mac_policy_list_busy(void);
205*27b03b36SApple OSS Distributions int   mac_policy_list_conditional_busy(void);
206*27b03b36SApple OSS Distributions void  mac_policy_list_unbusy(void);
207*27b03b36SApple OSS Distributions 
208*27b03b36SApple OSS Distributions #if KERNEL
209*27b03b36SApple OSS Distributions int   mac_check_structmac_consistent(struct user_mac *mac);
210*27b03b36SApple OSS Distributions #else
211*27b03b36SApple OSS Distributions int   mac_check_structmac_consistent(struct mac *mac);
212*27b03b36SApple OSS Distributions #endif
213*27b03b36SApple OSS Distributions 
214*27b03b36SApple OSS Distributions int mac_cred_label_externalize(struct label *, char *e, char *out, size_t olen, int flags);
215*27b03b36SApple OSS Distributions int mac_vnode_label_externalize(struct label *, char *e, char *out, size_t olen, int flags);
216*27b03b36SApple OSS Distributions 
217*27b03b36SApple OSS Distributions int mac_cred_label_internalize(struct label *label, char *string);
218*27b03b36SApple OSS Distributions int mac_vnode_label_internalize(struct label *label, char *string);
219*27b03b36SApple OSS Distributions 
220*27b03b36SApple OSS Distributions typedef int (^mac_getter_t)(char *, char *, size_t);
221*27b03b36SApple OSS Distributions typedef int (^mac_setter_t)(char *, size_t);
222*27b03b36SApple OSS Distributions 
223*27b03b36SApple OSS Distributions int mac_do_get(struct proc *p, user_addr_t mac_p, mac_getter_t getter);
224*27b03b36SApple OSS Distributions int mac_do_set(struct proc *p, user_addr_t mac_p, mac_setter_t setter);
225*27b03b36SApple OSS Distributions 
226*27b03b36SApple OSS Distributions #define MAC_POLICY_ITERATE(...) do {                                \
227*27b03b36SApple OSS Distributions     struct mac_policy_conf *mpc;                                    \
228*27b03b36SApple OSS Distributions     u_int i;                                                        \
229*27b03b36SApple OSS Distributions                                                                     \
230*27b03b36SApple OSS Distributions     for (i = 0; i < mac_policy_list.staticmax; i++) {               \
231*27b03b36SApple OSS Distributions 	    mpc = mac_policy_list.entries[i].mpc;                       \
232*27b03b36SApple OSS Distributions 	    if (mpc == NULL)                                            \
233*27b03b36SApple OSS Distributions 	            continue;                                           \
234*27b03b36SApple OSS Distributions                                                                     \
235*27b03b36SApple OSS Distributions 	    __VA_ARGS__                                                 \
236*27b03b36SApple OSS Distributions     }                                                               \
237*27b03b36SApple OSS Distributions     if (mac_policy_list_conditional_busy() != 0) {                  \
238*27b03b36SApple OSS Distributions 	    for (; i <= mac_policy_list.maxindex; i++) {                \
239*27b03b36SApple OSS Distributions 	            mpc = mac_policy_list.entries[i].mpc;               \
240*27b03b36SApple OSS Distributions 	            if (mpc == NULL)                                    \
241*27b03b36SApple OSS Distributions 	                    continue;                                   \
242*27b03b36SApple OSS Distributions                                                                     \
243*27b03b36SApple OSS Distributions 	            __VA_ARGS__                                         \
244*27b03b36SApple OSS Distributions 	    }                                                           \
245*27b03b36SApple OSS Distributions 	    mac_policy_list_unbusy();                                   \
246*27b03b36SApple OSS Distributions     }                                                               \
247*27b03b36SApple OSS Distributions } while (0)
248*27b03b36SApple OSS Distributions 
249*27b03b36SApple OSS Distributions enum mac_iterate_types {
250*27b03b36SApple OSS Distributions 	MAC_ITERATE_CHECK = 0,  // error starts at 0, callbacks can change it
251*27b03b36SApple OSS Distributions 	MAC_ITERATE_GRANT = 1,  // error starts as EPERM, callbacks can clear it
252*27b03b36SApple OSS Distributions 	MAC_ITERATE_PERFORM = 2, // no result
253*27b03b36SApple OSS Distributions };
254*27b03b36SApple OSS Distributions 
255*27b03b36SApple OSS Distributions /*
256*27b03b36SApple OSS Distributions  * MAC_CHECK performs the designated check by walking the policy
257*27b03b36SApple OSS Distributions  * module list and checking with each as to how it feels about the
258*27b03b36SApple OSS Distributions  * request.  Note that it returns its value via 'error' in the scope
259*27b03b36SApple OSS Distributions  * of the caller.
260*27b03b36SApple OSS Distributions  */
261*27b03b36SApple OSS Distributions #define MAC_CHECK(check, args...) do {                              \
262*27b03b36SApple OSS Distributions     error = 0;                                                      \
263*27b03b36SApple OSS Distributions     MAC_POLICY_ITERATE({                                            \
264*27b03b36SApple OSS Distributions 	    if (mpc->mpc_ops->mpo_ ## check != NULL) {              \
265*27b03b36SApple OSS Distributions 	            DTRACE_MACF3(mac__call__ ## check, void *, mpc, int, error, int, MAC_ITERATE_CHECK); \
266*27b03b36SApple OSS Distributions 	            int __step_err = mpc->mpc_ops->mpo_ ## check (args); \
267*27b03b36SApple OSS Distributions 	            DTRACE_MACF2(mac__rslt__ ## check, void *, mpc, int, __step_err); \
268*27b03b36SApple OSS Distributions 	            error = mac_error_select(__step_err, error);         \
269*27b03b36SApple OSS Distributions 	    }                                                           \
270*27b03b36SApple OSS Distributions     });                                                             \
271*27b03b36SApple OSS Distributions } while (0)
272*27b03b36SApple OSS Distributions 
273*27b03b36SApple OSS Distributions /*
274*27b03b36SApple OSS Distributions  * MAC_GRANT performs the designated check by walking the policy
275*27b03b36SApple OSS Distributions  * module list and checking with each as to how it feels about the
276*27b03b36SApple OSS Distributions  * request.  Unlike MAC_CHECK, it grants if any policies return '0',
277*27b03b36SApple OSS Distributions  * and otherwise returns EPERM.  Note that it returns its value via
278*27b03b36SApple OSS Distributions  * 'error' in the scope of the caller.
279*27b03b36SApple OSS Distributions  */
280*27b03b36SApple OSS Distributions #define MAC_GRANT(check, args...) do {                              \
281*27b03b36SApple OSS Distributions     error = EPERM;                                                  \
282*27b03b36SApple OSS Distributions     MAC_POLICY_ITERATE({                                            \
283*27b03b36SApple OSS Distributions 	if (mpc->mpc_ops->mpo_ ## check != NULL) {                  \
284*27b03b36SApple OSS Distributions 	        DTRACE_MACF3(mac__call__ ## check, void *, mpc, int, error, int, MAC_ITERATE_GRANT); \
285*27b03b36SApple OSS Distributions 	        int __step_res = mpc->mpc_ops->mpo_ ## check (args); \
286*27b03b36SApple OSS Distributions 	        if (__step_res == 0) {                              \
287*27b03b36SApple OSS Distributions 	                error = 0;                                  \
288*27b03b36SApple OSS Distributions 	        }                                                   \
289*27b03b36SApple OSS Distributions 	        DTRACE_MACF2(mac__rslt__ ## check, void *, mpc, int, __step_res); \
290*27b03b36SApple OSS Distributions 	    }                                                           \
291*27b03b36SApple OSS Distributions     });                                                             \
292*27b03b36SApple OSS Distributions } while (0)
293*27b03b36SApple OSS Distributions 
294*27b03b36SApple OSS Distributions #define MAC_INTERNALIZE(obj, label, instring)                       \
295*27b03b36SApple OSS Distributions     mac_internalize(offsetof(struct mac_policy_ops, mpo_ ## obj ## _label_internalize), label, instring)
296*27b03b36SApple OSS Distributions 
297*27b03b36SApple OSS Distributions #define MAC_EXTERNALIZE(obj, label, elementlist, outbuf, outbuflen) \
298*27b03b36SApple OSS Distributions     mac_externalize(offsetof(struct mac_policy_ops, mpo_ ## obj ## _label_externalize), label, elementlist, outbuf, outbuflen)
299*27b03b36SApple OSS Distributions 
300*27b03b36SApple OSS Distributions #define MAC_EXTERNALIZE_AUDIT(obj, label, outbuf, outbuflen)        \
301*27b03b36SApple OSS Distributions     mac_externalize(offsetof(struct mac_policy_ops, mpo_ ## obj ## _label_externalize_audit), label, "*", outbuf, outbuflen)
302*27b03b36SApple OSS Distributions 
303*27b03b36SApple OSS Distributions #define MAC_PERFORM_CALL(operation, mpc) DTRACE_MACF3(mac__call__ ## operation, void *, mpc, int, 0, int, MAC_ITERATE_PERFORM)
304*27b03b36SApple OSS Distributions #define MAC_PERFORM_RSLT(operation, mpc) DTRACE_MACF2(mac__rslt__ ## operation, void *, mpc, int, 0)
305*27b03b36SApple OSS Distributions 
306*27b03b36SApple OSS Distributions /*
307*27b03b36SApple OSS Distributions  * MAC_PERFORM performs the designated operation by walking the policy
308*27b03b36SApple OSS Distributions  * module list and invoking that operation for each policy.
309*27b03b36SApple OSS Distributions  */
310*27b03b36SApple OSS Distributions #define MAC_PERFORM(operation, args...) do {           \
311*27b03b36SApple OSS Distributions     MAC_POLICY_ITERATE({                                    \
312*27b03b36SApple OSS Distributions 	if (mpc->mpc_ops->mpo_ ## operation != NULL) {      \
313*27b03b36SApple OSS Distributions 	        MAC_PERFORM_CALL(operation, mpc);           \
314*27b03b36SApple OSS Distributions 	        mpc->mpc_ops->mpo_ ## operation (args);     \
315*27b03b36SApple OSS Distributions 	        MAC_PERFORM_RSLT(operation, mpc);           \
316*27b03b36SApple OSS Distributions 	}                                                   \
317*27b03b36SApple OSS Distributions     });                                                     \
318*27b03b36SApple OSS Distributions } while (0)
319*27b03b36SApple OSS Distributions 
320*27b03b36SApple OSS Distributions 
321*27b03b36SApple OSS Distributions #
322*27b03b36SApple OSS Distributions struct __mac_get_pid_args;
323*27b03b36SApple OSS Distributions struct __mac_get_proc_args;
324*27b03b36SApple OSS Distributions struct __mac_set_proc_args;
325*27b03b36SApple OSS Distributions struct __mac_get_lcid_args;
326*27b03b36SApple OSS Distributions struct __mac_get_fd_args;
327*27b03b36SApple OSS Distributions struct __mac_get_file_args;
328*27b03b36SApple OSS Distributions struct __mac_get_link_args;
329*27b03b36SApple OSS Distributions struct __mac_set_fd_args;
330*27b03b36SApple OSS Distributions struct __mac_set_file_args;
331*27b03b36SApple OSS Distributions struct __mac_syscall_args;
332*27b03b36SApple OSS Distributions 
333*27b03b36SApple OSS Distributions void mac_policy_addto_labellist(const mac_policy_handle_t, int);
334*27b03b36SApple OSS Distributions void mac_policy_removefrom_labellist(const mac_policy_handle_t);
335*27b03b36SApple OSS Distributions 
336*27b03b36SApple OSS Distributions int mac_externalize(size_t mpo_externalize_off, struct label *label,
337*27b03b36SApple OSS Distributions     const char *elementlist, char *outbuf, size_t outbuflen);
338*27b03b36SApple OSS Distributions int mac_internalize(size_t mpo_internalize_off, struct label *label,
339*27b03b36SApple OSS Distributions     char *elementlist);
340*27b03b36SApple OSS Distributions #endif  /* !_SECURITY_MAC_INTERNAL_H_ */
341