acl_get.c revision 74191
1254897Serwin/*-
2186448Sdougb * Copyright (c) 1999, 2000, 2001 Robert N. M. Watson
3186448Sdougb * All rights reserved.
4204619Sdougb *
5186448Sdougb * Redistribution and use in source and binary forms, with or without
6186448Sdougb * modification, are permitted provided that the following conditions
7186448Sdougb * are met:
8186448Sdougb * 1. Redistributions of source code must retain the above copyright
9186448Sdougb *    notice, this list of conditions and the following disclaimer.
10186448Sdougb * 2. Redistributions in binary form must reproduce the above copyright
11186448Sdougb *    notice, this list of conditions and the following disclaimer in the
12186448Sdougb *    documentation and/or other materials provided with the distribution.
13186448Sdougb *
14186448Sdougb * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15186448Sdougb * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16234010Sdougb * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17186448Sdougb * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18186448Sdougb * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19186448Sdougb * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20186448Sdougb * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21186448Sdougb * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22186448Sdougb * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23224092Sdougb * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24186448Sdougb * SUCH DAMAGE.
25186448Sdougb *
26186448Sdougb * $FreeBSD: head/lib/libc/posix1e/acl_get.c 74191 2001-03-13 02:31:32Z rwatson $
27224092Sdougb */
28186448Sdougb/*
29186448Sdougb * acl_get_file - syscall wrapper for retrieving ACL by filename
30186448Sdougb * acl_get_fd - syscall wrapper for retrieving access ACL by fd
31186448Sdougb * acl_get_fd_np - syscall wrapper for retrieving ACL by fd (non-POSIX)
32186448Sdougb */
33186448Sdougb
34186448Sdougb#include <sys/types.h>
35186448Sdougb#include <sys/acl.h>
36224092Sdougb#include <sys/errno.h>
37186448Sdougb#include <stdlib.h>
38186448Sdougb
39186448Sdougbacl_t
40224092Sdougbacl_get_file(const char *path_p, acl_type_t type)
41186448Sdougb{
42186448Sdougb	struct acl	*aclp;
43186448Sdougb	int	error;
44186448Sdougb
45186448Sdougb	aclp = acl_init(ACL_MAX_ENTRIES);
46186448Sdougb	if (!aclp) {
47186448Sdougb		return (NULL);
48186448Sdougb	}
49186448Sdougb
50186448Sdougb	error = __acl_get_file(path_p, type, aclp);
51186448Sdougb	if (error) {
52186448Sdougb		acl_free(aclp);
53186448Sdougb		return (NULL);
54186448Sdougb	}
55186448Sdougb
56193149Sdougb	return (aclp);
57193149Sdougb}
58193149Sdougb
59186448Sdougbacl_t
60193149Sdougbacl_get_fd(int fd)
61193149Sdougb{
62193149Sdougb	struct acl	*aclp;
63224092Sdougb	int	error;
64224092Sdougb
65224092Sdougb	aclp = acl_init(ACL_MAX_ENTRIES);
66224092Sdougb	if (!aclp) {
67224092Sdougb		return (NULL);
68193149Sdougb	}
69186448Sdougb
70186448Sdougb	error = __acl_get_fd(fd, ACL_TYPE_ACCESS, aclp);
71186448Sdougb	if (error) {
72186448Sdougb		acl_free(aclp);
73186448Sdougb		return (NULL);
74186448Sdougb	}
75186448Sdougb
76186448Sdougb	return (aclp);
77186448Sdougb}
78224092Sdougb
79186448Sdougbacl_t
80224092Sdougbacl_get_fd_np(int fd, acl_type_t type)
81224092Sdougb{
82224092Sdougb	struct acl	*aclp;
83224092Sdougb	int	error;
84224092Sdougb
85224092Sdougb	aclp = acl_init(ACL_MAX_ENTRIES);
86186448Sdougb	if (!aclp) {
87186448Sdougb		return (NULL);
88186448Sdougb	}
89186448Sdougb
90186448Sdougb	error = __acl_get_fd(fd, type, aclp);
91224092Sdougb	if (error) {
92224092Sdougb		acl_free(aclp);
93224092Sdougb		return (NULL);
94186448Sdougb	}
95186448Sdougb
96186448Sdougb	return (aclp);
97186448Sdougb}
98186448Sdougb