2 * linux/fs/nfsd/nfs2acl.c
4 * Process version 2 NFSACL requests.
6 * Copyright (C) 2002-2003 Andreas Gruenbacher <agruen@suse.de>
10 /* FIXME: nfsacl.h is a broken header */
11 #include <linux/nfsacl.h>
16 #define NFSDDBG_FACILITY NFSDDBG_PROC
17 #define RETURN_STATUS(st) { resp->status = (st); return (st); }
23 nfsacld_proc_null(struct svc_rqst *rqstp, void *argp, void *resp)
29 * Get the Access and/or Default ACL of a file.
31 static __be32 nfsacld_proc_getacl(struct svc_rqst * rqstp,
32 struct nfsd3_getaclargs *argp, struct nfsd3_getaclres *resp)
35 struct posix_acl *acl;
38 dprintk("nfsd: GETACL(2acl) %s\n", SVCFH_fmt(&argp->fh));
40 fh = fh_copy(&resp->fh, &argp->fh);
41 nfserr = fh_verify(rqstp, &resp->fh, 0, NFSD_MAY_NOP);
43 RETURN_STATUS(nfserr);
45 if (argp->mask & ~(NFS_ACL|NFS_ACLCNT|NFS_DFACL|NFS_DFACLCNT))
46 RETURN_STATUS(nfserr_inval);
47 resp->mask = argp->mask;
49 if (resp->mask & (NFS_ACL|NFS_ACLCNT)) {
50 acl = nfsd_get_posix_acl(fh, ACL_TYPE_ACCESS);
52 int err = PTR_ERR(acl);
54 if (err == -ENODATA || err == -EOPNOTSUPP)
57 nfserr = nfserrno(err);
62 /* Solaris returns the inode's minimum ACL. */
64 struct inode *inode = fh->fh_dentry->d_inode;
65 acl = posix_acl_from_mode(inode->i_mode, GFP_KERNEL);
67 resp->acl_access = acl;
69 if (resp->mask & (NFS_DFACL|NFS_DFACLCNT)) {
70 /* Check how Solaris handles requests for the Default ACL
71 of a non-directory! */
73 acl = nfsd_get_posix_acl(fh, ACL_TYPE_DEFAULT);
75 int err = PTR_ERR(acl);
77 if (err == -ENODATA || err == -EOPNOTSUPP)
80 nfserr = nfserrno(err);
84 resp->acl_default = acl;
87 /* resp->acl_{access,default} are released in nfssvc_release_getacl. */
91 posix_acl_release(resp->acl_access);
92 posix_acl_release(resp->acl_default);
93 RETURN_STATUS(nfserr);
97 * Set the Access and/or Default ACL of a file.
99 static __be32 nfsacld_proc_setacl(struct svc_rqst * rqstp,
100 struct nfsd3_setaclargs *argp,
101 struct nfsd_attrstat *resp)
106 dprintk("nfsd: SETACL(2acl) %s\n", SVCFH_fmt(&argp->fh));
108 fh = fh_copy(&resp->fh, &argp->fh);
109 nfserr = fh_verify(rqstp, &resp->fh, 0, NFSD_MAY_SATTR);
112 nfserr = nfserrno( nfsd_set_posix_acl(
113 fh, ACL_TYPE_ACCESS, argp->acl_access) );
116 nfserr = nfserrno( nfsd_set_posix_acl(
117 fh, ACL_TYPE_DEFAULT, argp->acl_default) );
120 /* argp->acl_{access,default} may have been allocated in
121 nfssvc_decode_setaclargs. */
122 posix_acl_release(argp->acl_access);
123 posix_acl_release(argp->acl_default);
128 * Check file attributes
130 static __be32 nfsacld_proc_getattr(struct svc_rqst * rqstp,
131 struct nfsd_fhandle *argp, struct nfsd_attrstat *resp)
133 dprintk("nfsd: GETATTR %s\n", SVCFH_fmt(&argp->fh));
135 fh_copy(&resp->fh, &argp->fh);
136 return fh_verify(rqstp, &resp->fh, 0, NFSD_MAY_NOP);
142 static __be32 nfsacld_proc_access(struct svc_rqst *rqstp, struct nfsd3_accessargs *argp,
143 struct nfsd3_accessres *resp)
147 dprintk("nfsd: ACCESS(2acl) %s 0x%x\n",
148 SVCFH_fmt(&argp->fh),
151 fh_copy(&resp->fh, &argp->fh);
152 resp->access = argp->access;
153 nfserr = nfsd_access(rqstp, &resp->fh, &resp->access, NULL);
158 * XDR decode functions
160 static int nfsaclsvc_decode_getaclargs(struct svc_rqst *rqstp, __be32 *p,
161 struct nfsd3_getaclargs *argp)
163 if (!(p = nfs2svc_decode_fh(p, &argp->fh)))
165 argp->mask = ntohl(*p); p++;
167 return xdr_argsize_check(rqstp, p);
171 static int nfsaclsvc_decode_setaclargs(struct svc_rqst *rqstp, __be32 *p,
172 struct nfsd3_setaclargs *argp)
174 struct kvec *head = rqstp->rq_arg.head;
178 if (!(p = nfs2svc_decode_fh(p, &argp->fh)))
180 argp->mask = ntohl(*p++);
181 if (argp->mask & ~(NFS_ACL|NFS_ACLCNT|NFS_DFACL|NFS_DFACLCNT) ||
182 !xdr_argsize_check(rqstp, p))
185 base = (char *)p - (char *)head->iov_base;
186 n = nfsacl_decode(&rqstp->rq_arg, base, NULL,
187 (argp->mask & NFS_ACL) ?
188 &argp->acl_access : NULL);
190 n = nfsacl_decode(&rqstp->rq_arg, base + n, NULL,
191 (argp->mask & NFS_DFACL) ?
192 &argp->acl_default : NULL);
196 static int nfsaclsvc_decode_fhandleargs(struct svc_rqst *rqstp, __be32 *p,
197 struct nfsd_fhandle *argp)
199 if (!(p = nfs2svc_decode_fh(p, &argp->fh)))
201 return xdr_argsize_check(rqstp, p);
204 static int nfsaclsvc_decode_accessargs(struct svc_rqst *rqstp, __be32 *p,
205 struct nfsd3_accessargs *argp)
207 if (!(p = nfs2svc_decode_fh(p, &argp->fh)))
209 argp->access = ntohl(*p++);
211 return xdr_argsize_check(rqstp, p);
215 * XDR encode functions
219 * There must be an encoding function for void results so svc_process
220 * will work properly.
223 nfsaclsvc_encode_voidres(struct svc_rqst *rqstp, __be32 *p, void *dummy)
225 return xdr_ressize_check(rqstp, p);
229 static int nfsaclsvc_encode_getaclres(struct svc_rqst *rqstp, __be32 *p,
230 struct nfsd3_getaclres *resp)
232 struct dentry *dentry = resp->fh.fh_dentry;
234 struct kvec *head = rqstp->rq_res.head;
240 * Since this is version 2, the check for nfserr in
241 * nfsd_dispatch actually ensures the following cannot happen.
242 * However, it seems fragile to depend on that.
244 if (dentry == NULL || dentry->d_inode == NULL)
246 inode = dentry->d_inode;
248 p = nfs2svc_encode_fattr(rqstp, p, &resp->fh);
249 *p++ = htonl(resp->mask);
250 if (!xdr_ressize_check(rqstp, p))
252 base = (char *)p - (char *)head->iov_base;
254 rqstp->rq_res.page_len = w = nfsacl_size(
255 (resp->mask & NFS_ACL) ? resp->acl_access : NULL,
256 (resp->mask & NFS_DFACL) ? resp->acl_default : NULL);
258 if (!rqstp->rq_respages[rqstp->rq_resused++])
263 n = nfsacl_encode(&rqstp->rq_res, base, inode,
265 resp->mask & NFS_ACL, 0);
267 n = nfsacl_encode(&rqstp->rq_res, base + n, inode,
269 resp->mask & NFS_DFACL,
276 static int nfsaclsvc_encode_attrstatres(struct svc_rqst *rqstp, __be32 *p,
277 struct nfsd_attrstat *resp)
279 p = nfs2svc_encode_fattr(rqstp, p, &resp->fh);
280 return xdr_ressize_check(rqstp, p);
284 static int nfsaclsvc_encode_accessres(struct svc_rqst *rqstp, __be32 *p,
285 struct nfsd3_accessres *resp)
287 p = nfs2svc_encode_fattr(rqstp, p, &resp->fh);
288 *p++ = htonl(resp->access);
289 return xdr_ressize_check(rqstp, p);
293 * XDR release functions
295 static int nfsaclsvc_release_getacl(struct svc_rqst *rqstp, __be32 *p,
296 struct nfsd3_getaclres *resp)
299 posix_acl_release(resp->acl_access);
300 posix_acl_release(resp->acl_default);
304 static int nfsaclsvc_release_attrstat(struct svc_rqst *rqstp, __be32 *p,
305 struct nfsd_attrstat *resp)
311 static int nfsaclsvc_release_access(struct svc_rqst *rqstp, __be32 *p,
312 struct nfsd3_accessres *resp)
318 #define nfsaclsvc_decode_voidargs NULL
319 #define nfsaclsvc_release_void NULL
320 #define nfsd3_fhandleargs nfsd_fhandle
321 #define nfsd3_attrstatres nfsd_attrstat
322 #define nfsd3_voidres nfsd3_voidargs
323 struct nfsd3_voidargs { int dummy; };
325 #define PROC(name, argt, rest, relt, cache, respsize) \
326 { (svc_procfunc) nfsacld_proc_##name, \
327 (kxdrproc_t) nfsaclsvc_decode_##argt##args, \
328 (kxdrproc_t) nfsaclsvc_encode_##rest##res, \
329 (kxdrproc_t) nfsaclsvc_release_##relt, \
330 sizeof(struct nfsd3_##argt##args), \
331 sizeof(struct nfsd3_##rest##res), \
337 #define ST 1 /* status*/
338 #define AT 21 /* attributes */
339 #define pAT (1+AT) /* post attributes - conditional */
340 #define ACL (1+NFS_ACL_MAX_ENTRIES*3) /* Access Control List */
342 static struct svc_procedure nfsd_acl_procedures2[] = {
343 PROC(null, void, void, void, RC_NOCACHE, ST),
344 PROC(getacl, getacl, getacl, getacl, RC_NOCACHE, ST+1+2*(1+ACL)),
345 PROC(setacl, setacl, attrstat, attrstat, RC_NOCACHE, ST+AT),
346 PROC(getattr, fhandle, attrstat, attrstat, RC_NOCACHE, ST+AT),
347 PROC(access, access, access, access, RC_NOCACHE, ST+AT+1),
350 struct svc_version nfsd_acl_version2 = {
353 .vs_proc = nfsd_acl_procedures2,
354 .vs_dispatch = nfsd_dispatch,
355 .vs_xdrsize = NFS3_SVC_XDRSIZE,