2 * linux/fs/nfsd/nfs2acl.c
4 * Process version 2 NFSACL requests.
6 * Copyright (C) 2002-2003 Andreas Gruenbacher <agruen@suse.de>
9 #include <linux/sunrpc/svc.h>
10 #include <linux/nfs.h>
11 #include <linux/nfsd/nfsd.h>
12 #include <linux/nfsd/cache.h>
13 #include <linux/nfsd/xdr.h>
14 #include <linux/nfsd/xdr3.h>
15 #include <linux/posix_acl.h>
16 #include <linux/nfsacl.h>
18 #define NFSDDBG_FACILITY NFSDDBG_PROC
19 #define RETURN_STATUS(st) { resp->status = (st); return (st); }
25 nfsacld_proc_null(struct svc_rqst *rqstp, void *argp, void *resp)
31 * Get the Access and/or Default ACL of a file.
33 static __be32 nfsacld_proc_getacl(struct svc_rqst * rqstp,
34 struct nfsd3_getaclargs *argp, struct nfsd3_getaclres *resp)
37 struct posix_acl *acl;
40 dprintk("nfsd: GETACL(2acl) %s\n", SVCFH_fmt(&argp->fh));
42 fh = fh_copy(&resp->fh, &argp->fh);
43 nfserr = fh_verify(rqstp, &resp->fh, 0, NFSD_MAY_NOP);
45 RETURN_STATUS(nfserr);
47 if (argp->mask & ~(NFS_ACL|NFS_ACLCNT|NFS_DFACL|NFS_DFACLCNT))
48 RETURN_STATUS(nfserr_inval);
49 resp->mask = argp->mask;
51 if (resp->mask & (NFS_ACL|NFS_ACLCNT)) {
52 acl = nfsd_get_posix_acl(fh, ACL_TYPE_ACCESS);
54 int err = PTR_ERR(acl);
56 if (err == -ENODATA || err == -EOPNOTSUPP)
59 nfserr = nfserrno(err);
64 /* Solaris returns the inode's minimum ACL. */
66 struct inode *inode = fh->fh_dentry->d_inode;
67 acl = posix_acl_from_mode(inode->i_mode, GFP_KERNEL);
69 resp->acl_access = acl;
71 if (resp->mask & (NFS_DFACL|NFS_DFACLCNT)) {
72 /* Check how Solaris handles requests for the Default ACL
73 of a non-directory! */
75 acl = nfsd_get_posix_acl(fh, ACL_TYPE_DEFAULT);
77 int err = PTR_ERR(acl);
79 if (err == -ENODATA || err == -EOPNOTSUPP)
82 nfserr = nfserrno(err);
86 resp->acl_default = acl;
89 /* resp->acl_{access,default} are released in nfssvc_release_getacl. */
93 posix_acl_release(resp->acl_access);
94 posix_acl_release(resp->acl_default);
95 RETURN_STATUS(nfserr);
99 * Set the Access and/or Default ACL of a file.
101 static __be32 nfsacld_proc_setacl(struct svc_rqst * rqstp,
102 struct nfsd3_setaclargs *argp,
103 struct nfsd_attrstat *resp)
108 dprintk("nfsd: SETACL(2acl) %s\n", SVCFH_fmt(&argp->fh));
110 fh = fh_copy(&resp->fh, &argp->fh);
111 nfserr = fh_verify(rqstp, &resp->fh, 0, NFSD_MAY_SATTR);
114 nfserr = nfserrno( nfsd_set_posix_acl(
115 fh, ACL_TYPE_ACCESS, argp->acl_access) );
118 nfserr = nfserrno( nfsd_set_posix_acl(
119 fh, ACL_TYPE_DEFAULT, argp->acl_default) );
122 /* argp->acl_{access,default} may have been allocated in
123 nfssvc_decode_setaclargs. */
124 posix_acl_release(argp->acl_access);
125 posix_acl_release(argp->acl_default);
130 * Check file attributes
132 static __be32 nfsacld_proc_getattr(struct svc_rqst * rqstp,
133 struct nfsd_fhandle *argp, struct nfsd_attrstat *resp)
135 dprintk("nfsd: GETATTR %s\n", SVCFH_fmt(&argp->fh));
137 fh_copy(&resp->fh, &argp->fh);
138 return fh_verify(rqstp, &resp->fh, 0, NFSD_MAY_NOP);
144 static __be32 nfsacld_proc_access(struct svc_rqst *rqstp, struct nfsd3_accessargs *argp,
145 struct nfsd3_accessres *resp)
149 dprintk("nfsd: ACCESS(2acl) %s 0x%x\n",
150 SVCFH_fmt(&argp->fh),
153 fh_copy(&resp->fh, &argp->fh);
154 resp->access = argp->access;
155 nfserr = nfsd_access(rqstp, &resp->fh, &resp->access, NULL);
160 * XDR decode functions
162 static int nfsaclsvc_decode_getaclargs(struct svc_rqst *rqstp, __be32 *p,
163 struct nfsd3_getaclargs *argp)
165 if (!(p = nfs2svc_decode_fh(p, &argp->fh)))
167 argp->mask = ntohl(*p); p++;
169 return xdr_argsize_check(rqstp, p);
173 static int nfsaclsvc_decode_setaclargs(struct svc_rqst *rqstp, __be32 *p,
174 struct nfsd3_setaclargs *argp)
176 struct kvec *head = rqstp->rq_arg.head;
180 if (!(p = nfs2svc_decode_fh(p, &argp->fh)))
182 argp->mask = ntohl(*p++);
183 if (argp->mask & ~(NFS_ACL|NFS_ACLCNT|NFS_DFACL|NFS_DFACLCNT) ||
184 !xdr_argsize_check(rqstp, p))
187 base = (char *)p - (char *)head->iov_base;
188 n = nfsacl_decode(&rqstp->rq_arg, base, NULL,
189 (argp->mask & NFS_ACL) ?
190 &argp->acl_access : NULL);
192 n = nfsacl_decode(&rqstp->rq_arg, base + n, NULL,
193 (argp->mask & NFS_DFACL) ?
194 &argp->acl_default : NULL);
198 static int nfsaclsvc_decode_fhandleargs(struct svc_rqst *rqstp, __be32 *p,
199 struct nfsd_fhandle *argp)
201 if (!(p = nfs2svc_decode_fh(p, &argp->fh)))
203 return xdr_argsize_check(rqstp, p);
206 static int nfsaclsvc_decode_accessargs(struct svc_rqst *rqstp, __be32 *p,
207 struct nfsd3_accessargs *argp)
209 if (!(p = nfs2svc_decode_fh(p, &argp->fh)))
211 argp->access = ntohl(*p++);
213 return xdr_argsize_check(rqstp, p);
217 * XDR encode functions
221 * There must be an encoding function for void results so svc_process
222 * will work properly.
225 nfsaclsvc_encode_voidres(struct svc_rqst *rqstp, __be32 *p, void *dummy)
227 return xdr_ressize_check(rqstp, p);
231 static int nfsaclsvc_encode_getaclres(struct svc_rqst *rqstp, __be32 *p,
232 struct nfsd3_getaclres *resp)
234 struct dentry *dentry = resp->fh.fh_dentry;
236 struct kvec *head = rqstp->rq_res.head;
242 * Since this is version 2, the check for nfserr in
243 * nfsd_dispatch actually ensures the following cannot happen.
244 * However, it seems fragile to depend on that.
246 if (dentry == NULL || dentry->d_inode == NULL)
248 inode = dentry->d_inode;
250 p = nfs2svc_encode_fattr(rqstp, p, &resp->fh);
251 *p++ = htonl(resp->mask);
252 if (!xdr_ressize_check(rqstp, p))
254 base = (char *)p - (char *)head->iov_base;
256 rqstp->rq_res.page_len = w = nfsacl_size(
257 (resp->mask & NFS_ACL) ? resp->acl_access : NULL,
258 (resp->mask & NFS_DFACL) ? resp->acl_default : NULL);
260 if (!rqstp->rq_respages[rqstp->rq_resused++])
265 n = nfsacl_encode(&rqstp->rq_res, base, inode,
267 resp->mask & NFS_ACL, 0);
269 n = nfsacl_encode(&rqstp->rq_res, base + n, inode,
271 resp->mask & NFS_DFACL,
278 static int nfsaclsvc_encode_attrstatres(struct svc_rqst *rqstp, __be32 *p,
279 struct nfsd_attrstat *resp)
281 p = nfs2svc_encode_fattr(rqstp, p, &resp->fh);
282 return xdr_ressize_check(rqstp, p);
286 static int nfsaclsvc_encode_accessres(struct svc_rqst *rqstp, __be32 *p,
287 struct nfsd3_accessres *resp)
289 p = nfs2svc_encode_fattr(rqstp, p, &resp->fh);
290 *p++ = htonl(resp->access);
291 return xdr_ressize_check(rqstp, p);
295 * XDR release functions
297 static int nfsaclsvc_release_getacl(struct svc_rqst *rqstp, __be32 *p,
298 struct nfsd3_getaclres *resp)
301 posix_acl_release(resp->acl_access);
302 posix_acl_release(resp->acl_default);
306 static int nfsaclsvc_release_attrstat(struct svc_rqst *rqstp, __be32 *p,
307 struct nfsd_attrstat *resp)
313 static int nfsaclsvc_release_access(struct svc_rqst *rqstp, __be32 *p,
314 struct nfsd3_accessres *resp)
320 #define nfsaclsvc_decode_voidargs NULL
321 #define nfsaclsvc_release_void NULL
322 #define nfsd3_fhandleargs nfsd_fhandle
323 #define nfsd3_attrstatres nfsd_attrstat
324 #define nfsd3_voidres nfsd3_voidargs
325 struct nfsd3_voidargs { int dummy; };
327 #define PROC(name, argt, rest, relt, cache, respsize) \
328 { (svc_procfunc) nfsacld_proc_##name, \
329 (kxdrproc_t) nfsaclsvc_decode_##argt##args, \
330 (kxdrproc_t) nfsaclsvc_encode_##rest##res, \
331 (kxdrproc_t) nfsaclsvc_release_##relt, \
332 sizeof(struct nfsd3_##argt##args), \
333 sizeof(struct nfsd3_##rest##res), \
339 #define ST 1 /* status*/
340 #define AT 21 /* attributes */
341 #define pAT (1+AT) /* post attributes - conditional */
342 #define ACL (1+NFS_ACL_MAX_ENTRIES*3) /* Access Control List */
344 static struct svc_procedure nfsd_acl_procedures2[] = {
345 PROC(null, void, void, void, RC_NOCACHE, ST),
346 PROC(getacl, getacl, getacl, getacl, RC_NOCACHE, ST+1+2*(1+ACL)),
347 PROC(setacl, setacl, attrstat, attrstat, RC_NOCACHE, ST+AT),
348 PROC(getattr, fhandle, attrstat, attrstat, RC_NOCACHE, ST+AT),
349 PROC(access, access, access, access, RC_NOCACHE, ST+AT+1),
352 struct svc_version nfsd_acl_version2 = {
355 .vs_proc = nfsd_acl_procedures2,
356 .vs_dispatch = nfsd_dispatch,
357 .vs_xdrsize = NFS3_SVC_XDRSIZE,