Linux Audio

Check our new training course

Loading...
v4.10.11
 
  1/*
  2 * Process version 3 NFSACL requests.
  3 *
  4 * Copyright (C) 2002-2003 Andreas Gruenbacher <agruen@suse.de>
  5 */
  6
  7#include "nfsd.h"
  8/* FIXME: nfsacl.h is a broken header */
  9#include <linux/nfsacl.h>
 10#include <linux/gfp.h>
 11#include "cache.h"
 12#include "xdr3.h"
 13#include "vfs.h"
 14
 15#define RETURN_STATUS(st)	{ resp->status = (st); return (st); }
 16
 17/*
 18 * NULL call.
 19 */
 20static __be32
 21nfsd3_proc_null(struct svc_rqst *rqstp, void *argp, void *resp)
 22{
 23	return nfs_ok;
 24}
 25
 26/*
 27 * Get the Access and/or Default ACL of a file.
 28 */
 29static __be32 nfsd3_proc_getacl(struct svc_rqst * rqstp,
 30		struct nfsd3_getaclargs *argp, struct nfsd3_getaclres *resp)
 31{
 
 
 32	struct posix_acl *acl;
 33	struct inode *inode;
 34	svc_fh *fh;
 35	__be32 nfserr = 0;
 36
 37	fh = fh_copy(&resp->fh, &argp->fh);
 38	nfserr = fh_verify(rqstp, &resp->fh, 0, NFSD_MAY_NOP);
 39	if (nfserr)
 40		RETURN_STATUS(nfserr);
 41
 42	inode = d_inode(fh->fh_dentry);
 43
 44	if (argp->mask & ~NFS_ACL_MASK)
 45		RETURN_STATUS(nfserr_inval);
 46	resp->mask = argp->mask;
 47
 48	if (resp->mask & (NFS_ACL|NFS_ACLCNT)) {
 49		acl = get_acl(inode, ACL_TYPE_ACCESS);
 50		if (acl == NULL) {
 51			/* Solaris returns the inode's minimum ACL. */
 52			acl = posix_acl_from_mode(inode->i_mode, GFP_KERNEL);
 53		}
 54		if (IS_ERR(acl)) {
 55			nfserr = nfserrno(PTR_ERR(acl));
 56			goto fail;
 57		}
 58		resp->acl_access = acl;
 59	}
 60	if (resp->mask & (NFS_DFACL|NFS_DFACLCNT)) {
 61		/* Check how Solaris handles requests for the Default ACL
 62		   of a non-directory! */
 63		acl = get_acl(inode, ACL_TYPE_DEFAULT);
 64		if (IS_ERR(acl)) {
 65			nfserr = nfserrno(PTR_ERR(acl));
 66			goto fail;
 67		}
 68		resp->acl_default = acl;
 69	}
 70
 71	/* resp->acl_{access,default} are released in nfs3svc_release_getacl. */
 72	RETURN_STATUS(0);
 73
 74fail:
 75	posix_acl_release(resp->acl_access);
 76	posix_acl_release(resp->acl_default);
 77	RETURN_STATUS(nfserr);
 78}
 79
 80/*
 81 * Set the Access and/or Default ACL of a file.
 82 */
 83static __be32 nfsd3_proc_setacl(struct svc_rqst * rqstp,
 84		struct nfsd3_setaclargs *argp,
 85		struct nfsd3_attrstat *resp)
 86{
 
 
 87	struct inode *inode;
 88	svc_fh *fh;
 89	__be32 nfserr = 0;
 90	int error;
 91
 92	fh = fh_copy(&resp->fh, &argp->fh);
 93	nfserr = fh_verify(rqstp, &resp->fh, 0, NFSD_MAY_SATTR);
 94	if (nfserr)
 95		goto out;
 96
 97	inode = d_inode(fh->fh_dentry);
 98
 99	error = fh_want_write(fh);
100	if (error)
101		goto out_errno;
102
103	fh_lock(fh);
104
105	error = set_posix_acl(inode, ACL_TYPE_ACCESS, argp->acl_access);
106	if (error)
107		goto out_drop_lock;
108	error = set_posix_acl(inode, ACL_TYPE_DEFAULT, argp->acl_default);
109
110out_drop_lock:
111	fh_unlock(fh);
112	fh_drop_write(fh);
113out_errno:
114	nfserr = nfserrno(error);
115out:
116	/* argp->acl_{access,default} may have been allocated in
117	   nfs3svc_decode_setaclargs. */
118	posix_acl_release(argp->acl_access);
119	posix_acl_release(argp->acl_default);
120	RETURN_STATUS(nfserr);
121}
122
123/*
124 * XDR decode functions
125 */
126static int nfs3svc_decode_getaclargs(struct svc_rqst *rqstp, __be32 *p,
127		struct nfsd3_getaclargs *args)
128{
 
 
129	p = nfs3svc_decode_fh(p, &args->fh);
130	if (!p)
131		return 0;
132	args->mask = ntohl(*p); p++;
133
134	return xdr_argsize_check(rqstp, p);
135}
136
137
138static int nfs3svc_decode_setaclargs(struct svc_rqst *rqstp, __be32 *p,
139		struct nfsd3_setaclargs *args)
140{
 
141	struct kvec *head = rqstp->rq_arg.head;
142	unsigned int base;
143	int n;
144
145	p = nfs3svc_decode_fh(p, &args->fh);
146	if (!p)
147		return 0;
148	args->mask = ntohl(*p++);
149	if (args->mask & ~NFS_ACL_MASK ||
150	    !xdr_argsize_check(rqstp, p))
151		return 0;
152
153	base = (char *)p - (char *)head->iov_base;
154	n = nfsacl_decode(&rqstp->rq_arg, base, NULL,
155			  (args->mask & NFS_ACL) ?
156			  &args->acl_access : NULL);
157	if (n > 0)
158		n = nfsacl_decode(&rqstp->rq_arg, base + n, NULL,
159				  (args->mask & NFS_DFACL) ?
160				  &args->acl_default : NULL);
161	return (n > 0);
162}
163
164/*
165 * XDR encode functions
166 */
167
168/* GETACL */
169static int nfs3svc_encode_getaclres(struct svc_rqst *rqstp, __be32 *p,
170		struct nfsd3_getaclres *resp)
171{
 
172	struct dentry *dentry = resp->fh.fh_dentry;
173
174	p = nfs3svc_encode_post_op_attr(rqstp, p, &resp->fh);
175	if (resp->status == 0 && dentry && d_really_is_positive(dentry)) {
176		struct inode *inode = d_inode(dentry);
177		struct kvec *head = rqstp->rq_res.head;
178		unsigned int base;
179		int n;
180		int w;
181
182		*p++ = htonl(resp->mask);
183		if (!xdr_ressize_check(rqstp, p))
184			return 0;
185		base = (char *)p - (char *)head->iov_base;
186
187		rqstp->rq_res.page_len = w = nfsacl_size(
188			(resp->mask & NFS_ACL)   ? resp->acl_access  : NULL,
189			(resp->mask & NFS_DFACL) ? resp->acl_default : NULL);
190		while (w > 0) {
191			if (!*(rqstp->rq_next_page++))
192				return 0;
193			w -= PAGE_SIZE;
194		}
195
196		n = nfsacl_encode(&rqstp->rq_res, base, inode,
197				  resp->acl_access,
198				  resp->mask & NFS_ACL, 0);
199		if (n > 0)
200			n = nfsacl_encode(&rqstp->rq_res, base + n, inode,
201					  resp->acl_default,
202					  resp->mask & NFS_DFACL,
203					  NFS_ACL_DEFAULT);
204		if (n <= 0)
205			return 0;
206	} else
207		if (!xdr_ressize_check(rqstp, p))
208			return 0;
209
210	return 1;
211}
212
213/* SETACL */
214static int nfs3svc_encode_setaclres(struct svc_rqst *rqstp, __be32 *p,
215		struct nfsd3_attrstat *resp)
216{
 
 
217	p = nfs3svc_encode_post_op_attr(rqstp, p, &resp->fh);
218
219	return xdr_ressize_check(rqstp, p);
220}
221
222/*
223 * XDR release functions
224 */
225static int nfs3svc_release_getacl(struct svc_rqst *rqstp, __be32 *p,
226		struct nfsd3_getaclres *resp)
227{
 
 
228	fh_put(&resp->fh);
229	posix_acl_release(resp->acl_access);
230	posix_acl_release(resp->acl_default);
231	return 1;
232}
233
234#define nfs3svc_decode_voidargs		NULL
235#define nfs3svc_release_void		NULL
236#define nfsd3_setaclres			nfsd3_attrstat
237#define nfsd3_voidres			nfsd3_voidargs
238struct nfsd3_voidargs { int dummy; };
239
240#define PROC(name, argt, rest, relt, cache, respsize)	\
241 { (svc_procfunc) nfsd3_proc_##name,		\
242   (kxdrproc_t) nfs3svc_decode_##argt##args,	\
243   (kxdrproc_t) nfs3svc_encode_##rest##res,	\
244   (kxdrproc_t) nfs3svc_release_##relt,		\
245   sizeof(struct nfsd3_##argt##args),		\
246   sizeof(struct nfsd3_##rest##res),		\
247   0,						\
248   cache,					\
249   respsize,					\
250 }
251
252#define ST 1		/* status*/
253#define AT 21		/* attributes */
254#define pAT (1+AT)	/* post attributes - conditional */
255#define ACL (1+NFS_ACL_MAX_ENTRIES*3)  /* Access Control List */
256
257static struct svc_procedure		nfsd_acl_procedures3[] = {
258  PROC(null,	void,		void,		void,	  RC_NOCACHE, ST),
259  PROC(getacl,	getacl,		getacl,		getacl,	  RC_NOCACHE, ST+1+2*(1+ACL)),
260  PROC(setacl,	setacl,		setacl,		fhandle,  RC_NOCACHE, ST+pAT),
261};
262
263struct svc_version	nfsd_acl_version3 = {
264		.vs_vers	= 3,
265		.vs_nproc	= 3,
266		.vs_proc	= nfsd_acl_procedures3,
267		.vs_dispatch	= nfsd_dispatch,
268		.vs_xdrsize	= NFS3_SVC_XDRSIZE,
269		.vs_hidden	= 0,
 
270};
271
v5.9
  1// SPDX-License-Identifier: GPL-2.0
  2/*
  3 * Process version 3 NFSACL requests.
  4 *
  5 * Copyright (C) 2002-2003 Andreas Gruenbacher <agruen@suse.de>
  6 */
  7
  8#include "nfsd.h"
  9/* FIXME: nfsacl.h is a broken header */
 10#include <linux/nfsacl.h>
 11#include <linux/gfp.h>
 12#include "cache.h"
 13#include "xdr3.h"
 14#include "vfs.h"
 15
 16#define RETURN_STATUS(st)	{ resp->status = (st); return (st); }
 17
 18/*
 19 * NULL call.
 20 */
 21static __be32
 22nfsd3_proc_null(struct svc_rqst *rqstp)
 23{
 24	return nfs_ok;
 25}
 26
 27/*
 28 * Get the Access and/or Default ACL of a file.
 29 */
 30static __be32 nfsd3_proc_getacl(struct svc_rqst *rqstp)
 
 31{
 32	struct nfsd3_getaclargs *argp = rqstp->rq_argp;
 33	struct nfsd3_getaclres *resp = rqstp->rq_resp;
 34	struct posix_acl *acl;
 35	struct inode *inode;
 36	svc_fh *fh;
 37	__be32 nfserr = 0;
 38
 39	fh = fh_copy(&resp->fh, &argp->fh);
 40	nfserr = fh_verify(rqstp, &resp->fh, 0, NFSD_MAY_NOP);
 41	if (nfserr)
 42		RETURN_STATUS(nfserr);
 43
 44	inode = d_inode(fh->fh_dentry);
 45
 46	if (argp->mask & ~NFS_ACL_MASK)
 47		RETURN_STATUS(nfserr_inval);
 48	resp->mask = argp->mask;
 49
 50	if (resp->mask & (NFS_ACL|NFS_ACLCNT)) {
 51		acl = get_acl(inode, ACL_TYPE_ACCESS);
 52		if (acl == NULL) {
 53			/* Solaris returns the inode's minimum ACL. */
 54			acl = posix_acl_from_mode(inode->i_mode, GFP_KERNEL);
 55		}
 56		if (IS_ERR(acl)) {
 57			nfserr = nfserrno(PTR_ERR(acl));
 58			goto fail;
 59		}
 60		resp->acl_access = acl;
 61	}
 62	if (resp->mask & (NFS_DFACL|NFS_DFACLCNT)) {
 63		/* Check how Solaris handles requests for the Default ACL
 64		   of a non-directory! */
 65		acl = get_acl(inode, ACL_TYPE_DEFAULT);
 66		if (IS_ERR(acl)) {
 67			nfserr = nfserrno(PTR_ERR(acl));
 68			goto fail;
 69		}
 70		resp->acl_default = acl;
 71	}
 72
 73	/* resp->acl_{access,default} are released in nfs3svc_release_getacl. */
 74	RETURN_STATUS(0);
 75
 76fail:
 77	posix_acl_release(resp->acl_access);
 78	posix_acl_release(resp->acl_default);
 79	RETURN_STATUS(nfserr);
 80}
 81
 82/*
 83 * Set the Access and/or Default ACL of a file.
 84 */
 85static __be32 nfsd3_proc_setacl(struct svc_rqst *rqstp)
 
 
 86{
 87	struct nfsd3_setaclargs *argp = rqstp->rq_argp;
 88	struct nfsd3_attrstat *resp = rqstp->rq_resp;
 89	struct inode *inode;
 90	svc_fh *fh;
 91	__be32 nfserr = 0;
 92	int error;
 93
 94	fh = fh_copy(&resp->fh, &argp->fh);
 95	nfserr = fh_verify(rqstp, &resp->fh, 0, NFSD_MAY_SATTR);
 96	if (nfserr)
 97		goto out;
 98
 99	inode = d_inode(fh->fh_dentry);
100
101	error = fh_want_write(fh);
102	if (error)
103		goto out_errno;
104
105	fh_lock(fh);
106
107	error = set_posix_acl(inode, ACL_TYPE_ACCESS, argp->acl_access);
108	if (error)
109		goto out_drop_lock;
110	error = set_posix_acl(inode, ACL_TYPE_DEFAULT, argp->acl_default);
111
112out_drop_lock:
113	fh_unlock(fh);
114	fh_drop_write(fh);
115out_errno:
116	nfserr = nfserrno(error);
117out:
118	/* argp->acl_{access,default} may have been allocated in
119	   nfs3svc_decode_setaclargs. */
120	posix_acl_release(argp->acl_access);
121	posix_acl_release(argp->acl_default);
122	RETURN_STATUS(nfserr);
123}
124
125/*
126 * XDR decode functions
127 */
128static int nfs3svc_decode_getaclargs(struct svc_rqst *rqstp, __be32 *p)
 
129{
130	struct nfsd3_getaclargs *args = rqstp->rq_argp;
131
132	p = nfs3svc_decode_fh(p, &args->fh);
133	if (!p)
134		return 0;
135	args->mask = ntohl(*p); p++;
136
137	return xdr_argsize_check(rqstp, p);
138}
139
140
141static int nfs3svc_decode_setaclargs(struct svc_rqst *rqstp, __be32 *p)
 
142{
143	struct nfsd3_setaclargs *args = rqstp->rq_argp;
144	struct kvec *head = rqstp->rq_arg.head;
145	unsigned int base;
146	int n;
147
148	p = nfs3svc_decode_fh(p, &args->fh);
149	if (!p)
150		return 0;
151	args->mask = ntohl(*p++);
152	if (args->mask & ~NFS_ACL_MASK ||
153	    !xdr_argsize_check(rqstp, p))
154		return 0;
155
156	base = (char *)p - (char *)head->iov_base;
157	n = nfsacl_decode(&rqstp->rq_arg, base, NULL,
158			  (args->mask & NFS_ACL) ?
159			  &args->acl_access : NULL);
160	if (n > 0)
161		n = nfsacl_decode(&rqstp->rq_arg, base + n, NULL,
162				  (args->mask & NFS_DFACL) ?
163				  &args->acl_default : NULL);
164	return (n > 0);
165}
166
167/*
168 * XDR encode functions
169 */
170
171/* GETACL */
172static int nfs3svc_encode_getaclres(struct svc_rqst *rqstp, __be32 *p)
 
173{
174	struct nfsd3_getaclres *resp = rqstp->rq_resp;
175	struct dentry *dentry = resp->fh.fh_dentry;
176
177	p = nfs3svc_encode_post_op_attr(rqstp, p, &resp->fh);
178	if (resp->status == 0 && dentry && d_really_is_positive(dentry)) {
179		struct inode *inode = d_inode(dentry);
180		struct kvec *head = rqstp->rq_res.head;
181		unsigned int base;
182		int n;
183		int w;
184
185		*p++ = htonl(resp->mask);
186		if (!xdr_ressize_check(rqstp, p))
187			return 0;
188		base = (char *)p - (char *)head->iov_base;
189
190		rqstp->rq_res.page_len = w = nfsacl_size(
191			(resp->mask & NFS_ACL)   ? resp->acl_access  : NULL,
192			(resp->mask & NFS_DFACL) ? resp->acl_default : NULL);
193		while (w > 0) {
194			if (!*(rqstp->rq_next_page++))
195				return 0;
196			w -= PAGE_SIZE;
197		}
198
199		n = nfsacl_encode(&rqstp->rq_res, base, inode,
200				  resp->acl_access,
201				  resp->mask & NFS_ACL, 0);
202		if (n > 0)
203			n = nfsacl_encode(&rqstp->rq_res, base + n, inode,
204					  resp->acl_default,
205					  resp->mask & NFS_DFACL,
206					  NFS_ACL_DEFAULT);
207		if (n <= 0)
208			return 0;
209	} else
210		if (!xdr_ressize_check(rqstp, p))
211			return 0;
212
213	return 1;
214}
215
216/* SETACL */
217static int nfs3svc_encode_setaclres(struct svc_rqst *rqstp, __be32 *p)
 
218{
219	struct nfsd3_attrstat *resp = rqstp->rq_resp;
220
221	p = nfs3svc_encode_post_op_attr(rqstp, p, &resp->fh);
222
223	return xdr_ressize_check(rqstp, p);
224}
225
226/*
227 * XDR release functions
228 */
229static void nfs3svc_release_getacl(struct svc_rqst *rqstp)
 
230{
231	struct nfsd3_getaclres *resp = rqstp->rq_resp;
232
233	fh_put(&resp->fh);
234	posix_acl_release(resp->acl_access);
235	posix_acl_release(resp->acl_default);
 
236}
237
238#define nfs3svc_decode_voidargs		NULL
239#define nfs3svc_release_void		NULL
240#define nfsd3_setaclres			nfsd3_attrstat
241#define nfsd3_voidres			nfsd3_voidargs
242struct nfsd3_voidargs { int dummy; };
243
244#define PROC(name, argt, rest, relt, cache, respsize)			\
245{									\
246	.pc_func	= nfsd3_proc_##name,				\
247	.pc_decode	= nfs3svc_decode_##argt##args,			\
248	.pc_encode	= nfs3svc_encode_##rest##res,			\
249	.pc_release	= nfs3svc_release_##relt,			\
250	.pc_argsize	= sizeof(struct nfsd3_##argt##args),		\
251	.pc_ressize	= sizeof(struct nfsd3_##rest##res),		\
252	.pc_cachetype	= cache,					\
253	.pc_xdrressize	= respsize,					\
254}
255
256#define ST 1		/* status*/
257#define AT 21		/* attributes */
258#define pAT (1+AT)	/* post attributes - conditional */
259#define ACL (1+NFS_ACL_MAX_ENTRIES*3)  /* Access Control List */
260
261static const struct svc_procedure nfsd_acl_procedures3[] = {
262  PROC(null,	void,		void,		void,	  RC_NOCACHE, ST),
263  PROC(getacl,	getacl,		getacl,		getacl,	  RC_NOCACHE, ST+1+2*(1+ACL)),
264  PROC(setacl,	setacl,		setacl,		fhandle,  RC_NOCACHE, ST+pAT),
265};
266
267static unsigned int nfsd_acl_count3[ARRAY_SIZE(nfsd_acl_procedures3)];
268const struct svc_version nfsd_acl_version3 = {
269	.vs_vers	= 3,
270	.vs_nproc	= 3,
271	.vs_proc	= nfsd_acl_procedures3,
272	.vs_count	= nfsd_acl_count3,
273	.vs_dispatch	= nfsd_dispatch,
274	.vs_xdrsize	= NFS3_SVC_XDRSIZE,
275};
276