xref: /openbmc/linux/fs/nfsd/nfs2acl.c (revision 63f8de37951a64cc24479eafd33085537e088075)
1a257cdd0SAndreas Gruenbacher /*
2a257cdd0SAndreas Gruenbacher  * Process version 2 NFSACL requests.
3a257cdd0SAndreas Gruenbacher  *
4a257cdd0SAndreas Gruenbacher  * Copyright (C) 2002-2003 Andreas Gruenbacher <agruen@suse.de>
5a257cdd0SAndreas Gruenbacher  */
6a257cdd0SAndreas Gruenbacher 
79a74af21SBoaz Harrosh #include "nfsd.h"
89a74af21SBoaz Harrosh /* FIXME: nfsacl.h is a broken header */
9a257cdd0SAndreas Gruenbacher #include <linux/nfsacl.h>
105a0e3ad6STejun Heo #include <linux/gfp.h>
119a74af21SBoaz Harrosh #include "cache.h"
129a74af21SBoaz Harrosh #include "xdr3.h"
130a3adadeSJ. Bruce Fields #include "vfs.h"
14a257cdd0SAndreas Gruenbacher 
15a257cdd0SAndreas Gruenbacher #define NFSDDBG_FACILITY		NFSDDBG_PROC
16a257cdd0SAndreas Gruenbacher #define RETURN_STATUS(st)	{ resp->status = (st); return (st); }
17a257cdd0SAndreas Gruenbacher 
18a257cdd0SAndreas Gruenbacher /*
19a257cdd0SAndreas Gruenbacher  * NULL call.
20a257cdd0SAndreas Gruenbacher  */
217111c66eSAl Viro static __be32
22a6beb732SChristoph Hellwig nfsacld_proc_null(struct svc_rqst *rqstp)
23a257cdd0SAndreas Gruenbacher {
24a257cdd0SAndreas Gruenbacher 	return nfs_ok;
25a257cdd0SAndreas Gruenbacher }
26a257cdd0SAndreas Gruenbacher 
27a257cdd0SAndreas Gruenbacher /*
28a257cdd0SAndreas Gruenbacher  * Get the Access and/or Default ACL of a file.
29a257cdd0SAndreas Gruenbacher  */
30a6beb732SChristoph Hellwig static __be32 nfsacld_proc_getacl(struct svc_rqst *rqstp)
31a257cdd0SAndreas Gruenbacher {
32a6beb732SChristoph Hellwig 	struct nfsd3_getaclargs *argp = rqstp->rq_argp;
33a6beb732SChristoph Hellwig 	struct nfsd3_getaclres *resp = rqstp->rq_resp;
34a257cdd0SAndreas Gruenbacher 	struct posix_acl *acl;
354ac7249eSChristoph Hellwig 	struct inode *inode;
364ac7249eSChristoph Hellwig 	svc_fh *fh;
37c4d987baSAl Viro 	__be32 nfserr = 0;
38a257cdd0SAndreas Gruenbacher 
39a257cdd0SAndreas Gruenbacher 	dprintk("nfsd: GETACL(2acl)   %s\n", SVCFH_fmt(&argp->fh));
40a257cdd0SAndreas Gruenbacher 
41a257cdd0SAndreas Gruenbacher 	fh = fh_copy(&resp->fh, &argp->fh);
428837abcaSMiklos Szeredi 	nfserr = fh_verify(rqstp, &resp->fh, 0, NFSD_MAY_NOP);
438837abcaSMiklos Szeredi 	if (nfserr)
44ac8587dcSJ. Bruce Fields 		RETURN_STATUS(nfserr);
45a257cdd0SAndreas Gruenbacher 
462b0143b5SDavid Howells 	inode = d_inode(fh->fh_dentry);
474ac7249eSChristoph Hellwig 
487b8f4586SKinglong Mee 	if (argp->mask & ~NFS_ACL_MASK)
49a257cdd0SAndreas Gruenbacher 		RETURN_STATUS(nfserr_inval);
50a257cdd0SAndreas Gruenbacher 	resp->mask = argp->mask;
51a257cdd0SAndreas Gruenbacher 
524f4a4fadSJ. Bruce Fields 	nfserr = fh_getattr(fh, &resp->stat);
534f4a4fadSJ. Bruce Fields 	if (nfserr)
547b8f4586SKinglong Mee 		RETURN_STATUS(nfserr);
554f4a4fadSJ. Bruce Fields 
56a257cdd0SAndreas Gruenbacher 	if (resp->mask & (NFS_ACL|NFS_ACLCNT)) {
574ac7249eSChristoph Hellwig 		acl = get_acl(inode, ACL_TYPE_ACCESS);
58a257cdd0SAndreas Gruenbacher 		if (acl == NULL) {
59a257cdd0SAndreas Gruenbacher 			/* Solaris returns the inode's minimum ACL. */
60a257cdd0SAndreas Gruenbacher 			acl = posix_acl_from_mode(inode->i_mode, GFP_KERNEL);
61a257cdd0SAndreas Gruenbacher 		}
6235e634b8SKinglong Mee 		if (IS_ERR(acl)) {
6335e634b8SKinglong Mee 			nfserr = nfserrno(PTR_ERR(acl));
6435e634b8SKinglong Mee 			goto fail;
6535e634b8SKinglong Mee 		}
66a257cdd0SAndreas Gruenbacher 		resp->acl_access = acl;
67a257cdd0SAndreas Gruenbacher 	}
68a257cdd0SAndreas Gruenbacher 	if (resp->mask & (NFS_DFACL|NFS_DFACLCNT)) {
69a257cdd0SAndreas Gruenbacher 		/* Check how Solaris handles requests for the Default ACL
70a257cdd0SAndreas Gruenbacher 		   of a non-directory! */
714ac7249eSChristoph Hellwig 		acl = get_acl(inode, ACL_TYPE_DEFAULT);
72a257cdd0SAndreas Gruenbacher 		if (IS_ERR(acl)) {
734ac7249eSChristoph Hellwig 			nfserr = nfserrno(PTR_ERR(acl));
74a257cdd0SAndreas Gruenbacher 			goto fail;
75a257cdd0SAndreas Gruenbacher 		}
76a257cdd0SAndreas Gruenbacher 		resp->acl_default = acl;
77a257cdd0SAndreas Gruenbacher 	}
78a257cdd0SAndreas Gruenbacher 
79a257cdd0SAndreas Gruenbacher 	/* resp->acl_{access,default} are released in nfssvc_release_getacl. */
80a257cdd0SAndreas Gruenbacher 	RETURN_STATUS(0);
81a257cdd0SAndreas Gruenbacher 
82a257cdd0SAndreas Gruenbacher fail:
83a257cdd0SAndreas Gruenbacher 	posix_acl_release(resp->acl_access);
84a257cdd0SAndreas Gruenbacher 	posix_acl_release(resp->acl_default);
85a257cdd0SAndreas Gruenbacher 	RETURN_STATUS(nfserr);
86a257cdd0SAndreas Gruenbacher }
87a257cdd0SAndreas Gruenbacher 
88a257cdd0SAndreas Gruenbacher /*
89a257cdd0SAndreas Gruenbacher  * Set the Access and/or Default ACL of a file.
90a257cdd0SAndreas Gruenbacher  */
91a6beb732SChristoph Hellwig static __be32 nfsacld_proc_setacl(struct svc_rqst *rqstp)
92a257cdd0SAndreas Gruenbacher {
93a6beb732SChristoph Hellwig 	struct nfsd3_setaclargs *argp = rqstp->rq_argp;
94a6beb732SChristoph Hellwig 	struct nfsd_attrstat *resp = rqstp->rq_resp;
954ac7249eSChristoph Hellwig 	struct inode *inode;
96a257cdd0SAndreas Gruenbacher 	svc_fh *fh;
97c4d987baSAl Viro 	__be32 nfserr = 0;
984ac7249eSChristoph Hellwig 	int error;
99a257cdd0SAndreas Gruenbacher 
100a257cdd0SAndreas Gruenbacher 	dprintk("nfsd: SETACL(2acl)   %s\n", SVCFH_fmt(&argp->fh));
101a257cdd0SAndreas Gruenbacher 
102a257cdd0SAndreas Gruenbacher 	fh = fh_copy(&resp->fh, &argp->fh);
1038837abcaSMiklos Szeredi 	nfserr = fh_verify(rqstp, &resp->fh, 0, NFSD_MAY_SATTR);
1044ac7249eSChristoph Hellwig 	if (nfserr)
1054ac7249eSChristoph Hellwig 		goto out;
106a257cdd0SAndreas Gruenbacher 
1072b0143b5SDavid Howells 	inode = d_inode(fh->fh_dentry);
1084ac7249eSChristoph Hellwig 
1094ac7249eSChristoph Hellwig 	error = fh_want_write(fh);
1104ac7249eSChristoph Hellwig 	if (error)
1114ac7249eSChristoph Hellwig 		goto out_errno;
1124ac7249eSChristoph Hellwig 
11399965378SBen Hutchings 	fh_lock(fh);
11499965378SBen Hutchings 
11599965378SBen Hutchings 	error = set_posix_acl(inode, ACL_TYPE_ACCESS, argp->acl_access);
1164ac7249eSChristoph Hellwig 	if (error)
11799965378SBen Hutchings 		goto out_drop_lock;
11899965378SBen Hutchings 	error = set_posix_acl(inode, ACL_TYPE_DEFAULT, argp->acl_default);
1194ac7249eSChristoph Hellwig 	if (error)
12099965378SBen Hutchings 		goto out_drop_lock;
12199965378SBen Hutchings 
12299965378SBen Hutchings 	fh_unlock(fh);
1234ac7249eSChristoph Hellwig 
1244ac7249eSChristoph Hellwig 	fh_drop_write(fh);
1254ac7249eSChristoph Hellwig 
1264f4a4fadSJ. Bruce Fields 	nfserr = fh_getattr(fh, &resp->stat);
127a257cdd0SAndreas Gruenbacher 
1284ac7249eSChristoph Hellwig out:
129a257cdd0SAndreas Gruenbacher 	/* argp->acl_{access,default} may have been allocated in
130a257cdd0SAndreas Gruenbacher 	   nfssvc_decode_setaclargs. */
131a257cdd0SAndreas Gruenbacher 	posix_acl_release(argp->acl_access);
132a257cdd0SAndreas Gruenbacher 	posix_acl_release(argp->acl_default);
133a257cdd0SAndreas Gruenbacher 	return nfserr;
13499965378SBen Hutchings out_drop_lock:
13599965378SBen Hutchings 	fh_unlock(fh);
1364ac7249eSChristoph Hellwig 	fh_drop_write(fh);
1374ac7249eSChristoph Hellwig out_errno:
1384ac7249eSChristoph Hellwig 	nfserr = nfserrno(error);
1394ac7249eSChristoph Hellwig 	goto out;
140a257cdd0SAndreas Gruenbacher }
141a257cdd0SAndreas Gruenbacher 
142a257cdd0SAndreas Gruenbacher /*
143a257cdd0SAndreas Gruenbacher  * Check file attributes
144a257cdd0SAndreas Gruenbacher  */
145a6beb732SChristoph Hellwig static __be32 nfsacld_proc_getattr(struct svc_rqst *rqstp)
146a257cdd0SAndreas Gruenbacher {
147a6beb732SChristoph Hellwig 	struct nfsd_fhandle *argp = rqstp->rq_argp;
148a6beb732SChristoph Hellwig 	struct nfsd_attrstat *resp = rqstp->rq_resp;
1494f4a4fadSJ. Bruce Fields 	__be32 nfserr;
150a257cdd0SAndreas Gruenbacher 	dprintk("nfsd: GETATTR  %s\n", SVCFH_fmt(&argp->fh));
151a257cdd0SAndreas Gruenbacher 
152a257cdd0SAndreas Gruenbacher 	fh_copy(&resp->fh, &argp->fh);
1534f4a4fadSJ. Bruce Fields 	nfserr = fh_verify(rqstp, &resp->fh, 0, NFSD_MAY_NOP);
1544f4a4fadSJ. Bruce Fields 	if (nfserr)
1554f4a4fadSJ. Bruce Fields 		return nfserr;
1564f4a4fadSJ. Bruce Fields 	nfserr = fh_getattr(&resp->fh, &resp->stat);
1574f4a4fadSJ. Bruce Fields 	return nfserr;
158a257cdd0SAndreas Gruenbacher }
159a257cdd0SAndreas Gruenbacher 
160a257cdd0SAndreas Gruenbacher /*
161a257cdd0SAndreas Gruenbacher  * Check file access
162a257cdd0SAndreas Gruenbacher  */
163a6beb732SChristoph Hellwig static __be32 nfsacld_proc_access(struct svc_rqst *rqstp)
164a257cdd0SAndreas Gruenbacher {
165a6beb732SChristoph Hellwig 	struct nfsd3_accessargs *argp = rqstp->rq_argp;
166a6beb732SChristoph Hellwig 	struct nfsd3_accessres *resp = rqstp->rq_resp;
167c4d987baSAl Viro 	__be32 nfserr;
168a257cdd0SAndreas Gruenbacher 
169a257cdd0SAndreas Gruenbacher 	dprintk("nfsd: ACCESS(2acl)   %s 0x%x\n",
170a257cdd0SAndreas Gruenbacher 			SVCFH_fmt(&argp->fh),
171a257cdd0SAndreas Gruenbacher 			argp->access);
172a257cdd0SAndreas Gruenbacher 
173a257cdd0SAndreas Gruenbacher 	fh_copy(&resp->fh, &argp->fh);
174a257cdd0SAndreas Gruenbacher 	resp->access = argp->access;
175a257cdd0SAndreas Gruenbacher 	nfserr = nfsd_access(rqstp, &resp->fh, &resp->access, NULL);
1764f4a4fadSJ. Bruce Fields 	if (nfserr)
1774f4a4fadSJ. Bruce Fields 		return nfserr;
1784f4a4fadSJ. Bruce Fields 	nfserr = fh_getattr(&resp->fh, &resp->stat);
179a257cdd0SAndreas Gruenbacher 	return nfserr;
180a257cdd0SAndreas Gruenbacher }
181a257cdd0SAndreas Gruenbacher 
182a257cdd0SAndreas Gruenbacher /*
183a257cdd0SAndreas Gruenbacher  * XDR decode functions
184a257cdd0SAndreas Gruenbacher  */
185026fec7eSChristoph Hellwig static int nfsaclsvc_decode_getaclargs(struct svc_rqst *rqstp, __be32 *p)
186a257cdd0SAndreas Gruenbacher {
187026fec7eSChristoph Hellwig 	struct nfsd3_getaclargs *argp = rqstp->rq_argp;
188026fec7eSChristoph Hellwig 
189d40aa337SBenoit Taine 	p = nfs2svc_decode_fh(p, &argp->fh);
190d40aa337SBenoit Taine 	if (!p)
191a257cdd0SAndreas Gruenbacher 		return 0;
192a257cdd0SAndreas Gruenbacher 	argp->mask = ntohl(*p); p++;
193a257cdd0SAndreas Gruenbacher 
194a257cdd0SAndreas Gruenbacher 	return xdr_argsize_check(rqstp, p);
195a257cdd0SAndreas Gruenbacher }
196a257cdd0SAndreas Gruenbacher 
197a257cdd0SAndreas Gruenbacher 
198026fec7eSChristoph Hellwig static int nfsaclsvc_decode_setaclargs(struct svc_rqst *rqstp, __be32 *p)
199a257cdd0SAndreas Gruenbacher {
200026fec7eSChristoph Hellwig 	struct nfsd3_setaclargs *argp = rqstp->rq_argp;
201a257cdd0SAndreas Gruenbacher 	struct kvec *head = rqstp->rq_arg.head;
202a257cdd0SAndreas Gruenbacher 	unsigned int base;
203a257cdd0SAndreas Gruenbacher 	int n;
204a257cdd0SAndreas Gruenbacher 
205d40aa337SBenoit Taine 	p = nfs2svc_decode_fh(p, &argp->fh);
206d40aa337SBenoit Taine 	if (!p)
207a257cdd0SAndreas Gruenbacher 		return 0;
208a257cdd0SAndreas Gruenbacher 	argp->mask = ntohl(*p++);
2097b8f4586SKinglong Mee 	if (argp->mask & ~NFS_ACL_MASK ||
210a257cdd0SAndreas Gruenbacher 	    !xdr_argsize_check(rqstp, p))
211a257cdd0SAndreas Gruenbacher 		return 0;
212a257cdd0SAndreas Gruenbacher 
213a257cdd0SAndreas Gruenbacher 	base = (char *)p - (char *)head->iov_base;
214a257cdd0SAndreas Gruenbacher 	n = nfsacl_decode(&rqstp->rq_arg, base, NULL,
215a257cdd0SAndreas Gruenbacher 			  (argp->mask & NFS_ACL) ?
216a257cdd0SAndreas Gruenbacher 			  &argp->acl_access : NULL);
217a257cdd0SAndreas Gruenbacher 	if (n > 0)
218a257cdd0SAndreas Gruenbacher 		n = nfsacl_decode(&rqstp->rq_arg, base + n, NULL,
219a257cdd0SAndreas Gruenbacher 				  (argp->mask & NFS_DFACL) ?
220a257cdd0SAndreas Gruenbacher 				  &argp->acl_default : NULL);
221a257cdd0SAndreas Gruenbacher 	return (n > 0);
222a257cdd0SAndreas Gruenbacher }
223a257cdd0SAndreas Gruenbacher 
224026fec7eSChristoph Hellwig static int nfsaclsvc_decode_fhandleargs(struct svc_rqst *rqstp, __be32 *p)
225a257cdd0SAndreas Gruenbacher {
226026fec7eSChristoph Hellwig 	struct nfsd_fhandle *argp = rqstp->rq_argp;
227026fec7eSChristoph Hellwig 
228d40aa337SBenoit Taine 	p = nfs2svc_decode_fh(p, &argp->fh);
229d40aa337SBenoit Taine 	if (!p)
230a257cdd0SAndreas Gruenbacher 		return 0;
231a257cdd0SAndreas Gruenbacher 	return xdr_argsize_check(rqstp, p);
232a257cdd0SAndreas Gruenbacher }
233a257cdd0SAndreas Gruenbacher 
234026fec7eSChristoph Hellwig static int nfsaclsvc_decode_accessargs(struct svc_rqst *rqstp, __be32 *p)
235a257cdd0SAndreas Gruenbacher {
236026fec7eSChristoph Hellwig 	struct nfsd3_accessargs *argp = rqstp->rq_argp;
237026fec7eSChristoph Hellwig 
238d40aa337SBenoit Taine 	p = nfs2svc_decode_fh(p, &argp->fh);
239d40aa337SBenoit Taine 	if (!p)
240a257cdd0SAndreas Gruenbacher 		return 0;
241a257cdd0SAndreas Gruenbacher 	argp->access = ntohl(*p++);
242a257cdd0SAndreas Gruenbacher 
243a257cdd0SAndreas Gruenbacher 	return xdr_argsize_check(rqstp, p);
244a257cdd0SAndreas Gruenbacher }
245a257cdd0SAndreas Gruenbacher 
246a257cdd0SAndreas Gruenbacher /*
247a257cdd0SAndreas Gruenbacher  * XDR encode functions
248a257cdd0SAndreas Gruenbacher  */
249a257cdd0SAndreas Gruenbacher 
2501b7e0403SPeter Staubach /*
2511b7e0403SPeter Staubach  * There must be an encoding function for void results so svc_process
2521b7e0403SPeter Staubach  * will work properly.
2531b7e0403SPeter Staubach  */
254*63f8de37SChristoph Hellwig static int nfsaclsvc_encode_voidres(struct svc_rqst *rqstp, __be32 *p)
2551b7e0403SPeter Staubach {
2561b7e0403SPeter Staubach 	return xdr_ressize_check(rqstp, p);
2571b7e0403SPeter Staubach }
2581b7e0403SPeter Staubach 
259a257cdd0SAndreas Gruenbacher /* GETACL */
260*63f8de37SChristoph Hellwig static int nfsaclsvc_encode_getaclres(struct svc_rqst *rqstp, __be32 *p)
261a257cdd0SAndreas Gruenbacher {
262*63f8de37SChristoph Hellwig 	struct nfsd3_getaclres *resp = rqstp->rq_resp;
263a257cdd0SAndreas Gruenbacher 	struct dentry *dentry = resp->fh.fh_dentry;
264aefa89d1SPrasad P 	struct inode *inode;
265a257cdd0SAndreas Gruenbacher 	struct kvec *head = rqstp->rq_res.head;
266a257cdd0SAndreas Gruenbacher 	unsigned int base;
267a257cdd0SAndreas Gruenbacher 	int n;
268cb65a5baSJesper Juhl 	int w;
269a257cdd0SAndreas Gruenbacher 
270aefa89d1SPrasad P 	/*
271aefa89d1SPrasad P 	 * Since this is version 2, the check for nfserr in
272aefa89d1SPrasad P 	 * nfsd_dispatch actually ensures the following cannot happen.
273aefa89d1SPrasad P 	 * However, it seems fragile to depend on that.
274aefa89d1SPrasad P 	 */
2752b0143b5SDavid Howells 	if (dentry == NULL || d_really_is_negative(dentry))
276a257cdd0SAndreas Gruenbacher 		return 0;
2772b0143b5SDavid Howells 	inode = d_inode(dentry);
278a257cdd0SAndreas Gruenbacher 
2794f4a4fadSJ. Bruce Fields 	p = nfs2svc_encode_fattr(rqstp, p, &resp->fh, &resp->stat);
280a257cdd0SAndreas Gruenbacher 	*p++ = htonl(resp->mask);
281a257cdd0SAndreas Gruenbacher 	if (!xdr_ressize_check(rqstp, p))
282a257cdd0SAndreas Gruenbacher 		return 0;
283a257cdd0SAndreas Gruenbacher 	base = (char *)p - (char *)head->iov_base;
284a257cdd0SAndreas Gruenbacher 
285cb65a5baSJesper Juhl 	rqstp->rq_res.page_len = w = nfsacl_size(
286cb65a5baSJesper Juhl 		(resp->mask & NFS_ACL)   ? resp->acl_access  : NULL,
287cb65a5baSJesper Juhl 		(resp->mask & NFS_DFACL) ? resp->acl_default : NULL);
288a257cdd0SAndreas Gruenbacher 	while (w > 0) {
289afc59400SJ. Bruce Fields 		if (!*(rqstp->rq_next_page++))
290a257cdd0SAndreas Gruenbacher 			return 0;
291a257cdd0SAndreas Gruenbacher 		w -= PAGE_SIZE;
292a257cdd0SAndreas Gruenbacher 	}
293a257cdd0SAndreas Gruenbacher 
294a257cdd0SAndreas Gruenbacher 	n = nfsacl_encode(&rqstp->rq_res, base, inode,
295a257cdd0SAndreas Gruenbacher 			  resp->acl_access,
296a257cdd0SAndreas Gruenbacher 			  resp->mask & NFS_ACL, 0);
297a257cdd0SAndreas Gruenbacher 	if (n > 0)
298a257cdd0SAndreas Gruenbacher 		n = nfsacl_encode(&rqstp->rq_res, base + n, inode,
299a257cdd0SAndreas Gruenbacher 				  resp->acl_default,
300a257cdd0SAndreas Gruenbacher 				  resp->mask & NFS_DFACL,
301a257cdd0SAndreas Gruenbacher 				  NFS_ACL_DEFAULT);
3027b8f4586SKinglong Mee 	return (n > 0);
303a257cdd0SAndreas Gruenbacher }
304a257cdd0SAndreas Gruenbacher 
305*63f8de37SChristoph Hellwig static int nfsaclsvc_encode_attrstatres(struct svc_rqst *rqstp, __be32 *p)
306a257cdd0SAndreas Gruenbacher {
307*63f8de37SChristoph Hellwig 	struct nfsd_attrstat *resp = rqstp->rq_resp;
308*63f8de37SChristoph Hellwig 
3094f4a4fadSJ. Bruce Fields 	p = nfs2svc_encode_fattr(rqstp, p, &resp->fh, &resp->stat);
310a257cdd0SAndreas Gruenbacher 	return xdr_ressize_check(rqstp, p);
311a257cdd0SAndreas Gruenbacher }
312a257cdd0SAndreas Gruenbacher 
313a257cdd0SAndreas Gruenbacher /* ACCESS */
314*63f8de37SChristoph Hellwig static int nfsaclsvc_encode_accessres(struct svc_rqst *rqstp, __be32 *p)
315a257cdd0SAndreas Gruenbacher {
316*63f8de37SChristoph Hellwig 	struct nfsd3_accessres *resp = rqstp->rq_resp;
317*63f8de37SChristoph Hellwig 
3184f4a4fadSJ. Bruce Fields 	p = nfs2svc_encode_fattr(rqstp, p, &resp->fh, &resp->stat);
319a257cdd0SAndreas Gruenbacher 	*p++ = htonl(resp->access);
320a257cdd0SAndreas Gruenbacher 	return xdr_ressize_check(rqstp, p);
321a257cdd0SAndreas Gruenbacher }
322a257cdd0SAndreas Gruenbacher 
323a257cdd0SAndreas Gruenbacher /*
324a257cdd0SAndreas Gruenbacher  * XDR release functions
325a257cdd0SAndreas Gruenbacher  */
3268537488bSChristoph Hellwig static void nfsaclsvc_release_getacl(struct svc_rqst *rqstp)
327a257cdd0SAndreas Gruenbacher {
3288537488bSChristoph Hellwig 	struct nfsd3_getaclres *resp = rqstp->rq_resp;
3298537488bSChristoph Hellwig 
330a257cdd0SAndreas Gruenbacher 	fh_put(&resp->fh);
331a257cdd0SAndreas Gruenbacher 	posix_acl_release(resp->acl_access);
332a257cdd0SAndreas Gruenbacher 	posix_acl_release(resp->acl_default);
333a257cdd0SAndreas Gruenbacher }
334a257cdd0SAndreas Gruenbacher 
3358537488bSChristoph Hellwig static void nfsaclsvc_release_attrstat(struct svc_rqst *rqstp)
336c9ce2283SGreg Banks {
3378537488bSChristoph Hellwig 	struct nfsd_attrstat *resp = rqstp->rq_resp;
3388537488bSChristoph Hellwig 
339c9ce2283SGreg Banks 	fh_put(&resp->fh);
340c9ce2283SGreg Banks }
341c9ce2283SGreg Banks 
3428537488bSChristoph Hellwig static void nfsaclsvc_release_access(struct svc_rqst *rqstp)
343a257cdd0SAndreas Gruenbacher {
3448537488bSChristoph Hellwig 	struct nfsd3_accessres *resp = rqstp->rq_resp;
3458537488bSChristoph Hellwig 
346a257cdd0SAndreas Gruenbacher 	fh_put(&resp->fh);
347a257cdd0SAndreas Gruenbacher }
348a257cdd0SAndreas Gruenbacher 
349a257cdd0SAndreas Gruenbacher #define nfsaclsvc_decode_voidargs	NULL
350a257cdd0SAndreas Gruenbacher #define nfsaclsvc_release_void		NULL
351a257cdd0SAndreas Gruenbacher #define nfsd3_fhandleargs	nfsd_fhandle
352a257cdd0SAndreas Gruenbacher #define nfsd3_attrstatres	nfsd_attrstat
353a257cdd0SAndreas Gruenbacher #define nfsd3_voidres		nfsd3_voidargs
354a257cdd0SAndreas Gruenbacher struct nfsd3_voidargs { int dummy; };
355a257cdd0SAndreas Gruenbacher 
356a257cdd0SAndreas Gruenbacher #define PROC(name, argt, rest, relt, cache, respsize)			\
357f7235b6bSChristoph Hellwig {									\
358a6beb732SChristoph Hellwig 	.pc_func	= nfsacld_proc_##name,				\
359026fec7eSChristoph Hellwig 	.pc_decode	= nfsaclsvc_decode_##argt##args,		\
360*63f8de37SChristoph Hellwig 	.pc_encode	= nfsaclsvc_encode_##rest##res,			\
3618537488bSChristoph Hellwig 	.pc_release	= nfsaclsvc_release_##relt,	\
362f7235b6bSChristoph Hellwig 	.pc_argsize	= sizeof(struct nfsd3_##argt##args),		\
363f7235b6bSChristoph Hellwig 	.pc_ressize	= sizeof(struct nfsd3_##rest##res),		\
364f7235b6bSChristoph Hellwig 	.pc_cachetype	= cache,					\
365f7235b6bSChristoph Hellwig 	.pc_xdrressize	= respsize,					\
366a257cdd0SAndreas Gruenbacher }
367a257cdd0SAndreas Gruenbacher 
368a257cdd0SAndreas Gruenbacher #define ST 1		/* status*/
369a257cdd0SAndreas Gruenbacher #define AT 21		/* attributes */
370a257cdd0SAndreas Gruenbacher #define pAT (1+AT)	/* post attributes - conditional */
371a257cdd0SAndreas Gruenbacher #define ACL (1+NFS_ACL_MAX_ENTRIES*3)  /* Access Control List */
372a257cdd0SAndreas Gruenbacher 
373a257cdd0SAndreas Gruenbacher static struct svc_procedure		nfsd_acl_procedures2[] = {
374a257cdd0SAndreas Gruenbacher   PROC(null,	void,		void,		void,	  RC_NOCACHE, ST),
375a257cdd0SAndreas Gruenbacher   PROC(getacl,	getacl,		getacl,		getacl,	  RC_NOCACHE, ST+1+2*(1+ACL)),
376c9ce2283SGreg Banks   PROC(setacl,	setacl,		attrstat,	attrstat, RC_NOCACHE, ST+AT),
377c9ce2283SGreg Banks   PROC(getattr, fhandle,	attrstat,	attrstat, RC_NOCACHE, ST+AT),
378c9ce2283SGreg Banks   PROC(access,	access,		access,		access,   RC_NOCACHE, ST+AT+1),
379a257cdd0SAndreas Gruenbacher };
380a257cdd0SAndreas Gruenbacher 
381a257cdd0SAndreas Gruenbacher struct svc_version	nfsd_acl_version2 = {
382a257cdd0SAndreas Gruenbacher 		.vs_vers	= 2,
383a257cdd0SAndreas Gruenbacher 		.vs_nproc	= 5,
384a257cdd0SAndreas Gruenbacher 		.vs_proc	= nfsd_acl_procedures2,
385a257cdd0SAndreas Gruenbacher 		.vs_dispatch	= nfsd_dispatch,
386a257cdd0SAndreas Gruenbacher 		.vs_xdrsize	= NFS3_SVC_XDRSIZE,
387a257cdd0SAndreas Gruenbacher };
388