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
527242a7cSthurlow  * Common Development and Distribution License (the "License").
627242a7cSthurlow  * 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*93aeed83Smarks  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate #include <sys/param.h>
297c478bd9Sstevel@tonic-gate #include <sys/types.h>
307c478bd9Sstevel@tonic-gate #include <sys/systm.h>
317c478bd9Sstevel@tonic-gate #include <sys/cred.h>
327c478bd9Sstevel@tonic-gate #include <sys/proc.h>
337c478bd9Sstevel@tonic-gate #include <sys/user.h>
347c478bd9Sstevel@tonic-gate #include <sys/buf.h>
357c478bd9Sstevel@tonic-gate #include <sys/vfs.h>
367c478bd9Sstevel@tonic-gate #include <sys/vnode.h>
377c478bd9Sstevel@tonic-gate #include <sys/pathname.h>
387c478bd9Sstevel@tonic-gate #include <sys/uio.h>
397c478bd9Sstevel@tonic-gate #include <sys/file.h>
407c478bd9Sstevel@tonic-gate #include <sys/stat.h>
417c478bd9Sstevel@tonic-gate #include <sys/errno.h>
427c478bd9Sstevel@tonic-gate #include <sys/socket.h>
437c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
447c478bd9Sstevel@tonic-gate #include <sys/siginfo.h>
457c478bd9Sstevel@tonic-gate #include <sys/tiuser.h>
467c478bd9Sstevel@tonic-gate #include <sys/statvfs.h>
477c478bd9Sstevel@tonic-gate #include <sys/t_kuser.h>
487c478bd9Sstevel@tonic-gate #include <sys/kmem.h>
497c478bd9Sstevel@tonic-gate #include <sys/kstat.h>
507c478bd9Sstevel@tonic-gate #include <sys/acl.h>
517c478bd9Sstevel@tonic-gate #include <sys/dirent.h>
527c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h>
537c478bd9Sstevel@tonic-gate #include <sys/debug.h>
547c478bd9Sstevel@tonic-gate #include <sys/unistd.h>
557c478bd9Sstevel@tonic-gate #include <sys/vtrace.h>
567c478bd9Sstevel@tonic-gate #include <sys/mode.h>
577c478bd9Sstevel@tonic-gate 
587c478bd9Sstevel@tonic-gate #include <rpc/types.h>
597c478bd9Sstevel@tonic-gate #include <rpc/auth.h>
607c478bd9Sstevel@tonic-gate #include <rpc/svc.h>
617c478bd9Sstevel@tonic-gate #include <rpc/xdr.h>
627c478bd9Sstevel@tonic-gate 
637c478bd9Sstevel@tonic-gate #include <nfs/nfs.h>
647c478bd9Sstevel@tonic-gate #include <nfs/export.h>
657c478bd9Sstevel@tonic-gate #include <nfs/nfssys.h>
667c478bd9Sstevel@tonic-gate #include <nfs/nfs_clnt.h>
677c478bd9Sstevel@tonic-gate #include <nfs/nfs_acl.h>
687c478bd9Sstevel@tonic-gate 
69fa9e4066Sahrens #include <fs/fs_subr.h>
70fa9e4066Sahrens 
717c478bd9Sstevel@tonic-gate /*
727c478bd9Sstevel@tonic-gate  * These are the interface routines for the server side of the
737c478bd9Sstevel@tonic-gate  * NFS ACL server.  See the NFS ACL protocol specification
747c478bd9Sstevel@tonic-gate  * for a description of this interface.
757c478bd9Sstevel@tonic-gate  */
767c478bd9Sstevel@tonic-gate 
777c478bd9Sstevel@tonic-gate /* ARGSUSED */
787c478bd9Sstevel@tonic-gate void
797c478bd9Sstevel@tonic-gate acl2_getacl(GETACL2args *args, GETACL2res *resp, struct exportinfo *exi,
807c478bd9Sstevel@tonic-gate 	struct svc_req *req, cred_t *cr)
817c478bd9Sstevel@tonic-gate {
827c478bd9Sstevel@tonic-gate 	int error;
837c478bd9Sstevel@tonic-gate 	vnode_t *vp;
847c478bd9Sstevel@tonic-gate 	vattr_t va;
857c478bd9Sstevel@tonic-gate 
867c478bd9Sstevel@tonic-gate 	vp = nfs_fhtovp(&args->fh, exi);
877c478bd9Sstevel@tonic-gate 	if (vp == NULL) {
887c478bd9Sstevel@tonic-gate 		resp->status = NFSERR_STALE;
897c478bd9Sstevel@tonic-gate 		return;
907c478bd9Sstevel@tonic-gate 	}
917c478bd9Sstevel@tonic-gate 
927c478bd9Sstevel@tonic-gate 	bzero((caddr_t)&resp->resok.acl, sizeof (resp->resok.acl));
937c478bd9Sstevel@tonic-gate 
947c478bd9Sstevel@tonic-gate 	resp->resok.acl.vsa_mask = args->mask;
957c478bd9Sstevel@tonic-gate 
96da6c28aaSamw 	error = VOP_GETSECATTR(vp, &resp->resok.acl, 0, cr, NULL);
977c478bd9Sstevel@tonic-gate 
98fa9e4066Sahrens 	if (error == ENOSYS) {
99fa9e4066Sahrens 		/*
100fa9e4066Sahrens 		 * If the underlying file system doesn't support
101fa9e4066Sahrens 		 * aclent_t type acls, fabricate an acl.  This is
102fa9e4066Sahrens 		 * required in order to to support existing clients
103fa9e4066Sahrens 		 * that require the call to VOP_GETSECATTR to
104fa9e4066Sahrens 		 * succeed while making the assumption that all
105fa9e4066Sahrens 		 * file systems support aclent_t type acls.  This
106fa9e4066Sahrens 		 * causes problems for servers exporting ZFS file
107fa9e4066Sahrens 		 * systems because ZFS supports ace_t type acls,
108fa9e4066Sahrens 		 * and fails (with ENOSYS) when asked for aclent_t
109fa9e4066Sahrens 		 * type acls.
110fa9e4066Sahrens 		 *
111fa9e4066Sahrens 		 * Note: if the fs_fab_acl() fails, we have other problems.
112fa9e4066Sahrens 		 * This error should be returned to the caller.
113fa9e4066Sahrens 		 */
114da6c28aaSamw 		error = fs_fab_acl(vp, &resp->resok.acl, 0, cr, NULL);
115fa9e4066Sahrens 	}
116fa9e4066Sahrens 
1177c478bd9Sstevel@tonic-gate 	if (error) {
1187c478bd9Sstevel@tonic-gate 		VN_RELE(vp);
1197c478bd9Sstevel@tonic-gate 		resp->status = puterrno(error);
1207c478bd9Sstevel@tonic-gate 		return;
1217c478bd9Sstevel@tonic-gate 	}
1227c478bd9Sstevel@tonic-gate 
1237c478bd9Sstevel@tonic-gate 	va.va_mask = AT_ALL;
1247c478bd9Sstevel@tonic-gate 	error = rfs4_delegated_getattr(vp, &va, 0, cr);
1257c478bd9Sstevel@tonic-gate 
1267c478bd9Sstevel@tonic-gate 	VN_RELE(vp);
1277c478bd9Sstevel@tonic-gate 
1287c478bd9Sstevel@tonic-gate 	/* check for overflowed values */
1297c478bd9Sstevel@tonic-gate 	if (!error) {
1307c478bd9Sstevel@tonic-gate 		error = vattr_to_nattr(&va, &resp->resok.attr);
1317c478bd9Sstevel@tonic-gate 	}
1327c478bd9Sstevel@tonic-gate 	if (error) {
1337c478bd9Sstevel@tonic-gate 		resp->status = puterrno(error);
1347c478bd9Sstevel@tonic-gate 		if (resp->resok.acl.vsa_aclcnt > 0 &&
1357c478bd9Sstevel@tonic-gate 		    resp->resok.acl.vsa_aclentp != NULL) {
1367c478bd9Sstevel@tonic-gate 			kmem_free((caddr_t)resp->resok.acl.vsa_aclentp,
1377c478bd9Sstevel@tonic-gate 			    resp->resok.acl.vsa_aclcnt * sizeof (aclent_t));
1387c478bd9Sstevel@tonic-gate 		}
1397c478bd9Sstevel@tonic-gate 		if (resp->resok.acl.vsa_dfaclcnt > 0 &&
1407c478bd9Sstevel@tonic-gate 		    resp->resok.acl.vsa_dfaclentp != NULL) {
1417c478bd9Sstevel@tonic-gate 			kmem_free((caddr_t)resp->resok.acl.vsa_dfaclentp,
1427c478bd9Sstevel@tonic-gate 			    resp->resok.acl.vsa_dfaclcnt * sizeof (aclent_t));
1437c478bd9Sstevel@tonic-gate 		}
1447c478bd9Sstevel@tonic-gate 		return;
1457c478bd9Sstevel@tonic-gate 	}
1467c478bd9Sstevel@tonic-gate 
1477c478bd9Sstevel@tonic-gate 	resp->status = NFS_OK;
1487c478bd9Sstevel@tonic-gate 	if (!(args->mask & NA_ACL)) {
1497c478bd9Sstevel@tonic-gate 		if (resp->resok.acl.vsa_aclcnt > 0 &&
1507c478bd9Sstevel@tonic-gate 		    resp->resok.acl.vsa_aclentp != NULL) {
1517c478bd9Sstevel@tonic-gate 			kmem_free((caddr_t)resp->resok.acl.vsa_aclentp,
1527c478bd9Sstevel@tonic-gate 			    resp->resok.acl.vsa_aclcnt * sizeof (aclent_t));
1537c478bd9Sstevel@tonic-gate 		}
1547c478bd9Sstevel@tonic-gate 		resp->resok.acl.vsa_aclentp = NULL;
1557c478bd9Sstevel@tonic-gate 	}
1567c478bd9Sstevel@tonic-gate 	if (!(args->mask & NA_DFACL)) {
1577c478bd9Sstevel@tonic-gate 		if (resp->resok.acl.vsa_dfaclcnt > 0 &&
1587c478bd9Sstevel@tonic-gate 		    resp->resok.acl.vsa_dfaclentp != NULL) {
1597c478bd9Sstevel@tonic-gate 			kmem_free((caddr_t)resp->resok.acl.vsa_dfaclentp,
1607c478bd9Sstevel@tonic-gate 			    resp->resok.acl.vsa_dfaclcnt * sizeof (aclent_t));
1617c478bd9Sstevel@tonic-gate 		}
1627c478bd9Sstevel@tonic-gate 		resp->resok.acl.vsa_dfaclentp = NULL;
1637c478bd9Sstevel@tonic-gate 	}
1647c478bd9Sstevel@tonic-gate }
1657c478bd9Sstevel@tonic-gate 
16627242a7cSthurlow void *
1677c478bd9Sstevel@tonic-gate acl2_getacl_getfh(GETACL2args *args)
1687c478bd9Sstevel@tonic-gate {
1697c478bd9Sstevel@tonic-gate 
1707c478bd9Sstevel@tonic-gate 	return (&args->fh);
1717c478bd9Sstevel@tonic-gate }
1727c478bd9Sstevel@tonic-gate 
1737c478bd9Sstevel@tonic-gate void
1747c478bd9Sstevel@tonic-gate acl2_getacl_free(GETACL2res *resp)
1757c478bd9Sstevel@tonic-gate {
1767c478bd9Sstevel@tonic-gate 
1777c478bd9Sstevel@tonic-gate 	if (resp->status == NFS_OK) {
1787c478bd9Sstevel@tonic-gate 		if (resp->resok.acl.vsa_aclcnt > 0 &&
1797c478bd9Sstevel@tonic-gate 		    resp->resok.acl.vsa_aclentp != NULL) {
1807c478bd9Sstevel@tonic-gate 			kmem_free((caddr_t)resp->resok.acl.vsa_aclentp,
1817c478bd9Sstevel@tonic-gate 			    resp->resok.acl.vsa_aclcnt * sizeof (aclent_t));
1827c478bd9Sstevel@tonic-gate 		}
1837c478bd9Sstevel@tonic-gate 		if (resp->resok.acl.vsa_dfaclcnt > 0 &&
1847c478bd9Sstevel@tonic-gate 		    resp->resok.acl.vsa_dfaclentp != NULL) {
1857c478bd9Sstevel@tonic-gate 			kmem_free((caddr_t)resp->resok.acl.vsa_dfaclentp,
1867c478bd9Sstevel@tonic-gate 			    resp->resok.acl.vsa_dfaclcnt * sizeof (aclent_t));
1877c478bd9Sstevel@tonic-gate 		}
1887c478bd9Sstevel@tonic-gate 	}
1897c478bd9Sstevel@tonic-gate }
1907c478bd9Sstevel@tonic-gate 
1917c478bd9Sstevel@tonic-gate /* ARGSUSED */
1927c478bd9Sstevel@tonic-gate void
1937c478bd9Sstevel@tonic-gate acl2_setacl(SETACL2args *args, SETACL2res *resp, struct exportinfo *exi,
1947c478bd9Sstevel@tonic-gate 	struct svc_req *req, cred_t *cr)
1957c478bd9Sstevel@tonic-gate {
1967c478bd9Sstevel@tonic-gate 	int error;
1977c478bd9Sstevel@tonic-gate 	vnode_t *vp;
1987c478bd9Sstevel@tonic-gate 	vattr_t va;
1997c478bd9Sstevel@tonic-gate 
2007c478bd9Sstevel@tonic-gate 	vp = nfs_fhtovp(&args->fh, exi);
2017c478bd9Sstevel@tonic-gate 	if (vp == NULL) {
2027c478bd9Sstevel@tonic-gate 		resp->status = NFSERR_STALE;
2037c478bd9Sstevel@tonic-gate 		return;
2047c478bd9Sstevel@tonic-gate 	}
2057c478bd9Sstevel@tonic-gate 
2067c478bd9Sstevel@tonic-gate 	if (rdonly(exi, req) || vn_is_readonly(vp)) {
2077c478bd9Sstevel@tonic-gate 		VN_RELE(vp);
2087c478bd9Sstevel@tonic-gate 		resp->status = NFSERR_ROFS;
2097c478bd9Sstevel@tonic-gate 		return;
2107c478bd9Sstevel@tonic-gate 	}
2117c478bd9Sstevel@tonic-gate 
2127c478bd9Sstevel@tonic-gate 	(void) VOP_RWLOCK(vp, V_WRITELOCK_TRUE, NULL);
213da6c28aaSamw 	error = VOP_SETSECATTR(vp, &args->acl, 0, cr, NULL);
2147c478bd9Sstevel@tonic-gate 	if (error) {
2157c478bd9Sstevel@tonic-gate 		VOP_RWUNLOCK(vp, V_WRITELOCK_TRUE, NULL);
2167c478bd9Sstevel@tonic-gate 		VN_RELE(vp);
2177c478bd9Sstevel@tonic-gate 		resp->status = puterrno(error);
2187c478bd9Sstevel@tonic-gate 		return;
2197c478bd9Sstevel@tonic-gate 	}
2207c478bd9Sstevel@tonic-gate 
2217c478bd9Sstevel@tonic-gate 	va.va_mask = AT_ALL;
2227c478bd9Sstevel@tonic-gate 	error = rfs4_delegated_getattr(vp, &va, 0, cr);
2237c478bd9Sstevel@tonic-gate 
2247c478bd9Sstevel@tonic-gate 	VOP_RWUNLOCK(vp, V_WRITELOCK_TRUE, NULL);
2257c478bd9Sstevel@tonic-gate 	VN_RELE(vp);
2267c478bd9Sstevel@tonic-gate 
2277c478bd9Sstevel@tonic-gate 	/* check for overflowed values */
2287c478bd9Sstevel@tonic-gate 	if (!error) {
2297c478bd9Sstevel@tonic-gate 		error = vattr_to_nattr(&va, &resp->resok.attr);
2307c478bd9Sstevel@tonic-gate 	}
2317c478bd9Sstevel@tonic-gate 	if (error) {
2327c478bd9Sstevel@tonic-gate 		resp->status = puterrno(error);
2337c478bd9Sstevel@tonic-gate 		return;
2347c478bd9Sstevel@tonic-gate 	}
2357c478bd9Sstevel@tonic-gate 
2367c478bd9Sstevel@tonic-gate 	resp->status = NFS_OK;
2377c478bd9Sstevel@tonic-gate }
2387c478bd9Sstevel@tonic-gate 
23927242a7cSthurlow void *
2407c478bd9Sstevel@tonic-gate acl2_setacl_getfh(SETACL2args *args)
2417c478bd9Sstevel@tonic-gate {
2427c478bd9Sstevel@tonic-gate 
2437c478bd9Sstevel@tonic-gate 	return (&args->fh);
2447c478bd9Sstevel@tonic-gate }
2457c478bd9Sstevel@tonic-gate 
2467c478bd9Sstevel@tonic-gate /* ARGSUSED */
2477c478bd9Sstevel@tonic-gate void
2487c478bd9Sstevel@tonic-gate acl2_getattr(GETATTR2args *args, GETATTR2res *resp, struct exportinfo *exi,
2497c478bd9Sstevel@tonic-gate 	struct svc_req *req, cred_t *cr)
2507c478bd9Sstevel@tonic-gate {
2517c478bd9Sstevel@tonic-gate 	int error;
2527c478bd9Sstevel@tonic-gate 	vnode_t *vp;
2537c478bd9Sstevel@tonic-gate 	vattr_t va;
2547c478bd9Sstevel@tonic-gate 
2557c478bd9Sstevel@tonic-gate 	vp = nfs_fhtovp(&args->fh, exi);
2567c478bd9Sstevel@tonic-gate 	if (vp == NULL) {
2577c478bd9Sstevel@tonic-gate 		resp->status = NFSERR_STALE;
2587c478bd9Sstevel@tonic-gate 		return;
2597c478bd9Sstevel@tonic-gate 	}
2607c478bd9Sstevel@tonic-gate 
2617c478bd9Sstevel@tonic-gate 	va.va_mask = AT_ALL;
2627c478bd9Sstevel@tonic-gate 	error = rfs4_delegated_getattr(vp, &va, 0, cr);
2637c478bd9Sstevel@tonic-gate 
2647c478bd9Sstevel@tonic-gate 	VN_RELE(vp);
2657c478bd9Sstevel@tonic-gate 
2667c478bd9Sstevel@tonic-gate 	/* check for overflowed values */
2677c478bd9Sstevel@tonic-gate 	if (!error) {
2687c478bd9Sstevel@tonic-gate 		error = vattr_to_nattr(&va, &resp->resok.attr);
2697c478bd9Sstevel@tonic-gate 	}
2707c478bd9Sstevel@tonic-gate 	if (error) {
2717c478bd9Sstevel@tonic-gate 		resp->status = puterrno(error);
2727c478bd9Sstevel@tonic-gate 		return;
2737c478bd9Sstevel@tonic-gate 	}
2747c478bd9Sstevel@tonic-gate 
2757c478bd9Sstevel@tonic-gate 	resp->status = NFS_OK;
2767c478bd9Sstevel@tonic-gate }
2777c478bd9Sstevel@tonic-gate 
27827242a7cSthurlow void *
2797c478bd9Sstevel@tonic-gate acl2_getattr_getfh(GETATTR2args *args)
2807c478bd9Sstevel@tonic-gate {
2817c478bd9Sstevel@tonic-gate 
2827c478bd9Sstevel@tonic-gate 	return (&args->fh);
2837c478bd9Sstevel@tonic-gate }
2847c478bd9Sstevel@tonic-gate 
2857c478bd9Sstevel@tonic-gate /* ARGSUSED */
2867c478bd9Sstevel@tonic-gate void
2877c478bd9Sstevel@tonic-gate acl2_access(ACCESS2args *args, ACCESS2res *resp, struct exportinfo *exi,
2887c478bd9Sstevel@tonic-gate 	struct svc_req *req, cred_t *cr)
2897c478bd9Sstevel@tonic-gate {
2907c478bd9Sstevel@tonic-gate 	int error;
2917c478bd9Sstevel@tonic-gate 	vnode_t *vp;
2927c478bd9Sstevel@tonic-gate 	vattr_t va;
2937c478bd9Sstevel@tonic-gate 	int checkwriteperm;
2947c478bd9Sstevel@tonic-gate 
2957c478bd9Sstevel@tonic-gate 	vp = nfs_fhtovp(&args->fh, exi);
2967c478bd9Sstevel@tonic-gate 	if (vp == NULL) {
2977c478bd9Sstevel@tonic-gate 		resp->status = NFSERR_STALE;
2987c478bd9Sstevel@tonic-gate 		return;
2997c478bd9Sstevel@tonic-gate 	}
3007c478bd9Sstevel@tonic-gate 
3017c478bd9Sstevel@tonic-gate 	/*
3027c478bd9Sstevel@tonic-gate 	 * If the file system is exported read only, it is not appropriate
3037c478bd9Sstevel@tonic-gate 	 * to check write permissions for regular files and directories.
3047c478bd9Sstevel@tonic-gate 	 * Special files are interpreted by the client, so the underlying
3057c478bd9Sstevel@tonic-gate 	 * permissions are sent back to the client for interpretation.
3067c478bd9Sstevel@tonic-gate 	 */
3077c478bd9Sstevel@tonic-gate 	if (rdonly(exi, req) && (vp->v_type == VREG || vp->v_type == VDIR))
3087c478bd9Sstevel@tonic-gate 		checkwriteperm = 0;
3097c478bd9Sstevel@tonic-gate 	else
3107c478bd9Sstevel@tonic-gate 		checkwriteperm = 1;
3117c478bd9Sstevel@tonic-gate 
3127c478bd9Sstevel@tonic-gate 	/*
3137c478bd9Sstevel@tonic-gate 	 * We need the mode so that we can correctly determine access
3147c478bd9Sstevel@tonic-gate 	 * permissions relative to a mandatory lock file.  Access to
3157c478bd9Sstevel@tonic-gate 	 * mandatory lock files is denied on the server, so it might
3167c478bd9Sstevel@tonic-gate 	 * as well be reflected to the server during the open.
3177c478bd9Sstevel@tonic-gate 	 */
3187c478bd9Sstevel@tonic-gate 	va.va_mask = AT_MODE;
319da6c28aaSamw 	error = VOP_GETATTR(vp, &va, 0, cr, NULL);
3207c478bd9Sstevel@tonic-gate 	if (error) {
3217c478bd9Sstevel@tonic-gate 		VN_RELE(vp);
3227c478bd9Sstevel@tonic-gate 		resp->status = puterrno(error);
3237c478bd9Sstevel@tonic-gate 		return;
3247c478bd9Sstevel@tonic-gate 	}
3257c478bd9Sstevel@tonic-gate 
3267c478bd9Sstevel@tonic-gate 	resp->resok.access = 0;
3277c478bd9Sstevel@tonic-gate 
3287c478bd9Sstevel@tonic-gate 	if (args->access & ACCESS2_READ) {
329da6c28aaSamw 		error = VOP_ACCESS(vp, VREAD, 0, cr, NULL);
3307c478bd9Sstevel@tonic-gate 		if (!error && !MANDLOCK(vp, va.va_mode))
3317c478bd9Sstevel@tonic-gate 			resp->resok.access |= ACCESS2_READ;
3327c478bd9Sstevel@tonic-gate 	}
3337c478bd9Sstevel@tonic-gate 	if ((args->access & ACCESS2_LOOKUP) && vp->v_type == VDIR) {
334da6c28aaSamw 		error = VOP_ACCESS(vp, VEXEC, 0, cr, NULL);
3357c478bd9Sstevel@tonic-gate 		if (!error)
3367c478bd9Sstevel@tonic-gate 			resp->resok.access |= ACCESS2_LOOKUP;
3377c478bd9Sstevel@tonic-gate 	}
3387c478bd9Sstevel@tonic-gate 	if (checkwriteperm &&
3397c478bd9Sstevel@tonic-gate 	    (args->access & (ACCESS2_MODIFY|ACCESS2_EXTEND))) {
340da6c28aaSamw 		error = VOP_ACCESS(vp, VWRITE, 0, cr, NULL);
3417c478bd9Sstevel@tonic-gate 		if (!error && !MANDLOCK(vp, va.va_mode))
3427c478bd9Sstevel@tonic-gate 			resp->resok.access |=
3437c478bd9Sstevel@tonic-gate 			    (args->access & (ACCESS2_MODIFY|ACCESS2_EXTEND));
3447c478bd9Sstevel@tonic-gate 	}
3457c478bd9Sstevel@tonic-gate 	if (checkwriteperm &&
3467c478bd9Sstevel@tonic-gate 	    (args->access & ACCESS2_DELETE) && (vp->v_type == VDIR)) {
347da6c28aaSamw 		error = VOP_ACCESS(vp, VWRITE, 0, cr, NULL);
3487c478bd9Sstevel@tonic-gate 		if (!error)
3497c478bd9Sstevel@tonic-gate 			resp->resok.access |= ACCESS2_DELETE;
3507c478bd9Sstevel@tonic-gate 	}
3517c478bd9Sstevel@tonic-gate 	if (args->access & ACCESS2_EXECUTE) {
352da6c28aaSamw 		error = VOP_ACCESS(vp, VEXEC, 0, cr, NULL);
3537c478bd9Sstevel@tonic-gate 		if (!error && !MANDLOCK(vp, va.va_mode))
3547c478bd9Sstevel@tonic-gate 			resp->resok.access |= ACCESS2_EXECUTE;
3557c478bd9Sstevel@tonic-gate 	}
3567c478bd9Sstevel@tonic-gate 
3577c478bd9Sstevel@tonic-gate 	va.va_mask = AT_ALL;
3587c478bd9Sstevel@tonic-gate 	error = rfs4_delegated_getattr(vp, &va, 0, cr);
3597c478bd9Sstevel@tonic-gate 
3607c478bd9Sstevel@tonic-gate 	VN_RELE(vp);
3617c478bd9Sstevel@tonic-gate 
3627c478bd9Sstevel@tonic-gate 	/* check for overflowed values */
3637c478bd9Sstevel@tonic-gate 	if (!error) {
3647c478bd9Sstevel@tonic-gate 		error = vattr_to_nattr(&va, &resp->resok.attr);
3657c478bd9Sstevel@tonic-gate 	}
3667c478bd9Sstevel@tonic-gate 	if (error) {
3677c478bd9Sstevel@tonic-gate 		resp->status = puterrno(error);
3687c478bd9Sstevel@tonic-gate 		return;
3697c478bd9Sstevel@tonic-gate 	}
3707c478bd9Sstevel@tonic-gate 
3717c478bd9Sstevel@tonic-gate 	resp->status = NFS_OK;
3727c478bd9Sstevel@tonic-gate }
3737c478bd9Sstevel@tonic-gate 
37427242a7cSthurlow void *
3757c478bd9Sstevel@tonic-gate acl2_access_getfh(ACCESS2args *args)
3767c478bd9Sstevel@tonic-gate {
3777c478bd9Sstevel@tonic-gate 
3787c478bd9Sstevel@tonic-gate 	return (&args->fh);
3797c478bd9Sstevel@tonic-gate }
3807c478bd9Sstevel@tonic-gate 
3817c478bd9Sstevel@tonic-gate /* ARGSUSED */
3827c478bd9Sstevel@tonic-gate void
3837c478bd9Sstevel@tonic-gate acl2_getxattrdir(GETXATTRDIR2args *args, GETXATTRDIR2res *resp,
3847c478bd9Sstevel@tonic-gate 	struct exportinfo *exi, struct svc_req *req, cred_t *cr)
3857c478bd9Sstevel@tonic-gate {
3867c478bd9Sstevel@tonic-gate 	int error;
3877c478bd9Sstevel@tonic-gate 	int flags;
3887c478bd9Sstevel@tonic-gate 	vnode_t *vp, *avp;
3897c478bd9Sstevel@tonic-gate 
3907c478bd9Sstevel@tonic-gate 	vp = nfs_fhtovp(&args->fh, exi);
3917c478bd9Sstevel@tonic-gate 	if (vp == NULL) {
3927c478bd9Sstevel@tonic-gate 		resp->status = NFSERR_STALE;
3937c478bd9Sstevel@tonic-gate 		return;
3947c478bd9Sstevel@tonic-gate 	}
3957c478bd9Sstevel@tonic-gate 
3967c478bd9Sstevel@tonic-gate 	flags = LOOKUP_XATTR;
3977c478bd9Sstevel@tonic-gate 	if (args->create)
3987c478bd9Sstevel@tonic-gate 		flags |= CREATE_XATTR_DIR;
3997c478bd9Sstevel@tonic-gate 	else {
4007c478bd9Sstevel@tonic-gate 		ulong_t val = 0;
401*93aeed83Smarks 		error = VOP_PATHCONF(vp, _PC_SATTR_EXISTS, &val, cr, NULL);
4027c478bd9Sstevel@tonic-gate 		if (!error && val == 0) {
403*93aeed83Smarks 			error = VOP_PATHCONF(vp, _PC_XATTR_EXISTS,
404*93aeed83Smarks 			    &val, cr, NULL);
405*93aeed83Smarks 			if (!error && val == 0) {
406*93aeed83Smarks 				VN_RELE(vp);
407*93aeed83Smarks 				resp->status = NFSERR_NOENT;
408*93aeed83Smarks 				return;
409*93aeed83Smarks 			}
4107c478bd9Sstevel@tonic-gate 		}
4117c478bd9Sstevel@tonic-gate 	}
4127c478bd9Sstevel@tonic-gate 
413da6c28aaSamw 	error = VOP_LOOKUP(vp, "", &avp, NULL, flags, NULL, cr,
414da6c28aaSamw 	    NULL, NULL, NULL);
4157c478bd9Sstevel@tonic-gate 	if (!error && avp == vp) {	/* lookup of "" on old FS? */
4167c478bd9Sstevel@tonic-gate 		error = EINVAL;
4177c478bd9Sstevel@tonic-gate 		VN_RELE(avp);
4187c478bd9Sstevel@tonic-gate 	}
4197c478bd9Sstevel@tonic-gate 	if (!error) {
4207c478bd9Sstevel@tonic-gate 		struct vattr va;
4217c478bd9Sstevel@tonic-gate 		va.va_mask = AT_ALL;
4227c478bd9Sstevel@tonic-gate 		error = rfs4_delegated_getattr(avp, &va, 0, cr);
4237c478bd9Sstevel@tonic-gate 		if (!error) {
4247c478bd9Sstevel@tonic-gate 			error = vattr_to_nattr(&va, &resp->resok.attr);
4257c478bd9Sstevel@tonic-gate 			if (!error)
4267c478bd9Sstevel@tonic-gate 				error = makefh(&resp->resok.fh, avp, exi);
4277c478bd9Sstevel@tonic-gate 		}
4287c478bd9Sstevel@tonic-gate 		VN_RELE(avp);
4297c478bd9Sstevel@tonic-gate 	}
4307c478bd9Sstevel@tonic-gate 
4317c478bd9Sstevel@tonic-gate 	VN_RELE(vp);
4327c478bd9Sstevel@tonic-gate 
4337c478bd9Sstevel@tonic-gate 	if (error) {
4347c478bd9Sstevel@tonic-gate 		resp->status = puterrno(error);
4357c478bd9Sstevel@tonic-gate 		return;
4367c478bd9Sstevel@tonic-gate 	}
4377c478bd9Sstevel@tonic-gate 	resp->status = NFS_OK;
4387c478bd9Sstevel@tonic-gate }
4397c478bd9Sstevel@tonic-gate 
44027242a7cSthurlow void *
4417c478bd9Sstevel@tonic-gate acl2_getxattrdir_getfh(GETXATTRDIR2args *args)
4427c478bd9Sstevel@tonic-gate {
4437c478bd9Sstevel@tonic-gate 	return (&args->fh);
4447c478bd9Sstevel@tonic-gate }
4457c478bd9Sstevel@tonic-gate 
4467c478bd9Sstevel@tonic-gate /* ARGSUSED */
4477c478bd9Sstevel@tonic-gate void
4487c478bd9Sstevel@tonic-gate acl3_getacl(GETACL3args *args, GETACL3res *resp, struct exportinfo *exi,
4497c478bd9Sstevel@tonic-gate 	struct svc_req *req, cred_t *cr)
4507c478bd9Sstevel@tonic-gate {
4517c478bd9Sstevel@tonic-gate 	int error;
4527c478bd9Sstevel@tonic-gate 	vnode_t *vp;
4537c478bd9Sstevel@tonic-gate 	vattr_t *vap;
4547c478bd9Sstevel@tonic-gate 	vattr_t va;
4557c478bd9Sstevel@tonic-gate 
4567c478bd9Sstevel@tonic-gate 	vap = NULL;
4577c478bd9Sstevel@tonic-gate 
4587c478bd9Sstevel@tonic-gate 	vp = nfs3_fhtovp(&args->fh, exi);
4597c478bd9Sstevel@tonic-gate 	if (vp == NULL) {
4607c478bd9Sstevel@tonic-gate 		error = ESTALE;
4617c478bd9Sstevel@tonic-gate 		goto out;
4627c478bd9Sstevel@tonic-gate 	}
4637c478bd9Sstevel@tonic-gate 
4647c478bd9Sstevel@tonic-gate #ifdef DEBUG
4657c478bd9Sstevel@tonic-gate 	if (rfs3_do_post_op_attr) {
4667c478bd9Sstevel@tonic-gate 		va.va_mask = AT_ALL;
4677c478bd9Sstevel@tonic-gate 		vap = rfs4_delegated_getattr(vp, &va, 0, cr) ? NULL : &va;
4687c478bd9Sstevel@tonic-gate 	} else
4697c478bd9Sstevel@tonic-gate 		vap = NULL;
4707c478bd9Sstevel@tonic-gate #else
4717c478bd9Sstevel@tonic-gate 	va.va_mask = AT_ALL;
4727c478bd9Sstevel@tonic-gate 	vap = rfs4_delegated_getattr(vp, &va, 0, cr) ? NULL : &va;
4737c478bd9Sstevel@tonic-gate #endif
4747c478bd9Sstevel@tonic-gate 
4757c478bd9Sstevel@tonic-gate 	bzero((caddr_t)&resp->resok.acl, sizeof (resp->resok.acl));
4767c478bd9Sstevel@tonic-gate 
4777c478bd9Sstevel@tonic-gate 	resp->resok.acl.vsa_mask = args->mask;
4787c478bd9Sstevel@tonic-gate 
479da6c28aaSamw 	error = VOP_GETSECATTR(vp, &resp->resok.acl, 0, cr, NULL);
4807c478bd9Sstevel@tonic-gate 
481fa9e4066Sahrens 	if (error == ENOSYS) {
482fa9e4066Sahrens 		/*
483fa9e4066Sahrens 		 * If the underlying file system doesn't support
484fa9e4066Sahrens 		 * aclent_t type acls, fabricate an acl.  This is
485fa9e4066Sahrens 		 * required in order to to support existing clients
486fa9e4066Sahrens 		 * that require the call to VOP_GETSECATTR to
487fa9e4066Sahrens 		 * succeed while making the assumption that all
488fa9e4066Sahrens 		 * file systems support aclent_t type acls.  This
489fa9e4066Sahrens 		 * causes problems for servers exporting ZFS file
490fa9e4066Sahrens 		 * systems because ZFS supports ace_t type acls,
491fa9e4066Sahrens 		 * and fails (with ENOSYS) when asked for aclent_t
492fa9e4066Sahrens 		 * type acls.
493fa9e4066Sahrens 		 *
494fa9e4066Sahrens 		 * Note: if the fs_fab_acl() fails, we have other problems.
495fa9e4066Sahrens 		 * This error should be returned to the caller.
496fa9e4066Sahrens 		 */
497da6c28aaSamw 		error = fs_fab_acl(vp, &resp->resok.acl, 0, cr, NULL);
498fa9e4066Sahrens 	}
499fa9e4066Sahrens 
5007c478bd9Sstevel@tonic-gate 	if (error)
5017c478bd9Sstevel@tonic-gate 		goto out;
5027c478bd9Sstevel@tonic-gate 
5037c478bd9Sstevel@tonic-gate #ifdef DEBUG
5047c478bd9Sstevel@tonic-gate 	if (rfs3_do_post_op_attr) {
5057c478bd9Sstevel@tonic-gate 		va.va_mask = AT_ALL;
5067c478bd9Sstevel@tonic-gate 		vap = rfs4_delegated_getattr(vp, &va, 0, cr) ? NULL : &va;
5077c478bd9Sstevel@tonic-gate 	} else
5087c478bd9Sstevel@tonic-gate 		vap = NULL;
5097c478bd9Sstevel@tonic-gate #else
5107c478bd9Sstevel@tonic-gate 	va.va_mask = AT_ALL;
5117c478bd9Sstevel@tonic-gate 	vap = rfs4_delegated_getattr(vp, &va, 0, cr) ? NULL : &va;
5127c478bd9Sstevel@tonic-gate #endif
5137c478bd9Sstevel@tonic-gate 
5147c478bd9Sstevel@tonic-gate 	VN_RELE(vp);
5157c478bd9Sstevel@tonic-gate 
5167c478bd9Sstevel@tonic-gate 	resp->status = NFS3_OK;
5177c478bd9Sstevel@tonic-gate 	vattr_to_post_op_attr(vap, &resp->resok.attr);
5187c478bd9Sstevel@tonic-gate 	if (!(args->mask & NA_ACL)) {
5197c478bd9Sstevel@tonic-gate 		if (resp->resok.acl.vsa_aclcnt > 0 &&
5207c478bd9Sstevel@tonic-gate 		    resp->resok.acl.vsa_aclentp != NULL) {
5217c478bd9Sstevel@tonic-gate 			kmem_free((caddr_t)resp->resok.acl.vsa_aclentp,
5227c478bd9Sstevel@tonic-gate 			    resp->resok.acl.vsa_aclcnt * sizeof (aclent_t));
5237c478bd9Sstevel@tonic-gate 		}
5247c478bd9Sstevel@tonic-gate 		resp->resok.acl.vsa_aclentp = NULL;
5257c478bd9Sstevel@tonic-gate 	}
5267c478bd9Sstevel@tonic-gate 	if (!(args->mask & NA_DFACL)) {
5277c478bd9Sstevel@tonic-gate 		if (resp->resok.acl.vsa_dfaclcnt > 0 &&
5287c478bd9Sstevel@tonic-gate 		    resp->resok.acl.vsa_dfaclentp != NULL) {
5297c478bd9Sstevel@tonic-gate 			kmem_free((caddr_t)resp->resok.acl.vsa_dfaclentp,
5307c478bd9Sstevel@tonic-gate 			    resp->resok.acl.vsa_dfaclcnt * sizeof (aclent_t));
5317c478bd9Sstevel@tonic-gate 		}
5327c478bd9Sstevel@tonic-gate 		resp->resok.acl.vsa_dfaclentp = NULL;
5337c478bd9Sstevel@tonic-gate 	}
5347c478bd9Sstevel@tonic-gate 	return;
5357c478bd9Sstevel@tonic-gate 
5367c478bd9Sstevel@tonic-gate out:
5377c478bd9Sstevel@tonic-gate 	if (curthread->t_flag & T_WOULDBLOCK) {
5387c478bd9Sstevel@tonic-gate 		curthread->t_flag &= ~T_WOULDBLOCK;
5397c478bd9Sstevel@tonic-gate 		resp->status = NFS3ERR_JUKEBOX;
5407c478bd9Sstevel@tonic-gate 	} else
5417c478bd9Sstevel@tonic-gate 		resp->status = puterrno3(error);
5427c478bd9Sstevel@tonic-gate out1:
5437c478bd9Sstevel@tonic-gate 	if (vp != NULL)
5447c478bd9Sstevel@tonic-gate 		VN_RELE(vp);
5457c478bd9Sstevel@tonic-gate 	vattr_to_post_op_attr(vap, &resp->resfail.attr);
5467c478bd9Sstevel@tonic-gate }
5477c478bd9Sstevel@tonic-gate 
54827242a7cSthurlow void *
5497c478bd9Sstevel@tonic-gate acl3_getacl_getfh(GETACL3args *args)
5507c478bd9Sstevel@tonic-gate {
5517c478bd9Sstevel@tonic-gate 
55227242a7cSthurlow 	return (&args->fh);
5537c478bd9Sstevel@tonic-gate }
5547c478bd9Sstevel@tonic-gate 
5557c478bd9Sstevel@tonic-gate void
5567c478bd9Sstevel@tonic-gate acl3_getacl_free(GETACL3res *resp)
5577c478bd9Sstevel@tonic-gate {
5587c478bd9Sstevel@tonic-gate 
5597c478bd9Sstevel@tonic-gate 	if (resp->status == NFS3_OK) {
5607c478bd9Sstevel@tonic-gate 		if (resp->resok.acl.vsa_aclcnt > 0 &&
5617c478bd9Sstevel@tonic-gate 		    resp->resok.acl.vsa_aclentp != NULL) {
5627c478bd9Sstevel@tonic-gate 			kmem_free((caddr_t)resp->resok.acl.vsa_aclentp,
5637c478bd9Sstevel@tonic-gate 			    resp->resok.acl.vsa_aclcnt * sizeof (aclent_t));
5647c478bd9Sstevel@tonic-gate 		}
5657c478bd9Sstevel@tonic-gate 		if (resp->resok.acl.vsa_dfaclcnt > 0 &&
5667c478bd9Sstevel@tonic-gate 		    resp->resok.acl.vsa_dfaclentp != NULL) {
5677c478bd9Sstevel@tonic-gate 			kmem_free((caddr_t)resp->resok.acl.vsa_dfaclentp,
5687c478bd9Sstevel@tonic-gate 			    resp->resok.acl.vsa_dfaclcnt * sizeof (aclent_t));
5697c478bd9Sstevel@tonic-gate 		}
5707c478bd9Sstevel@tonic-gate 	}
5717c478bd9Sstevel@tonic-gate }
5727c478bd9Sstevel@tonic-gate 
5737c478bd9Sstevel@tonic-gate /* ARGSUSED */
5747c478bd9Sstevel@tonic-gate void
5757c478bd9Sstevel@tonic-gate acl3_setacl(SETACL3args *args, SETACL3res *resp, struct exportinfo *exi,
5767c478bd9Sstevel@tonic-gate 	struct svc_req *req, cred_t *cr)
5777c478bd9Sstevel@tonic-gate {
5787c478bd9Sstevel@tonic-gate 	int error;
5797c478bd9Sstevel@tonic-gate 	vnode_t *vp;
5807c478bd9Sstevel@tonic-gate 	vattr_t *vap;
5817c478bd9Sstevel@tonic-gate 	vattr_t va;
5827c478bd9Sstevel@tonic-gate 
5837c478bd9Sstevel@tonic-gate 	vap = NULL;
5847c478bd9Sstevel@tonic-gate 
5857c478bd9Sstevel@tonic-gate 	vp = nfs3_fhtovp(&args->fh, exi);
5867c478bd9Sstevel@tonic-gate 	if (vp == NULL) {
5877c478bd9Sstevel@tonic-gate 		error = ESTALE;
5887c478bd9Sstevel@tonic-gate 		goto out1;
5897c478bd9Sstevel@tonic-gate 	}
5907c478bd9Sstevel@tonic-gate 
5917c478bd9Sstevel@tonic-gate 	(void) VOP_RWLOCK(vp, V_WRITELOCK_TRUE, NULL);
5927c478bd9Sstevel@tonic-gate 
5937c478bd9Sstevel@tonic-gate #ifdef DEBUG
5947c478bd9Sstevel@tonic-gate 	if (rfs3_do_post_op_attr) {
5957c478bd9Sstevel@tonic-gate 		va.va_mask = AT_ALL;
5967c478bd9Sstevel@tonic-gate 		vap = rfs4_delegated_getattr(vp, &va, 0, cr) ? NULL : &va;
5977c478bd9Sstevel@tonic-gate 	} else
5987c478bd9Sstevel@tonic-gate 		vap = NULL;
5997c478bd9Sstevel@tonic-gate #else
6007c478bd9Sstevel@tonic-gate 	va.va_mask = AT_ALL;
6017c478bd9Sstevel@tonic-gate 	vap = rfs4_delegated_getattr(vp, &va, 0, cr) ? NULL : &va;
6027c478bd9Sstevel@tonic-gate #endif
6037c478bd9Sstevel@tonic-gate 
6047c478bd9Sstevel@tonic-gate 	if (rdonly(exi, req) || vn_is_readonly(vp)) {
6057c478bd9Sstevel@tonic-gate 		resp->status = NFS3ERR_ROFS;
6067c478bd9Sstevel@tonic-gate 		goto out1;
6077c478bd9Sstevel@tonic-gate 	}
6087c478bd9Sstevel@tonic-gate 
609da6c28aaSamw 	error = VOP_SETSECATTR(vp, &args->acl, 0, cr, NULL);
6107c478bd9Sstevel@tonic-gate 
6117c478bd9Sstevel@tonic-gate #ifdef DEBUG
6127c478bd9Sstevel@tonic-gate 	if (rfs3_do_post_op_attr) {
6137c478bd9Sstevel@tonic-gate 		va.va_mask = AT_ALL;
6147c478bd9Sstevel@tonic-gate 		vap = rfs4_delegated_getattr(vp, &va, 0, cr) ? NULL : &va;
6157c478bd9Sstevel@tonic-gate 	} else
6167c478bd9Sstevel@tonic-gate 		vap = NULL;
6177c478bd9Sstevel@tonic-gate #else
6187c478bd9Sstevel@tonic-gate 	va.va_mask = AT_ALL;
6197c478bd9Sstevel@tonic-gate 	vap = rfs4_delegated_getattr(vp, &va, 0, cr) ? NULL : &va;
6207c478bd9Sstevel@tonic-gate #endif
6217c478bd9Sstevel@tonic-gate 
6227c478bd9Sstevel@tonic-gate 	if (error)
6237c478bd9Sstevel@tonic-gate 		goto out;
6247c478bd9Sstevel@tonic-gate 
6257c478bd9Sstevel@tonic-gate 	VOP_RWUNLOCK(vp, V_WRITELOCK_TRUE, NULL);
6267c478bd9Sstevel@tonic-gate 	VN_RELE(vp);
6277c478bd9Sstevel@tonic-gate 
6287c478bd9Sstevel@tonic-gate 	resp->status = NFS3_OK;
6297c478bd9Sstevel@tonic-gate 	vattr_to_post_op_attr(vap, &resp->resok.attr);
6307c478bd9Sstevel@tonic-gate 	return;
6317c478bd9Sstevel@tonic-gate 
6327c478bd9Sstevel@tonic-gate out:
6337c478bd9Sstevel@tonic-gate 	if (curthread->t_flag & T_WOULDBLOCK) {
6347c478bd9Sstevel@tonic-gate 		curthread->t_flag &= ~T_WOULDBLOCK;
6357c478bd9Sstevel@tonic-gate 		resp->status = NFS3ERR_JUKEBOX;
6367c478bd9Sstevel@tonic-gate 	} else
6377c478bd9Sstevel@tonic-gate 		resp->status = puterrno3(error);
6387c478bd9Sstevel@tonic-gate out1:
6397c478bd9Sstevel@tonic-gate 	if (vp != NULL) {
6407c478bd9Sstevel@tonic-gate 		VOP_RWUNLOCK(vp, V_WRITELOCK_TRUE, NULL);
6417c478bd9Sstevel@tonic-gate 		VN_RELE(vp);
6427c478bd9Sstevel@tonic-gate 	}
6437c478bd9Sstevel@tonic-gate 	vattr_to_post_op_attr(vap, &resp->resfail.attr);
6447c478bd9Sstevel@tonic-gate }
6457c478bd9Sstevel@tonic-gate 
64627242a7cSthurlow void *
6477c478bd9Sstevel@tonic-gate acl3_setacl_getfh(SETACL3args *args)
6487c478bd9Sstevel@tonic-gate {
6497c478bd9Sstevel@tonic-gate 
65027242a7cSthurlow 	return (&args->fh);
6517c478bd9Sstevel@tonic-gate }
6527c478bd9Sstevel@tonic-gate 
6537c478bd9Sstevel@tonic-gate /* ARGSUSED */
6547c478bd9Sstevel@tonic-gate void
6557c478bd9Sstevel@tonic-gate acl3_getxattrdir(GETXATTRDIR3args *args, GETXATTRDIR3res *resp,
6567c478bd9Sstevel@tonic-gate 	struct exportinfo *exi, struct svc_req *req, cred_t *cr)
6577c478bd9Sstevel@tonic-gate {
6587c478bd9Sstevel@tonic-gate 	int error;
6597c478bd9Sstevel@tonic-gate 	int flags;
6607c478bd9Sstevel@tonic-gate 	vnode_t *vp, *avp;
6617c478bd9Sstevel@tonic-gate 
6627c478bd9Sstevel@tonic-gate 	vp = nfs3_fhtovp(&args->fh, exi);
6637c478bd9Sstevel@tonic-gate 	if (vp == NULL) {
6647c478bd9Sstevel@tonic-gate 		resp->status = NFS3ERR_STALE;
6657c478bd9Sstevel@tonic-gate 		return;
6667c478bd9Sstevel@tonic-gate 	}
6677c478bd9Sstevel@tonic-gate 
6687c478bd9Sstevel@tonic-gate 	flags = LOOKUP_XATTR;
6697c478bd9Sstevel@tonic-gate 	if (args->create)
6707c478bd9Sstevel@tonic-gate 		flags |= CREATE_XATTR_DIR;
6717c478bd9Sstevel@tonic-gate 	else {
6727c478bd9Sstevel@tonic-gate 		ulong_t val = 0;
673*93aeed83Smarks 
674*93aeed83Smarks 		error = VOP_PATHCONF(vp, _PC_SATTR_EXISTS, &val, cr, NULL);
6757c478bd9Sstevel@tonic-gate 		if (!error && val == 0) {
676*93aeed83Smarks 			error = VOP_PATHCONF(vp, _PC_XATTR_EXISTS,
677*93aeed83Smarks 			    &val, cr, NULL);
678*93aeed83Smarks 			if (!error && val == 0) {
679*93aeed83Smarks 				VN_RELE(vp);
680*93aeed83Smarks 				resp->status = NFS3ERR_NOENT;
681*93aeed83Smarks 				return;
682*93aeed83Smarks 			}
6837c478bd9Sstevel@tonic-gate 		}
6847c478bd9Sstevel@tonic-gate 	}
6857c478bd9Sstevel@tonic-gate 
686da6c28aaSamw 	error = VOP_LOOKUP(vp, "", &avp, NULL, flags, NULL, cr,
687da6c28aaSamw 	    NULL, NULL, NULL);
6887c478bd9Sstevel@tonic-gate 	if (!error && avp == vp) {	/* lookup of "" on old FS? */
6897c478bd9Sstevel@tonic-gate 		error = EINVAL;
6907c478bd9Sstevel@tonic-gate 		VN_RELE(avp);
6917c478bd9Sstevel@tonic-gate 	}
6927c478bd9Sstevel@tonic-gate 	if (!error) {
6937c478bd9Sstevel@tonic-gate 		struct vattr va;
6947c478bd9Sstevel@tonic-gate 		va.va_mask = AT_ALL;
6957c478bd9Sstevel@tonic-gate 		error = rfs4_delegated_getattr(avp, &va, 0, cr);
6967c478bd9Sstevel@tonic-gate 		if (!error) {
6977c478bd9Sstevel@tonic-gate 			vattr_to_post_op_attr(&va, &resp->resok.attr);
6987c478bd9Sstevel@tonic-gate 			error = makefh3(&resp->resok.fh, avp, exi);
6997c478bd9Sstevel@tonic-gate 		}
7007c478bd9Sstevel@tonic-gate 		VN_RELE(avp);
7017c478bd9Sstevel@tonic-gate 	}
7027c478bd9Sstevel@tonic-gate 
7037c478bd9Sstevel@tonic-gate 	VN_RELE(vp);
7047c478bd9Sstevel@tonic-gate 
7057c478bd9Sstevel@tonic-gate 	if (error) {
7067c478bd9Sstevel@tonic-gate 		resp->status = puterrno3(error);
7077c478bd9Sstevel@tonic-gate 		return;
7087c478bd9Sstevel@tonic-gate 	}
7097c478bd9Sstevel@tonic-gate 	resp->status = NFS3_OK;
7107c478bd9Sstevel@tonic-gate }
7117c478bd9Sstevel@tonic-gate 
71227242a7cSthurlow void *
7137c478bd9Sstevel@tonic-gate acl3_getxattrdir_getfh(GETXATTRDIR3args *args)
7147c478bd9Sstevel@tonic-gate {
71527242a7cSthurlow 	return (&args->fh);
7167c478bd9Sstevel@tonic-gate }
717