1*d915a14eSPedro F. Giffuni /*-
2*d915a14eSPedro F. Giffuni * SPDX-License-Identifier: BSD-3-Clause
3*d915a14eSPedro F. Giffuni *
4d97fcfceSRobert Watson * Copyright (c) 1999, 2000, 2001, 2002 Robert N. M. Watson
5d97fcfceSRobert Watson * All rights reserved.
6d97fcfceSRobert Watson *
7d97fcfceSRobert Watson * This software was developed by Robert Watson for the TrustedBSD Project.
8d97fcfceSRobert Watson *
9d97fcfceSRobert Watson * Redistribution and use in source and binary forms, with or without
10d97fcfceSRobert Watson * modification, are permitted provided that the following conditions
11d97fcfceSRobert Watson * are met:
12d97fcfceSRobert Watson * 1. Redistributions of source code must retain the above copyright
13d97fcfceSRobert Watson * notice, this list of conditions and the following disclaimer.
14d97fcfceSRobert Watson * 2. Redistributions in binary form must reproduce the above copyright
15d97fcfceSRobert Watson * notice, this list of conditions and the following disclaimer in the
16d97fcfceSRobert Watson * documentation and/or other materials provided with the distribution.
17d97fcfceSRobert Watson * 3. The names of the authors may not be used to endorse or promote
18d97fcfceSRobert Watson * products derived from this software without specific prior written
19d97fcfceSRobert Watson * permission.
20d97fcfceSRobert Watson *
21d97fcfceSRobert Watson * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
22d97fcfceSRobert Watson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23d97fcfceSRobert Watson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24d97fcfceSRobert Watson * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
25d97fcfceSRobert Watson * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26d97fcfceSRobert Watson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27d97fcfceSRobert Watson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28d97fcfceSRobert Watson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29d97fcfceSRobert Watson * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30d97fcfceSRobert Watson * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31d97fcfceSRobert Watson * SUCH DAMAGE.
32d97fcfceSRobert Watson */
33d97fcfceSRobert Watson
34d97fcfceSRobert Watson #include <sys/types.h>
35d97fcfceSRobert Watson #include <sys/mac.h>
36920325eeSRobert Watson #include <sys/socket.h>
37d97fcfceSRobert Watson
38e0554a53SJacques Vidrine extern int __mac_get_fd(int fd, struct mac *mac_p);
39e0554a53SJacques Vidrine extern int __mac_get_file(const char *path_p, struct mac *mac_p);
40e0554a53SJacques Vidrine extern int __mac_get_link(const char *path_p, struct mac *mac_p);
41e0554a53SJacques Vidrine extern int __mac_get_pid(pid_t pid, struct mac *mac_p);
42e0554a53SJacques Vidrine extern int __mac_get_proc(struct mac *mac_p);
43e0554a53SJacques Vidrine
44391b1d75SRobert Watson int
mac_get_fd(int fd,struct mac * label)45391b1d75SRobert Watson mac_get_fd(int fd, struct mac *label)
46d97fcfceSRobert Watson {
47d97fcfceSRobert Watson
48391b1d75SRobert Watson return (__mac_get_fd(fd, label));
49d97fcfceSRobert Watson }
50d97fcfceSRobert Watson
51391b1d75SRobert Watson int
mac_get_file(const char * path,struct mac * label)52391b1d75SRobert Watson mac_get_file(const char *path, struct mac *label)
53d97fcfceSRobert Watson {
54d97fcfceSRobert Watson
55391b1d75SRobert Watson return (__mac_get_file(path, label));
56d97fcfceSRobert Watson }
57d97fcfceSRobert Watson
58391b1d75SRobert Watson int
mac_get_link(const char * path,struct mac * label)59391b1d75SRobert Watson mac_get_link(const char *path, struct mac *label)
60d97fcfceSRobert Watson {
61d97fcfceSRobert Watson
62391b1d75SRobert Watson return (__mac_get_link(path, label));
63d97fcfceSRobert Watson }
64d97fcfceSRobert Watson
65920325eeSRobert Watson int
mac_get_peer(int fd,struct mac * label)66920325eeSRobert Watson mac_get_peer(int fd, struct mac *label)
67920325eeSRobert Watson {
68920325eeSRobert Watson socklen_t len;
69920325eeSRobert Watson
70920325eeSRobert Watson len = sizeof(*label);
71920325eeSRobert Watson return (getsockopt(fd, SOL_SOCKET, SO_PEERLABEL, label, &len));
72920325eeSRobert Watson }
735be39711SRobert Watson
74391b1d75SRobert Watson int
mac_get_pid(pid_t pid,struct mac * label)75391b1d75SRobert Watson mac_get_pid(pid_t pid, struct mac *label)
76391b1d75SRobert Watson {
77391b1d75SRobert Watson
78391b1d75SRobert Watson return (__mac_get_pid(pid, label));
79d97fcfceSRobert Watson }
80d97fcfceSRobert Watson
81391b1d75SRobert Watson int
mac_get_proc(struct mac * label)82391b1d75SRobert Watson mac_get_proc(struct mac *label)
83391b1d75SRobert Watson {
84391b1d75SRobert Watson
85391b1d75SRobert Watson return (__mac_get_proc(label));
86d97fcfceSRobert Watson }
87