1/*-
2 * SPDX-License-Identifier: BSD-2-Clause
3 *
4 * Copyright (c) 1999-2002 Robert N. M. Watson
5 * Copyright (c) 2001-2005 Networks Associates Technology, Inc.
6 * Copyright (c) 2005-2006 SPARTA, Inc.
7 * All rights reserved.
8 *
9 * This software was developed by Robert Watson for the TrustedBSD Project.
10 *
11 * This software was developed for the FreeBSD Project in part by Network
12 * Associates Laboratories, the Security Research Division of Network
13 * Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"),
14 * as part of the DARPA CHATS research program.
15 *
16 * This software was enhanced by SPARTA ISSO under SPAWAR contract
17 * N66001-04-C-6019 ("SEFOS").
18 *
19 * Redistribution and use in source and binary forms, with or without
20 * modification, are permitted provided that the following conditions
21 * are met:
22 * 1. Redistributions of source code must retain the above copyright
23 * notice, this list of conditions and the following disclaimer.
24 * 2. Redistributions in binary form must reproduce the above copyright
25 * notice, this list of conditions and the following disclaimer in the
26 * documentation and/or other materials provided with the distribution.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
29 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
32 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 * SUCH DAMAGE.
39 */
40/*
41 * Userland interface for Mandatory Access Control. Loosely based on the
42 * POSIX.1e API. More information may be found at:
43 *
44 * http://www.TrustedBSD.org/
45 */
46
47#ifndef _SYS_MAC_H_
48#define _SYS_MAC_H_
49
50#include <sys/_types.h>
51
52#ifndef _SIZE_T_DECLARED
53typedef __size_t size_t;
54#define _SIZE_T_DECLARED
55#endif
56
57#ifndef _POSIX_MAC
58#define _POSIX_MAC
59#endif
60
61/*
62 * MAC framework-related constants and limits.
63 */
64#define MAC_MAX_POLICY_NAME 32
65#define MAC_MAX_LABEL_ELEMENT_NAME 32
66#define MAC_MAX_LABEL_ELEMENT_DATA 4096
67#define MAC_MAX_LABEL_BUF_LEN 8192
68
69/*
70 * struct mac is the data structure used to carry MAC labels in system calls
71 * and ioctls between userspace and the kernel.
72 */
73struct mac {
74 size_t m_buflen;
75 char *m_string;
76};
77
78typedef struct mac *mac_t;
79
80#ifndef _KERNEL
81
82#include <sys/cdefs.h> /* For __BEGIN_DECLS and __END_DECLS. */
83
84#ifndef _PID_T_DECLARED
85typedef __pid_t pid_t; /* process id */
86#define _PID_T_DECLARED
87#endif
88
89/*
90 * Location of the userland MAC framework configuration file. mac.conf
91 * set defaults for MAC-aware applications.
92 */
93#define MAC_CONFFILE "/etc/mac.conf"
94
95/*
96 * Extended non-POSIX.1e interfaces that offer additional services available
97 * from the userland and kernel MAC frameworks.
98 */
99__BEGIN_DECLS
100int mac_execve(char *fname, char **argv, char **envv, mac_t _label);
101int mac_free(mac_t _label);
102int mac_from_text(mac_t *_label, const char *_text);
103int mac_get_fd(int _fd, mac_t _label);
104int mac_get_file(const char *_path, mac_t _label);
105int mac_get_link(const char *_path, mac_t _label);
106int mac_get_peer(int _fd, mac_t _label);
107int mac_get_pid(pid_t _pid, mac_t _label);
108int mac_get_proc(mac_t _label);
109int mac_is_present(const char *_policyname);
110int mac_prepare(mac_t *_label, const char *_elements);
111int mac_prepare_file_label(mac_t *_label);
112int mac_prepare_ifnet_label(mac_t *_label);
113int mac_prepare_process_label(mac_t *_label);
114int mac_prepare_type(mac_t *_label, const char *_type);
115int mac_set_fd(int _fildes, const mac_t _label);
116int mac_set_file(const char *_path, mac_t _label);
117int mac_set_link(const char *_path, mac_t _label);
118int mac_set_proc(const mac_t _label);
119int mac_syscall(const char *_policyname, int _call, void *_arg);
120int mac_to_text(mac_t mac, char **_text);
121__END_DECLS
122
123#endif /* !_KERNEL */
124
125#endif /* !_SYS_MAC_H_ */