xref: /freebsd/lib/libc/posix1e/mac_get.c (revision 920325ee1da9e6c8d191ab0b2a3b11ee9a1831c0)
1d97fcfceSRobert Watson /*
2d97fcfceSRobert Watson  * Copyright (c) 1999, 2000, 2001, 2002 Robert N. M. Watson
3d97fcfceSRobert Watson  * All rights reserved.
4d97fcfceSRobert Watson  *
5d97fcfceSRobert Watson  * This software was developed by Robert Watson for the TrustedBSD Project.
6d97fcfceSRobert Watson  *
7d97fcfceSRobert Watson  * Redistribution and use in source and binary forms, with or without
8d97fcfceSRobert Watson  * modification, are permitted provided that the following conditions
9d97fcfceSRobert Watson  * are met:
10d97fcfceSRobert Watson  * 1. Redistributions of source code must retain the above copyright
11d97fcfceSRobert Watson  *    notice, this list of conditions and the following disclaimer.
12d97fcfceSRobert Watson  * 2. Redistributions in binary form must reproduce the above copyright
13d97fcfceSRobert Watson  *    notice, this list of conditions and the following disclaimer in the
14d97fcfceSRobert Watson  *    documentation and/or other materials provided with the distribution.
15d97fcfceSRobert Watson  * 3. The names of the authors may not be used to endorse or promote
16d97fcfceSRobert Watson  *    products derived from this software without specific prior written
17d97fcfceSRobert Watson  *    permission.
18d97fcfceSRobert Watson  *
19d97fcfceSRobert Watson  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20d97fcfceSRobert Watson  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21d97fcfceSRobert Watson  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22d97fcfceSRobert Watson  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23d97fcfceSRobert Watson  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24d97fcfceSRobert Watson  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25d97fcfceSRobert Watson  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26d97fcfceSRobert Watson  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27d97fcfceSRobert Watson  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28d97fcfceSRobert Watson  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29d97fcfceSRobert Watson  * SUCH DAMAGE.
30d97fcfceSRobert Watson  *
31d97fcfceSRobert Watson  * $FreeBSD$
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
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
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
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 
66920325eeSRobert Watson int
67920325eeSRobert Watson mac_get_peer(int fd, struct mac *label)
68920325eeSRobert Watson {
69920325eeSRobert Watson 	socklen_t len;
70920325eeSRobert Watson 
71920325eeSRobert Watson 	len = sizeof(*label);
72920325eeSRobert Watson 	return (getsockopt(fd, SOL_SOCKET, SO_PEERLABEL, label, &len));
73920325eeSRobert Watson }
74391b1d75SRobert Watson int
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
82391b1d75SRobert Watson mac_get_proc(struct mac *label)
83391b1d75SRobert Watson {
84391b1d75SRobert Watson 
85391b1d75SRobert Watson 	return (__mac_get_proc(label));
86d97fcfceSRobert Watson }
87