2 * Copyright (c) 2001 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 THE VOICES IN HIS HEAD BE
18 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24 * POSSIBILITY OF SUCH DAMAGE.
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
36 #include "acl_support.h"
39 * These three routines from sys/kern/subr_acl_nfs4.c are used by both kernel
42 void acl_nfs4_trivial_from_mode(struct acl *aclp, mode_t mode);
43 void acl_nfs4_sync_acl_from_mode(struct acl *aclp, mode_t mode,
45 void acl_nfs4_sync_mode_from_acl(mode_t *_mode, const struct acl *aclp);
48 _nfs4_acl_strip_np(const acl_t aclp, int canonical_six)
53 newacl = acl_init(ACL_MAX_ENTRIES);
59 _acl_brand_as(newacl, ACL_BRAND_NFS4);
61 acl_nfs4_sync_mode_from_acl(&mode, &(aclp->ats_acl));
63 acl_nfs4_sync_acl_from_mode(&(newacl->ats_acl), mode, -1);
65 acl_nfs4_trivial_from_mode(&(newacl->ats_acl), mode);
71 _posix1e_acl_strip_np(const acl_t aclp, int recalculate_mask)
73 acl_t acl_new, acl_old;
74 acl_entry_t entry, entry_new;
77 int entry_id, have_mask_entry;
79 assert(_acl_brand(aclp) == ACL_BRAND_POSIX);
81 acl_old = acl_dup(aclp);
85 assert(_acl_brand(acl_old) == ACL_BRAND_POSIX);
88 acl_new = acl_init(ACL_MAX_ENTRIES);
91 tag = ACL_UNDEFINED_TAG;
93 /* only save the default user/group/other entries */
94 entry_id = ACL_FIRST_ENTRY;
95 while (acl_get_entry(acl_old, entry_id, &entry) == 1) {
96 entry_id = ACL_NEXT_ENTRY;
98 assert(_entry_brand(entry) == ACL_BRAND_POSIX);
100 if (acl_get_tag_type(entry, &tag) == -1)
107 if (acl_get_tag_type(entry, &tag) == -1)
109 if (acl_get_permset(entry, &perm) == -1)
111 if (acl_create_entry(&acl_new, &entry_new) == -1)
113 if (acl_set_tag_type(entry_new, tag) == -1)
115 if (acl_set_permset(entry_new, perm) == -1)
117 if (acl_copy_entry(entry_new, entry) == -1)
119 assert(_entry_brand(entry_new) == ACL_BRAND_POSIX);
129 assert(_acl_brand(acl_new) == ACL_BRAND_POSIX);
131 if (have_mask_entry && recalculate_mask) {
132 if (acl_calc_mask(&acl_new) == -1)
140 acl_strip_np(const acl_t aclp, int recalculate_mask)
142 switch (_acl_brand(aclp)) {
144 return (_nfs4_acl_strip_np(aclp, 1));
146 case ACL_BRAND_POSIX:
147 return (_posix1e_acl_strip_np(aclp, recalculate_mask));
156 * Return 1, if ACL is trivial, 0 otherwise.
158 * ACL is trivial, iff its meaning could be fully expressed using just file
159 * mode. In other words, ACL is trivial iff it doesn't have "+" to the right
160 * of the mode bits in "ls -l" output ;-)
163 acl_is_trivial_np(const acl_t aclp, int *trivialp)
168 if (aclp == NULL || trivialp == NULL) {
173 switch (_acl_brand(aclp)) {
174 case ACL_BRAND_POSIX:
175 if (aclp->ats_acl.acl_cnt == 3)
184 * If the ACL has more than canonical six entries,
185 * it's non trivial by definition.
187 if (aclp->ats_acl.acl_cnt > 6) {
193 * Calculate trivial ACL - using acl_strip_np(3) - and compare
196 tmpacl = _nfs4_acl_strip_np(aclp, 0);
200 differs = _acl_differs(aclp, tmpacl);
209 * Try again with an old-style, "canonical six" trivial ACL.
211 tmpacl = _nfs4_acl_strip_np(aclp, 1);
215 differs = _acl_differs(aclp, tmpacl);