xref: /openbmc/linux/fs/nfsd/nfs2acl.c (revision 35e634b83cbe23e5673289d1536752968aab8f75)
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
22a257cdd0SAndreas Gruenbacher nfsacld_proc_null(struct svc_rqst *rqstp, void *argp, void *resp)
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  */
307111c66eSAl Viro static __be32 nfsacld_proc_getacl(struct svc_rqst * rqstp,
31a257cdd0SAndreas Gruenbacher 		struct nfsd3_getaclargs *argp, struct nfsd3_getaclres *resp)
32a257cdd0SAndreas Gruenbacher {
33a257cdd0SAndreas Gruenbacher 	struct posix_acl *acl;
344ac7249eSChristoph Hellwig 	struct inode *inode;
354ac7249eSChristoph Hellwig 	svc_fh *fh;
36c4d987baSAl Viro 	__be32 nfserr = 0;
37a257cdd0SAndreas Gruenbacher 
38a257cdd0SAndreas Gruenbacher 	dprintk("nfsd: GETACL(2acl)   %s\n", SVCFH_fmt(&argp->fh));
39a257cdd0SAndreas Gruenbacher 
40a257cdd0SAndreas Gruenbacher 	fh = fh_copy(&resp->fh, &argp->fh);
418837abcaSMiklos Szeredi 	nfserr = fh_verify(rqstp, &resp->fh, 0, NFSD_MAY_NOP);
428837abcaSMiklos Szeredi 	if (nfserr)
43ac8587dcSJ. Bruce Fields 		RETURN_STATUS(nfserr);
44a257cdd0SAndreas Gruenbacher 
454ac7249eSChristoph Hellwig 	inode = fh->fh_dentry->d_inode;
464ac7249eSChristoph Hellwig 
47a257cdd0SAndreas Gruenbacher 	if (argp->mask & ~(NFS_ACL|NFS_ACLCNT|NFS_DFACL|NFS_DFACLCNT))
48a257cdd0SAndreas Gruenbacher 		RETURN_STATUS(nfserr_inval);
49a257cdd0SAndreas Gruenbacher 	resp->mask = argp->mask;
50a257cdd0SAndreas Gruenbacher 
514f4a4fadSJ. Bruce Fields 	nfserr = fh_getattr(fh, &resp->stat);
524f4a4fadSJ. Bruce Fields 	if (nfserr)
534f4a4fadSJ. Bruce Fields 		goto fail;
544f4a4fadSJ. Bruce Fields 
55a257cdd0SAndreas Gruenbacher 	if (resp->mask & (NFS_ACL|NFS_ACLCNT)) {
564ac7249eSChristoph Hellwig 		acl = get_acl(inode, ACL_TYPE_ACCESS);
57a257cdd0SAndreas Gruenbacher 		if (acl == NULL) {
58a257cdd0SAndreas Gruenbacher 			/* Solaris returns the inode's minimum ACL. */
59a257cdd0SAndreas Gruenbacher 			acl = posix_acl_from_mode(inode->i_mode, GFP_KERNEL);
60a257cdd0SAndreas Gruenbacher 		}
61*35e634b8SKinglong Mee 		if (IS_ERR(acl)) {
62*35e634b8SKinglong Mee 			nfserr = nfserrno(PTR_ERR(acl));
63*35e634b8SKinglong Mee 			goto fail;
64*35e634b8SKinglong Mee 		}
65a257cdd0SAndreas Gruenbacher 		resp->acl_access = acl;
66a257cdd0SAndreas Gruenbacher 	}
67a257cdd0SAndreas Gruenbacher 	if (resp->mask & (NFS_DFACL|NFS_DFACLCNT)) {
68a257cdd0SAndreas Gruenbacher 		/* Check how Solaris handles requests for the Default ACL
69a257cdd0SAndreas Gruenbacher 		   of a non-directory! */
704ac7249eSChristoph Hellwig 		acl = get_acl(inode, ACL_TYPE_DEFAULT);
71a257cdd0SAndreas Gruenbacher 		if (IS_ERR(acl)) {
724ac7249eSChristoph Hellwig 			nfserr = nfserrno(PTR_ERR(acl));
73a257cdd0SAndreas Gruenbacher 			goto fail;
74a257cdd0SAndreas Gruenbacher 		}
75a257cdd0SAndreas Gruenbacher 		resp->acl_default = acl;
76a257cdd0SAndreas Gruenbacher 	}
77a257cdd0SAndreas Gruenbacher 
78a257cdd0SAndreas Gruenbacher 	/* resp->acl_{access,default} are released in nfssvc_release_getacl. */
79a257cdd0SAndreas Gruenbacher 	RETURN_STATUS(0);
80a257cdd0SAndreas Gruenbacher 
81a257cdd0SAndreas Gruenbacher fail:
82a257cdd0SAndreas Gruenbacher 	posix_acl_release(resp->acl_access);
83a257cdd0SAndreas Gruenbacher 	posix_acl_release(resp->acl_default);
84a257cdd0SAndreas Gruenbacher 	RETURN_STATUS(nfserr);
85a257cdd0SAndreas Gruenbacher }
86a257cdd0SAndreas Gruenbacher 
87a257cdd0SAndreas Gruenbacher /*
88a257cdd0SAndreas Gruenbacher  * Set the Access and/or Default ACL of a file.
89a257cdd0SAndreas Gruenbacher  */
907111c66eSAl Viro static __be32 nfsacld_proc_setacl(struct svc_rqst * rqstp,
91a257cdd0SAndreas Gruenbacher 		struct nfsd3_setaclargs *argp,
92a257cdd0SAndreas Gruenbacher 		struct nfsd_attrstat *resp)
93a257cdd0SAndreas Gruenbacher {
944ac7249eSChristoph Hellwig 	struct inode *inode;
95a257cdd0SAndreas Gruenbacher 	svc_fh *fh;
96c4d987baSAl Viro 	__be32 nfserr = 0;
974ac7249eSChristoph Hellwig 	int error;
98a257cdd0SAndreas Gruenbacher 
99a257cdd0SAndreas Gruenbacher 	dprintk("nfsd: SETACL(2acl)   %s\n", SVCFH_fmt(&argp->fh));
100a257cdd0SAndreas Gruenbacher 
101a257cdd0SAndreas Gruenbacher 	fh = fh_copy(&resp->fh, &argp->fh);
1028837abcaSMiklos Szeredi 	nfserr = fh_verify(rqstp, &resp->fh, 0, NFSD_MAY_SATTR);
1034ac7249eSChristoph Hellwig 	if (nfserr)
1044ac7249eSChristoph Hellwig 		goto out;
105a257cdd0SAndreas Gruenbacher 
1064ac7249eSChristoph Hellwig 	inode = fh->fh_dentry->d_inode;
1074ac7249eSChristoph Hellwig 	if (!IS_POSIXACL(inode) || !inode->i_op->set_acl) {
1084ac7249eSChristoph Hellwig 		error = -EOPNOTSUPP;
1094ac7249eSChristoph Hellwig 		goto out_errno;
110a257cdd0SAndreas Gruenbacher 	}
1114ac7249eSChristoph Hellwig 
1124ac7249eSChristoph Hellwig 	error = fh_want_write(fh);
1134ac7249eSChristoph Hellwig 	if (error)
1144ac7249eSChristoph Hellwig 		goto out_errno;
1154ac7249eSChristoph Hellwig 
1164ac7249eSChristoph Hellwig 	error = inode->i_op->set_acl(inode, argp->acl_access, ACL_TYPE_ACCESS);
1174ac7249eSChristoph Hellwig 	if (error)
1184ac7249eSChristoph Hellwig 		goto out_drop_write;
1194ac7249eSChristoph Hellwig 	error = inode->i_op->set_acl(inode, argp->acl_default,
1204ac7249eSChristoph Hellwig 				     ACL_TYPE_DEFAULT);
1214ac7249eSChristoph Hellwig 	if (error)
1224ac7249eSChristoph Hellwig 		goto out_drop_write;
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;
1344ac7249eSChristoph Hellwig out_drop_write:
1354ac7249eSChristoph Hellwig 	fh_drop_write(fh);
1364ac7249eSChristoph Hellwig out_errno:
1374ac7249eSChristoph Hellwig 	nfserr = nfserrno(error);
1384ac7249eSChristoph Hellwig 	goto out;
139a257cdd0SAndreas Gruenbacher }
140a257cdd0SAndreas Gruenbacher 
141a257cdd0SAndreas Gruenbacher /*
142a257cdd0SAndreas Gruenbacher  * Check file attributes
143a257cdd0SAndreas Gruenbacher  */
1447111c66eSAl Viro static __be32 nfsacld_proc_getattr(struct svc_rqst * rqstp,
145a257cdd0SAndreas Gruenbacher 		struct nfsd_fhandle *argp, struct nfsd_attrstat *resp)
146a257cdd0SAndreas Gruenbacher {
1474f4a4fadSJ. Bruce Fields 	__be32 nfserr;
148a257cdd0SAndreas Gruenbacher 	dprintk("nfsd: GETATTR  %s\n", SVCFH_fmt(&argp->fh));
149a257cdd0SAndreas Gruenbacher 
150a257cdd0SAndreas Gruenbacher 	fh_copy(&resp->fh, &argp->fh);
1514f4a4fadSJ. Bruce Fields 	nfserr = fh_verify(rqstp, &resp->fh, 0, NFSD_MAY_NOP);
1524f4a4fadSJ. Bruce Fields 	if (nfserr)
1534f4a4fadSJ. Bruce Fields 		return nfserr;
1544f4a4fadSJ. Bruce Fields 	nfserr = fh_getattr(&resp->fh, &resp->stat);
1554f4a4fadSJ. Bruce Fields 	return nfserr;
156a257cdd0SAndreas Gruenbacher }
157a257cdd0SAndreas Gruenbacher 
158a257cdd0SAndreas Gruenbacher /*
159a257cdd0SAndreas Gruenbacher  * Check file access
160a257cdd0SAndreas Gruenbacher  */
1617111c66eSAl Viro static __be32 nfsacld_proc_access(struct svc_rqst *rqstp, struct nfsd3_accessargs *argp,
162a257cdd0SAndreas Gruenbacher 		struct nfsd3_accessres *resp)
163a257cdd0SAndreas Gruenbacher {
164c4d987baSAl Viro 	__be32 nfserr;
165a257cdd0SAndreas Gruenbacher 
166a257cdd0SAndreas Gruenbacher 	dprintk("nfsd: ACCESS(2acl)   %s 0x%x\n",
167a257cdd0SAndreas Gruenbacher 			SVCFH_fmt(&argp->fh),
168a257cdd0SAndreas Gruenbacher 			argp->access);
169a257cdd0SAndreas Gruenbacher 
170a257cdd0SAndreas Gruenbacher 	fh_copy(&resp->fh, &argp->fh);
171a257cdd0SAndreas Gruenbacher 	resp->access = argp->access;
172a257cdd0SAndreas Gruenbacher 	nfserr = nfsd_access(rqstp, &resp->fh, &resp->access, NULL);
1734f4a4fadSJ. Bruce Fields 	if (nfserr)
1744f4a4fadSJ. Bruce Fields 		return nfserr;
1754f4a4fadSJ. Bruce Fields 	nfserr = fh_getattr(&resp->fh, &resp->stat);
176a257cdd0SAndreas Gruenbacher 	return nfserr;
177a257cdd0SAndreas Gruenbacher }
178a257cdd0SAndreas Gruenbacher 
179a257cdd0SAndreas Gruenbacher /*
180a257cdd0SAndreas Gruenbacher  * XDR decode functions
181a257cdd0SAndreas Gruenbacher  */
182131a21c2SAl Viro static int nfsaclsvc_decode_getaclargs(struct svc_rqst *rqstp, __be32 *p,
183a257cdd0SAndreas Gruenbacher 		struct nfsd3_getaclargs *argp)
184a257cdd0SAndreas Gruenbacher {
185d40aa337SBenoit Taine 	p = nfs2svc_decode_fh(p, &argp->fh);
186d40aa337SBenoit Taine 	if (!p)
187a257cdd0SAndreas Gruenbacher 		return 0;
188a257cdd0SAndreas Gruenbacher 	argp->mask = ntohl(*p); p++;
189a257cdd0SAndreas Gruenbacher 
190a257cdd0SAndreas Gruenbacher 	return xdr_argsize_check(rqstp, p);
191a257cdd0SAndreas Gruenbacher }
192a257cdd0SAndreas Gruenbacher 
193a257cdd0SAndreas Gruenbacher 
194131a21c2SAl Viro static int nfsaclsvc_decode_setaclargs(struct svc_rqst *rqstp, __be32 *p,
195a257cdd0SAndreas Gruenbacher 		struct nfsd3_setaclargs *argp)
196a257cdd0SAndreas Gruenbacher {
197a257cdd0SAndreas Gruenbacher 	struct kvec *head = rqstp->rq_arg.head;
198a257cdd0SAndreas Gruenbacher 	unsigned int base;
199a257cdd0SAndreas Gruenbacher 	int n;
200a257cdd0SAndreas Gruenbacher 
201d40aa337SBenoit Taine 	p = nfs2svc_decode_fh(p, &argp->fh);
202d40aa337SBenoit Taine 	if (!p)
203a257cdd0SAndreas Gruenbacher 		return 0;
204a257cdd0SAndreas Gruenbacher 	argp->mask = ntohl(*p++);
205a257cdd0SAndreas Gruenbacher 	if (argp->mask & ~(NFS_ACL|NFS_ACLCNT|NFS_DFACL|NFS_DFACLCNT) ||
206a257cdd0SAndreas Gruenbacher 	    !xdr_argsize_check(rqstp, p))
207a257cdd0SAndreas Gruenbacher 		return 0;
208a257cdd0SAndreas Gruenbacher 
209a257cdd0SAndreas Gruenbacher 	base = (char *)p - (char *)head->iov_base;
210a257cdd0SAndreas Gruenbacher 	n = nfsacl_decode(&rqstp->rq_arg, base, NULL,
211a257cdd0SAndreas Gruenbacher 			  (argp->mask & NFS_ACL) ?
212a257cdd0SAndreas Gruenbacher 			  &argp->acl_access : NULL);
213a257cdd0SAndreas Gruenbacher 	if (n > 0)
214a257cdd0SAndreas Gruenbacher 		n = nfsacl_decode(&rqstp->rq_arg, base + n, NULL,
215a257cdd0SAndreas Gruenbacher 				  (argp->mask & NFS_DFACL) ?
216a257cdd0SAndreas Gruenbacher 				  &argp->acl_default : NULL);
217a257cdd0SAndreas Gruenbacher 	return (n > 0);
218a257cdd0SAndreas Gruenbacher }
219a257cdd0SAndreas Gruenbacher 
220131a21c2SAl Viro static int nfsaclsvc_decode_fhandleargs(struct svc_rqst *rqstp, __be32 *p,
221a257cdd0SAndreas Gruenbacher 		struct nfsd_fhandle *argp)
222a257cdd0SAndreas Gruenbacher {
223d40aa337SBenoit Taine 	p = nfs2svc_decode_fh(p, &argp->fh);
224d40aa337SBenoit Taine 	if (!p)
225a257cdd0SAndreas Gruenbacher 		return 0;
226a257cdd0SAndreas Gruenbacher 	return xdr_argsize_check(rqstp, p);
227a257cdd0SAndreas Gruenbacher }
228a257cdd0SAndreas Gruenbacher 
229131a21c2SAl Viro static int nfsaclsvc_decode_accessargs(struct svc_rqst *rqstp, __be32 *p,
230a257cdd0SAndreas Gruenbacher 		struct nfsd3_accessargs *argp)
231a257cdd0SAndreas Gruenbacher {
232d40aa337SBenoit Taine 	p = nfs2svc_decode_fh(p, &argp->fh);
233d40aa337SBenoit Taine 	if (!p)
234a257cdd0SAndreas Gruenbacher 		return 0;
235a257cdd0SAndreas Gruenbacher 	argp->access = ntohl(*p++);
236a257cdd0SAndreas Gruenbacher 
237a257cdd0SAndreas Gruenbacher 	return xdr_argsize_check(rqstp, p);
238a257cdd0SAndreas Gruenbacher }
239a257cdd0SAndreas Gruenbacher 
240a257cdd0SAndreas Gruenbacher /*
241a257cdd0SAndreas Gruenbacher  * XDR encode functions
242a257cdd0SAndreas Gruenbacher  */
243a257cdd0SAndreas Gruenbacher 
2441b7e0403SPeter Staubach /*
2451b7e0403SPeter Staubach  * There must be an encoding function for void results so svc_process
2461b7e0403SPeter Staubach  * will work properly.
2471b7e0403SPeter Staubach  */
2489c0b0ff7SJ. Bruce Fields static int nfsaclsvc_encode_voidres(struct svc_rqst *rqstp, __be32 *p, void *dummy)
2491b7e0403SPeter Staubach {
2501b7e0403SPeter Staubach 	return xdr_ressize_check(rqstp, p);
2511b7e0403SPeter Staubach }
2521b7e0403SPeter Staubach 
253a257cdd0SAndreas Gruenbacher /* GETACL */
254131a21c2SAl Viro static int nfsaclsvc_encode_getaclres(struct svc_rqst *rqstp, __be32 *p,
255a257cdd0SAndreas Gruenbacher 		struct nfsd3_getaclres *resp)
256a257cdd0SAndreas Gruenbacher {
257a257cdd0SAndreas Gruenbacher 	struct dentry *dentry = resp->fh.fh_dentry;
258aefa89d1SPrasad P 	struct inode *inode;
259a257cdd0SAndreas Gruenbacher 	struct kvec *head = rqstp->rq_res.head;
260a257cdd0SAndreas Gruenbacher 	unsigned int base;
261a257cdd0SAndreas Gruenbacher 	int n;
262cb65a5baSJesper Juhl 	int w;
263a257cdd0SAndreas Gruenbacher 
264aefa89d1SPrasad P 	/*
265aefa89d1SPrasad P 	 * Since this is version 2, the check for nfserr in
266aefa89d1SPrasad P 	 * nfsd_dispatch actually ensures the following cannot happen.
267aefa89d1SPrasad P 	 * However, it seems fragile to depend on that.
268aefa89d1SPrasad P 	 */
269a257cdd0SAndreas Gruenbacher 	if (dentry == NULL || dentry->d_inode == NULL)
270a257cdd0SAndreas Gruenbacher 		return 0;
271a257cdd0SAndreas Gruenbacher 	inode = dentry->d_inode;
272a257cdd0SAndreas Gruenbacher 
2734f4a4fadSJ. Bruce Fields 	p = nfs2svc_encode_fattr(rqstp, p, &resp->fh, &resp->stat);
274a257cdd0SAndreas Gruenbacher 	*p++ = htonl(resp->mask);
275a257cdd0SAndreas Gruenbacher 	if (!xdr_ressize_check(rqstp, p))
276a257cdd0SAndreas Gruenbacher 		return 0;
277a257cdd0SAndreas Gruenbacher 	base = (char *)p - (char *)head->iov_base;
278a257cdd0SAndreas Gruenbacher 
279cb65a5baSJesper Juhl 	rqstp->rq_res.page_len = w = nfsacl_size(
280cb65a5baSJesper Juhl 		(resp->mask & NFS_ACL)   ? resp->acl_access  : NULL,
281cb65a5baSJesper Juhl 		(resp->mask & NFS_DFACL) ? resp->acl_default : NULL);
282a257cdd0SAndreas Gruenbacher 	while (w > 0) {
283afc59400SJ. Bruce Fields 		if (!*(rqstp->rq_next_page++))
284a257cdd0SAndreas Gruenbacher 			return 0;
285a257cdd0SAndreas Gruenbacher 		w -= PAGE_SIZE;
286a257cdd0SAndreas Gruenbacher 	}
287a257cdd0SAndreas Gruenbacher 
288a257cdd0SAndreas Gruenbacher 	n = nfsacl_encode(&rqstp->rq_res, base, inode,
289a257cdd0SAndreas Gruenbacher 			  resp->acl_access,
290a257cdd0SAndreas Gruenbacher 			  resp->mask & NFS_ACL, 0);
291a257cdd0SAndreas Gruenbacher 	if (n > 0)
292a257cdd0SAndreas Gruenbacher 		n = nfsacl_encode(&rqstp->rq_res, base + n, inode,
293a257cdd0SAndreas Gruenbacher 				  resp->acl_default,
294a257cdd0SAndreas Gruenbacher 				  resp->mask & NFS_DFACL,
295a257cdd0SAndreas Gruenbacher 				  NFS_ACL_DEFAULT);
296a257cdd0SAndreas Gruenbacher 	if (n <= 0)
297a257cdd0SAndreas Gruenbacher 		return 0;
298a257cdd0SAndreas Gruenbacher 	return 1;
299a257cdd0SAndreas Gruenbacher }
300a257cdd0SAndreas Gruenbacher 
301131a21c2SAl Viro static int nfsaclsvc_encode_attrstatres(struct svc_rqst *rqstp, __be32 *p,
302a257cdd0SAndreas Gruenbacher 		struct nfsd_attrstat *resp)
303a257cdd0SAndreas Gruenbacher {
3044f4a4fadSJ. Bruce Fields 	p = nfs2svc_encode_fattr(rqstp, p, &resp->fh, &resp->stat);
305a257cdd0SAndreas Gruenbacher 	return xdr_ressize_check(rqstp, p);
306a257cdd0SAndreas Gruenbacher }
307a257cdd0SAndreas Gruenbacher 
308a257cdd0SAndreas Gruenbacher /* ACCESS */
309131a21c2SAl Viro static int nfsaclsvc_encode_accessres(struct svc_rqst *rqstp, __be32 *p,
310a257cdd0SAndreas Gruenbacher 		struct nfsd3_accessres *resp)
311a257cdd0SAndreas Gruenbacher {
3124f4a4fadSJ. Bruce Fields 	p = nfs2svc_encode_fattr(rqstp, p, &resp->fh, &resp->stat);
313a257cdd0SAndreas Gruenbacher 	*p++ = htonl(resp->access);
314a257cdd0SAndreas Gruenbacher 	return xdr_ressize_check(rqstp, p);
315a257cdd0SAndreas Gruenbacher }
316a257cdd0SAndreas Gruenbacher 
317a257cdd0SAndreas Gruenbacher /*
318a257cdd0SAndreas Gruenbacher  * XDR release functions
319a257cdd0SAndreas Gruenbacher  */
320131a21c2SAl Viro static int nfsaclsvc_release_getacl(struct svc_rqst *rqstp, __be32 *p,
321a257cdd0SAndreas Gruenbacher 		struct nfsd3_getaclres *resp)
322a257cdd0SAndreas Gruenbacher {
323a257cdd0SAndreas Gruenbacher 	fh_put(&resp->fh);
324a257cdd0SAndreas Gruenbacher 	posix_acl_release(resp->acl_access);
325a257cdd0SAndreas Gruenbacher 	posix_acl_release(resp->acl_default);
326a257cdd0SAndreas Gruenbacher 	return 1;
327a257cdd0SAndreas Gruenbacher }
328a257cdd0SAndreas Gruenbacher 
329c9ce2283SGreg Banks static int nfsaclsvc_release_attrstat(struct svc_rqst *rqstp, __be32 *p,
330c9ce2283SGreg Banks 		struct nfsd_attrstat *resp)
331c9ce2283SGreg Banks {
332c9ce2283SGreg Banks 	fh_put(&resp->fh);
333c9ce2283SGreg Banks 	return 1;
334c9ce2283SGreg Banks }
335c9ce2283SGreg Banks 
336c9ce2283SGreg Banks static int nfsaclsvc_release_access(struct svc_rqst *rqstp, __be32 *p,
337c9ce2283SGreg Banks                struct nfsd3_accessres *resp)
338a257cdd0SAndreas Gruenbacher {
339a257cdd0SAndreas Gruenbacher        fh_put(&resp->fh);
340a257cdd0SAndreas Gruenbacher        return 1;
341a257cdd0SAndreas Gruenbacher }
342a257cdd0SAndreas Gruenbacher 
343a257cdd0SAndreas Gruenbacher #define nfsaclsvc_decode_voidargs	NULL
344a257cdd0SAndreas Gruenbacher #define nfsaclsvc_release_void		NULL
345a257cdd0SAndreas Gruenbacher #define nfsd3_fhandleargs	nfsd_fhandle
346a257cdd0SAndreas Gruenbacher #define nfsd3_attrstatres	nfsd_attrstat
347a257cdd0SAndreas Gruenbacher #define nfsd3_voidres		nfsd3_voidargs
348a257cdd0SAndreas Gruenbacher struct nfsd3_voidargs { int dummy; };
349a257cdd0SAndreas Gruenbacher 
350a257cdd0SAndreas Gruenbacher #define PROC(name, argt, rest, relt, cache, respsize)	\
351a257cdd0SAndreas Gruenbacher  { (svc_procfunc) nfsacld_proc_##name,		\
352a257cdd0SAndreas Gruenbacher    (kxdrproc_t) nfsaclsvc_decode_##argt##args,	\
353a257cdd0SAndreas Gruenbacher    (kxdrproc_t) nfsaclsvc_encode_##rest##res,	\
354a257cdd0SAndreas Gruenbacher    (kxdrproc_t) nfsaclsvc_release_##relt,		\
355a257cdd0SAndreas Gruenbacher    sizeof(struct nfsd3_##argt##args),		\
356a257cdd0SAndreas Gruenbacher    sizeof(struct nfsd3_##rest##res),		\
357a257cdd0SAndreas Gruenbacher    0,						\
358a257cdd0SAndreas Gruenbacher    cache,					\
359a257cdd0SAndreas Gruenbacher    respsize,					\
360a257cdd0SAndreas Gruenbacher  }
361a257cdd0SAndreas Gruenbacher 
362a257cdd0SAndreas Gruenbacher #define ST 1		/* status*/
363a257cdd0SAndreas Gruenbacher #define AT 21		/* attributes */
364a257cdd0SAndreas Gruenbacher #define pAT (1+AT)	/* post attributes - conditional */
365a257cdd0SAndreas Gruenbacher #define ACL (1+NFS_ACL_MAX_ENTRIES*3)  /* Access Control List */
366a257cdd0SAndreas Gruenbacher 
367a257cdd0SAndreas Gruenbacher static struct svc_procedure		nfsd_acl_procedures2[] = {
368a257cdd0SAndreas Gruenbacher   PROC(null,	void,		void,		void,	  RC_NOCACHE, ST),
369a257cdd0SAndreas Gruenbacher   PROC(getacl,	getacl,		getacl,		getacl,	  RC_NOCACHE, ST+1+2*(1+ACL)),
370c9ce2283SGreg Banks   PROC(setacl,	setacl,		attrstat,	attrstat, RC_NOCACHE, ST+AT),
371c9ce2283SGreg Banks   PROC(getattr, fhandle,	attrstat,	attrstat, RC_NOCACHE, ST+AT),
372c9ce2283SGreg Banks   PROC(access,	access,		access,		access,   RC_NOCACHE, ST+AT+1),
373a257cdd0SAndreas Gruenbacher };
374a257cdd0SAndreas Gruenbacher 
375a257cdd0SAndreas Gruenbacher struct svc_version	nfsd_acl_version2 = {
376a257cdd0SAndreas Gruenbacher 		.vs_vers	= 2,
377a257cdd0SAndreas Gruenbacher 		.vs_nproc	= 5,
378a257cdd0SAndreas Gruenbacher 		.vs_proc	= nfsd_acl_procedures2,
379a257cdd0SAndreas Gruenbacher 		.vs_dispatch	= nfsd_dispatch,
380a257cdd0SAndreas Gruenbacher 		.vs_xdrsize	= NFS3_SVC_XDRSIZE,
3811b7e0403SPeter Staubach 		.vs_hidden	= 0,
382a257cdd0SAndreas Gruenbacher };
383