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