Blame view
fs/nfsd/nfs2acl.c
9.28 KB
b24413180 License cleanup: ... |
1 |
// SPDX-License-Identifier: GPL-2.0 |
a257cdd0e [PATCH] NFSD: Add... |
2 |
/* |
a257cdd0e [PATCH] NFSD: Add... |
3 4 5 6 |
* Process version 2 NFSACL requests. * * Copyright (C) 2002-2003 Andreas Gruenbacher <agruen@suse.de> */ |
9a74af213 nfsd: Move privat... |
7 8 |
#include "nfsd.h" /* FIXME: nfsacl.h is a broken header */ |
a257cdd0e [PATCH] NFSD: Add... |
9 |
#include <linux/nfsacl.h> |
5a0e3ad6a include cleanup: ... |
10 |
#include <linux/gfp.h> |
9a74af213 nfsd: Move privat... |
11 12 |
#include "cache.h" #include "xdr3.h" |
0a3adadee nfsd: make fs/nfs... |
13 |
#include "vfs.h" |
a257cdd0e [PATCH] NFSD: Add... |
14 15 16 17 18 19 20 |
#define NFSDDBG_FACILITY NFSDDBG_PROC #define RETURN_STATUS(st) { resp->status = (st); return (st); } /* * NULL call. */ |
7111c66e4 [PATCH] fix svc_p... |
21 |
static __be32 |
a6beb7327 sunrpc: properly ... |
22 |
nfsacld_proc_null(struct svc_rqst *rqstp) |
a257cdd0e [PATCH] NFSD: Add... |
23 24 25 26 27 28 29 |
{ return nfs_ok; } /* * Get the Access and/or Default ACL of a file. */ |
a6beb7327 sunrpc: properly ... |
30 |
static __be32 nfsacld_proc_getacl(struct svc_rqst *rqstp) |
a257cdd0e [PATCH] NFSD: Add... |
31 |
{ |
a6beb7327 sunrpc: properly ... |
32 33 |
struct nfsd3_getaclargs *argp = rqstp->rq_argp; struct nfsd3_getaclres *resp = rqstp->rq_resp; |
a257cdd0e [PATCH] NFSD: Add... |
34 |
struct posix_acl *acl; |
4ac7249ea nfsd: use get_acl... |
35 36 |
struct inode *inode; svc_fh *fh; |
c4d987ba8 [PATCH] nfsd: NFS... |
37 |
__be32 nfserr = 0; |
a257cdd0e [PATCH] NFSD: Add... |
38 39 40 41 42 |
dprintk("nfsd: GETACL(2acl) %s ", SVCFH_fmt(&argp->fh)); fh = fh_copy(&resp->fh, &argp->fh); |
8837abcab nfsd: rename MAY_... |
43 44 |
nfserr = fh_verify(rqstp, &resp->fh, 0, NFSD_MAY_NOP); if (nfserr) |
ac8587dcb knfsd: fix spurio... |
45 |
RETURN_STATUS(nfserr); |
a257cdd0e [PATCH] NFSD: Add... |
46 |
|
2b0143b5c VFS: normal files... |
47 |
inode = d_inode(fh->fh_dentry); |
4ac7249ea nfsd: use get_acl... |
48 |
|
7b8f45865 nfsd: Add macro N... |
49 |
if (argp->mask & ~NFS_ACL_MASK) |
a257cdd0e [PATCH] NFSD: Add... |
50 51 |
RETURN_STATUS(nfserr_inval); resp->mask = argp->mask; |
4f4a4fadd nfsd: handle vfs_... |
52 53 |
nfserr = fh_getattr(fh, &resp->stat); if (nfserr) |
7b8f45865 nfsd: Add macro N... |
54 |
RETURN_STATUS(nfserr); |
4f4a4fadd nfsd: handle vfs_... |
55 |
|
a257cdd0e [PATCH] NFSD: Add... |
56 |
if (resp->mask & (NFS_ACL|NFS_ACLCNT)) { |
4ac7249ea nfsd: use get_acl... |
57 |
acl = get_acl(inode, ACL_TYPE_ACCESS); |
a257cdd0e [PATCH] NFSD: Add... |
58 59 |
if (acl == NULL) { /* Solaris returns the inode's minimum ACL. */ |
a257cdd0e [PATCH] NFSD: Add... |
60 61 |
acl = posix_acl_from_mode(inode->i_mode, GFP_KERNEL); } |
35e634b83 NFSD: Check acl r... |
62 63 64 65 |
if (IS_ERR(acl)) { nfserr = nfserrno(PTR_ERR(acl)); goto fail; } |
a257cdd0e [PATCH] NFSD: Add... |
66 67 68 69 70 |
resp->acl_access = acl; } if (resp->mask & (NFS_DFACL|NFS_DFACLCNT)) { /* Check how Solaris handles requests for the Default ACL of a non-directory! */ |
4ac7249ea nfsd: use get_acl... |
71 |
acl = get_acl(inode, ACL_TYPE_DEFAULT); |
a257cdd0e [PATCH] NFSD: Add... |
72 |
if (IS_ERR(acl)) { |
4ac7249ea nfsd: use get_acl... |
73 74 |
nfserr = nfserrno(PTR_ERR(acl)); goto fail; |
a257cdd0e [PATCH] NFSD: Add... |
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
} resp->acl_default = acl; } /* resp->acl_{access,default} are released in nfssvc_release_getacl. */ RETURN_STATUS(0); fail: posix_acl_release(resp->acl_access); posix_acl_release(resp->acl_default); RETURN_STATUS(nfserr); } /* * Set the Access and/or Default ACL of a file. */ |
a6beb7327 sunrpc: properly ... |
91 |
static __be32 nfsacld_proc_setacl(struct svc_rqst *rqstp) |
a257cdd0e [PATCH] NFSD: Add... |
92 |
{ |
a6beb7327 sunrpc: properly ... |
93 94 |
struct nfsd3_setaclargs *argp = rqstp->rq_argp; struct nfsd_attrstat *resp = rqstp->rq_resp; |
4ac7249ea nfsd: use get_acl... |
95 |
struct inode *inode; |
a257cdd0e [PATCH] NFSD: Add... |
96 |
svc_fh *fh; |
c4d987ba8 [PATCH] nfsd: NFS... |
97 |
__be32 nfserr = 0; |
4ac7249ea nfsd: use get_acl... |
98 |
int error; |
a257cdd0e [PATCH] NFSD: Add... |
99 100 101 102 103 |
dprintk("nfsd: SETACL(2acl) %s ", SVCFH_fmt(&argp->fh)); fh = fh_copy(&resp->fh, &argp->fh); |
8837abcab nfsd: rename MAY_... |
104 |
nfserr = fh_verify(rqstp, &resp->fh, 0, NFSD_MAY_SATTR); |
4ac7249ea nfsd: use get_acl... |
105 106 |
if (nfserr) goto out; |
a257cdd0e [PATCH] NFSD: Add... |
107 |
|
2b0143b5c VFS: normal files... |
108 |
inode = d_inode(fh->fh_dentry); |
a257cdd0e [PATCH] NFSD: Add... |
109 |
|
4ac7249ea nfsd: use get_acl... |
110 111 112 |
error = fh_want_write(fh); if (error) goto out_errno; |
999653786 nfsd: check permi... |
113 114 115 |
fh_lock(fh); error = set_posix_acl(inode, ACL_TYPE_ACCESS, argp->acl_access); |
4ac7249ea nfsd: use get_acl... |
116 |
if (error) |
999653786 nfsd: check permi... |
117 118 |
goto out_drop_lock; error = set_posix_acl(inode, ACL_TYPE_DEFAULT, argp->acl_default); |
4ac7249ea nfsd: use get_acl... |
119 |
if (error) |
999653786 nfsd: check permi... |
120 121 122 |
goto out_drop_lock; fh_unlock(fh); |
4ac7249ea nfsd: use get_acl... |
123 124 125 126 127 128 |
fh_drop_write(fh); nfserr = fh_getattr(fh, &resp->stat); out: |
a257cdd0e [PATCH] NFSD: Add... |
129 130 131 132 133 |
/* argp->acl_{access,default} may have been allocated in nfssvc_decode_setaclargs. */ posix_acl_release(argp->acl_access); posix_acl_release(argp->acl_default); return nfserr; |
999653786 nfsd: check permi... |
134 135 |
out_drop_lock: fh_unlock(fh); |
4ac7249ea nfsd: use get_acl... |
136 137 138 139 |
fh_drop_write(fh); out_errno: nfserr = nfserrno(error); goto out; |
a257cdd0e [PATCH] NFSD: Add... |
140 141 142 143 144 |
} /* * Check file attributes */ |
a6beb7327 sunrpc: properly ... |
145 |
static __be32 nfsacld_proc_getattr(struct svc_rqst *rqstp) |
a257cdd0e [PATCH] NFSD: Add... |
146 |
{ |
a6beb7327 sunrpc: properly ... |
147 148 |
struct nfsd_fhandle *argp = rqstp->rq_argp; struct nfsd_attrstat *resp = rqstp->rq_resp; |
4f4a4fadd nfsd: handle vfs_... |
149 |
__be32 nfserr; |
a257cdd0e [PATCH] NFSD: Add... |
150 151 152 153 |
dprintk("nfsd: GETATTR %s ", SVCFH_fmt(&argp->fh)); fh_copy(&resp->fh, &argp->fh); |
4f4a4fadd nfsd: handle vfs_... |
154 155 156 157 158 |
nfserr = fh_verify(rqstp, &resp->fh, 0, NFSD_MAY_NOP); if (nfserr) return nfserr; nfserr = fh_getattr(&resp->fh, &resp->stat); return nfserr; |
a257cdd0e [PATCH] NFSD: Add... |
159 160 161 162 163 |
} /* * Check file access */ |
a6beb7327 sunrpc: properly ... |
164 |
static __be32 nfsacld_proc_access(struct svc_rqst *rqstp) |
a257cdd0e [PATCH] NFSD: Add... |
165 |
{ |
a6beb7327 sunrpc: properly ... |
166 167 |
struct nfsd3_accessargs *argp = rqstp->rq_argp; struct nfsd3_accessres *resp = rqstp->rq_resp; |
c4d987ba8 [PATCH] nfsd: NFS... |
168 |
__be32 nfserr; |
a257cdd0e [PATCH] NFSD: Add... |
169 170 171 172 173 174 175 176 177 |
dprintk("nfsd: ACCESS(2acl) %s 0x%x ", SVCFH_fmt(&argp->fh), argp->access); fh_copy(&resp->fh, &argp->fh); resp->access = argp->access; nfserr = nfsd_access(rqstp, &resp->fh, &resp->access, NULL); |
4f4a4fadd nfsd: handle vfs_... |
178 179 180 |
if (nfserr) return nfserr; nfserr = fh_getattr(&resp->fh, &resp->stat); |
a257cdd0e [PATCH] NFSD: Add... |
181 182 183 184 185 186 |
return nfserr; } /* * XDR decode functions */ |
026fec7e7 sunrpc: properly ... |
187 |
static int nfsaclsvc_decode_getaclargs(struct svc_rqst *rqstp, __be32 *p) |
a257cdd0e [PATCH] NFSD: Add... |
188 |
{ |
026fec7e7 sunrpc: properly ... |
189 |
struct nfsd3_getaclargs *argp = rqstp->rq_argp; |
d40aa3372 nfsd: Remove assi... |
190 191 |
p = nfs2svc_decode_fh(p, &argp->fh); if (!p) |
a257cdd0e [PATCH] NFSD: Add... |
192 193 194 195 196 |
return 0; argp->mask = ntohl(*p); p++; return xdr_argsize_check(rqstp, p); } |
026fec7e7 sunrpc: properly ... |
197 |
static int nfsaclsvc_decode_setaclargs(struct svc_rqst *rqstp, __be32 *p) |
a257cdd0e [PATCH] NFSD: Add... |
198 |
{ |
026fec7e7 sunrpc: properly ... |
199 |
struct nfsd3_setaclargs *argp = rqstp->rq_argp; |
a257cdd0e [PATCH] NFSD: Add... |
200 201 202 |
struct kvec *head = rqstp->rq_arg.head; unsigned int base; int n; |
d40aa3372 nfsd: Remove assi... |
203 204 |
p = nfs2svc_decode_fh(p, &argp->fh); if (!p) |
a257cdd0e [PATCH] NFSD: Add... |
205 206 |
return 0; argp->mask = ntohl(*p++); |
7b8f45865 nfsd: Add macro N... |
207 |
if (argp->mask & ~NFS_ACL_MASK || |
a257cdd0e [PATCH] NFSD: Add... |
208 209 210 211 212 213 214 215 216 217 218 219 220 |
!xdr_argsize_check(rqstp, p)) return 0; base = (char *)p - (char *)head->iov_base; n = nfsacl_decode(&rqstp->rq_arg, base, NULL, (argp->mask & NFS_ACL) ? &argp->acl_access : NULL); if (n > 0) n = nfsacl_decode(&rqstp->rq_arg, base + n, NULL, (argp->mask & NFS_DFACL) ? &argp->acl_default : NULL); return (n > 0); } |
026fec7e7 sunrpc: properly ... |
221 |
static int nfsaclsvc_decode_fhandleargs(struct svc_rqst *rqstp, __be32 *p) |
a257cdd0e [PATCH] NFSD: Add... |
222 |
{ |
026fec7e7 sunrpc: properly ... |
223 |
struct nfsd_fhandle *argp = rqstp->rq_argp; |
d40aa3372 nfsd: Remove assi... |
224 225 |
p = nfs2svc_decode_fh(p, &argp->fh); if (!p) |
a257cdd0e [PATCH] NFSD: Add... |
226 227 228 |
return 0; return xdr_argsize_check(rqstp, p); } |
026fec7e7 sunrpc: properly ... |
229 |
static int nfsaclsvc_decode_accessargs(struct svc_rqst *rqstp, __be32 *p) |
a257cdd0e [PATCH] NFSD: Add... |
230 |
{ |
026fec7e7 sunrpc: properly ... |
231 |
struct nfsd3_accessargs *argp = rqstp->rq_argp; |
d40aa3372 nfsd: Remove assi... |
232 233 |
p = nfs2svc_decode_fh(p, &argp->fh); if (!p) |
a257cdd0e [PATCH] NFSD: Add... |
234 235 236 237 238 239 240 241 242 |
return 0; argp->access = ntohl(*p++); return xdr_argsize_check(rqstp, p); } /* * XDR encode functions */ |
1b7e0403c nfsd: register NF... |
243 244 245 246 |
/* * There must be an encoding function for void results so svc_process * will work properly. */ |
63f8de379 sunrpc: properly ... |
247 |
static int nfsaclsvc_encode_voidres(struct svc_rqst *rqstp, __be32 *p) |
1b7e0403c nfsd: register NF... |
248 249 250 |
{ return xdr_ressize_check(rqstp, p); } |
a257cdd0e [PATCH] NFSD: Add... |
251 |
/* GETACL */ |
63f8de379 sunrpc: properly ... |
252 |
static int nfsaclsvc_encode_getaclres(struct svc_rqst *rqstp, __be32 *p) |
a257cdd0e [PATCH] NFSD: Add... |
253 |
{ |
63f8de379 sunrpc: properly ... |
254 |
struct nfsd3_getaclres *resp = rqstp->rq_resp; |
a257cdd0e [PATCH] NFSD: Add... |
255 |
struct dentry *dentry = resp->fh.fh_dentry; |
aefa89d17 nfsd: Fix inconsi... |
256 |
struct inode *inode; |
a257cdd0e [PATCH] NFSD: Add... |
257 258 259 |
struct kvec *head = rqstp->rq_res.head; unsigned int base; int n; |
cb65a5ba3 [PATCH] NFS2: Cal... |
260 |
int w; |
a257cdd0e [PATCH] NFSD: Add... |
261 |
|
aefa89d17 nfsd: Fix inconsi... |
262 263 264 265 266 |
/* * Since this is version 2, the check for nfserr in * nfsd_dispatch actually ensures the following cannot happen. * However, it seems fragile to depend on that. */ |
2b0143b5c VFS: normal files... |
267 |
if (dentry == NULL || d_really_is_negative(dentry)) |
a257cdd0e [PATCH] NFSD: Add... |
268 |
return 0; |
2b0143b5c VFS: normal files... |
269 |
inode = d_inode(dentry); |
a257cdd0e [PATCH] NFSD: Add... |
270 |
|
4f4a4fadd nfsd: handle vfs_... |
271 |
p = nfs2svc_encode_fattr(rqstp, p, &resp->fh, &resp->stat); |
a257cdd0e [PATCH] NFSD: Add... |
272 273 274 275 |
*p++ = htonl(resp->mask); if (!xdr_ressize_check(rqstp, p)) return 0; base = (char *)p - (char *)head->iov_base; |
cb65a5ba3 [PATCH] NFS2: Cal... |
276 277 278 |
rqstp->rq_res.page_len = w = nfsacl_size( (resp->mask & NFS_ACL) ? resp->acl_access : NULL, (resp->mask & NFS_DFACL) ? resp->acl_default : NULL); |
a257cdd0e [PATCH] NFSD: Add... |
279 |
while (w > 0) { |
afc59400d nfsd4: cleanup: r... |
280 |
if (!*(rqstp->rq_next_page++)) |
a257cdd0e [PATCH] NFSD: Add... |
281 282 283 284 285 286 287 288 289 290 291 292 |
return 0; w -= PAGE_SIZE; } n = nfsacl_encode(&rqstp->rq_res, base, inode, resp->acl_access, resp->mask & NFS_ACL, 0); if (n > 0) n = nfsacl_encode(&rqstp->rq_res, base + n, inode, resp->acl_default, resp->mask & NFS_DFACL, NFS_ACL_DEFAULT); |
7b8f45865 nfsd: Add macro N... |
293 |
return (n > 0); |
a257cdd0e [PATCH] NFSD: Add... |
294 |
} |
63f8de379 sunrpc: properly ... |
295 |
static int nfsaclsvc_encode_attrstatres(struct svc_rqst *rqstp, __be32 *p) |
a257cdd0e [PATCH] NFSD: Add... |
296 |
{ |
63f8de379 sunrpc: properly ... |
297 |
struct nfsd_attrstat *resp = rqstp->rq_resp; |
4f4a4fadd nfsd: handle vfs_... |
298 |
p = nfs2svc_encode_fattr(rqstp, p, &resp->fh, &resp->stat); |
a257cdd0e [PATCH] NFSD: Add... |
299 300 301 302 |
return xdr_ressize_check(rqstp, p); } /* ACCESS */ |
63f8de379 sunrpc: properly ... |
303 |
static int nfsaclsvc_encode_accessres(struct svc_rqst *rqstp, __be32 *p) |
a257cdd0e [PATCH] NFSD: Add... |
304 |
{ |
63f8de379 sunrpc: properly ... |
305 |
struct nfsd3_accessres *resp = rqstp->rq_resp; |
4f4a4fadd nfsd: handle vfs_... |
306 |
p = nfs2svc_encode_fattr(rqstp, p, &resp->fh, &resp->stat); |
a257cdd0e [PATCH] NFSD: Add... |
307 308 309 310 311 312 313 |
*p++ = htonl(resp->access); return xdr_ressize_check(rqstp, p); } /* * XDR release functions */ |
8537488b5 sunrpc: properly ... |
314 |
static void nfsaclsvc_release_getacl(struct svc_rqst *rqstp) |
a257cdd0e [PATCH] NFSD: Add... |
315 |
{ |
8537488b5 sunrpc: properly ... |
316 |
struct nfsd3_getaclres *resp = rqstp->rq_resp; |
a257cdd0e [PATCH] NFSD: Add... |
317 318 319 |
fh_put(&resp->fh); posix_acl_release(resp->acl_access); posix_acl_release(resp->acl_default); |
a257cdd0e [PATCH] NFSD: Add... |
320 |
} |
8537488b5 sunrpc: properly ... |
321 |
static void nfsaclsvc_release_attrstat(struct svc_rqst *rqstp) |
a257cdd0e [PATCH] NFSD: Add... |
322 |
{ |
8537488b5 sunrpc: properly ... |
323 |
struct nfsd_attrstat *resp = rqstp->rq_resp; |
a257cdd0e [PATCH] NFSD: Add... |
324 |
fh_put(&resp->fh); |
a257cdd0e [PATCH] NFSD: Add... |
325 |
} |
8537488b5 sunrpc: properly ... |
326 |
static void nfsaclsvc_release_access(struct svc_rqst *rqstp) |
c9ce22830 [PATCH] Fix a fre... |
327 |
{ |
8537488b5 sunrpc: properly ... |
328 329 330 |
struct nfsd3_accessres *resp = rqstp->rq_resp; fh_put(&resp->fh); |
c9ce22830 [PATCH] Fix a fre... |
331 |
} |
a257cdd0e [PATCH] NFSD: Add... |
332 |
#define nfsaclsvc_decode_voidargs NULL |
a257cdd0e [PATCH] NFSD: Add... |
333 334 335 336 337 |
#define nfsaclsvc_release_void NULL #define nfsd3_fhandleargs nfsd_fhandle #define nfsd3_attrstatres nfsd_attrstat #define nfsd3_voidres nfsd3_voidargs struct nfsd3_voidargs { int dummy; }; |
f7235b6bc nfsd: use named i... |
338 339 |
#define PROC(name, argt, rest, relt, cache, respsize) \ { \ |
a6beb7327 sunrpc: properly ... |
340 |
.pc_func = nfsacld_proc_##name, \ |
026fec7e7 sunrpc: properly ... |
341 |
.pc_decode = nfsaclsvc_decode_##argt##args, \ |
63f8de379 sunrpc: properly ... |
342 |
.pc_encode = nfsaclsvc_encode_##rest##res, \ |
8537488b5 sunrpc: properly ... |
343 |
.pc_release = nfsaclsvc_release_##relt, \ |
f7235b6bc nfsd: use named i... |
344 345 346 347 348 |
.pc_argsize = sizeof(struct nfsd3_##argt##args), \ .pc_ressize = sizeof(struct nfsd3_##rest##res), \ .pc_cachetype = cache, \ .pc_xdrressize = respsize, \ } |
a257cdd0e [PATCH] NFSD: Add... |
349 350 351 352 353 |
#define ST 1 /* status*/ #define AT 21 /* attributes */ #define pAT (1+AT) /* post attributes - conditional */ #define ACL (1+NFS_ACL_MAX_ENTRIES*3) /* Access Control List */ |
860bda29b sunrpc: mark all ... |
354 |
static const struct svc_procedure nfsd_acl_procedures2[] = { |
a257cdd0e [PATCH] NFSD: Add... |
355 356 |
PROC(null, void, void, void, RC_NOCACHE, ST), PROC(getacl, getacl, getacl, getacl, RC_NOCACHE, ST+1+2*(1+ACL)), |
c9ce22830 [PATCH] Fix a fre... |
357 358 359 |
PROC(setacl, setacl, attrstat, attrstat, RC_NOCACHE, ST+AT), PROC(getattr, fhandle, attrstat, attrstat, RC_NOCACHE, ST+AT), PROC(access, access, access, access, RC_NOCACHE, ST+AT+1), |
a257cdd0e [PATCH] NFSD: Add... |
360 |
}; |
7fd38af9c sunrpc: move pc_c... |
361 |
static unsigned int nfsd_acl_count2[ARRAY_SIZE(nfsd_acl_procedures2)]; |
e9679189e sunrpc: mark all ... |
362 363 364 365 366 367 368 |
const struct svc_version nfsd_acl_version2 = { .vs_vers = 2, .vs_nproc = 5, .vs_proc = nfsd_acl_procedures2, .vs_count = nfsd_acl_count2, .vs_dispatch = nfsd_dispatch, .vs_xdrsize = NFS3_SVC_XDRSIZE, |
a257cdd0e [PATCH] NFSD: Add... |
369 |
}; |