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