2 * Process version 2 NFSACL requests.
4 * Copyright (C) 2002-2003 Andreas Gruenbacher <agruen@suse.de>
8 /* FIXME: nfsacl.h is a broken header */
9 #include <linux/nfsacl.h>
10 #include <linux/gfp.h>
15 #define NFSDDBG_FACILITY NFSDDBG_PROC
16 #define RETURN_STATUS(st) { resp->status = (st); return (st); }
22 nfsacld_proc_null(struct svc_rqst
*rqstp
)
28 * Get the Access and/or Default ACL of a file.
30 static __be32
nfsacld_proc_getacl(struct svc_rqst
*rqstp
)
32 struct nfsd3_getaclargs
*argp
= rqstp
->rq_argp
;
33 struct nfsd3_getaclres
*resp
= rqstp
->rq_resp
;
34 struct posix_acl
*acl
;
39 dprintk("nfsd: GETACL(2acl) %s\n", SVCFH_fmt(&argp
->fh
));
41 fh
= fh_copy(&resp
->fh
, &argp
->fh
);
42 nfserr
= fh_verify(rqstp
, &resp
->fh
, 0, NFSD_MAY_NOP
);
44 RETURN_STATUS(nfserr
);
46 inode
= d_inode(fh
->fh_dentry
);
48 if (argp
->mask
& ~NFS_ACL_MASK
)
49 RETURN_STATUS(nfserr_inval
);
50 resp
->mask
= argp
->mask
;
52 nfserr
= fh_getattr(fh
, &resp
->stat
);
54 RETURN_STATUS(nfserr
);
56 if (resp
->mask
& (NFS_ACL
|NFS_ACLCNT
)) {
57 acl
= get_acl(inode
, ACL_TYPE_ACCESS
);
59 /* Solaris returns the inode's minimum ACL. */
60 acl
= posix_acl_from_mode(inode
->i_mode
, GFP_KERNEL
);
63 nfserr
= nfserrno(PTR_ERR(acl
));
66 resp
->acl_access
= acl
;
68 if (resp
->mask
& (NFS_DFACL
|NFS_DFACLCNT
)) {
69 /* Check how Solaris handles requests for the Default ACL
70 of a non-directory! */
71 acl
= get_acl(inode
, ACL_TYPE_DEFAULT
);
73 nfserr
= nfserrno(PTR_ERR(acl
));
76 resp
->acl_default
= acl
;
79 /* resp->acl_{access,default} are released in nfssvc_release_getacl. */
83 posix_acl_release(resp
->acl_access
);
84 posix_acl_release(resp
->acl_default
);
85 RETURN_STATUS(nfserr
);
89 * Set the Access and/or Default ACL of a file.
91 static __be32
nfsacld_proc_setacl(struct svc_rqst
*rqstp
)
93 struct nfsd3_setaclargs
*argp
= rqstp
->rq_argp
;
94 struct nfsd_attrstat
*resp
= rqstp
->rq_resp
;
100 dprintk("nfsd: SETACL(2acl) %s\n", SVCFH_fmt(&argp
->fh
));
102 fh
= fh_copy(&resp
->fh
, &argp
->fh
);
103 nfserr
= fh_verify(rqstp
, &resp
->fh
, 0, NFSD_MAY_SATTR
);
107 inode
= d_inode(fh
->fh_dentry
);
109 error
= fh_want_write(fh
);
115 error
= set_posix_acl(inode
, ACL_TYPE_ACCESS
, argp
->acl_access
);
118 error
= set_posix_acl(inode
, ACL_TYPE_DEFAULT
, argp
->acl_default
);
126 nfserr
= fh_getattr(fh
, &resp
->stat
);
129 /* argp->acl_{access,default} may have been allocated in
130 nfssvc_decode_setaclargs. */
131 posix_acl_release(argp
->acl_access
);
132 posix_acl_release(argp
->acl_default
);
138 nfserr
= nfserrno(error
);
143 * Check file attributes
145 static __be32
nfsacld_proc_getattr(struct svc_rqst
*rqstp
)
147 struct nfsd_fhandle
*argp
= rqstp
->rq_argp
;
148 struct nfsd_attrstat
*resp
= rqstp
->rq_resp
;
150 dprintk("nfsd: GETATTR %s\n", SVCFH_fmt(&argp
->fh
));
152 fh_copy(&resp
->fh
, &argp
->fh
);
153 nfserr
= fh_verify(rqstp
, &resp
->fh
, 0, NFSD_MAY_NOP
);
156 nfserr
= fh_getattr(&resp
->fh
, &resp
->stat
);
163 static __be32
nfsacld_proc_access(struct svc_rqst
*rqstp
)
165 struct nfsd3_accessargs
*argp
= rqstp
->rq_argp
;
166 struct nfsd3_accessres
*resp
= rqstp
->rq_resp
;
169 dprintk("nfsd: ACCESS(2acl) %s 0x%x\n",
170 SVCFH_fmt(&argp
->fh
),
173 fh_copy(&resp
->fh
, &argp
->fh
);
174 resp
->access
= argp
->access
;
175 nfserr
= nfsd_access(rqstp
, &resp
->fh
, &resp
->access
, NULL
);
178 nfserr
= fh_getattr(&resp
->fh
, &resp
->stat
);
183 * XDR decode functions
185 static int nfsaclsvc_decode_getaclargs(struct svc_rqst
*rqstp
, __be32
*p
)
187 struct nfsd3_getaclargs
*argp
= rqstp
->rq_argp
;
189 p
= nfs2svc_decode_fh(p
, &argp
->fh
);
192 argp
->mask
= ntohl(*p
); p
++;
194 return xdr_argsize_check(rqstp
, p
);
198 static int nfsaclsvc_decode_setaclargs(struct svc_rqst
*rqstp
, __be32
*p
)
200 struct nfsd3_setaclargs
*argp
= rqstp
->rq_argp
;
201 struct kvec
*head
= rqstp
->rq_arg
.head
;
205 p
= nfs2svc_decode_fh(p
, &argp
->fh
);
208 argp
->mask
= ntohl(*p
++);
209 if (argp
->mask
& ~NFS_ACL_MASK
||
210 !xdr_argsize_check(rqstp
, p
))
213 base
= (char *)p
- (char *)head
->iov_base
;
214 n
= nfsacl_decode(&rqstp
->rq_arg
, base
, NULL
,
215 (argp
->mask
& NFS_ACL
) ?
216 &argp
->acl_access
: NULL
);
218 n
= nfsacl_decode(&rqstp
->rq_arg
, base
+ n
, NULL
,
219 (argp
->mask
& NFS_DFACL
) ?
220 &argp
->acl_default
: NULL
);
224 static int nfsaclsvc_decode_fhandleargs(struct svc_rqst
*rqstp
, __be32
*p
)
226 struct nfsd_fhandle
*argp
= rqstp
->rq_argp
;
228 p
= nfs2svc_decode_fh(p
, &argp
->fh
);
231 return xdr_argsize_check(rqstp
, p
);
234 static int nfsaclsvc_decode_accessargs(struct svc_rqst
*rqstp
, __be32
*p
)
236 struct nfsd3_accessargs
*argp
= rqstp
->rq_argp
;
238 p
= nfs2svc_decode_fh(p
, &argp
->fh
);
241 argp
->access
= ntohl(*p
++);
243 return xdr_argsize_check(rqstp
, p
);
247 * XDR encode functions
251 * There must be an encoding function for void results so svc_process
252 * will work properly.
254 static int nfsaclsvc_encode_voidres(struct svc_rqst
*rqstp
, __be32
*p
)
256 return xdr_ressize_check(rqstp
, p
);
260 static int nfsaclsvc_encode_getaclres(struct svc_rqst
*rqstp
, __be32
*p
)
262 struct nfsd3_getaclres
*resp
= rqstp
->rq_resp
;
263 struct dentry
*dentry
= resp
->fh
.fh_dentry
;
265 struct kvec
*head
= rqstp
->rq_res
.head
;
271 * Since this is version 2, the check for nfserr in
272 * nfsd_dispatch actually ensures the following cannot happen.
273 * However, it seems fragile to depend on that.
275 if (dentry
== NULL
|| d_really_is_negative(dentry
))
277 inode
= d_inode(dentry
);
279 p
= nfs2svc_encode_fattr(rqstp
, p
, &resp
->fh
, &resp
->stat
);
280 *p
++ = htonl(resp
->mask
);
281 if (!xdr_ressize_check(rqstp
, p
))
283 base
= (char *)p
- (char *)head
->iov_base
;
285 rqstp
->rq_res
.page_len
= w
= nfsacl_size(
286 (resp
->mask
& NFS_ACL
) ? resp
->acl_access
: NULL
,
287 (resp
->mask
& NFS_DFACL
) ? resp
->acl_default
: NULL
);
289 if (!*(rqstp
->rq_next_page
++))
294 n
= nfsacl_encode(&rqstp
->rq_res
, base
, inode
,
296 resp
->mask
& NFS_ACL
, 0);
298 n
= nfsacl_encode(&rqstp
->rq_res
, base
+ n
, inode
,
300 resp
->mask
& NFS_DFACL
,
305 static int nfsaclsvc_encode_attrstatres(struct svc_rqst
*rqstp
, __be32
*p
)
307 struct nfsd_attrstat
*resp
= rqstp
->rq_resp
;
309 p
= nfs2svc_encode_fattr(rqstp
, p
, &resp
->fh
, &resp
->stat
);
310 return xdr_ressize_check(rqstp
, p
);
314 static int nfsaclsvc_encode_accessres(struct svc_rqst
*rqstp
, __be32
*p
)
316 struct nfsd3_accessres
*resp
= rqstp
->rq_resp
;
318 p
= nfs2svc_encode_fattr(rqstp
, p
, &resp
->fh
, &resp
->stat
);
319 *p
++ = htonl(resp
->access
);
320 return xdr_ressize_check(rqstp
, p
);
324 * XDR release functions
326 static void nfsaclsvc_release_getacl(struct svc_rqst
*rqstp
)
328 struct nfsd3_getaclres
*resp
= rqstp
->rq_resp
;
331 posix_acl_release(resp
->acl_access
);
332 posix_acl_release(resp
->acl_default
);
335 static void nfsaclsvc_release_attrstat(struct svc_rqst
*rqstp
)
337 struct nfsd_attrstat
*resp
= rqstp
->rq_resp
;
342 static void nfsaclsvc_release_access(struct svc_rqst
*rqstp
)
344 struct nfsd3_accessres
*resp
= rqstp
->rq_resp
;
349 #define nfsaclsvc_decode_voidargs NULL
350 #define nfsaclsvc_release_void NULL
351 #define nfsd3_fhandleargs nfsd_fhandle
352 #define nfsd3_attrstatres nfsd_attrstat
353 #define nfsd3_voidres nfsd3_voidargs
354 struct nfsd3_voidargs
{ int dummy
; };
356 #define PROC(name, argt, rest, relt, cache, respsize) \
358 .pc_func = nfsacld_proc_##name, \
359 .pc_decode = nfsaclsvc_decode_##argt##args, \
360 .pc_encode = nfsaclsvc_encode_##rest##res, \
361 .pc_release = nfsaclsvc_release_##relt, \
362 .pc_argsize = sizeof(struct nfsd3_##argt##args), \
363 .pc_ressize = sizeof(struct nfsd3_##rest##res), \
364 .pc_cachetype = cache, \
365 .pc_xdrressize = respsize, \
368 #define ST 1 /* status*/
369 #define AT 21 /* attributes */
370 #define pAT (1+AT) /* post attributes - conditional */
371 #define ACL (1+NFS_ACL_MAX_ENTRIES*3) /* Access Control List */
373 static const struct svc_procedure nfsd_acl_procedures2
[] = {
374 PROC(null
, void, void, void, RC_NOCACHE
, ST
),
375 PROC(getacl
, getacl
, getacl
, getacl
, RC_NOCACHE
, ST
+1+2*(1+ACL
)),
376 PROC(setacl
, setacl
, attrstat
, attrstat
, RC_NOCACHE
, ST
+AT
),
377 PROC(getattr
, fhandle
, attrstat
, attrstat
, RC_NOCACHE
, ST
+AT
),
378 PROC(access
, access
, access
, access
, RC_NOCACHE
, ST
+AT
+1),
381 static unsigned int nfsd_acl_count2
[ARRAY_SIZE(nfsd_acl_procedures2
)];
382 const struct svc_version nfsd_acl_version2
= {
385 .vs_proc
= nfsd_acl_procedures2
,
386 .vs_count
= nfsd_acl_count2
,
387 .vs_dispatch
= nfsd_dispatch
,
388 .vs_xdrsize
= NFS3_SVC_XDRSIZE
,