acl_get.c revision 75185
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 75185 2001-04-04 18:00:52Z tmm $
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 "namespace.h"
39#include <sys/acl.h>
40#include "un-namespace.h"
41
42#include <errno.h>
43#include <stdlib.h>
44#include <string.h>
45
46acl_t
47acl_get_file(const char *path_p, acl_type_t type)
48{
49	struct acl	*aclp;
50	int	error;
51
52	aclp = acl_init(ACL_MAX_ENTRIES);
53	if (!aclp) {
54		return (NULL);
55	}
56
57	error = __acl_get_file(path_p, type, aclp);
58	if (error) {
59		acl_free(aclp);
60		return (NULL);
61	}
62
63	return (aclp);
64}
65
66acl_t
67acl_get_fd(int fd)
68{
69	struct acl	*aclp;
70	int	error;
71
72	aclp = acl_init(ACL_MAX_ENTRIES);
73	if (!aclp) {
74		return (NULL);
75	}
76
77	error = ___acl_get_fd(fd, ACL_TYPE_ACCESS, aclp);
78	if (error) {
79		acl_free(aclp);
80		return (NULL);
81	}
82
83	return (aclp);
84}
85
86acl_t
87acl_get_fd_np(int fd, acl_type_t type)
88{
89	struct acl	*aclp;
90	int	error;
91
92	aclp = acl_init(ACL_MAX_ENTRIES);
93	if (!aclp) {
94		return (NULL);
95	}
96
97	error = ___acl_get_fd(fd, type, aclp);
98	if (error) {
99		acl_free(aclp);
100		return (NULL);
101	}
102
103	return (aclp);
104}
105
106int
107acl_get_permset(acl_entry_t entry_d, acl_permset_t *permset_p)
108{
109
110	if (!entry_d || !permset_p) {
111		errno = EINVAL;
112		return -1;
113	}
114
115	*permset_p = &entry_d->ae_perm;
116
117	return 0;
118}
119
120void *
121acl_get_qualifier(acl_entry_t entry_d)
122{
123	uid_t *retval;
124
125	if (!entry_d) {
126		errno = EINVAL;
127		return NULL;
128	}
129
130	switch(entry_d->ae_tag) {
131	case ACL_USER:
132	case ACL_GROUP:
133		retval = malloc(sizeof(uid_t));
134		if (retval) {
135			*retval = entry_d->ae_id;
136			return retval;
137		}
138	}
139
140	errno = EINVAL;
141	return NULL;
142}
143
144int
145acl_get_tag_type(acl_entry_t entry_d, acl_tag_t *tag_type_p)
146{
147
148	if (!entry_d || !tag_type_p) {
149		errno = EINVAL;
150		return -1;
151	}
152
153	*tag_type_p = entry_d->ae_tag;
154
155	return 0;
156}
157