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 if ((nfserr
= fh_verify(rqstp
, &resp
->fh
, 0, MAY_NOP
)))
44 RETURN_STATUS(nfserr
);
46 if (argp
->mask
& ~(NFS_ACL
|NFS_ACLCNT
|NFS_DFACL
|NFS_DFACLCNT
))
47 RETURN_STATUS(nfserr_inval
);
48 resp
->mask
= argp
->mask
;
50 if (resp
->mask
& (NFS_ACL
|NFS_ACLCNT
)) {
51 acl
= nfsd_get_posix_acl(fh
, ACL_TYPE_ACCESS
);
53 int err
= PTR_ERR(acl
);
55 if (err
== -ENODATA
|| err
== -EOPNOTSUPP
)
58 nfserr
= nfserrno(err
);
63 /* Solaris returns the inode's minimum ACL. */
65 struct inode
*inode
= fh
->fh_dentry
->d_inode
;
66 acl
= posix_acl_from_mode(inode
->i_mode
, GFP_KERNEL
);
68 resp
->acl_access
= acl
;
70 if (resp
->mask
& (NFS_DFACL
|NFS_DFACLCNT
)) {
71 /* Check how Solaris handles requests for the Default ACL
72 of a non-directory! */
74 acl
= nfsd_get_posix_acl(fh
, ACL_TYPE_DEFAULT
);
76 int err
= PTR_ERR(acl
);
78 if (err
== -ENODATA
|| err
== -EOPNOTSUPP
)
81 nfserr
= nfserrno(err
);
85 resp
->acl_default
= acl
;
88 /* resp->acl_{access,default} are released in nfssvc_release_getacl. */
92 posix_acl_release(resp
->acl_access
);
93 posix_acl_release(resp
->acl_default
);
94 RETURN_STATUS(nfserr
);
98 * Set the Access and/or Default ACL of a file.
100 static __be32
nfsacld_proc_setacl(struct svc_rqst
* rqstp
,
101 struct nfsd3_setaclargs
*argp
,
102 struct nfsd_attrstat
*resp
)
107 dprintk("nfsd: SETACL(2acl) %s\n", SVCFH_fmt(&argp
->fh
));
109 fh
= fh_copy(&resp
->fh
, &argp
->fh
);
110 nfserr
= fh_verify(rqstp
, &resp
->fh
, 0, MAY_SATTR
);
113 nfserr
= nfserrno( nfsd_set_posix_acl(
114 fh
, ACL_TYPE_ACCESS
, argp
->acl_access
) );
117 nfserr
= nfserrno( nfsd_set_posix_acl(
118 fh
, ACL_TYPE_DEFAULT
, argp
->acl_default
) );
121 /* argp->acl_{access,default} may have been allocated in
122 nfssvc_decode_setaclargs. */
123 posix_acl_release(argp
->acl_access
);
124 posix_acl_release(argp
->acl_default
);
129 * Check file attributes
131 static __be32
nfsacld_proc_getattr(struct svc_rqst
* rqstp
,
132 struct nfsd_fhandle
*argp
, struct nfsd_attrstat
*resp
)
134 dprintk("nfsd: GETATTR %s\n", SVCFH_fmt(&argp
->fh
));
136 fh_copy(&resp
->fh
, &argp
->fh
);
137 return fh_verify(rqstp
, &resp
->fh
, 0, MAY_NOP
);
143 static __be32
nfsacld_proc_access(struct svc_rqst
*rqstp
, struct nfsd3_accessargs
*argp
,
144 struct nfsd3_accessres
*resp
)
148 dprintk("nfsd: ACCESS(2acl) %s 0x%x\n",
149 SVCFH_fmt(&argp
->fh
),
152 fh_copy(&resp
->fh
, &argp
->fh
);
153 resp
->access
= argp
->access
;
154 nfserr
= nfsd_access(rqstp
, &resp
->fh
, &resp
->access
, NULL
);
159 * XDR decode functions
161 static int nfsaclsvc_decode_getaclargs(struct svc_rqst
*rqstp
, __be32
*p
,
162 struct nfsd3_getaclargs
*argp
)
164 if (!(p
= nfs2svc_decode_fh(p
, &argp
->fh
)))
166 argp
->mask
= ntohl(*p
); p
++;
168 return xdr_argsize_check(rqstp
, p
);
172 static int nfsaclsvc_decode_setaclargs(struct svc_rqst
*rqstp
, __be32
*p
,
173 struct nfsd3_setaclargs
*argp
)
175 struct kvec
*head
= rqstp
->rq_arg
.head
;
179 if (!(p
= nfs2svc_decode_fh(p
, &argp
->fh
)))
181 argp
->mask
= ntohl(*p
++);
182 if (argp
->mask
& ~(NFS_ACL
|NFS_ACLCNT
|NFS_DFACL
|NFS_DFACLCNT
) ||
183 !xdr_argsize_check(rqstp
, p
))
186 base
= (char *)p
- (char *)head
->iov_base
;
187 n
= nfsacl_decode(&rqstp
->rq_arg
, base
, NULL
,
188 (argp
->mask
& NFS_ACL
) ?
189 &argp
->acl_access
: NULL
);
191 n
= nfsacl_decode(&rqstp
->rq_arg
, base
+ n
, NULL
,
192 (argp
->mask
& NFS_DFACL
) ?
193 &argp
->acl_default
: NULL
);
197 static int nfsaclsvc_decode_fhandleargs(struct svc_rqst
*rqstp
, __be32
*p
,
198 struct nfsd_fhandle
*argp
)
200 if (!(p
= nfs2svc_decode_fh(p
, &argp
->fh
)))
202 return xdr_argsize_check(rqstp
, p
);
205 static int nfsaclsvc_decode_accessargs(struct svc_rqst
*rqstp
, __be32
*p
,
206 struct nfsd3_accessargs
*argp
)
208 if (!(p
= nfs2svc_decode_fh(p
, &argp
->fh
)))
210 argp
->access
= ntohl(*p
++);
212 return xdr_argsize_check(rqstp
, p
);
216 * XDR encode functions
220 static int nfsaclsvc_encode_getaclres(struct svc_rqst
*rqstp
, __be32
*p
,
221 struct nfsd3_getaclres
*resp
)
223 struct dentry
*dentry
= resp
->fh
.fh_dentry
;
225 struct kvec
*head
= rqstp
->rq_res
.head
;
231 * Since this is version 2, the check for nfserr in
232 * nfsd_dispatch actually ensures the following cannot happen.
233 * However, it seems fragile to depend on that.
235 if (dentry
== NULL
|| dentry
->d_inode
== NULL
)
237 inode
= dentry
->d_inode
;
239 p
= nfs2svc_encode_fattr(rqstp
, p
, &resp
->fh
);
240 *p
++ = htonl(resp
->mask
);
241 if (!xdr_ressize_check(rqstp
, p
))
243 base
= (char *)p
- (char *)head
->iov_base
;
245 rqstp
->rq_res
.page_len
= w
= nfsacl_size(
246 (resp
->mask
& NFS_ACL
) ? resp
->acl_access
: NULL
,
247 (resp
->mask
& NFS_DFACL
) ? resp
->acl_default
: NULL
);
249 if (!rqstp
->rq_respages
[rqstp
->rq_resused
++])
254 n
= nfsacl_encode(&rqstp
->rq_res
, base
, inode
,
256 resp
->mask
& NFS_ACL
, 0);
258 n
= nfsacl_encode(&rqstp
->rq_res
, base
+ n
, inode
,
260 resp
->mask
& NFS_DFACL
,
267 static int nfsaclsvc_encode_attrstatres(struct svc_rqst
*rqstp
, __be32
*p
,
268 struct nfsd_attrstat
*resp
)
270 p
= nfs2svc_encode_fattr(rqstp
, p
, &resp
->fh
);
271 return xdr_ressize_check(rqstp
, p
);
275 static int nfsaclsvc_encode_accessres(struct svc_rqst
*rqstp
, __be32
*p
,
276 struct nfsd3_accessres
*resp
)
278 p
= nfs2svc_encode_fattr(rqstp
, p
, &resp
->fh
);
279 *p
++ = htonl(resp
->access
);
280 return xdr_ressize_check(rqstp
, p
);
284 * XDR release functions
286 static int nfsaclsvc_release_getacl(struct svc_rqst
*rqstp
, __be32
*p
,
287 struct nfsd3_getaclres
*resp
)
290 posix_acl_release(resp
->acl_access
);
291 posix_acl_release(resp
->acl_default
);
295 static int nfsaclsvc_release_attrstat(struct svc_rqst
*rqstp
, __be32
*p
,
296 struct nfsd_attrstat
*resp
)
302 static int nfsaclsvc_release_access(struct svc_rqst
*rqstp
, __be32
*p
,
303 struct nfsd3_accessres
*resp
)
309 #define nfsaclsvc_decode_voidargs NULL
310 #define nfsaclsvc_encode_voidres NULL
311 #define nfsaclsvc_release_void NULL
312 #define nfsd3_fhandleargs nfsd_fhandle
313 #define nfsd3_attrstatres nfsd_attrstat
314 #define nfsd3_voidres nfsd3_voidargs
315 struct nfsd3_voidargs
{ int dummy
; };
317 #define PROC(name, argt, rest, relt, cache, respsize) \
318 { (svc_procfunc) nfsacld_proc_##name, \
319 (kxdrproc_t) nfsaclsvc_decode_##argt##args, \
320 (kxdrproc_t) nfsaclsvc_encode_##rest##res, \
321 (kxdrproc_t) nfsaclsvc_release_##relt, \
322 sizeof(struct nfsd3_##argt##args), \
323 sizeof(struct nfsd3_##rest##res), \
329 #define ST 1 /* status*/
330 #define AT 21 /* attributes */
331 #define pAT (1+AT) /* post attributes - conditional */
332 #define ACL (1+NFS_ACL_MAX_ENTRIES*3) /* Access Control List */
334 static struct svc_procedure nfsd_acl_procedures2
[] = {
335 PROC(null
, void, void, void, RC_NOCACHE
, ST
),
336 PROC(getacl
, getacl
, getacl
, getacl
, RC_NOCACHE
, ST
+1+2*(1+ACL
)),
337 PROC(setacl
, setacl
, attrstat
, attrstat
, RC_NOCACHE
, ST
+AT
),
338 PROC(getattr
, fhandle
, attrstat
, attrstat
, RC_NOCACHE
, ST
+AT
),
339 PROC(access
, access
, access
, access
, RC_NOCACHE
, ST
+AT
+1),
342 struct svc_version nfsd_acl_version2
= {
345 .vs_proc
= nfsd_acl_procedures2
,
346 .vs_dispatch
= nfsd_dispatch
,
347 .vs_xdrsize
= NFS3_SVC_XDRSIZE
,