1
2
3
4
5
6
7#include "nfsd.h"
8
9#include <linux/nfsacl.h>
10#include <linux/gfp.h>
11#include "cache.h"
12#include "xdr3.h"
13#include "vfs.h"
14
15#define NFSDDBG_FACILITY NFSDDBG_PROC
16#define RETURN_STATUS(st) { resp->status = (st); return (st); }
17
18
19
20
21static __be32
22nfsacld_proc_null(struct svc_rqst *rqstp, void *argp, void *resp)
23{
24 return nfs_ok;
25}
26
27
28
29
30static __be32 nfsacld_proc_getacl(struct svc_rqst * rqstp,
31 struct nfsd3_getaclargs *argp, struct nfsd3_getaclres *resp)
32{
33 svc_fh *fh;
34 struct posix_acl *acl;
35 __be32 nfserr = 0;
36
37 dprintk("nfsd: GETACL(2acl) %s\n", SVCFH_fmt(&argp->fh));
38
39 fh = fh_copy(&resp->fh, &argp->fh);
40 nfserr = fh_verify(rqstp, &resp->fh, 0, NFSD_MAY_NOP);
41 if (nfserr)
42 RETURN_STATUS(nfserr);
43
44 if (argp->mask & ~NFS_ACL_MASK)
45 RETURN_STATUS(nfserr_inval);
46 resp->mask = argp->mask;
47
48 nfserr = fh_getattr(fh, &resp->stat);
49 if (nfserr)
50 RETURN_STATUS(nfserr);
51
52 if (resp->mask & (NFS_ACL|NFS_ACLCNT)) {
53 acl = nfsd_get_posix_acl(fh, ACL_TYPE_ACCESS);
54 if (IS_ERR(acl)) {
55 int err = PTR_ERR(acl);
56
57 if (err == -ENODATA || err == -EOPNOTSUPP)
58 acl = NULL;
59 else {
60 nfserr = nfserrno(err);
61 goto fail;
62 }
63 }
64 if (acl == NULL) {
65
66
67 struct inode *inode = fh->fh_dentry->d_inode;
68 acl = posix_acl_from_mode(inode->i_mode, GFP_KERNEL);
69 }
70 resp->acl_access = acl;
71 }
72 if (resp->mask & (NFS_DFACL|NFS_DFACLCNT)) {
73
74
75
76 acl = nfsd_get_posix_acl(fh, ACL_TYPE_DEFAULT);
77 if (IS_ERR(acl)) {
78 int err = PTR_ERR(acl);
79
80 if (err == -ENODATA || err == -EOPNOTSUPP)
81 acl = NULL;
82 else {
83 nfserr = nfserrno(err);
84 goto fail;
85 }
86 }
87 resp->acl_default = acl;
88 }
89
90
91 RETURN_STATUS(0);
92
93fail:
94 posix_acl_release(resp->acl_access);
95 posix_acl_release(resp->acl_default);
96 RETURN_STATUS(nfserr);
97}
98
99
100
101
102static __be32 nfsacld_proc_setacl(struct svc_rqst * rqstp,
103 struct nfsd3_setaclargs *argp,
104 struct nfsd_attrstat *resp)
105{
106 svc_fh *fh;
107 __be32 nfserr = 0;
108
109 dprintk("nfsd: SETACL(2acl) %s\n", SVCFH_fmt(&argp->fh));
110
111 fh = fh_copy(&resp->fh, &argp->fh);
112 nfserr = fh_verify(rqstp, &resp->fh, 0, NFSD_MAY_SATTR);
113
114 if (!nfserr) {
115 nfserr = nfserrno( nfsd_set_posix_acl(
116 fh, ACL_TYPE_ACCESS, argp->acl_access) );
117 }
118 if (!nfserr) {
119 nfserr = nfserrno( nfsd_set_posix_acl(
120 fh, ACL_TYPE_DEFAULT, argp->acl_default) );
121 }
122 if (!nfserr) {
123 nfserr = fh_getattr(fh, &resp->stat);
124 }
125
126
127
128 posix_acl_release(argp->acl_access);
129 posix_acl_release(argp->acl_default);
130 return nfserr;
131}
132
133
134
135
136static __be32 nfsacld_proc_getattr(struct svc_rqst * rqstp,
137 struct nfsd_fhandle *argp, struct nfsd_attrstat *resp)
138{
139 __be32 nfserr;
140 dprintk("nfsd: GETATTR %s\n", SVCFH_fmt(&argp->fh));
141
142 fh_copy(&resp->fh, &argp->fh);
143 nfserr = fh_verify(rqstp, &resp->fh, 0, NFSD_MAY_NOP);
144 if (nfserr)
145 return nfserr;
146 nfserr = fh_getattr(&resp->fh, &resp->stat);
147 return nfserr;
148}
149
150
151
152
153static __be32 nfsacld_proc_access(struct svc_rqst *rqstp, struct nfsd3_accessargs *argp,
154 struct nfsd3_accessres *resp)
155{
156 __be32 nfserr;
157
158 dprintk("nfsd: ACCESS(2acl) %s 0x%x\n",
159 SVCFH_fmt(&argp->fh),
160 argp->access);
161
162 fh_copy(&resp->fh, &argp->fh);
163 resp->access = argp->access;
164 nfserr = nfsd_access(rqstp, &resp->fh, &resp->access, NULL);
165 if (nfserr)
166 return nfserr;
167 nfserr = fh_getattr(&resp->fh, &resp->stat);
168 return nfserr;
169}
170
171
172
173
174static int nfsaclsvc_decode_getaclargs(struct svc_rqst *rqstp, __be32 *p,
175 struct nfsd3_getaclargs *argp)
176{
177 p = nfs2svc_decode_fh(p, &argp->fh);
178 if (!p)
179 return 0;
180 argp->mask = ntohl(*p); p++;
181
182 return xdr_argsize_check(rqstp, p);
183}
184
185
186static int nfsaclsvc_decode_setaclargs(struct svc_rqst *rqstp, __be32 *p,
187 struct nfsd3_setaclargs *argp)
188{
189 struct kvec *head = rqstp->rq_arg.head;
190 unsigned int base;
191 int n;
192
193 p = nfs2svc_decode_fh(p, &argp->fh);
194 if (!p)
195 return 0;
196 argp->mask = ntohl(*p++);
197 if (argp->mask & ~NFS_ACL_MASK ||
198 !xdr_argsize_check(rqstp, p))
199 return 0;
200
201 base = (char *)p - (char *)head->iov_base;
202 n = nfsacl_decode(&rqstp->rq_arg, base, NULL,
203 (argp->mask & NFS_ACL) ?
204 &argp->acl_access : NULL);
205 if (n > 0)
206 n = nfsacl_decode(&rqstp->rq_arg, base + n, NULL,
207 (argp->mask & NFS_DFACL) ?
208 &argp->acl_default : NULL);
209 return (n > 0);
210}
211
212static int nfsaclsvc_decode_fhandleargs(struct svc_rqst *rqstp, __be32 *p,
213 struct nfsd_fhandle *argp)
214{
215 p = nfs2svc_decode_fh(p, &argp->fh);
216 if (!p)
217 return 0;
218 return xdr_argsize_check(rqstp, p);
219}
220
221static int nfsaclsvc_decode_accessargs(struct svc_rqst *rqstp, __be32 *p,
222 struct nfsd3_accessargs *argp)
223{
224 p = nfs2svc_decode_fh(p, &argp->fh);
225 if (!p)
226 return 0;
227 argp->access = ntohl(*p++);
228
229 return xdr_argsize_check(rqstp, p);
230}
231
232
233
234
235
236
237
238
239
240static int nfsaclsvc_encode_voidres(struct svc_rqst *rqstp, __be32 *p, void *dummy)
241{
242 return xdr_ressize_check(rqstp, p);
243}
244
245
246static int nfsaclsvc_encode_getaclres(struct svc_rqst *rqstp, __be32 *p,
247 struct nfsd3_getaclres *resp)
248{
249 struct dentry *dentry = resp->fh.fh_dentry;
250 struct inode *inode;
251 struct kvec *head = rqstp->rq_res.head;
252 unsigned int base;
253 int n;
254 int w;
255
256
257
258
259
260
261 if (dentry == NULL || dentry->d_inode == NULL)
262 return 0;
263 inode = dentry->d_inode;
264
265 p = nfs2svc_encode_fattr(rqstp, p, &resp->fh, &resp->stat);
266 *p++ = htonl(resp->mask);
267 if (!xdr_ressize_check(rqstp, p))
268 return 0;
269 base = (char *)p - (char *)head->iov_base;
270
271 rqstp->rq_res.page_len = w = nfsacl_size(
272 (resp->mask & NFS_ACL) ? resp->acl_access : NULL,
273 (resp->mask & NFS_DFACL) ? resp->acl_default : NULL);
274 while (w > 0) {
275 if (!*(rqstp->rq_next_page++))
276 return 0;
277 w -= PAGE_SIZE;
278 }
279
280 n = nfsacl_encode(&rqstp->rq_res, base, inode,
281 resp->acl_access,
282 resp->mask & NFS_ACL, 0);
283 if (n > 0)
284 n = nfsacl_encode(&rqstp->rq_res, base + n, inode,
285 resp->acl_default,
286 resp->mask & NFS_DFACL,
287 NFS_ACL_DEFAULT);
288 return (n > 0);
289}
290
291static int nfsaclsvc_encode_attrstatres(struct svc_rqst *rqstp, __be32 *p,
292 struct nfsd_attrstat *resp)
293{
294 p = nfs2svc_encode_fattr(rqstp, p, &resp->fh, &resp->stat);
295 return xdr_ressize_check(rqstp, p);
296}
297
298
299static int nfsaclsvc_encode_accessres(struct svc_rqst *rqstp, __be32 *p,
300 struct nfsd3_accessres *resp)
301{
302 p = nfs2svc_encode_fattr(rqstp, p, &resp->fh, &resp->stat);
303 *p++ = htonl(resp->access);
304 return xdr_ressize_check(rqstp, p);
305}
306
307
308
309
310static int nfsaclsvc_release_getacl(struct svc_rqst *rqstp, __be32 *p,
311 struct nfsd3_getaclres *resp)
312{
313 fh_put(&resp->fh);
314 posix_acl_release(resp->acl_access);
315 posix_acl_release(resp->acl_default);
316 return 1;
317}
318
319static int nfsaclsvc_release_attrstat(struct svc_rqst *rqstp, __be32 *p,
320 struct nfsd_attrstat *resp)
321{
322 fh_put(&resp->fh);
323 return 1;
324}
325
326static int nfsaclsvc_release_access(struct svc_rqst *rqstp, __be32 *p,
327 struct nfsd3_accessres *resp)
328{
329 fh_put(&resp->fh);
330 return 1;
331}
332
333#define nfsaclsvc_decode_voidargs NULL
334#define nfsaclsvc_release_void NULL
335#define nfsd3_fhandleargs nfsd_fhandle
336#define nfsd3_attrstatres nfsd_attrstat
337#define nfsd3_voidres nfsd3_voidargs
338struct nfsd3_voidargs { int dummy; };
339
340#define PROC(name, argt, rest, relt, cache, respsize) \
341 { (svc_procfunc) nfsacld_proc_##name, \
342 (kxdrproc_t) nfsaclsvc_decode_##argt##args, \
343 (kxdrproc_t) nfsaclsvc_encode_##rest##res, \
344 (kxdrproc_t) nfsaclsvc_release_##relt, \
345 sizeof(struct nfsd3_##argt##args), \
346 sizeof(struct nfsd3_##rest##res), \
347 0, \
348 cache, \
349 respsize, \
350 }
351
352#define ST 1
353#define AT 21
354#define pAT (1+AT)
355#define ACL (1+NFS_ACL_MAX_ENTRIES*3)
356
357static struct svc_procedure nfsd_acl_procedures2[] = {
358 PROC(null, void, void, void, RC_NOCACHE, ST),
359 PROC(getacl, getacl, getacl, getacl, RC_NOCACHE, ST+1+2*(1+ACL)),
360 PROC(setacl, setacl, attrstat, attrstat, RC_NOCACHE, ST+AT),
361 PROC(getattr, fhandle, attrstat, attrstat, RC_NOCACHE, ST+AT),
362 PROC(access, access, access, access, RC_NOCACHE, ST+AT+1),
363};
364
365struct svc_version nfsd_acl_version2 = {
366 .vs_vers = 2,
367 .vs_nproc = 5,
368 .vs_proc = nfsd_acl_procedures2,
369 .vs_dispatch = nfsd_dispatch,
370 .vs_xdrsize = NFS3_SVC_XDRSIZE,
371 .vs_hidden = 0,
372};
373