xref: /freebsd/sys/sys/mac.h (revision c697fb7f)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
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  * $FreeBSD$
41  */
42 /*
43  * Userland interface for Mandatory Access Control.  Loosely based on the
44  * POSIX.1e API.  More information may be found at:
45  *
46  * http://www.TrustedBSD.org/
47  */
48 
49 #ifndef _SYS_MAC_H_
50 #define	_SYS_MAC_H_
51 
52 #ifndef _POSIX_MAC
53 #define	_POSIX_MAC
54 #endif
55 
56 /*
57  * MAC framework-related constants and limits.
58  */
59 #define	MAC_MAX_POLICY_NAME		32
60 #define	MAC_MAX_LABEL_ELEMENT_NAME	32
61 #define	MAC_MAX_LABEL_ELEMENT_DATA	4096
62 #define	MAC_MAX_LABEL_BUF_LEN		8192
63 
64 /*
65  * struct mac is the data structure used to carry MAC labels in system calls
66  * and ioctls between userspace and the kernel.
67  */
68 struct mac {
69 	size_t		 m_buflen;
70 	char		*m_string;
71 };
72 
73 typedef struct mac	*mac_t;
74 
75 #ifndef _KERNEL
76 
77 /*
78  * Location of the userland MAC framework configuration file.  mac.conf
79  * set defaults for MAC-aware applications.
80  */
81 #define	MAC_CONFFILE	"/etc/mac.conf"
82 
83 /*
84  * Extended non-POSIX.1e interfaces that offer additional services available
85  * from the userland and kernel MAC frameworks.
86  */
87 __BEGIN_DECLS
88 int	 mac_execve(char *fname, char **argv, char **envv, mac_t _label);
89 int	 mac_free(mac_t _label);
90 int	 mac_from_text(mac_t *_label, const char *_text);
91 int	 mac_get_fd(int _fd, mac_t _label);
92 int	 mac_get_file(const char *_path, mac_t _label);
93 int	 mac_get_link(const char *_path, mac_t _label);
94 int	 mac_get_peer(int _fd, mac_t _label);
95 int	 mac_get_pid(pid_t _pid, mac_t _label);
96 int	 mac_get_proc(mac_t _label);
97 int	 mac_is_present(const char *_policyname);
98 int	 mac_prepare(mac_t *_label, const char *_elements);
99 int	 mac_prepare_file_label(mac_t *_label);
100 int	 mac_prepare_ifnet_label(mac_t *_label);
101 int	 mac_prepare_process_label(mac_t *_label);
102 int	 mac_prepare_type(mac_t *_label, const char *_type);
103 int	 mac_set_fd(int _fildes, const mac_t _label);
104 int	 mac_set_file(const char *_path, mac_t _label);
105 int	 mac_set_link(const char *_path, mac_t _label);
106 int	 mac_set_proc(const mac_t _label);
107 int	 mac_syscall(const char *_policyname, int _call, void *_arg);
108 int	 mac_to_text(mac_t mac, char **_text);
109 __END_DECLS
110 
111 #endif /* !_KERNEL */
112 
113 #endif /* !_SYS_MAC_H_ */
114