2 * linux/fs/nfsd/nfs3acl.c
4 * Process version 3 NFSACL requests.
6 * Copyright (C) 2002-2003 Andreas Gruenbacher <agruen@suse.de>
9 #include <linux/sunrpc/svc.h>
10 #include <linux/nfs3.h>
11 #include <linux/nfsd/nfsd.h>
12 #include <linux/nfsd/cache.h>
13 #include <linux/nfsd/xdr3.h>
14 #include <linux/posix_acl.h>
15 #include <linux/nfsacl.h>
17 #define RETURN_STATUS(st) { resp->status = (st); return (st); }
23 nfsd3_proc_null(struct svc_rqst *rqstp, void *argp, void *resp)
29 * Get the Access and/or Default ACL of a file.
31 static int nfsd3_proc_getacl(struct svc_rqst * rqstp,
32 struct nfsd3_getaclargs *argp, struct nfsd3_getaclres *resp)
35 struct posix_acl *acl;
38 fh = fh_copy(&resp->fh, &argp->fh);
39 if ((nfserr = fh_verify(rqstp, &resp->fh, 0, MAY_NOP)))
40 RETURN_STATUS(nfserr_inval);
42 if (argp->mask & ~(NFS_ACL|NFS_ACLCNT|NFS_DFACL|NFS_DFACLCNT))
43 RETURN_STATUS(nfserr_inval);
44 resp->mask = argp->mask;
46 if (resp->mask & (NFS_ACL|NFS_ACLCNT)) {
47 acl = nfsd_get_posix_acl(fh, ACL_TYPE_ACCESS);
49 int err = PTR_ERR(acl);
51 if (err == -ENODATA || err == -EOPNOTSUPP)
54 nfserr = nfserrno(err);
59 /* Solaris returns the inode's minimum ACL. */
61 struct inode *inode = fh->fh_dentry->d_inode;
62 acl = posix_acl_from_mode(inode->i_mode, GFP_KERNEL);
64 resp->acl_access = acl;
66 if (resp->mask & (NFS_DFACL|NFS_DFACLCNT)) {
67 /* Check how Solaris handles requests for the Default ACL
68 of a non-directory! */
70 acl = nfsd_get_posix_acl(fh, ACL_TYPE_DEFAULT);
72 int err = PTR_ERR(acl);
74 if (err == -ENODATA || err == -EOPNOTSUPP)
77 nfserr = nfserrno(err);
81 resp->acl_default = acl;
84 /* resp->acl_{access,default} are released in nfs3svc_release_getacl. */
88 posix_acl_release(resp->acl_access);
89 posix_acl_release(resp->acl_default);
90 RETURN_STATUS(nfserr);
94 * Set the Access and/or Default ACL of a file.
96 static int nfsd3_proc_setacl(struct svc_rqst * rqstp,
97 struct nfsd3_setaclargs *argp,
98 struct nfsd3_attrstat *resp)
103 fh = fh_copy(&resp->fh, &argp->fh);
104 nfserr = fh_verify(rqstp, &resp->fh, 0, MAY_SATTR);
107 nfserr = nfserrno( nfsd_set_posix_acl(
108 fh, ACL_TYPE_ACCESS, argp->acl_access) );
111 nfserr = nfserrno( nfsd_set_posix_acl(
112 fh, ACL_TYPE_DEFAULT, argp->acl_default) );
115 /* argp->acl_{access,default} may have been allocated in
116 nfs3svc_decode_setaclargs. */
117 posix_acl_release(argp->acl_access);
118 posix_acl_release(argp->acl_default);
119 RETURN_STATUS(nfserr);
123 * XDR decode functions
125 static int nfs3svc_decode_getaclargs(struct svc_rqst *rqstp, u32 *p,
126 struct nfsd3_getaclargs *args)
128 if (!(p = nfs3svc_decode_fh(p, &args->fh)))
130 args->mask = ntohl(*p); p++;
132 return xdr_argsize_check(rqstp, p);
136 static int nfs3svc_decode_setaclargs(struct svc_rqst *rqstp, u32 *p,
137 struct nfsd3_setaclargs *args)
139 struct kvec *head = rqstp->rq_arg.head;
143 if (!(p = nfs3svc_decode_fh(p, &args->fh)))
145 args->mask = ntohl(*p++);
146 if (args->mask & ~(NFS_ACL|NFS_ACLCNT|NFS_DFACL|NFS_DFACLCNT) ||
147 !xdr_argsize_check(rqstp, p))
150 base = (char *)p - (char *)head->iov_base;
151 n = nfsacl_decode(&rqstp->rq_arg, base, NULL,
152 (args->mask & NFS_ACL) ?
153 &args->acl_access : NULL);
155 n = nfsacl_decode(&rqstp->rq_arg, base + n, NULL,
156 (args->mask & NFS_DFACL) ?
157 &args->acl_default : NULL);
162 * XDR encode functions
166 static int nfs3svc_encode_getaclres(struct svc_rqst *rqstp, u32 *p,
167 struct nfsd3_getaclres *resp)
169 struct dentry *dentry = resp->fh.fh_dentry;
171 p = nfs3svc_encode_post_op_attr(rqstp, p, &resp->fh);
172 if (resp->status == 0 && dentry && dentry->d_inode) {
173 struct inode *inode = dentry->d_inode;
175 (resp->mask & NFS_ACL) ? resp->acl_access : NULL,
176 (resp->mask & NFS_DFACL) ? resp->acl_default : NULL);
177 struct kvec *head = rqstp->rq_res.head;
181 *p++ = htonl(resp->mask);
182 if (!xdr_ressize_check(rqstp, p))
184 base = (char *)p - (char *)head->iov_base;
186 rqstp->rq_res.page_len = w;
188 if (!svc_take_res_page(rqstp))
193 n = nfsacl_encode(&rqstp->rq_res, base, inode,
195 resp->mask & NFS_ACL, 0);
197 n = nfsacl_encode(&rqstp->rq_res, base + n, inode,
199 resp->mask & NFS_DFACL,
204 if (!xdr_ressize_check(rqstp, p))
211 static int nfs3svc_encode_setaclres(struct svc_rqst *rqstp, u32 *p,
212 struct nfsd3_attrstat *resp)
214 p = nfs3svc_encode_post_op_attr(rqstp, p, &resp->fh);
216 return xdr_ressize_check(rqstp, p);
220 * XDR release functions
222 static int nfs3svc_release_getacl(struct svc_rqst *rqstp, u32 *p,
223 struct nfsd3_getaclres *resp)
226 posix_acl_release(resp->acl_access);
227 posix_acl_release(resp->acl_default);
231 #define nfs3svc_decode_voidargs NULL
232 #define nfs3svc_release_void NULL
233 #define nfsd3_setaclres nfsd3_attrstat
234 #define nfsd3_voidres nfsd3_voidargs
235 struct nfsd3_voidargs { int dummy; };
237 #define PROC(name, argt, rest, relt, cache, respsize) \
238 { (svc_procfunc) nfsd3_proc_##name, \
239 (kxdrproc_t) nfs3svc_decode_##argt##args, \
240 (kxdrproc_t) nfs3svc_encode_##rest##res, \
241 (kxdrproc_t) nfs3svc_release_##relt, \
242 sizeof(struct nfsd3_##argt##args), \
243 sizeof(struct nfsd3_##rest##res), \
249 #define ST 1 /* status*/
250 #define AT 21 /* attributes */
251 #define pAT (1+AT) /* post attributes - conditional */
252 #define ACL (1+NFS_ACL_MAX_ENTRIES*3) /* Access Control List */
254 static struct svc_procedure nfsd_acl_procedures3[] = {
255 PROC(null, void, void, void, RC_NOCACHE, ST),
256 PROC(getacl, getacl, getacl, getacl, RC_NOCACHE, ST+1+2*(1+ACL)),
257 PROC(setacl, setacl, setacl, fhandle, RC_NOCACHE, ST+pAT),
260 struct svc_version nfsd_acl_version3 = {
263 .vs_proc = nfsd_acl_procedures3,
264 .vs_dispatch = nfsd_dispatch,
265 .vs_xdrsize = NFS3_SVC_XDRSIZE,