acl_get.c revision 74667
1/*-
2 * Copyright (c) 1999, 2000, 2001 Robert N. M. Watson
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 * $FreeBSD: head/lib/libc/posix1e/acl_get.c 74667 2001-03-22 22:31:01Z jedgar $
27 */
28/*
29 * acl_get_file - syscall wrapper for retrieving ACL by filename
30 * acl_get_fd - syscall wrapper for retrieving access ACL by fd
31 * acl_get_fd_np - syscall wrapper for retrieving ACL by fd (non-POSIX)
32 * acl_get_permset() returns the permission set in the ACL entry
33 * acl_get_qualifier() retrieves the qualifier of the tag from the ACL entry
34 * acl_get_tag_type() returns the tag type for the ACL entry entry_d
35 */
36
37#include <sys/types.h>
38#include <sys/acl.h>
39
40#include <errno.h>
41#include <stdlib.h>
42#include <string.h>
43
44acl_t
45acl_get_file(const char *path_p, acl_type_t type)
46{
47	struct acl	*aclp;
48	int	error;
49
50	aclp = acl_init(ACL_MAX_ENTRIES);
51	if (!aclp) {
52		return (NULL);
53	}
54
55	error = __acl_get_file(path_p, type, aclp);
56	if (error) {
57		acl_free(aclp);
58		return (NULL);
59	}
60
61	return (aclp);
62}
63
64acl_t
65acl_get_fd(int fd)
66{
67	struct acl	*aclp;
68	int	error;
69
70	aclp = acl_init(ACL_MAX_ENTRIES);
71	if (!aclp) {
72		return (NULL);
73	}
74
75	error = __acl_get_fd(fd, ACL_TYPE_ACCESS, aclp);
76	if (error) {
77		acl_free(aclp);
78		return (NULL);
79	}
80
81	return (aclp);
82}
83
84acl_t
85acl_get_fd_np(int fd, acl_type_t type)
86{
87	struct acl	*aclp;
88	int	error;
89
90	aclp = acl_init(ACL_MAX_ENTRIES);
91	if (!aclp) {
92		return (NULL);
93	}
94
95	error = __acl_get_fd(fd, type, aclp);
96	if (error) {
97		acl_free(aclp);
98		return (NULL);
99	}
100
101	return (aclp);
102}
103
104int
105acl_get_permset(acl_entry_t entry_d, acl_permset_t *permset_p)
106{
107
108	if (!entry_d || !permset_p) {
109		errno = EINVAL;
110		return -1;
111	}
112
113	*permset_p = &entry_d->ae_perm;
114
115	return 0;
116}
117
118void *
119acl_get_qualifier(acl_entry_t entry_d)
120{
121	uid_t *retval;
122
123	if (!entry_d) {
124		errno = EINVAL;
125		return NULL;
126	}
127
128	switch(entry_d->ae_tag) {
129	case ACL_USER:
130	case ACL_GROUP:
131		retval = malloc(sizeof(uid_t));
132		if (retval) {
133			*retval = entry_d->ae_id;
134			return retval;
135		}
136	}
137
138	errno = EINVAL;
139	return NULL;
140}
141
142int
143acl_get_tag_type(acl_entry_t entry_d, acl_tag_t *tag_type_p)
144{
145
146	if (!entry_d || !tag_type_p) {
147		errno = EINVAL;
148		return -1;
149	}
150
151	*tag_type_p = entry_d->ae_tag;
152
153	return 0;
154}
155