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