xref: /illumos-gate/usr/src/uts/common/fs/nfs/nfs4_acl.c (revision e913d9ec)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5354a1801Ssamf  * Common Development and Distribution License (the "License").
6354a1801Ssamf  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*e913d9ecSLisa Week  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate /*
277c478bd9Sstevel@tonic-gate  * The following naming convention is used in function names.
287c478bd9Sstevel@tonic-gate  *
297c478bd9Sstevel@tonic-gate  * If an argument is one or more aclent_t, we use "aent".
307c478bd9Sstevel@tonic-gate  * If an argument is one or more nfsace4, we use "ace4".
317c478bd9Sstevel@tonic-gate  * If an argument is one or more ace_t, we use "acet".
327c478bd9Sstevel@tonic-gate  *
337c478bd9Sstevel@tonic-gate  * If there is an aggregate of the one above...
347c478bd9Sstevel@tonic-gate  *     If it's contained in a vsecattr_t, we prepend "vs_".
357c478bd9Sstevel@tonic-gate  *     If it's contained in an "array" (pointer) and length, we prepend "ln_".
367c478bd9Sstevel@tonic-gate  *
377c478bd9Sstevel@tonic-gate  * Thus, for example, suppose you have a function that converts an
387c478bd9Sstevel@tonic-gate  * array of aclent_t structures into an array of nfsace4 structures,
397c478bd9Sstevel@tonic-gate  * it's name would be "ln_aent_to_ace4".
407c478bd9Sstevel@tonic-gate  */
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate #include <sys/acl.h>
437c478bd9Sstevel@tonic-gate #include <nfs/nfs4_kprot.h>
447c478bd9Sstevel@tonic-gate #include <nfs/nfs4.h>
457c478bd9Sstevel@tonic-gate #include <nfs/rnode4.h>
467c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h>
477c478bd9Sstevel@tonic-gate #include <sys/systm.h>
487c478bd9Sstevel@tonic-gate #include <sys/sdt.h>
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate #define	ACE4_POSIX_SUPPORTED_BITS (ACE4_READ_DATA | \
517c478bd9Sstevel@tonic-gate     ACE4_WRITE_DATA | \
527c478bd9Sstevel@tonic-gate     ACE4_APPEND_DATA | \
537c478bd9Sstevel@tonic-gate     ACE4_EXECUTE | \
547c478bd9Sstevel@tonic-gate     ACE4_READ_ATTRIBUTES | \
557c478bd9Sstevel@tonic-gate     ACE4_READ_ACL | \
567c478bd9Sstevel@tonic-gate     ACE4_WRITE_ACL)
577c478bd9Sstevel@tonic-gate 
587c478bd9Sstevel@tonic-gate static int ace4vals_compare(const void *, const void *);
597c478bd9Sstevel@tonic-gate static int nfs4_ace4_list_construct(void *, void *, int);
607c478bd9Sstevel@tonic-gate static void nfs4_ace4_list_destroy(void *, void *);
617c478bd9Sstevel@tonic-gate static void ace4_list_free(ace4_list_t *);
627c478bd9Sstevel@tonic-gate static void ace4vals_init(ace4vals_t *, utf8string *);
637c478bd9Sstevel@tonic-gate static void ace4_list_init(ace4_list_t *, int);
647c478bd9Sstevel@tonic-gate static int ln_aent_preprocess(aclent_t *, int,
657c478bd9Sstevel@tonic-gate     int *, o_mode_t *, int *, int *, int *);
667c478bd9Sstevel@tonic-gate static void ace4_make_deny(nfsace4 *, nfsace4 *, int, int, int);
677c478bd9Sstevel@tonic-gate static acemask4 mode_to_ace4_access(o_mode_t, int, int, int, int);
687c478bd9Sstevel@tonic-gate static int ln_aent_to_ace4(aclent_t *, int, nfsace4 **, int *, int, int);
697c478bd9Sstevel@tonic-gate static int ace4_mask_to_mode(acemask4, o_mode_t *, int);
707c478bd9Sstevel@tonic-gate static int ace4_allow_to_mode(acemask4, o_mode_t *, int);
717c478bd9Sstevel@tonic-gate static ace4vals_t *ace4vals_find(nfsace4 *, avl_tree_t *, int *);
727c478bd9Sstevel@tonic-gate static int ace4_to_aent_legal(nfsace4 *, int);
737c478bd9Sstevel@tonic-gate static int ace4vals_to_aent(ace4vals_t *, aclent_t *, ace4_list_t *,
74*e913d9ecSLisa Week     uid_t, gid_t, int, int);
757c478bd9Sstevel@tonic-gate static int ace4_list_to_aent(ace4_list_t *, aclent_t **, int *, uid_t, gid_t,
76*e913d9ecSLisa Week     int, int);
777c478bd9Sstevel@tonic-gate static int ln_ace4_to_aent(nfsace4 *ace4, int n, uid_t, gid_t,
78*e913d9ecSLisa Week     aclent_t **, int *, aclent_t **, int *, int, int);
797c478bd9Sstevel@tonic-gate static int ace4_cmp(nfsace4 *, nfsace4 *);
80fa9e4066Sahrens static int acet_to_ace4(ace_t *, nfsace4 *, int);
81*e913d9ecSLisa Week static int ace4_to_acet(nfsace4 *, ace_t *, uid_t, gid_t, int);
82*e913d9ecSLisa Week static int validate_idmapping(utf8string *, uid_t *, int, int);
837c478bd9Sstevel@tonic-gate static int u8s_mapped_to_nobody(utf8string *, uid_t, int);
84*e913d9ecSLisa Week static void remap_id(uid_t *, int);
85fa9e4066Sahrens static void ace4_mask_to_acet_mask(acemask4, uint32_t *);
86fa9e4066Sahrens static void acet_mask_to_ace4_mask(uint32_t, acemask4 *);
87fa9e4066Sahrens static void ace4_flags_to_acet_flags(aceflag4, uint16_t *);
88fa9e4066Sahrens static void acet_flags_to_ace4_flags(uint16_t, aceflag4 *);
89fa9e4066Sahrens 
907c478bd9Sstevel@tonic-gate /*
917c478bd9Sstevel@tonic-gate  * The following two functions check and set ACE4_SYNCRONIZE, ACE4_WRITE_OWNER,
927c478bd9Sstevel@tonic-gate  * ACE4_DELETE and ACE4_WRITE_ATTRIBUTES.
937c478bd9Sstevel@tonic-gate  */
947c478bd9Sstevel@tonic-gate static int access_mask_check(nfsace4 *, int, int, int);
957c478bd9Sstevel@tonic-gate static acemask4 access_mask_set(int, int, int, int, int);
967c478bd9Sstevel@tonic-gate 
977c478bd9Sstevel@tonic-gate static int nfs4_acl_debug = 0;
987c478bd9Sstevel@tonic-gate 
997c478bd9Sstevel@tonic-gate #define	ACL_SYNCHRONIZE_SET_DENY		0x0000001
1007c478bd9Sstevel@tonic-gate #define	ACL_SYNCHRONIZE_SET_ALLOW		0x0000002
1017c478bd9Sstevel@tonic-gate #define	ACL_SYNCHRONIZE_ERR_DENY		0x0000004
1027c478bd9Sstevel@tonic-gate #define	ACL_SYNCHRONIZE_ERR_ALLOW		0x0000008
1037c478bd9Sstevel@tonic-gate 
1047c478bd9Sstevel@tonic-gate #define	ACL_WRITE_OWNER_SET_DENY		0x0000010
1057c478bd9Sstevel@tonic-gate #define	ACL_WRITE_OWNER_SET_ALLOW		0x0000020
1067c478bd9Sstevel@tonic-gate #define	ACL_WRITE_OWNER_ERR_DENY		0x0000040
1077c478bd9Sstevel@tonic-gate #define	ACL_WRITE_OWNER_ERR_ALLOW		0x0000080
1087c478bd9Sstevel@tonic-gate 
1097c478bd9Sstevel@tonic-gate #define	ACL_DELETE_SET_DENY			0x0000100
1107c478bd9Sstevel@tonic-gate #define	ACL_DELETE_SET_ALLOW			0x0000200
1117c478bd9Sstevel@tonic-gate #define	ACL_DELETE_ERR_DENY			0x0000400
1127c478bd9Sstevel@tonic-gate #define	ACL_DELETE_ERR_ALLOW			0x0000800
1137c478bd9Sstevel@tonic-gate 
1147c478bd9Sstevel@tonic-gate #define	ACL_WRITE_ATTRS_OWNER_SET_DENY		0x0001000
1157c478bd9Sstevel@tonic-gate #define	ACL_WRITE_ATTRS_OWNER_SET_ALLOW		0x0002000
1167c478bd9Sstevel@tonic-gate #define	ACL_WRITE_ATTRS_OWNER_ERR_DENY		0x0004000
1177c478bd9Sstevel@tonic-gate #define	ACL_WRITE_ATTRS_OWNER_ERR_ALLOW		0x0008000
1187c478bd9Sstevel@tonic-gate 
1197c478bd9Sstevel@tonic-gate #define	ACL_WRITE_ATTRS_WRITER_SET_DENY		0x0010000
1207c478bd9Sstevel@tonic-gate #define	ACL_WRITE_ATTRS_WRITER_SET_ALLOW	0x0020000
1217c478bd9Sstevel@tonic-gate #define	ACL_WRITE_ATTRS_WRITER_ERR_DENY		0x0040000
1227c478bd9Sstevel@tonic-gate #define	ACL_WRITE_ATTRS_WRITER_ERR_ALLOW	0x0080000
1237c478bd9Sstevel@tonic-gate 
1247c478bd9Sstevel@tonic-gate #define	ACL_WRITE_NAMED_WRITER_SET_DENY		0x0100000
1257c478bd9Sstevel@tonic-gate #define	ACL_WRITE_NAMED_WRITER_SET_ALLOW	0x0200000
1267c478bd9Sstevel@tonic-gate #define	ACL_WRITE_NAMED_WRITER_ERR_DENY		0x0400000
1277c478bd9Sstevel@tonic-gate #define	ACL_WRITE_NAMED_WRITER_ERR_ALLOW	0x0800000
1287c478bd9Sstevel@tonic-gate 
1297c478bd9Sstevel@tonic-gate #define	ACL_READ_NAMED_READER_SET_DENY		0x1000000
1307c478bd9Sstevel@tonic-gate #define	ACL_READ_NAMED_READER_SET_ALLOW		0x2000000
1317c478bd9Sstevel@tonic-gate #define	ACL_READ_NAMED_READER_ERR_DENY		0x4000000
1327c478bd9Sstevel@tonic-gate #define	ACL_READ_NAMED_READER_ERR_ALLOW		0x8000000
1337c478bd9Sstevel@tonic-gate 
1347c478bd9Sstevel@tonic-gate /*
1357c478bd9Sstevel@tonic-gate  * What we will send the server upon setting an ACL on our client
1367c478bd9Sstevel@tonic-gate  */
1377c478bd9Sstevel@tonic-gate static int nfs4_acl_client_produce =
1387c478bd9Sstevel@tonic-gate 	(ACL_SYNCHRONIZE_SET_ALLOW |
1397c478bd9Sstevel@tonic-gate 	ACL_WRITE_ATTRS_OWNER_SET_ALLOW |
1407c478bd9Sstevel@tonic-gate 	ACL_WRITE_ATTRS_WRITER_SET_DENY);
1417c478bd9Sstevel@tonic-gate 
1427c478bd9Sstevel@tonic-gate /*
1437c478bd9Sstevel@tonic-gate  * What we will accept upon getting an ACL on our client
1447c478bd9Sstevel@tonic-gate  */
1457c478bd9Sstevel@tonic-gate static int nfs4_acl_client_consume =
1467c478bd9Sstevel@tonic-gate 	(ACL_WRITE_OWNER_ERR_DENY |
1477c478bd9Sstevel@tonic-gate 	ACL_WRITE_OWNER_ERR_ALLOW |
1487c478bd9Sstevel@tonic-gate 	ACL_WRITE_ATTRS_OWNER_ERR_DENY |
1497c478bd9Sstevel@tonic-gate 	ACL_WRITE_ATTRS_OWNER_SET_ALLOW |
1507c478bd9Sstevel@tonic-gate 	ACL_WRITE_ATTRS_WRITER_ERR_ALLOW |
1517c478bd9Sstevel@tonic-gate 	ACL_WRITE_ATTRS_WRITER_SET_DENY);
1527c478bd9Sstevel@tonic-gate 
1537c478bd9Sstevel@tonic-gate /*
1547c478bd9Sstevel@tonic-gate  * What we will produce as an ACL on a newly created file
1557c478bd9Sstevel@tonic-gate  */
1567c478bd9Sstevel@tonic-gate static int nfs4_acl_server_produce =
1577c478bd9Sstevel@tonic-gate 	(ACL_SYNCHRONIZE_SET_ALLOW |
1587c478bd9Sstevel@tonic-gate 	ACL_WRITE_ATTRS_OWNER_SET_ALLOW |
1597c478bd9Sstevel@tonic-gate 	ACL_WRITE_ATTRS_WRITER_SET_DENY);
1607c478bd9Sstevel@tonic-gate 
1617c478bd9Sstevel@tonic-gate /*
1627c478bd9Sstevel@tonic-gate  * What we will accept upon setting an ACL on our server
1637c478bd9Sstevel@tonic-gate  */
1647c478bd9Sstevel@tonic-gate static int nfs4_acl_server_consume =
1657c478bd9Sstevel@tonic-gate 	(ACL_SYNCHRONIZE_ERR_DENY |
1667c478bd9Sstevel@tonic-gate 	ACL_DELETE_ERR_DENY |
1677c478bd9Sstevel@tonic-gate 	ACL_WRITE_OWNER_ERR_DENY |
1687c478bd9Sstevel@tonic-gate 	ACL_WRITE_OWNER_ERR_ALLOW |
1697c478bd9Sstevel@tonic-gate 	ACL_WRITE_ATTRS_OWNER_SET_ALLOW |
1707c478bd9Sstevel@tonic-gate 	ACL_WRITE_ATTRS_OWNER_ERR_DENY |
1717c478bd9Sstevel@tonic-gate 	ACL_WRITE_ATTRS_WRITER_SET_DENY |
1727c478bd9Sstevel@tonic-gate 	ACL_WRITE_ATTRS_WRITER_ERR_ALLOW |
1737c478bd9Sstevel@tonic-gate 	ACL_WRITE_NAMED_WRITER_ERR_DENY |
1747c478bd9Sstevel@tonic-gate 	ACL_READ_NAMED_READER_ERR_DENY);
1757c478bd9Sstevel@tonic-gate 
1767c478bd9Sstevel@tonic-gate static kmem_cache_t *nfs4_ace4vals_cache = NULL;
1777c478bd9Sstevel@tonic-gate static kmem_cache_t *nfs4_ace4_list_cache = NULL;
1787c478bd9Sstevel@tonic-gate 
1797c478bd9Sstevel@tonic-gate static int
ace4vals_compare(const void * va,const void * vb)1807c478bd9Sstevel@tonic-gate ace4vals_compare(const void *va, const void *vb)
1817c478bd9Sstevel@tonic-gate {
1827c478bd9Sstevel@tonic-gate 	const ace4vals_t *a = va, *b = vb;
1837c478bd9Sstevel@tonic-gate 
1847c478bd9Sstevel@tonic-gate 	if ((a->key == NULL) && (b->key == NULL))
1857c478bd9Sstevel@tonic-gate 		return (0);
1867c478bd9Sstevel@tonic-gate 	else if (a->key == NULL)
1877c478bd9Sstevel@tonic-gate 		return (-1);
1887c478bd9Sstevel@tonic-gate 	else if (b->key == NULL)
1897c478bd9Sstevel@tonic-gate 		return (1);
1907c478bd9Sstevel@tonic-gate 
1917c478bd9Sstevel@tonic-gate 	return (utf8_compare(a->key, b->key));
1927c478bd9Sstevel@tonic-gate }
1937c478bd9Sstevel@tonic-gate 
1947c478bd9Sstevel@tonic-gate /*ARGSUSED*/
1957c478bd9Sstevel@tonic-gate static int
nfs4_ace4_list_construct(void * voidp,void * arg,int kmem_flags)1967c478bd9Sstevel@tonic-gate nfs4_ace4_list_construct(void *voidp, void *arg, int kmem_flags)
1977c478bd9Sstevel@tonic-gate {
1987c478bd9Sstevel@tonic-gate 	ace4_list_t *a4l = voidp;
1997c478bd9Sstevel@tonic-gate 
2007c478bd9Sstevel@tonic-gate 	avl_create(&a4l->user, ace4vals_compare, sizeof (ace4vals_t),
2017c478bd9Sstevel@tonic-gate 	    offsetof(ace4vals_t, avl));
2027c478bd9Sstevel@tonic-gate 	avl_create(&a4l->group, ace4vals_compare, sizeof (ace4vals_t),
2037c478bd9Sstevel@tonic-gate 	    offsetof(ace4vals_t, avl));
2047c478bd9Sstevel@tonic-gate 	return (0);
2057c478bd9Sstevel@tonic-gate }
2067c478bd9Sstevel@tonic-gate 
2077c478bd9Sstevel@tonic-gate /*ARGSUSED*/
2087c478bd9Sstevel@tonic-gate static void
nfs4_ace4_list_destroy(void * voidp,void * arg)2097c478bd9Sstevel@tonic-gate nfs4_ace4_list_destroy(void *voidp, void *arg)
2107c478bd9Sstevel@tonic-gate {
2117c478bd9Sstevel@tonic-gate 	ace4_list_t *a4l = voidp;
2127c478bd9Sstevel@tonic-gate 
2137c478bd9Sstevel@tonic-gate 	avl_destroy(&a4l->user);
2147c478bd9Sstevel@tonic-gate 	avl_destroy(&a4l->group);
2157c478bd9Sstevel@tonic-gate }
2167c478bd9Sstevel@tonic-gate 
2177c478bd9Sstevel@tonic-gate void
nfs4_acl_init(void)2187c478bd9Sstevel@tonic-gate nfs4_acl_init(void)
2197c478bd9Sstevel@tonic-gate {
2207c478bd9Sstevel@tonic-gate 	nfs4_ace4vals_cache = kmem_cache_create("nfs4_ace4vals_cache",
2217c478bd9Sstevel@tonic-gate 	    sizeof (ace4vals_t), 0,
2227c478bd9Sstevel@tonic-gate 	    NULL, NULL,
2237c478bd9Sstevel@tonic-gate 	    NULL, NULL,
2247c478bd9Sstevel@tonic-gate 	    NULL,
2257c478bd9Sstevel@tonic-gate 	    0);
2267c478bd9Sstevel@tonic-gate 	nfs4_ace4_list_cache = kmem_cache_create("nfs4_ace4_list_cache",
2277c478bd9Sstevel@tonic-gate 	    sizeof (ace4_list_t), 0,
2287c478bd9Sstevel@tonic-gate 	    nfs4_ace4_list_construct, nfs4_ace4_list_destroy,
2297c478bd9Sstevel@tonic-gate 	    NULL, NULL,
2307c478bd9Sstevel@tonic-gate 	    NULL,
2317c478bd9Sstevel@tonic-gate 	    0);
2327c478bd9Sstevel@tonic-gate }
2337c478bd9Sstevel@tonic-gate 
2347c478bd9Sstevel@tonic-gate void
vs_acet_destroy(vsecattr_t * vsp)2357c478bd9Sstevel@tonic-gate vs_acet_destroy(vsecattr_t *vsp)
2367c478bd9Sstevel@tonic-gate {
2377c478bd9Sstevel@tonic-gate 	if (vsp->vsa_mask != (VSA_ACE | VSA_ACECNT))
2387c478bd9Sstevel@tonic-gate 		return;
2397c478bd9Sstevel@tonic-gate 
2407c478bd9Sstevel@tonic-gate 	if ((vsp->vsa_aclentp != NULL) &&
2417c478bd9Sstevel@tonic-gate 	    (vsp->vsa_aclcnt > 0) &&
2427c478bd9Sstevel@tonic-gate 	    (vsp->vsa_mask & VSA_ACE) &&
2437c478bd9Sstevel@tonic-gate 	    (vsp->vsa_mask & VSA_ACECNT))
2447c478bd9Sstevel@tonic-gate 		kmem_free(vsp->vsa_aclentp,
2457c478bd9Sstevel@tonic-gate 		    vsp->vsa_aclcnt * sizeof (ace_t));
2467c478bd9Sstevel@tonic-gate 
2477c478bd9Sstevel@tonic-gate 	vsp->vsa_aclentp = NULL;
2487c478bd9Sstevel@tonic-gate 	vsp->vsa_aclcnt = 0;
2497c478bd9Sstevel@tonic-gate }
2507c478bd9Sstevel@tonic-gate 
2517c478bd9Sstevel@tonic-gate void
vs_ace4_destroy(vsecattr_t * vsp)2527c478bd9Sstevel@tonic-gate vs_ace4_destroy(vsecattr_t *vsp)
2537c478bd9Sstevel@tonic-gate {
2547c478bd9Sstevel@tonic-gate 	nfsace4 *ace4;
2557c478bd9Sstevel@tonic-gate 	int i;
2567c478bd9Sstevel@tonic-gate 
2577c478bd9Sstevel@tonic-gate 	if (vsp->vsa_mask != (VSA_ACE | VSA_ACECNT))
2587c478bd9Sstevel@tonic-gate 		return;
2597c478bd9Sstevel@tonic-gate 
2607c478bd9Sstevel@tonic-gate 	if ((vsp->vsa_aclentp != NULL) &&
2617c478bd9Sstevel@tonic-gate 	    (vsp->vsa_aclcnt > 0) &&
2627c478bd9Sstevel@tonic-gate 	    (vsp->vsa_mask & VSA_ACE) &&
2637c478bd9Sstevel@tonic-gate 	    (vsp->vsa_mask & VSA_ACECNT)) {
2647c478bd9Sstevel@tonic-gate 		for (i = 0; i < vsp->vsa_aclcnt; i++) {
2657c478bd9Sstevel@tonic-gate 			ace4 = (nfsace4 *)vsp->vsa_aclentp + i;
2667c478bd9Sstevel@tonic-gate 			if ((ace4->who.utf8string_len > 0) &&
2677c478bd9Sstevel@tonic-gate 			    (ace4->who.utf8string_val != NULL))
2687c478bd9Sstevel@tonic-gate 				kmem_free(ace4->who.utf8string_val,
2697c478bd9Sstevel@tonic-gate 				    ace4->who.utf8string_len);
2707c478bd9Sstevel@tonic-gate 
2717c478bd9Sstevel@tonic-gate 			ace4->who.utf8string_val = NULL;
2727c478bd9Sstevel@tonic-gate 			ace4->who.utf8string_len = 0;
2737c478bd9Sstevel@tonic-gate 		}
2747c478bd9Sstevel@tonic-gate 
2757c478bd9Sstevel@tonic-gate 		kmem_free(vsp->vsa_aclentp,
2767c478bd9Sstevel@tonic-gate 		    vsp->vsa_aclcnt * sizeof (nfsace4));
2777c478bd9Sstevel@tonic-gate 	}
2787c478bd9Sstevel@tonic-gate 
2797c478bd9Sstevel@tonic-gate 	vsp->vsa_aclentp = NULL;
2807c478bd9Sstevel@tonic-gate 	vsp->vsa_aclcnt = 0;
2817c478bd9Sstevel@tonic-gate }
2827c478bd9Sstevel@tonic-gate 
2837c478bd9Sstevel@tonic-gate void
vs_aent_destroy(vsecattr_t * vsp)2847c478bd9Sstevel@tonic-gate vs_aent_destroy(vsecattr_t *vsp)
2857c478bd9Sstevel@tonic-gate {
2867c478bd9Sstevel@tonic-gate 	if (vsp->vsa_mask & (VSA_ACE | VSA_ACECNT))
2877c478bd9Sstevel@tonic-gate 		return;
2887c478bd9Sstevel@tonic-gate 
2897c478bd9Sstevel@tonic-gate 	if ((vsp->vsa_aclentp != NULL) &&
2907c478bd9Sstevel@tonic-gate 	    (vsp->vsa_aclcnt > 0) &&
2917c478bd9Sstevel@tonic-gate 	    (vsp->vsa_mask & VSA_ACL) &&
2927c478bd9Sstevel@tonic-gate 	    (vsp->vsa_mask & VSA_ACLCNT))
2937c478bd9Sstevel@tonic-gate 		kmem_free(vsp->vsa_aclentp,
2947c478bd9Sstevel@tonic-gate 		    vsp->vsa_aclcnt * sizeof (aclent_t));
2957c478bd9Sstevel@tonic-gate 	if ((vsp->vsa_dfaclentp != NULL) &&
2967c478bd9Sstevel@tonic-gate 	    (vsp->vsa_dfaclcnt > 0) &&
2977c478bd9Sstevel@tonic-gate 	    (vsp->vsa_mask & VSA_DFACL) &&
2987c478bd9Sstevel@tonic-gate 	    (vsp->vsa_mask & VSA_DFACLCNT))
2997c478bd9Sstevel@tonic-gate 		kmem_free(vsp->vsa_dfaclentp,
3007c478bd9Sstevel@tonic-gate 		    vsp->vsa_dfaclcnt * sizeof (aclent_t));
3017c478bd9Sstevel@tonic-gate 
3027c478bd9Sstevel@tonic-gate 	vsp->vsa_aclentp = NULL;
3037c478bd9Sstevel@tonic-gate 	vsp->vsa_aclcnt = 0;
3047c478bd9Sstevel@tonic-gate 
3057c478bd9Sstevel@tonic-gate 	vsp->vsa_dfaclentp = NULL;
3067c478bd9Sstevel@tonic-gate 	vsp->vsa_aclcnt = 0;
3077c478bd9Sstevel@tonic-gate }
3087c478bd9Sstevel@tonic-gate 
3097c478bd9Sstevel@tonic-gate /*
3107c478bd9Sstevel@tonic-gate  * free all data associated with an ace4_list
3117c478bd9Sstevel@tonic-gate  */
3127c478bd9Sstevel@tonic-gate static void
ace4_list_free(ace4_list_t * a4l)3137c478bd9Sstevel@tonic-gate ace4_list_free(ace4_list_t *a4l)
3147c478bd9Sstevel@tonic-gate {
3157c478bd9Sstevel@tonic-gate 	ace4vals_t *node;
3167c478bd9Sstevel@tonic-gate 	void *cookie;
3177c478bd9Sstevel@tonic-gate 
3187c478bd9Sstevel@tonic-gate 	if (a4l == NULL)
3197c478bd9Sstevel@tonic-gate 		return;
3207c478bd9Sstevel@tonic-gate 
3217c478bd9Sstevel@tonic-gate 	/* free all nodes, but don't destroy the trees themselves */
3227c478bd9Sstevel@tonic-gate 	cookie = NULL;
3237c478bd9Sstevel@tonic-gate 	while ((node = avl_destroy_nodes(&a4l->user, &cookie)) != NULL)
3247c478bd9Sstevel@tonic-gate 		kmem_cache_free(nfs4_ace4vals_cache, node);
3257c478bd9Sstevel@tonic-gate 	cookie = NULL;
3267c478bd9Sstevel@tonic-gate 	while ((node = avl_destroy_nodes(&a4l->group, &cookie)) != NULL)
3277c478bd9Sstevel@tonic-gate 		kmem_cache_free(nfs4_ace4vals_cache, node);
3287c478bd9Sstevel@tonic-gate 
3297c478bd9Sstevel@tonic-gate 	/* free the container itself */
3307c478bd9Sstevel@tonic-gate 	kmem_cache_free(nfs4_ace4_list_cache, a4l);
3317c478bd9Sstevel@tonic-gate }
3327c478bd9Sstevel@tonic-gate 
3337c478bd9Sstevel@tonic-gate static void
ace4vals_init(ace4vals_t * vals,utf8string * key)3347c478bd9Sstevel@tonic-gate ace4vals_init(ace4vals_t *vals, utf8string *key)
3357c478bd9Sstevel@tonic-gate {
3367c478bd9Sstevel@tonic-gate 	bzero(vals, sizeof (*vals));
3377c478bd9Sstevel@tonic-gate 	vals->allowed = ACE4_MASK_UNDEFINED;
3387c478bd9Sstevel@tonic-gate 	vals->denied = ACE4_MASK_UNDEFINED;
3397c478bd9Sstevel@tonic-gate 	vals->mask = ACE4_MASK_UNDEFINED;
3407c478bd9Sstevel@tonic-gate 	vals->key = key;
3417c478bd9Sstevel@tonic-gate }
3427c478bd9Sstevel@tonic-gate 
3437c478bd9Sstevel@tonic-gate static void
ace4_list_init(ace4_list_t * a4l,int dfacl_flag)3447c478bd9Sstevel@tonic-gate ace4_list_init(ace4_list_t *a4l, int dfacl_flag)
3457c478bd9Sstevel@tonic-gate {
3467c478bd9Sstevel@tonic-gate 	ace4vals_init(&a4l->user_obj, NULL);
3477c478bd9Sstevel@tonic-gate 	ace4vals_init(&a4l->group_obj, NULL);
3487c478bd9Sstevel@tonic-gate 	ace4vals_init(&a4l->other_obj, NULL);
3497c478bd9Sstevel@tonic-gate 	a4l->numusers = 0;
3507c478bd9Sstevel@tonic-gate 	a4l->numgroups = 0;
3517c478bd9Sstevel@tonic-gate 	a4l->acl_mask = 0;
3527c478bd9Sstevel@tonic-gate 	a4l->hasmask = 0;
3537c478bd9Sstevel@tonic-gate 	a4l->state = ace4_unused;
3547c478bd9Sstevel@tonic-gate 	a4l->seen = 0;
3557c478bd9Sstevel@tonic-gate 	a4l->dfacl_flag = dfacl_flag;
3567c478bd9Sstevel@tonic-gate }
3577c478bd9Sstevel@tonic-gate 
3587c478bd9Sstevel@tonic-gate /*
3597c478bd9Sstevel@tonic-gate  * Make an initial pass over an array of aclent_t's.  Gather
3607c478bd9Sstevel@tonic-gate  * information such as an ACL_MASK (if any), number of users,
3617c478bd9Sstevel@tonic-gate  * number of groups, and whether the array needs to be sorted.
3627c478bd9Sstevel@tonic-gate  */
3637c478bd9Sstevel@tonic-gate static int
ln_aent_preprocess(aclent_t * aclent,int n,int * hasmask,o_mode_t * mask,int * numuser,int * numgroup,int * needsort)3647c478bd9Sstevel@tonic-gate ln_aent_preprocess(aclent_t *aclent, int n,
3657c478bd9Sstevel@tonic-gate     int *hasmask, o_mode_t *mask,
3667c478bd9Sstevel@tonic-gate     int *numuser, int *numgroup, int *needsort)
3677c478bd9Sstevel@tonic-gate {
3687c478bd9Sstevel@tonic-gate 	int error = 0;
3697c478bd9Sstevel@tonic-gate 	int i;
3707c478bd9Sstevel@tonic-gate 	int curtype = 0;
3717c478bd9Sstevel@tonic-gate 
3727c478bd9Sstevel@tonic-gate 	*hasmask = 0;
3737c478bd9Sstevel@tonic-gate 	*mask = 07;
3747c478bd9Sstevel@tonic-gate 	*needsort = 0;
3757c478bd9Sstevel@tonic-gate 	*numuser = 0;
3767c478bd9Sstevel@tonic-gate 	*numgroup = 0;
3777c478bd9Sstevel@tonic-gate 
3787c478bd9Sstevel@tonic-gate 	for (i = 0; i < n; i++) {
3797c478bd9Sstevel@tonic-gate 		if (aclent[i].a_type < curtype)
3807c478bd9Sstevel@tonic-gate 			*needsort = 1;
3817c478bd9Sstevel@tonic-gate 		else if (aclent[i].a_type > curtype)
3827c478bd9Sstevel@tonic-gate 			curtype = aclent[i].a_type;
3837c478bd9Sstevel@tonic-gate 		if (aclent[i].a_type & USER)
3847c478bd9Sstevel@tonic-gate 			(*numuser)++;
3857c478bd9Sstevel@tonic-gate 		if (aclent[i].a_type & (GROUP | GROUP_OBJ))
3867c478bd9Sstevel@tonic-gate 			(*numgroup)++;
3877c478bd9Sstevel@tonic-gate 		if (aclent[i].a_type & CLASS_OBJ) {
3887c478bd9Sstevel@tonic-gate 			if (*hasmask) {
3897c478bd9Sstevel@tonic-gate 				NFS4_DEBUG(nfs4_acl_debug, (CE_NOTE,
3907c478bd9Sstevel@tonic-gate 				    "ln_aent_preprocess: multiple CLASS_OBJs "
3917c478bd9Sstevel@tonic-gate 				    "(masks) found"));
3927c478bd9Sstevel@tonic-gate 				error = EINVAL;
3937c478bd9Sstevel@tonic-gate 				goto out;
3947c478bd9Sstevel@tonic-gate 			} else {
3957c478bd9Sstevel@tonic-gate 				*hasmask = 1;
3967c478bd9Sstevel@tonic-gate 				*mask = aclent[i].a_perm;
3977c478bd9Sstevel@tonic-gate 			}
3987c478bd9Sstevel@tonic-gate 		}
3997c478bd9Sstevel@tonic-gate 	}
4007c478bd9Sstevel@tonic-gate 
4017c478bd9Sstevel@tonic-gate 	if ((! *hasmask) && (*numuser + *numgroup > 1)) {
4027c478bd9Sstevel@tonic-gate 		NFS4_DEBUG(nfs4_acl_debug, (CE_NOTE,
4037c478bd9Sstevel@tonic-gate 		    "ln_aent_preprocess: no CLASS_OBJs "
4047c478bd9Sstevel@tonic-gate 		    "(masks) found"));
4057c478bd9Sstevel@tonic-gate 		error = EINVAL;
4067c478bd9Sstevel@tonic-gate 		goto out;
4077c478bd9Sstevel@tonic-gate 	}
4087c478bd9Sstevel@tonic-gate 
4097c478bd9Sstevel@tonic-gate out:
4107c478bd9Sstevel@tonic-gate 	return (error);
4117c478bd9Sstevel@tonic-gate }
4127c478bd9Sstevel@tonic-gate 
4137c478bd9Sstevel@tonic-gate static acemask4
access_mask_set(int haswriteperm,int hasreadperm,int isowner,int isallow,int isserver)4147c478bd9Sstevel@tonic-gate access_mask_set(int haswriteperm, int hasreadperm, int isowner, int isallow,
4157c478bd9Sstevel@tonic-gate     int isserver)
4167c478bd9Sstevel@tonic-gate {
4177c478bd9Sstevel@tonic-gate 	acemask4 access_mask = 0;
4187c478bd9Sstevel@tonic-gate 	int nfs4_acl_produce;
4197c478bd9Sstevel@tonic-gate 	int synchronize_set = 0, write_owner_set = 0;
4207c478bd9Sstevel@tonic-gate 	int delete_set = 0, write_attrs_set = 0;
4217c478bd9Sstevel@tonic-gate 	int read_named_set = 0, write_named_set = 0;
4227c478bd9Sstevel@tonic-gate 
4237c478bd9Sstevel@tonic-gate 	if (isserver)
4247c478bd9Sstevel@tonic-gate 		nfs4_acl_produce = nfs4_acl_server_produce;
4257c478bd9Sstevel@tonic-gate 	else
4267c478bd9Sstevel@tonic-gate 		nfs4_acl_produce = nfs4_acl_client_produce;
4277c478bd9Sstevel@tonic-gate 
4287c478bd9Sstevel@tonic-gate 	if (isallow) {
4297c478bd9Sstevel@tonic-gate 		synchronize_set = ACL_SYNCHRONIZE_SET_ALLOW;
4307c478bd9Sstevel@tonic-gate 		write_owner_set = ACL_WRITE_OWNER_SET_ALLOW;
4317c478bd9Sstevel@tonic-gate 		delete_set = ACL_DELETE_SET_ALLOW;
4327c478bd9Sstevel@tonic-gate 		if (hasreadperm)
4337c478bd9Sstevel@tonic-gate 			read_named_set = ACL_READ_NAMED_READER_SET_ALLOW;
4347c478bd9Sstevel@tonic-gate 		if (haswriteperm)
4357c478bd9Sstevel@tonic-gate 			write_named_set = ACL_WRITE_NAMED_WRITER_SET_ALLOW;
4367c478bd9Sstevel@tonic-gate 		if (isowner)
4377c478bd9Sstevel@tonic-gate 			write_attrs_set = ACL_WRITE_ATTRS_OWNER_SET_ALLOW;
4387c478bd9Sstevel@tonic-gate 		else if (haswriteperm)
4397c478bd9Sstevel@tonic-gate 			write_attrs_set = ACL_WRITE_ATTRS_WRITER_SET_ALLOW;
4407c478bd9Sstevel@tonic-gate 	} else {
4417c478bd9Sstevel@tonic-gate 		synchronize_set = ACL_SYNCHRONIZE_SET_DENY;
4427c478bd9Sstevel@tonic-gate 		write_owner_set = ACL_WRITE_OWNER_SET_DENY;
4437c478bd9Sstevel@tonic-gate 		delete_set = ACL_DELETE_SET_DENY;
4447c478bd9Sstevel@tonic-gate 		if (hasreadperm)
4457c478bd9Sstevel@tonic-gate 			read_named_set = ACL_READ_NAMED_READER_SET_DENY;
4467c478bd9Sstevel@tonic-gate 		if (haswriteperm)
4477c478bd9Sstevel@tonic-gate 			write_named_set = ACL_WRITE_NAMED_WRITER_SET_DENY;
4487c478bd9Sstevel@tonic-gate 		if (isowner)
4497c478bd9Sstevel@tonic-gate 			write_attrs_set = ACL_WRITE_ATTRS_OWNER_SET_DENY;
4507c478bd9Sstevel@tonic-gate 		else if (haswriteperm)
4517c478bd9Sstevel@tonic-gate 			write_attrs_set = ACL_WRITE_ATTRS_WRITER_SET_DENY;
4527c478bd9Sstevel@tonic-gate 		else
4537c478bd9Sstevel@tonic-gate 			/*
4547c478bd9Sstevel@tonic-gate 			 * If the entity is not the owner and does not
4557c478bd9Sstevel@tonic-gate 			 * have write permissions ACE4_WRITE_ATTRIBUTES will
4567c478bd9Sstevel@tonic-gate 			 * always go in the DENY ACE.
4577c478bd9Sstevel@tonic-gate 			 */
4587c478bd9Sstevel@tonic-gate 			access_mask |= ACE4_WRITE_ATTRIBUTES;
4597c478bd9Sstevel@tonic-gate 	}
4607c478bd9Sstevel@tonic-gate 
4617c478bd9Sstevel@tonic-gate 	if (nfs4_acl_produce & synchronize_set)
4627c478bd9Sstevel@tonic-gate 		access_mask |= ACE4_SYNCHRONIZE;
4637c478bd9Sstevel@tonic-gate 	if (nfs4_acl_produce & write_owner_set)
4647c478bd9Sstevel@tonic-gate 		access_mask |= ACE4_WRITE_OWNER;
4657c478bd9Sstevel@tonic-gate 	if (nfs4_acl_produce & delete_set)
4667c478bd9Sstevel@tonic-gate 		access_mask |= ACE4_DELETE;
4677c478bd9Sstevel@tonic-gate 	if (nfs4_acl_produce & write_attrs_set)
4687c478bd9Sstevel@tonic-gate 		access_mask |= ACE4_WRITE_ATTRIBUTES;
4697c478bd9Sstevel@tonic-gate 	if (nfs4_acl_produce & read_named_set)
4707c478bd9Sstevel@tonic-gate 		access_mask |= ACE4_READ_NAMED_ATTRS;
4717c478bd9Sstevel@tonic-gate 	if (nfs4_acl_produce & write_named_set)
4727c478bd9Sstevel@tonic-gate 		access_mask |= ACE4_WRITE_NAMED_ATTRS;
4737c478bd9Sstevel@tonic-gate 
4747c478bd9Sstevel@tonic-gate 	return (access_mask);
4757c478bd9Sstevel@tonic-gate }
4767c478bd9Sstevel@tonic-gate 
4777c478bd9Sstevel@tonic-gate /*
4787c478bd9Sstevel@tonic-gate  * Given an nfsace4 (presumably an ALLOW entry), make a
4797c478bd9Sstevel@tonic-gate  * corresponding DENY entry at the address given.
4807c478bd9Sstevel@tonic-gate  */
4817c478bd9Sstevel@tonic-gate static void
ace4_make_deny(nfsace4 * allow,nfsace4 * deny,int isdir,int isowner,int isserver)4827c478bd9Sstevel@tonic-gate ace4_make_deny(nfsace4 *allow, nfsace4 *deny, int isdir, int isowner,
4837c478bd9Sstevel@tonic-gate     int isserver)
4847c478bd9Sstevel@tonic-gate {
4857c478bd9Sstevel@tonic-gate 	bcopy(allow, deny, sizeof (nfsace4));
4867c478bd9Sstevel@tonic-gate 
4877c478bd9Sstevel@tonic-gate 	(void) utf8_copy(&allow->who, &deny->who);
4887c478bd9Sstevel@tonic-gate 
4897c478bd9Sstevel@tonic-gate 	deny->type = ACE4_ACCESS_DENIED_ACE_TYPE;
4907c478bd9Sstevel@tonic-gate 	deny->access_mask ^= ACE4_POSIX_SUPPORTED_BITS;
4917c478bd9Sstevel@tonic-gate 	if (isdir)
4927c478bd9Sstevel@tonic-gate 		deny->access_mask ^= ACE4_DELETE_CHILD;
4937c478bd9Sstevel@tonic-gate 
4947c478bd9Sstevel@tonic-gate 	deny->access_mask &= ~(ACE4_SYNCHRONIZE | ACE4_WRITE_OWNER |
4957c478bd9Sstevel@tonic-gate 	    ACE4_DELETE | ACE4_WRITE_ATTRIBUTES | ACE4_READ_NAMED_ATTRS |
4967c478bd9Sstevel@tonic-gate 	    ACE4_WRITE_NAMED_ATTRS);
4977c478bd9Sstevel@tonic-gate 	deny->access_mask |= access_mask_set((allow->access_mask &
4987c478bd9Sstevel@tonic-gate 	    ACE4_WRITE_DATA), (allow->access_mask & ACE4_READ_DATA), isowner,
4997c478bd9Sstevel@tonic-gate 	    FALSE, isserver);
5007c478bd9Sstevel@tonic-gate }
5017c478bd9Sstevel@tonic-gate 
5027c478bd9Sstevel@tonic-gate /*
5037c478bd9Sstevel@tonic-gate  * Given an o_mode_t, convert it into an access_mask as used
5047c478bd9Sstevel@tonic-gate  * by nfsace4, assuming aclent_t -> nfsace4 semantics.
5057c478bd9Sstevel@tonic-gate  */
5067c478bd9Sstevel@tonic-gate static acemask4
mode_to_ace4_access(o_mode_t mode,int isdir,int isowner,int isallow,int isserver)5077c478bd9Sstevel@tonic-gate mode_to_ace4_access(o_mode_t mode, int isdir, int isowner, int isallow,
5087c478bd9Sstevel@tonic-gate     int isserver)
5097c478bd9Sstevel@tonic-gate {
5107c478bd9Sstevel@tonic-gate 	acemask4 access = 0;
5117c478bd9Sstevel@tonic-gate 	int haswriteperm = 0;
5127c478bd9Sstevel@tonic-gate 	int hasreadperm = 0;
5137c478bd9Sstevel@tonic-gate 
5147c478bd9Sstevel@tonic-gate 	if (isallow) {
5157c478bd9Sstevel@tonic-gate 		haswriteperm = (mode & 02);
5167c478bd9Sstevel@tonic-gate 		hasreadperm = (mode & 04);
5177c478bd9Sstevel@tonic-gate 	} else {
5187c478bd9Sstevel@tonic-gate 		haswriteperm = !(mode & 02);
5197c478bd9Sstevel@tonic-gate 		hasreadperm = !(mode & 04);
5207c478bd9Sstevel@tonic-gate 	}
5217c478bd9Sstevel@tonic-gate 
5227c478bd9Sstevel@tonic-gate 	/*
5237c478bd9Sstevel@tonic-gate 	 * The following call takes care of correctly setting the following
5247c478bd9Sstevel@tonic-gate 	 * mask bits in the access_mask:
5257c478bd9Sstevel@tonic-gate 	 * ACE4_SYNCHRONIZE, ACE4_WRITE_OWNER, ACE4_DELETE,
5267c478bd9Sstevel@tonic-gate 	 * ACE4_WRITE_ATTRIBUTES, ACE4_WRITE_NAMED_ATTRS, ACE4_READ_NAMED_ATTRS
5277c478bd9Sstevel@tonic-gate 	 */
5287c478bd9Sstevel@tonic-gate 	access = access_mask_set(haswriteperm, hasreadperm, isowner, isallow,
5297c478bd9Sstevel@tonic-gate 	    isserver);
5307c478bd9Sstevel@tonic-gate 
5317c478bd9Sstevel@tonic-gate 	if (isallow) {
5327c478bd9Sstevel@tonic-gate 		access |= ACE4_READ_ACL | ACE4_READ_ATTRIBUTES;
5337c478bd9Sstevel@tonic-gate 		if (isowner)
5347c478bd9Sstevel@tonic-gate 			access |= ACE4_WRITE_ACL;
5357c478bd9Sstevel@tonic-gate 	} else {
5367c478bd9Sstevel@tonic-gate 		if (! isowner)
5377c478bd9Sstevel@tonic-gate 			access |= ACE4_WRITE_ACL;
5387c478bd9Sstevel@tonic-gate 	}
5397c478bd9Sstevel@tonic-gate 
5407c478bd9Sstevel@tonic-gate 	/* read */
5417c478bd9Sstevel@tonic-gate 	if (mode & 04) {
5427c478bd9Sstevel@tonic-gate 		access |= ACE4_READ_DATA;
5437c478bd9Sstevel@tonic-gate 	}
5447c478bd9Sstevel@tonic-gate 	/* write */
5457c478bd9Sstevel@tonic-gate 	if (mode & 02) {
5467c478bd9Sstevel@tonic-gate 		access |= ACE4_WRITE_DATA |
5477c478bd9Sstevel@tonic-gate 		    ACE4_APPEND_DATA;
5487c478bd9Sstevel@tonic-gate 		if (isdir)
5497c478bd9Sstevel@tonic-gate 			access |= ACE4_DELETE_CHILD;
5507c478bd9Sstevel@tonic-gate 	}
5517c478bd9Sstevel@tonic-gate 	/* exec */
5527c478bd9Sstevel@tonic-gate 	if (mode & 01) {
5537c478bd9Sstevel@tonic-gate 		access |= ACE4_EXECUTE;
5547c478bd9Sstevel@tonic-gate 	}
5557c478bd9Sstevel@tonic-gate 
5567c478bd9Sstevel@tonic-gate 	return (access);
5577c478bd9Sstevel@tonic-gate }
5587c478bd9Sstevel@tonic-gate 
5597c478bd9Sstevel@tonic-gate /*
5607c478bd9Sstevel@tonic-gate  * Convert an array of aclent_t into an array of nfsace4 entries,
5617c478bd9Sstevel@tonic-gate  * following POSIX draft -> nfsv4 conversion semantics as outlined in
5627c478bd9Sstevel@tonic-gate  * the IETF draft.
5637c478bd9Sstevel@tonic-gate  */
5647c478bd9Sstevel@tonic-gate static int
ln_aent_to_ace4(aclent_t * aclent,int n,nfsace4 ** acepp,int * rescount,int isdir,int isserver)5657c478bd9Sstevel@tonic-gate ln_aent_to_ace4(aclent_t *aclent, int n, nfsace4 **acepp, int *rescount,
5667c478bd9Sstevel@tonic-gate     int isdir, int isserver)
5677c478bd9Sstevel@tonic-gate {
5687c478bd9Sstevel@tonic-gate 	int error = 0;
5697c478bd9Sstevel@tonic-gate 	o_mode_t mask;
5707c478bd9Sstevel@tonic-gate 	int numuser, numgroup, needsort;
5717c478bd9Sstevel@tonic-gate 	int resultsize = 0;
5727c478bd9Sstevel@tonic-gate 	int i, groupi = 0, skip;
5737c478bd9Sstevel@tonic-gate 	nfsace4 *acep, *result = NULL;
5747c478bd9Sstevel@tonic-gate 	int hasmask;
5757c478bd9Sstevel@tonic-gate 
5767c478bd9Sstevel@tonic-gate 	error = ln_aent_preprocess(aclent, n, &hasmask, &mask,
5777c478bd9Sstevel@tonic-gate 	    &numuser, &numgroup, &needsort);
5787c478bd9Sstevel@tonic-gate 	if (error != 0)
5797c478bd9Sstevel@tonic-gate 		goto out;
5807c478bd9Sstevel@tonic-gate 
5817c478bd9Sstevel@tonic-gate 	/* allow + deny for each aclent */
5827c478bd9Sstevel@tonic-gate 	resultsize = n * 2;
5837c478bd9Sstevel@tonic-gate 	if (hasmask) {
5847c478bd9Sstevel@tonic-gate 		/*
5857c478bd9Sstevel@tonic-gate 		 * stick extra deny on the group_obj and on each
5867c478bd9Sstevel@tonic-gate 		 * user|group for the mask (the group_obj was added
5877c478bd9Sstevel@tonic-gate 		 * into the count for numgroup)
5887c478bd9Sstevel@tonic-gate 		 */
5897c478bd9Sstevel@tonic-gate 		resultsize += numuser + numgroup;
5907c478bd9Sstevel@tonic-gate 		/* ... and don't count the mask itself */
5917c478bd9Sstevel@tonic-gate 		resultsize -= 2;
5927c478bd9Sstevel@tonic-gate 	}
5937c478bd9Sstevel@tonic-gate 
5947c478bd9Sstevel@tonic-gate 	/* sort the source if necessary */
5957c478bd9Sstevel@tonic-gate 	if (needsort)
5967c478bd9Sstevel@tonic-gate 		ksort((caddr_t)aclent, n, sizeof (aclent_t), cmp2acls);
5977c478bd9Sstevel@tonic-gate 
5987c478bd9Sstevel@tonic-gate 	result = acep = kmem_zalloc(resultsize * sizeof (nfsace4), KM_SLEEP);
5997c478bd9Sstevel@tonic-gate 
6007c478bd9Sstevel@tonic-gate 	for (i = 0; i < n; i++) {
6017c478bd9Sstevel@tonic-gate 		/*
6027c478bd9Sstevel@tonic-gate 		 * don't process CLASS_OBJ (mask); mask was grabbed in
6037c478bd9Sstevel@tonic-gate 		 * ln_aent_preprocess()
6047c478bd9Sstevel@tonic-gate 		 */
6057c478bd9Sstevel@tonic-gate 		if (aclent[i].a_type & CLASS_OBJ)
6067c478bd9Sstevel@tonic-gate 			continue;
6077c478bd9Sstevel@tonic-gate 
6087c478bd9Sstevel@tonic-gate 		/* If we need an ACL_MASK emulator, prepend it now */
6097c478bd9Sstevel@tonic-gate 		if ((hasmask) &&
6107c478bd9Sstevel@tonic-gate 		    (aclent[i].a_type & (USER | GROUP | GROUP_OBJ))) {
6117c478bd9Sstevel@tonic-gate 			acep->type = ACE4_ACCESS_DENIED_ACE_TYPE;
6127c478bd9Sstevel@tonic-gate 			acep->flag = 0;
6137c478bd9Sstevel@tonic-gate 			if (aclent[i].a_type & GROUP_OBJ) {
6147c478bd9Sstevel@tonic-gate 				(void) str_to_utf8(ACE4_WHO_GROUP, &acep->who);
6157c478bd9Sstevel@tonic-gate 				acep->flag |= ACE4_IDENTIFIER_GROUP;
6167c478bd9Sstevel@tonic-gate 				error = 0;
6177c478bd9Sstevel@tonic-gate 			} else if (aclent[i].a_type & USER) {
618*e913d9ecSLisa Week 				/*
619*e913d9ecSLisa Week 				 * On the client, we do not allow an ACL with
620*e913d9ecSLisa Week 				 * ACEs containing the UID_UNKNOWN user to be
621*e913d9ecSLisa Week 				 * set.  This is because having UID_UNKNOWN in
622*e913d9ecSLisa Week 				 * an ACE can only come from the user having
623*e913d9ecSLisa Week 				 * done a read-modify-write ACL manipulation
624*e913d9ecSLisa Week 				 * (e.g. setfacl -m or chmod A+) when there
625*e913d9ecSLisa Week 				 * was an ACE with an unmappable group already
626*e913d9ecSLisa Week 				 * present.
627*e913d9ecSLisa Week 				 */
628*e913d9ecSLisa Week 				if (aclent[i].a_id == UID_UNKNOWN &&
629*e913d9ecSLisa Week 				    !isserver) {
630*e913d9ecSLisa Week 					DTRACE_PROBE(
631*e913d9ecSLisa Week 					    nfs4clnt__err__acl__uid__unknown);
632*e913d9ecSLisa Week 					NFS4_DEBUG(nfs4_acl_debug, (CE_NOTE,
633*e913d9ecSLisa Week 					    "ln_aent_to_ace4: UID_UNKNOWN is "
634*e913d9ecSLisa Week 					    "not allowed in the ACL"));
635*e913d9ecSLisa Week 					error = EACCES;
636*e913d9ecSLisa Week 					goto out;
637*e913d9ecSLisa Week 				}
638*e913d9ecSLisa Week 
6397c478bd9Sstevel@tonic-gate 				error = nfs_idmap_uid_str(aclent[i].a_id,
6407c478bd9Sstevel@tonic-gate 				    &acep->who, isserver);
6417c478bd9Sstevel@tonic-gate 			} else {
642*e913d9ecSLisa Week 				/*
643*e913d9ecSLisa Week 				 * Same rule as UID_UNKNOWN (above).
644*e913d9ecSLisa Week 				 */
645*e913d9ecSLisa Week 				if (aclent[i].a_id == GID_UNKNOWN &&
646*e913d9ecSLisa Week 				    !isserver) {
647*e913d9ecSLisa Week 					DTRACE_PROBE(
648*e913d9ecSLisa Week 					    nfs4clnt__err__acl__gid__unknown);
649*e913d9ecSLisa Week 					NFS4_DEBUG(nfs4_acl_debug, (CE_NOTE,
650*e913d9ecSLisa Week 					    "ln_aent_to_ace4: GID_UNKNOWN is "
651*e913d9ecSLisa Week 					    "not allowed in the ACL"));
652*e913d9ecSLisa Week 					error = EACCES;
653*e913d9ecSLisa Week 					goto out;
654*e913d9ecSLisa Week 				}
655*e913d9ecSLisa Week 
6567c478bd9Sstevel@tonic-gate 				error = nfs_idmap_gid_str(aclent[i].a_id,
6577c478bd9Sstevel@tonic-gate 				    &acep->who, isserver);
6587c478bd9Sstevel@tonic-gate 				acep->flag |= ACE4_IDENTIFIER_GROUP;
6597c478bd9Sstevel@tonic-gate 			}
6607c478bd9Sstevel@tonic-gate 			if (error != 0) {
6617c478bd9Sstevel@tonic-gate 				NFS4_DEBUG(nfs4_acl_debug, (CE_NOTE,
6627c478bd9Sstevel@tonic-gate 				    "ln_aent_to_ace4: idmap translate "
6637c478bd9Sstevel@tonic-gate 				    "failed with %d", error));
6647c478bd9Sstevel@tonic-gate 				goto out;
6657c478bd9Sstevel@tonic-gate 			}
6667c478bd9Sstevel@tonic-gate 			if (aclent[i].a_type & ACL_DEFAULT) {
6677c478bd9Sstevel@tonic-gate 				acep->flag |= ACE4_INHERIT_ONLY_ACE |
6687c478bd9Sstevel@tonic-gate 				    ACE4_FILE_INHERIT_ACE |
6697c478bd9Sstevel@tonic-gate 				    ACE4_DIRECTORY_INHERIT_ACE;
6707c478bd9Sstevel@tonic-gate 			}
6717c478bd9Sstevel@tonic-gate 			/*
6727c478bd9Sstevel@tonic-gate 			 * Set the access mask for the prepended deny
6737c478bd9Sstevel@tonic-gate 			 * ace.  To do this, we invert the mask (found
6747c478bd9Sstevel@tonic-gate 			 * in ln_aent_preprocess()) then convert it to an
6757c478bd9Sstevel@tonic-gate 			 * DENY ace access_mask.
6767c478bd9Sstevel@tonic-gate 			 */
6777c478bd9Sstevel@tonic-gate 			acep->access_mask = mode_to_ace4_access((mask ^ 07),
6787c478bd9Sstevel@tonic-gate 			    isdir, 0, 0, isserver);
6797c478bd9Sstevel@tonic-gate 			acep += 1;
6807c478bd9Sstevel@tonic-gate 		}
6817c478bd9Sstevel@tonic-gate 
6827c478bd9Sstevel@tonic-gate 		/* handle a_perm -> access_mask */
6837c478bd9Sstevel@tonic-gate 		acep->access_mask = mode_to_ace4_access(aclent[i].a_perm,
6847c478bd9Sstevel@tonic-gate 		    isdir, aclent[i].a_type & USER_OBJ, 1, isserver);
6857c478bd9Sstevel@tonic-gate 
6867c478bd9Sstevel@tonic-gate 		/* emulate a default aclent */
6877c478bd9Sstevel@tonic-gate 		if (aclent[i].a_type & ACL_DEFAULT) {
6887c478bd9Sstevel@tonic-gate 			acep->flag |= ACE4_INHERIT_ONLY_ACE |
6897c478bd9Sstevel@tonic-gate 			    ACE4_FILE_INHERIT_ACE |
6907c478bd9Sstevel@tonic-gate 			    ACE4_DIRECTORY_INHERIT_ACE;
6917c478bd9Sstevel@tonic-gate 		}
6927c478bd9Sstevel@tonic-gate 
6937c478bd9Sstevel@tonic-gate 		/*
6947c478bd9Sstevel@tonic-gate 		 * handle a_perm and a_id
6957c478bd9Sstevel@tonic-gate 		 *
6967c478bd9Sstevel@tonic-gate 		 * this must be done last, since it involves the
6977c478bd9Sstevel@tonic-gate 		 * corresponding deny aces, which are handled
6987c478bd9Sstevel@tonic-gate 		 * differently for each different a_type.
6997c478bd9Sstevel@tonic-gate 		 */
7007c478bd9Sstevel@tonic-gate 		if (aclent[i].a_type & USER_OBJ) {
7017c478bd9Sstevel@tonic-gate 			(void) str_to_utf8(ACE4_WHO_OWNER, &acep->who);
7027c478bd9Sstevel@tonic-gate 			ace4_make_deny(acep, acep + 1, isdir, TRUE, isserver);
7037c478bd9Sstevel@tonic-gate 			acep += 2;
7047c478bd9Sstevel@tonic-gate 		} else if (aclent[i].a_type & USER) {
7057c478bd9Sstevel@tonic-gate 			error = nfs_idmap_uid_str(aclent[i].a_id, &acep->who,
7067c478bd9Sstevel@tonic-gate 			    isserver);
7077c478bd9Sstevel@tonic-gate 			if (error != 0) {
7087c478bd9Sstevel@tonic-gate 				NFS4_DEBUG(nfs4_acl_debug, (CE_NOTE,
7097c478bd9Sstevel@tonic-gate 				    "ln_aent_to_ace4: uid idmap failed "
7107c478bd9Sstevel@tonic-gate 				    "with error %d", error));
7117c478bd9Sstevel@tonic-gate 				goto out;
7127c478bd9Sstevel@tonic-gate 			}
7137c478bd9Sstevel@tonic-gate 			ace4_make_deny(acep, acep + 1, isdir, FALSE, isserver);
7147c478bd9Sstevel@tonic-gate 			acep += 2;
7157c478bd9Sstevel@tonic-gate 		} else if (aclent[i].a_type & (GROUP_OBJ | GROUP)) {
7167c478bd9Sstevel@tonic-gate 			if (aclent[i].a_type & GROUP_OBJ) {
7177c478bd9Sstevel@tonic-gate 				(void) str_to_utf8(ACE4_WHO_GROUP, &acep->who);
7187c478bd9Sstevel@tonic-gate 				error = 0;
7197c478bd9Sstevel@tonic-gate 			} else {
7207c478bd9Sstevel@tonic-gate 				error = nfs_idmap_gid_str(aclent[i].a_id,
7217c478bd9Sstevel@tonic-gate 				    &acep->who, isserver);
7227c478bd9Sstevel@tonic-gate 			}
7237c478bd9Sstevel@tonic-gate 			if (error != 0) {
7247c478bd9Sstevel@tonic-gate 				NFS4_DEBUG(nfs4_acl_debug, (CE_NOTE,
7257c478bd9Sstevel@tonic-gate 				    "ln_aent_to_ace4: gid idmap failed "
7267c478bd9Sstevel@tonic-gate 				    "with error %d", error));
7277c478bd9Sstevel@tonic-gate 				goto out;
7287c478bd9Sstevel@tonic-gate 			}
7297c478bd9Sstevel@tonic-gate 			acep->flag |= ACE4_IDENTIFIER_GROUP;
7307c478bd9Sstevel@tonic-gate 			/*
7317c478bd9Sstevel@tonic-gate 			 * Set the corresponding deny for the group ace.
7327c478bd9Sstevel@tonic-gate 			 *
7337c478bd9Sstevel@tonic-gate 			 * The deny aces go after all of the groups, unlike
7347c478bd9Sstevel@tonic-gate 			 * everything else, where they immediately follow
7357c478bd9Sstevel@tonic-gate 			 * the allow ace.
7367c478bd9Sstevel@tonic-gate 			 *
7377c478bd9Sstevel@tonic-gate 			 * We calculate "skip", the number of slots to
7387c478bd9Sstevel@tonic-gate 			 * skip ahead for the deny ace, here.
7397c478bd9Sstevel@tonic-gate 			 *
7407c478bd9Sstevel@tonic-gate 			 * The pattern is:
7417c478bd9Sstevel@tonic-gate 			 * MD1 A1 MD2 A2 MD3 A3 D1 D2 D3
7427c478bd9Sstevel@tonic-gate 			 * thus, skip is
7437c478bd9Sstevel@tonic-gate 			 * (2 * numgroup) - 1 - groupi
7447c478bd9Sstevel@tonic-gate 			 * (2 * numgroup) to account for MD + A
7457c478bd9Sstevel@tonic-gate 			 * - 1 to account for the fact that we're on the
7467c478bd9Sstevel@tonic-gate 			 * access (A), not the mask (MD)
7477c478bd9Sstevel@tonic-gate 			 * - groupi to account for the fact that we have
7487c478bd9Sstevel@tonic-gate 			 * passed up groupi number of MD's.
7497c478bd9Sstevel@tonic-gate 			 */
7507c478bd9Sstevel@tonic-gate 			skip = (2 * numgroup) - 1 - groupi;
7517c478bd9Sstevel@tonic-gate 			ace4_make_deny(acep, acep + skip, isdir, FALSE,
7527c478bd9Sstevel@tonic-gate 			    isserver);
7537c478bd9Sstevel@tonic-gate 			/*
7547c478bd9Sstevel@tonic-gate 			 * If we just did the last group, skip acep past
7557c478bd9Sstevel@tonic-gate 			 * all of the denies; else, just move ahead one.
7567c478bd9Sstevel@tonic-gate 			 */
7577c478bd9Sstevel@tonic-gate 			if (++groupi >= numgroup)
7587c478bd9Sstevel@tonic-gate 				acep += numgroup + 1;
7597c478bd9Sstevel@tonic-gate 			else
7607c478bd9Sstevel@tonic-gate 				acep += 1;
7617c478bd9Sstevel@tonic-gate 		} else if (aclent[i].a_type & OTHER_OBJ) {
7627c478bd9Sstevel@tonic-gate 			(void) str_to_utf8(ACE4_WHO_EVERYONE, &acep->who);
7637c478bd9Sstevel@tonic-gate 			ace4_make_deny(acep, acep + 1, isdir, FALSE, isserver);
7647c478bd9Sstevel@tonic-gate 			acep += 2;
7657c478bd9Sstevel@tonic-gate 		} else {
7667c478bd9Sstevel@tonic-gate 			NFS4_DEBUG(nfs4_acl_debug, (CE_NOTE,
7677c478bd9Sstevel@tonic-gate 			    "ln_aent_to_ace4: aclent_t with invalid type: %x",
7687c478bd9Sstevel@tonic-gate 			    aclent[i].a_type));
7697c478bd9Sstevel@tonic-gate 			error = EINVAL;
7707c478bd9Sstevel@tonic-gate 			goto out;
7717c478bd9Sstevel@tonic-gate 		}
7727c478bd9Sstevel@tonic-gate 	}
7737c478bd9Sstevel@tonic-gate 
7747c478bd9Sstevel@tonic-gate 	*acepp = result;
7757c478bd9Sstevel@tonic-gate 	*rescount = resultsize;
7767c478bd9Sstevel@tonic-gate 
7777c478bd9Sstevel@tonic-gate out:
7787c478bd9Sstevel@tonic-gate 
7797c478bd9Sstevel@tonic-gate 	if (error != 0) {
7807c478bd9Sstevel@tonic-gate 		if ((result != NULL) && (resultsize > 0)) {
7817c478bd9Sstevel@tonic-gate 			/* free any embedded "who" strings */
7827c478bd9Sstevel@tonic-gate 			for (i = 0; i < resultsize; i++) {
7837c478bd9Sstevel@tonic-gate 				acep = result + i;
7847c478bd9Sstevel@tonic-gate 				if ((acep->who.utf8string_len > 0) &&
7857c478bd9Sstevel@tonic-gate 				    (acep->who.utf8string_val != NULL)) {
7867c478bd9Sstevel@tonic-gate 					kmem_free(acep->who.utf8string_val,
7877c478bd9Sstevel@tonic-gate 					    acep->who.utf8string_len);
7887c478bd9Sstevel@tonic-gate 				}
7897c478bd9Sstevel@tonic-gate 			}
7907c478bd9Sstevel@tonic-gate 
7917c478bd9Sstevel@tonic-gate 			/* free the nfsace4 block */
7927c478bd9Sstevel@tonic-gate 			kmem_free(result, resultsize * sizeof (nfsace4));
7937c478bd9Sstevel@tonic-gate 		}
7947c478bd9Sstevel@tonic-gate 	}
7957c478bd9Sstevel@tonic-gate 
7967c478bd9Sstevel@tonic-gate 	return (error);
7977c478bd9Sstevel@tonic-gate }
7987c478bd9Sstevel@tonic-gate 
7997c478bd9Sstevel@tonic-gate /*
8007c478bd9Sstevel@tonic-gate  * Convert a POSIX draft ACL (in a vsecattr_t) to an NFSv4 ACL, following
8017c478bd9Sstevel@tonic-gate  * the semantics of the IETF draft, draft-ietf-nfsv4-acl-mapping-01.txt.
8027c478bd9Sstevel@tonic-gate  */
8037c478bd9Sstevel@tonic-gate int
vs_aent_to_ace4(vsecattr_t * aclentacl,vsecattr_t * vs_ace4,int isdir,int isserver)8047c478bd9Sstevel@tonic-gate vs_aent_to_ace4(vsecattr_t *aclentacl, vsecattr_t *vs_ace4,
8057c478bd9Sstevel@tonic-gate     int isdir, int isserver)
8067c478bd9Sstevel@tonic-gate {
8077c478bd9Sstevel@tonic-gate 	int error = 0;
8087c478bd9Sstevel@tonic-gate 	nfsace4 *acebuf = NULL;
8097c478bd9Sstevel@tonic-gate 	int acecnt = 0;
8107c478bd9Sstevel@tonic-gate 	nfsace4 *dfacebuf = NULL;
8117c478bd9Sstevel@tonic-gate 	int dfacecnt = 0;
8127c478bd9Sstevel@tonic-gate 
8137c478bd9Sstevel@tonic-gate 	/* initialize vs_ace4 in case we can't complete our work */
8147c478bd9Sstevel@tonic-gate 	vs_ace4->vsa_mask = 0;
8157c478bd9Sstevel@tonic-gate 	vs_ace4->vsa_aclentp = NULL;
8167c478bd9Sstevel@tonic-gate 	vs_ace4->vsa_aclcnt = 0;
8177c478bd9Sstevel@tonic-gate 	vs_ace4->vsa_dfaclentp = NULL;
8187c478bd9Sstevel@tonic-gate 	vs_ace4->vsa_dfaclcnt = 0;
819da6c28aaSamw 	vs_ace4->vsa_aclentsz = 0;
8207c478bd9Sstevel@tonic-gate 
8217c478bd9Sstevel@tonic-gate 	if (! (aclentacl->vsa_mask & (VSA_ACL | VSA_ACLCNT |
8227c478bd9Sstevel@tonic-gate 	    VSA_DFACL | VSA_DFACLCNT))) {
8237c478bd9Sstevel@tonic-gate 		NFS4_DEBUG(nfs4_acl_debug, (CE_NOTE,
8247c478bd9Sstevel@tonic-gate 		    "vs_aent_to_ace4: vsa_mask lacking proper mask"));
8257c478bd9Sstevel@tonic-gate 		error = EINVAL;
8267c478bd9Sstevel@tonic-gate 		goto out;
8277c478bd9Sstevel@tonic-gate 	}
8287c478bd9Sstevel@tonic-gate 
8297c478bd9Sstevel@tonic-gate 	if ((aclentacl->vsa_aclcnt < 3) &&
8307c478bd9Sstevel@tonic-gate 	    (aclentacl->vsa_mask & (VSA_ACL | VSA_ACLCNT))) {
8317c478bd9Sstevel@tonic-gate 		NFS4_DEBUG(nfs4_acl_debug, (CE_NOTE,
8327c478bd9Sstevel@tonic-gate 		    "vs_aent_to_ace4: too small vsa_aclcnt, %d",
8337c478bd9Sstevel@tonic-gate 		    aclentacl->vsa_aclcnt));
8347c478bd9Sstevel@tonic-gate 		error = EINVAL;
8357c478bd9Sstevel@tonic-gate 		goto out;
8367c478bd9Sstevel@tonic-gate 	}
8377c478bd9Sstevel@tonic-gate 
8387c478bd9Sstevel@tonic-gate 	if ((aclentacl->vsa_dfaclcnt != 0) && (aclentacl->vsa_dfaclcnt < 3) &&
8397c478bd9Sstevel@tonic-gate 	    (aclentacl->vsa_mask & (VSA_DFACL | VSA_DFACLCNT))) {
8407c478bd9Sstevel@tonic-gate 		NFS4_DEBUG(nfs4_acl_debug, (CE_NOTE,
8417c478bd9Sstevel@tonic-gate 		    "vs_aent_to_ace4: too small vsa_dfaclcnt, %d",
8427c478bd9Sstevel@tonic-gate 		    aclentacl->vsa_dfaclcnt));
8437c478bd9Sstevel@tonic-gate 		error = EINVAL;
8447c478bd9Sstevel@tonic-gate 		goto out;
8457c478bd9Sstevel@tonic-gate 	}
8467c478bd9Sstevel@tonic-gate 
8477c478bd9Sstevel@tonic-gate 	if (aclentacl->vsa_aclcnt > 0) {
8487c478bd9Sstevel@tonic-gate 		error = ln_aent_to_ace4(aclentacl->vsa_aclentp,
849*e913d9ecSLisa Week 		    aclentacl->vsa_aclcnt, &acebuf, &acecnt, isdir, isserver);
8507c478bd9Sstevel@tonic-gate 		if (error != 0)
8517c478bd9Sstevel@tonic-gate 			goto out;
8527c478bd9Sstevel@tonic-gate 	}
8537c478bd9Sstevel@tonic-gate 	if (aclentacl->vsa_dfaclcnt > 0) {
8547c478bd9Sstevel@tonic-gate 		error = ln_aent_to_ace4(aclentacl->vsa_dfaclentp,
855*e913d9ecSLisa Week 		    aclentacl->vsa_dfaclcnt, &dfacebuf, &dfacecnt, isdir,
856*e913d9ecSLisa Week 		    isserver);
8577c478bd9Sstevel@tonic-gate 		if (error != 0)
8587c478bd9Sstevel@tonic-gate 			goto out;
8597c478bd9Sstevel@tonic-gate 	}
8607c478bd9Sstevel@tonic-gate 
8617c478bd9Sstevel@tonic-gate 	vs_ace4->vsa_aclcnt = acecnt + dfacecnt;
8627c478bd9Sstevel@tonic-gate 	/* on error, this is freed by vs_ace4_destroy() */
8637c478bd9Sstevel@tonic-gate 	if (vs_ace4->vsa_aclcnt > 0)
8647c478bd9Sstevel@tonic-gate 		vs_ace4->vsa_aclentp = kmem_zalloc(vs_ace4->vsa_aclcnt *
8657c478bd9Sstevel@tonic-gate 		    sizeof (nfsace4), KM_SLEEP);
8667c478bd9Sstevel@tonic-gate 	/*
8677c478bd9Sstevel@tonic-gate 	 * When we bcopy the nfsace4's, the result (in vsa_aclentp)
8687c478bd9Sstevel@tonic-gate 	 * will have its "who.utf8string_val" pointer pointing to the
8697c478bd9Sstevel@tonic-gate 	 * allocated strings.  Thus, when we free acebuf and dbacebuf,
8707c478bd9Sstevel@tonic-gate 	 * we don't need to free these strings.
8717c478bd9Sstevel@tonic-gate 	 */
8727c478bd9Sstevel@tonic-gate 	if (acecnt > 0)
8737c478bd9Sstevel@tonic-gate 		bcopy(acebuf, vs_ace4->vsa_aclentp, acecnt * sizeof (nfsace4));
8747c478bd9Sstevel@tonic-gate 	if (dfacecnt > 0)
8757c478bd9Sstevel@tonic-gate 		bcopy(dfacebuf, (nfsace4 *) vs_ace4->vsa_aclentp + acecnt,
8767c478bd9Sstevel@tonic-gate 		    dfacecnt * sizeof (nfsace4));
8777c478bd9Sstevel@tonic-gate 	vs_ace4->vsa_mask = VSA_ACE | VSA_ACECNT;
8787c478bd9Sstevel@tonic-gate 
8797c478bd9Sstevel@tonic-gate out:
8807c478bd9Sstevel@tonic-gate 	if (error != 0)
8817c478bd9Sstevel@tonic-gate 		vs_ace4_destroy(vs_ace4);
8827c478bd9Sstevel@tonic-gate 
8837c478bd9Sstevel@tonic-gate 	if (acebuf != NULL)
8847c478bd9Sstevel@tonic-gate 		kmem_free(acebuf, acecnt * sizeof (nfsace4));
8857c478bd9Sstevel@tonic-gate 	if (dfacebuf != NULL)
8867c478bd9Sstevel@tonic-gate 		kmem_free(dfacebuf, dfacecnt * sizeof (nfsace4));
8877c478bd9Sstevel@tonic-gate 
8887c478bd9Sstevel@tonic-gate 	return (error);
8897c478bd9Sstevel@tonic-gate }
8907c478bd9Sstevel@tonic-gate 
8917c478bd9Sstevel@tonic-gate static int
ace4_mask_to_mode(acemask4 mask,o_mode_t * modep,int isdir)8927c478bd9Sstevel@tonic-gate ace4_mask_to_mode(acemask4 mask, o_mode_t *modep, int isdir)
8937c478bd9Sstevel@tonic-gate {
8947c478bd9Sstevel@tonic-gate 	int error = 0;
8957c478bd9Sstevel@tonic-gate 	o_mode_t mode = 0;
8967c478bd9Sstevel@tonic-gate 	acemask4 bits, wantbits;
8977c478bd9Sstevel@tonic-gate 
8987c478bd9Sstevel@tonic-gate 	/* read */
8997c478bd9Sstevel@tonic-gate 	if (mask & ACE4_READ_DATA)
9007c478bd9Sstevel@tonic-gate 		mode |= 04;
9017c478bd9Sstevel@tonic-gate 
9027c478bd9Sstevel@tonic-gate 	/* write */
9037c478bd9Sstevel@tonic-gate 	wantbits = (ACE4_WRITE_DATA |
9047c478bd9Sstevel@tonic-gate 	    ACE4_APPEND_DATA);
9057c478bd9Sstevel@tonic-gate 	if (isdir)
9067c478bd9Sstevel@tonic-gate 		wantbits |= ACE4_DELETE_CHILD;
9077c478bd9Sstevel@tonic-gate 	bits = mask & wantbits;
9087c478bd9Sstevel@tonic-gate 	if (bits != 0) {
9097c478bd9Sstevel@tonic-gate 		if (bits != wantbits) {
9107c478bd9Sstevel@tonic-gate 			NFS4_DEBUG(nfs4_acl_debug, (CE_NOTE,
9117c478bd9Sstevel@tonic-gate 			    "ace4_mask_to_mode: bad subset of write flags "
9127c478bd9Sstevel@tonic-gate 			    "%x", bits));
9137c478bd9Sstevel@tonic-gate 			error = ENOTSUP;
9147c478bd9Sstevel@tonic-gate 			goto out;
9157c478bd9Sstevel@tonic-gate 		}
9167c478bd9Sstevel@tonic-gate 		mode |= 02;
9177c478bd9Sstevel@tonic-gate 	}
9187c478bd9Sstevel@tonic-gate 
9197c478bd9Sstevel@tonic-gate 	/* exec */
9207c478bd9Sstevel@tonic-gate 	if (mask & ACE4_EXECUTE) {
9217c478bd9Sstevel@tonic-gate 		mode |= 01;
9227c478bd9Sstevel@tonic-gate 	}
9237c478bd9Sstevel@tonic-gate 
9247c478bd9Sstevel@tonic-gate 	*modep = mode;
9257c478bd9Sstevel@tonic-gate 
9267c478bd9Sstevel@tonic-gate out:
9277c478bd9Sstevel@tonic-gate 	return (error);
9287c478bd9Sstevel@tonic-gate }
9297c478bd9Sstevel@tonic-gate 
9307c478bd9Sstevel@tonic-gate static int
ace4_allow_to_mode(acemask4 mask,o_mode_t * modep,int isdir)9317c478bd9Sstevel@tonic-gate ace4_allow_to_mode(acemask4 mask, o_mode_t *modep, int isdir)
9327c478bd9Sstevel@tonic-gate {
9337c478bd9Sstevel@tonic-gate 	/* ACE4_READ_ACL and ACE4_READ_ATTRIBUTES must both be set */
9347c478bd9Sstevel@tonic-gate 	if ((mask & (ACE4_READ_ACL | ACE4_READ_ATTRIBUTES)) !=
9357c478bd9Sstevel@tonic-gate 	    (ACE4_READ_ACL | ACE4_READ_ATTRIBUTES)) {
9367c478bd9Sstevel@tonic-gate 		return (ENOTSUP);
9377c478bd9Sstevel@tonic-gate 	}
9387c478bd9Sstevel@tonic-gate 
9397c478bd9Sstevel@tonic-gate 	return (ace4_mask_to_mode(mask, modep, isdir));
9407c478bd9Sstevel@tonic-gate }
9417c478bd9Sstevel@tonic-gate 
9427c478bd9Sstevel@tonic-gate /*
9437c478bd9Sstevel@tonic-gate  * Find or create an ace4vals holder for a given id and avl tree.
9447c478bd9Sstevel@tonic-gate  *
9457c478bd9Sstevel@tonic-gate  * Note that only one thread will ever touch these avl trees, so
9467c478bd9Sstevel@tonic-gate  * there is no need for locking.
9477c478bd9Sstevel@tonic-gate  */
9487c478bd9Sstevel@tonic-gate static ace4vals_t *
ace4vals_find(nfsace4 * ace4,avl_tree_t * avl,int * num)9497c478bd9Sstevel@tonic-gate ace4vals_find(nfsace4 *ace4, avl_tree_t *avl, int *num)
9507c478bd9Sstevel@tonic-gate {
9517c478bd9Sstevel@tonic-gate 	ace4vals_t key, *rc;
9527c478bd9Sstevel@tonic-gate 	avl_index_t where;
9537c478bd9Sstevel@tonic-gate 
9547c478bd9Sstevel@tonic-gate 	key.key = &ace4->who;
9557c478bd9Sstevel@tonic-gate 	rc = avl_find(avl, &key, &where);
9567c478bd9Sstevel@tonic-gate 	if (rc != NULL)
9577c478bd9Sstevel@tonic-gate 		return (rc);
9587c478bd9Sstevel@tonic-gate 
9597c478bd9Sstevel@tonic-gate 	/* this memory is freed by ln_ace4_to_aent()->ace4_list_free() */
9607c478bd9Sstevel@tonic-gate 	rc = kmem_cache_alloc(nfs4_ace4vals_cache, KM_SLEEP);
9617c478bd9Sstevel@tonic-gate 	ace4vals_init(rc, &ace4->who);
9627c478bd9Sstevel@tonic-gate 	avl_insert(avl, rc, where);
9637c478bd9Sstevel@tonic-gate 	(*num)++;
9647c478bd9Sstevel@tonic-gate 
9657c478bd9Sstevel@tonic-gate 	return (rc);
9667c478bd9Sstevel@tonic-gate }
9677c478bd9Sstevel@tonic-gate 
9687c478bd9Sstevel@tonic-gate static int
access_mask_check(nfsace4 * ace4p,int mask_bit,int isserver,int isowner)9697c478bd9Sstevel@tonic-gate access_mask_check(nfsace4 *ace4p, int mask_bit, int isserver, int isowner)
9707c478bd9Sstevel@tonic-gate {
9717c478bd9Sstevel@tonic-gate 	int set_deny, err_deny;
9727c478bd9Sstevel@tonic-gate 	int set_allow, err_allow;
9737c478bd9Sstevel@tonic-gate 	int nfs4_acl_consume;
9747c478bd9Sstevel@tonic-gate 	int haswriteperm, hasreadperm;
9757c478bd9Sstevel@tonic-gate 
9767c478bd9Sstevel@tonic-gate 	if (ace4p->type == ACE4_ACCESS_DENIED_ACE_TYPE) {
9777c478bd9Sstevel@tonic-gate 		haswriteperm = (ace4p->access_mask & ACE4_WRITE_DATA) ? 0 : 1;
9787c478bd9Sstevel@tonic-gate 		hasreadperm = (ace4p->access_mask & ACE4_READ_DATA) ? 0 : 1;
9797c478bd9Sstevel@tonic-gate 	} else {
9807c478bd9Sstevel@tonic-gate 		haswriteperm = (ace4p->access_mask & ACE4_WRITE_DATA) ? 1 : 0;
9817c478bd9Sstevel@tonic-gate 		hasreadperm = (ace4p->access_mask & ACE4_READ_DATA) ? 1 : 0;
9827c478bd9Sstevel@tonic-gate 	}
9837c478bd9Sstevel@tonic-gate 
9847c478bd9Sstevel@tonic-gate 	if (isserver)
9857c478bd9Sstevel@tonic-gate 		nfs4_acl_consume = nfs4_acl_server_consume;
9867c478bd9Sstevel@tonic-gate 	else
9877c478bd9Sstevel@tonic-gate 		nfs4_acl_consume = nfs4_acl_client_consume;
9887c478bd9Sstevel@tonic-gate 
9897c478bd9Sstevel@tonic-gate 	if (mask_bit == ACE4_SYNCHRONIZE) {
9907c478bd9Sstevel@tonic-gate 		set_deny = ACL_SYNCHRONIZE_SET_DENY;
9917c478bd9Sstevel@tonic-gate 		err_deny =  ACL_SYNCHRONIZE_ERR_DENY;
9927c478bd9Sstevel@tonic-gate 		set_allow = ACL_SYNCHRONIZE_SET_ALLOW;
9937c478bd9Sstevel@tonic-gate 		err_allow = ACL_SYNCHRONIZE_ERR_ALLOW;
9947c478bd9Sstevel@tonic-gate 	} else if (mask_bit == ACE4_WRITE_OWNER) {
9957c478bd9Sstevel@tonic-gate 		set_deny = ACL_WRITE_OWNER_SET_DENY;
9967c478bd9Sstevel@tonic-gate 		err_deny =  ACL_WRITE_OWNER_ERR_DENY;
9977c478bd9Sstevel@tonic-gate 		set_allow = ACL_WRITE_OWNER_SET_ALLOW;
9987c478bd9Sstevel@tonic-gate 		err_allow = ACL_WRITE_OWNER_ERR_ALLOW;
9997c478bd9Sstevel@tonic-gate 	} else if (mask_bit == ACE4_DELETE) {
10007c478bd9Sstevel@tonic-gate 		set_deny = ACL_DELETE_SET_DENY;
10017c478bd9Sstevel@tonic-gate 		err_deny =  ACL_DELETE_ERR_DENY;
10027c478bd9Sstevel@tonic-gate 		set_allow = ACL_DELETE_SET_ALLOW;
10037c478bd9Sstevel@tonic-gate 		err_allow = ACL_DELETE_ERR_ALLOW;
10047c478bd9Sstevel@tonic-gate 	} else if (mask_bit == ACE4_WRITE_ATTRIBUTES) {
10057c478bd9Sstevel@tonic-gate 		if (isowner) {
10067c478bd9Sstevel@tonic-gate 			set_deny = ACL_WRITE_ATTRS_OWNER_SET_DENY;
10077c478bd9Sstevel@tonic-gate 			err_deny =  ACL_WRITE_ATTRS_OWNER_ERR_DENY;
10087c478bd9Sstevel@tonic-gate 			set_allow = ACL_WRITE_ATTRS_OWNER_SET_ALLOW;
10097c478bd9Sstevel@tonic-gate 			err_allow = ACL_WRITE_ATTRS_OWNER_ERR_ALLOW;
10107c478bd9Sstevel@tonic-gate 		} else if (haswriteperm) {
10117c478bd9Sstevel@tonic-gate 			set_deny = ACL_WRITE_ATTRS_WRITER_SET_DENY;
10127c478bd9Sstevel@tonic-gate 			err_deny =  ACL_WRITE_ATTRS_WRITER_ERR_DENY;
10137c478bd9Sstevel@tonic-gate 			set_allow = ACL_WRITE_ATTRS_WRITER_SET_ALLOW;
10147c478bd9Sstevel@tonic-gate 			err_allow = ACL_WRITE_ATTRS_WRITER_ERR_ALLOW;
10157c478bd9Sstevel@tonic-gate 		} else {
10167c478bd9Sstevel@tonic-gate 			if ((ace4p->access_mask & mask_bit) &&
10177c478bd9Sstevel@tonic-gate 			    (ace4p->type & ACE4_ACCESS_ALLOWED_ACE_TYPE)) {
10187c478bd9Sstevel@tonic-gate 				return (ENOTSUP);
10197c478bd9Sstevel@tonic-gate 			}
10207c478bd9Sstevel@tonic-gate 			return (0);
10217c478bd9Sstevel@tonic-gate 		}
10227c478bd9Sstevel@tonic-gate 	} else if (mask_bit == ACE4_READ_NAMED_ATTRS) {
10237c478bd9Sstevel@tonic-gate 		if (!hasreadperm)
10247c478bd9Sstevel@tonic-gate 			return (0);
10257c478bd9Sstevel@tonic-gate 
10267c478bd9Sstevel@tonic-gate 		set_deny = ACL_READ_NAMED_READER_SET_DENY;
10277c478bd9Sstevel@tonic-gate 		err_deny = ACL_READ_NAMED_READER_ERR_DENY;
10287c478bd9Sstevel@tonic-gate 		set_allow = ACL_READ_NAMED_READER_SET_ALLOW;
10297c478bd9Sstevel@tonic-gate 		err_allow = ACL_READ_NAMED_READER_ERR_ALLOW;
10307c478bd9Sstevel@tonic-gate 	} else if (mask_bit == ACE4_WRITE_NAMED_ATTRS) {
10317c478bd9Sstevel@tonic-gate 		if (!haswriteperm)
10327c478bd9Sstevel@tonic-gate 			return (0);
10337c478bd9Sstevel@tonic-gate 
10347c478bd9Sstevel@tonic-gate 		set_deny = ACL_WRITE_NAMED_WRITER_SET_DENY;
10357c478bd9Sstevel@tonic-gate 		err_deny = ACL_WRITE_NAMED_WRITER_ERR_DENY;
10367c478bd9Sstevel@tonic-gate 		set_allow = ACL_WRITE_NAMED_WRITER_SET_ALLOW;
10377c478bd9Sstevel@tonic-gate 		err_allow = ACL_WRITE_NAMED_WRITER_ERR_ALLOW;
10387c478bd9Sstevel@tonic-gate 	} else
10397c478bd9Sstevel@tonic-gate 		return (EINVAL);
10407c478bd9Sstevel@tonic-gate 
10417c478bd9Sstevel@tonic-gate 	if (ace4p->type == ACE4_ACCESS_DENIED_ACE_TYPE) {
10427c478bd9Sstevel@tonic-gate 		if (nfs4_acl_consume & set_deny) {
10437c478bd9Sstevel@tonic-gate 			if (!(ace4p->access_mask & mask_bit)) {
10447c478bd9Sstevel@tonic-gate 				return (ENOTSUP);
10457c478bd9Sstevel@tonic-gate 			}
10467c478bd9Sstevel@tonic-gate 		} else if (nfs4_acl_consume & err_deny) {
10477c478bd9Sstevel@tonic-gate 			if (ace4p->access_mask & mask_bit) {
10487c478bd9Sstevel@tonic-gate 				return (ENOTSUP);
10497c478bd9Sstevel@tonic-gate 			}
10507c478bd9Sstevel@tonic-gate 		}
10517c478bd9Sstevel@tonic-gate 	} else {
10527c478bd9Sstevel@tonic-gate 		/* ACE4_ACCESS_ALLOWED_ACE_TYPE */
10537c478bd9Sstevel@tonic-gate 		if (nfs4_acl_consume & set_allow) {
10547c478bd9Sstevel@tonic-gate 			if (!(ace4p->access_mask & mask_bit)) {
10557c478bd9Sstevel@tonic-gate 				return (ENOTSUP);
10567c478bd9Sstevel@tonic-gate 			}
10577c478bd9Sstevel@tonic-gate 		} else if (nfs4_acl_consume & err_allow) {
10587c478bd9Sstevel@tonic-gate 			if (ace4p->access_mask & mask_bit) {
10597c478bd9Sstevel@tonic-gate 				return (ENOTSUP);
10607c478bd9Sstevel@tonic-gate 			}
10617c478bd9Sstevel@tonic-gate 		}
10627c478bd9Sstevel@tonic-gate 	}
10637c478bd9Sstevel@tonic-gate 	return (0);
10647c478bd9Sstevel@tonic-gate }
10657c478bd9Sstevel@tonic-gate 
10667c478bd9Sstevel@tonic-gate static int
ace4_to_aent_legal(nfsace4 * ace4p,int isserver)10677c478bd9Sstevel@tonic-gate ace4_to_aent_legal(nfsace4 *ace4p, int isserver)
10687c478bd9Sstevel@tonic-gate {
10697c478bd9Sstevel@tonic-gate 	int error = 0;
10707c478bd9Sstevel@tonic-gate 	int isowner;
10717c478bd9Sstevel@tonic-gate 
10727c478bd9Sstevel@tonic-gate 	/* check for NULL who string */
10737c478bd9Sstevel@tonic-gate 	if (ace4p->who.utf8string_val == NULL) {
10747c478bd9Sstevel@tonic-gate 		NFS4_DEBUG(nfs4_acl_debug, (CE_NOTE,
10757c478bd9Sstevel@tonic-gate 		    "ace4_to_aent_legal: NULL who string"));
10767c478bd9Sstevel@tonic-gate 		error = EINVAL;
10777c478bd9Sstevel@tonic-gate 		goto out;
10787c478bd9Sstevel@tonic-gate 	}
10797c478bd9Sstevel@tonic-gate 
10807c478bd9Sstevel@tonic-gate 	/* only ALLOW or DENY */
10817c478bd9Sstevel@tonic-gate 	if ((ace4p->type != ACE4_ACCESS_ALLOWED_ACE_TYPE) &&
10827c478bd9Sstevel@tonic-gate 	    (ace4p->type != ACE4_ACCESS_DENIED_ACE_TYPE)) {
10837c478bd9Sstevel@tonic-gate 		NFS4_DEBUG(nfs4_acl_debug, (CE_NOTE,
10847c478bd9Sstevel@tonic-gate 		    "ace4_to_aent_legal: neither allow nor deny"));
10857c478bd9Sstevel@tonic-gate 		error = ENOTSUP;
10867c478bd9Sstevel@tonic-gate 		goto out;
10877c478bd9Sstevel@tonic-gate 	}
10887c478bd9Sstevel@tonic-gate 
10897c478bd9Sstevel@tonic-gate 	/* check for invalid flags */
10907c478bd9Sstevel@tonic-gate 	if (ace4p->flag & ~(ACE4_VALID_FLAG_BITS)) {
10917c478bd9Sstevel@tonic-gate 		NFS4_DEBUG(nfs4_acl_debug, (CE_NOTE,
10927c478bd9Sstevel@tonic-gate 		    "ace4_to_aent_legal: invalid flags: %x", ace4p->flag));
10937c478bd9Sstevel@tonic-gate 		error = EINVAL;
10947c478bd9Sstevel@tonic-gate 		goto out;
10957c478bd9Sstevel@tonic-gate 	}
10967c478bd9Sstevel@tonic-gate 
10977c478bd9Sstevel@tonic-gate 	/* some flags are illegal */
10987c478bd9Sstevel@tonic-gate 	if (ace4p->flag & (ACE4_SUCCESSFUL_ACCESS_ACE_FLAG |
10997c478bd9Sstevel@tonic-gate 	    ACE4_FAILED_ACCESS_ACE_FLAG |
11007c478bd9Sstevel@tonic-gate 	    ACE4_NO_PROPAGATE_INHERIT_ACE)) {
11017c478bd9Sstevel@tonic-gate 		NFS4_DEBUG(nfs4_acl_debug, (CE_NOTE,
11027c478bd9Sstevel@tonic-gate 		    "ace4_to_aent_legal: illegal flags: %x", ace4p->flag));
11037c478bd9Sstevel@tonic-gate 		error = ENOTSUP;
11047c478bd9Sstevel@tonic-gate 		goto out;
11057c478bd9Sstevel@tonic-gate 	}
11067c478bd9Sstevel@tonic-gate 
11077c478bd9Sstevel@tonic-gate 	/* check for invalid masks */
11087c478bd9Sstevel@tonic-gate 	if (ace4p->access_mask & ~(ACE4_VALID_MASK_BITS)) {
11097c478bd9Sstevel@tonic-gate 		NFS4_DEBUG(nfs4_acl_debug, (CE_NOTE,
11107c478bd9Sstevel@tonic-gate 		    "ace4_to_aent_legal: invalid mask: %x",
11117c478bd9Sstevel@tonic-gate 		    ace4p->access_mask));
11127c478bd9Sstevel@tonic-gate 		error = EINVAL;
11137c478bd9Sstevel@tonic-gate 		goto out;
11147c478bd9Sstevel@tonic-gate 	}
11157c478bd9Sstevel@tonic-gate 
11167c478bd9Sstevel@tonic-gate 	if ((ace4p->who.utf8string_len == 6) &&
11177c478bd9Sstevel@tonic-gate 	    (bcmp(ACE4_WHO_OWNER, ace4p->who.utf8string_val, 6) == 0)) {
11187c478bd9Sstevel@tonic-gate 		isowner = 1;
11197c478bd9Sstevel@tonic-gate 	} else {
11207c478bd9Sstevel@tonic-gate 		isowner = 0;
11217c478bd9Sstevel@tonic-gate 	}
11227c478bd9Sstevel@tonic-gate 
11237c478bd9Sstevel@tonic-gate 	error = access_mask_check(ace4p, ACE4_SYNCHRONIZE, isserver, isowner);
11247c478bd9Sstevel@tonic-gate 	if (error)
11257c478bd9Sstevel@tonic-gate 		goto out;
11267c478bd9Sstevel@tonic-gate 
11277c478bd9Sstevel@tonic-gate 	error = access_mask_check(ace4p, ACE4_WRITE_OWNER, isserver, isowner);
11287c478bd9Sstevel@tonic-gate 	if (error)
11297c478bd9Sstevel@tonic-gate 		goto out;
11307c478bd9Sstevel@tonic-gate 
11317c478bd9Sstevel@tonic-gate 	error = access_mask_check(ace4p, ACE4_DELETE, isserver, isowner);
11327c478bd9Sstevel@tonic-gate 	if (error)
11337c478bd9Sstevel@tonic-gate 		goto out;
11347c478bd9Sstevel@tonic-gate 
11357c478bd9Sstevel@tonic-gate 	error = access_mask_check(ace4p, ACE4_WRITE_ATTRIBUTES, isserver,
11367c478bd9Sstevel@tonic-gate 	    isowner);
11377c478bd9Sstevel@tonic-gate 	if (error)
11387c478bd9Sstevel@tonic-gate 		goto out;
11397c478bd9Sstevel@tonic-gate 
11407c478bd9Sstevel@tonic-gate 	error = access_mask_check(ace4p, ACE4_READ_NAMED_ATTRS, isserver,
1141