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