2 * Copyright (c) 2001-2002 Chris D. Faulhaber
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
30 #include <sys/types.h>
31 #include "namespace.h"
33 #include "un-namespace.h"
38 #include "acl_support.h"
41 _entry_matches(const acl_entry_t a, const acl_entry_t b)
44 * There is a semantical difference here between NFSv4 and POSIX
45 * draft ACLs. In POSIX, there may be only one entry for the particular
46 * user or group. In NFSv4 ACL, there may be any number of them. We're
47 * trying to be more specific here in that case.
49 switch (_entry_brand(a)) {
51 if (a->ae_tag != b->ae_tag || a->ae_entry_type != b->ae_entry_type)
54 /* If ae_ids matter, compare them as well. */
55 if (a->ae_tag == ACL_USER || a->ae_tag == ACL_GROUP) {
56 if (a->ae_id != b->ae_id)
63 if ((a->ae_tag == b->ae_tag) && (a->ae_id == b->ae_id))
71 * acl_delete_entry() (23.4.9): remove the ACL entry indicated by entry_d
75 acl_delete_entry(acl_t acl, acl_entry_t entry_d)
78 struct acl_entry entry_int;
81 if (acl == NULL || entry_d == NULL) {
86 acl_int = &acl->ats_acl;
88 if (_entry_brand(entry_d) != _acl_brand(acl)) {
93 if ((acl->ats_acl.acl_cnt < 1) ||
94 (acl->ats_acl.acl_cnt > ACL_MAX_ENTRIES)) {
99 /* Use a local copy to prevent deletion of more than this entry */
100 entry_int = *entry_d;
102 for (i = 0; i < acl->ats_acl.acl_cnt;) {
103 if (_entry_matches(&(acl->ats_acl.acl_entry[i]), &entry_int)) {
104 /* ...shift the remaining entries... */
105 for (j = i; j < acl->ats_acl.acl_cnt - 1; ++j)
106 acl->ats_acl.acl_entry[j] =
107 acl->ats_acl.acl_entry[j+1];
108 /* ...drop the count and zero the unused entry... */
109 acl->ats_acl.acl_cnt--;
110 bzero(&acl->ats_acl.acl_entry[j],
111 sizeof(struct acl_entry));
112 acl->ats_cur_entry = 0;
114 /* Continue with the loop to remove all maching entries. */
128 acl_delete_entry_np(acl_t acl, int offset)
138 acl_int = &acl->ats_acl;
140 if (offset < 0 || offset >= acl_int->acl_cnt) {
145 if ((acl->ats_acl.acl_cnt < 1) ||
146 (acl->ats_acl.acl_cnt > ACL_MAX_ENTRIES)) {
151 /* ...shift the remaining entries... */
152 for (i = offset; i < acl->ats_acl.acl_cnt - 1; ++i)
153 acl->ats_acl.acl_entry[i] =
154 acl->ats_acl.acl_entry[i+1];
155 /* ...drop the count and zero the unused entry... */
156 acl->ats_acl.acl_cnt--;
157 bzero(&acl->ats_acl.acl_entry[i],
158 sizeof(struct acl_entry));
159 acl->ats_cur_entry = 0;