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