mac_get.c revision 101242
1101242Srwatson/*
2101242Srwatson * Copyright (c) 1999, 2000, 2001, 2002 Robert N. M. Watson
3101242Srwatson * All rights reserved.
4101242Srwatson *
5101242Srwatson * This software was developed by Robert Watson for the TrustedBSD Project.
6101242Srwatson *
7101242Srwatson * Redistribution and use in source and binary forms, with or without
8101242Srwatson * modification, are permitted provided that the following conditions
9101242Srwatson * are met:
10101242Srwatson * 1. Redistributions of source code must retain the above copyright
11101242Srwatson *    notice, this list of conditions and the following disclaimer.
12101242Srwatson * 2. Redistributions in binary form must reproduce the above copyright
13101242Srwatson *    notice, this list of conditions and the following disclaimer in the
14101242Srwatson *    documentation and/or other materials provided with the distribution.
15101242Srwatson * 3. The names of the authors may not be used to endorse or promote
16101242Srwatson *    products derived from this software without specific prior written
17101242Srwatson *    permission.
18101242Srwatson *
19101242Srwatson * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20101242Srwatson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21101242Srwatson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22101242Srwatson * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23101242Srwatson * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24101242Srwatson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25101242Srwatson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26101242Srwatson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27101242Srwatson * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28101242Srwatson * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29101242Srwatson * SUCH DAMAGE.
30101242Srwatson *
31101242Srwatson * $FreeBSD: head/lib/libc/posix1e/mac_get.c 101242 2002-08-02 21:14:42Z rwatson $
32101242Srwatson */
33101242Srwatson
34101242Srwatson#include <sys/types.h>
35101242Srwatson#include <sys/mac.h>
36101242Srwatson
37101242Srwatson#include <errno.h>
38101242Srwatson#include <stdlib.h>
39101242Srwatson
40101242Srwatsonmac_t
41101242Srwatsonmac_get_file(const char *path_p)
42101242Srwatson{
43101242Srwatson	struct mac *label;
44101242Srwatson	int error;
45101242Srwatson
46101242Srwatson	label = (mac_t) malloc(sizeof(*label));
47101242Srwatson	if (label == NULL) {
48101242Srwatson		errno = ENOMEM;
49101242Srwatson		return (NULL);
50101242Srwatson	}
51101242Srwatson
52101242Srwatson	error = __mac_get_file(path_p, label);
53101242Srwatson	if (error) {
54101242Srwatson		mac_free(label);
55101242Srwatson		return (NULL);
56101242Srwatson	}
57101242Srwatson
58101242Srwatson	return (label);
59101242Srwatson}
60101242Srwatson
61101242Srwatsonmac_t
62101242Srwatsonmac_get_fd(int fd)
63101242Srwatson{
64101242Srwatson	struct mac *label;
65101242Srwatson	int error;
66101242Srwatson
67101242Srwatson	label = (mac_t) malloc(sizeof(*label));
68101242Srwatson	if (label == NULL) {
69101242Srwatson		errno = ENOMEM;
70101242Srwatson		return (NULL);
71101242Srwatson	}
72101242Srwatson
73101242Srwatson	error = __mac_get_fd(fd, label);
74101242Srwatson	if (error) {
75101242Srwatson		mac_free(label);
76101242Srwatson		return (NULL);
77101242Srwatson	}
78101242Srwatson
79101242Srwatson	return (label);
80101242Srwatson}
81101242Srwatson
82101242Srwatsonmac_t
83101242Srwatsonmac_get_proc()
84101242Srwatson{
85101242Srwatson	struct mac *label;
86101242Srwatson	int error;
87101242Srwatson
88101242Srwatson	label = (mac_t) malloc(sizeof(*label));
89101242Srwatson	if (label == NULL) {
90101242Srwatson		errno = ENOMEM;
91101242Srwatson		return (NULL);
92101242Srwatson	}
93101242Srwatson
94101242Srwatson	error = __mac_get_proc(label);
95101242Srwatson	if (error) {
96101242Srwatson		mac_free(label);
97101242Srwatson		return (NULL);
98101242Srwatson	}
99101242Srwatson
100101242Srwatson	return (label);
101101242Srwatson}
102