Commit | Line | Data |
---|---|---|
b2441318 | 1 | // SPDX-License-Identifier: GPL-2.0 |
a257cdd0 | 2 | /* |
a257cdd0 AG |
3 | * Process version 3 NFSACL requests. |
4 | * | |
5 | * Copyright (C) 2002-2003 Andreas Gruenbacher <agruen@suse.de> | |
6 | */ | |
7 | ||
9a74af21 BH |
8 | #include "nfsd.h" |
9 | /* FIXME: nfsacl.h is a broken header */ | |
a257cdd0 | 10 | #include <linux/nfsacl.h> |
5a0e3ad6 | 11 | #include <linux/gfp.h> |
9a74af21 BH |
12 | #include "cache.h" |
13 | #include "xdr3.h" | |
0a3adade | 14 | #include "vfs.h" |
a257cdd0 | 15 | |
a257cdd0 AG |
16 | /* |
17 | * NULL call. | |
18 | */ | |
7111c66e | 19 | static __be32 |
a6beb732 | 20 | nfsd3_proc_null(struct svc_rqst *rqstp) |
a257cdd0 | 21 | { |
cc028a10 | 22 | return rpc_success; |
a257cdd0 AG |
23 | } |
24 | ||
25 | /* | |
26 | * Get the Access and/or Default ACL of a file. | |
27 | */ | |
a6beb732 | 28 | static __be32 nfsd3_proc_getacl(struct svc_rqst *rqstp) |
a257cdd0 | 29 | { |
a6beb732 CH |
30 | struct nfsd3_getaclargs *argp = rqstp->rq_argp; |
31 | struct nfsd3_getaclres *resp = rqstp->rq_resp; | |
a257cdd0 | 32 | struct posix_acl *acl; |
4ac7249e CH |
33 | struct inode *inode; |
34 | svc_fh *fh; | |
a257cdd0 AG |
35 | |
36 | fh = fh_copy(&resp->fh, &argp->fh); | |
14168d67 CL |
37 | resp->status = fh_verify(rqstp, &resp->fh, 0, NFSD_MAY_NOP); |
38 | if (resp->status != nfs_ok) | |
39 | goto out; | |
a257cdd0 | 40 | |
2b0143b5 | 41 | inode = d_inode(fh->fh_dentry); |
4ac7249e | 42 | |
14168d67 CL |
43 | if (argp->mask & ~NFS_ACL_MASK) { |
44 | resp->status = nfserr_inval; | |
45 | goto out; | |
46 | } | |
a257cdd0 AG |
47 | resp->mask = argp->mask; |
48 | ||
49 | if (resp->mask & (NFS_ACL|NFS_ACLCNT)) { | |
4ac7249e | 50 | acl = get_acl(inode, ACL_TYPE_ACCESS); |
a257cdd0 AG |
51 | if (acl == NULL) { |
52 | /* Solaris returns the inode's minimum ACL. */ | |
a257cdd0 AG |
53 | acl = posix_acl_from_mode(inode->i_mode, GFP_KERNEL); |
54 | } | |
35e634b8 | 55 | if (IS_ERR(acl)) { |
14168d67 | 56 | resp->status = nfserrno(PTR_ERR(acl)); |
35e634b8 KM |
57 | goto fail; |
58 | } | |
a257cdd0 AG |
59 | resp->acl_access = acl; |
60 | } | |
61 | if (resp->mask & (NFS_DFACL|NFS_DFACLCNT)) { | |
62 | /* Check how Solaris handles requests for the Default ACL | |
63 | of a non-directory! */ | |
4ac7249e | 64 | acl = get_acl(inode, ACL_TYPE_DEFAULT); |
a257cdd0 | 65 | if (IS_ERR(acl)) { |
14168d67 | 66 | resp->status = nfserrno(PTR_ERR(acl)); |
4ac7249e | 67 | goto fail; |
a257cdd0 AG |
68 | } |
69 | resp->acl_default = acl; | |
70 | } | |
71 | ||
72 | /* resp->acl_{access,default} are released in nfs3svc_release_getacl. */ | |
14168d67 | 73 | out: |
cc028a10 | 74 | return rpc_success; |
a257cdd0 AG |
75 | |
76 | fail: | |
77 | posix_acl_release(resp->acl_access); | |
78 | posix_acl_release(resp->acl_default); | |
14168d67 | 79 | goto out; |
a257cdd0 AG |
80 | } |
81 | ||
82 | /* | |
83 | * Set the Access and/or Default ACL of a file. | |
84 | */ | |
a6beb732 | 85 | static __be32 nfsd3_proc_setacl(struct svc_rqst *rqstp) |
a257cdd0 | 86 | { |
a6beb732 CH |
87 | struct nfsd3_setaclargs *argp = rqstp->rq_argp; |
88 | struct nfsd3_attrstat *resp = rqstp->rq_resp; | |
4ac7249e | 89 | struct inode *inode; |
a257cdd0 | 90 | svc_fh *fh; |
4ac7249e | 91 | int error; |
a257cdd0 AG |
92 | |
93 | fh = fh_copy(&resp->fh, &argp->fh); | |
14168d67 CL |
94 | resp->status = fh_verify(rqstp, &resp->fh, 0, NFSD_MAY_SATTR); |
95 | if (resp->status != nfs_ok) | |
4ac7249e | 96 | goto out; |
a257cdd0 | 97 | |
2b0143b5 | 98 | inode = d_inode(fh->fh_dentry); |
a257cdd0 | 99 | |
4ac7249e CH |
100 | error = fh_want_write(fh); |
101 | if (error) | |
102 | goto out_errno; | |
103 | ||
99965378 BH |
104 | fh_lock(fh); |
105 | ||
e65ce2a5 CB |
106 | error = set_posix_acl(&init_user_ns, inode, ACL_TYPE_ACCESS, |
107 | argp->acl_access); | |
4ac7249e | 108 | if (error) |
99965378 | 109 | goto out_drop_lock; |
e65ce2a5 CB |
110 | error = set_posix_acl(&init_user_ns, inode, ACL_TYPE_DEFAULT, |
111 | argp->acl_default); | |
4ac7249e | 112 | |
99965378 BH |
113 | out_drop_lock: |
114 | fh_unlock(fh); | |
4ac7249e CH |
115 | fh_drop_write(fh); |
116 | out_errno: | |
14168d67 | 117 | resp->status = nfserrno(error); |
4ac7249e | 118 | out: |
a257cdd0 AG |
119 | /* argp->acl_{access,default} may have been allocated in |
120 | nfs3svc_decode_setaclargs. */ | |
121 | posix_acl_release(argp->acl_access); | |
122 | posix_acl_release(argp->acl_default); | |
cc028a10 | 123 | return rpc_success; |
a257cdd0 AG |
124 | } |
125 | ||
126 | /* | |
127 | * XDR decode functions | |
128 | */ | |
026fec7e | 129 | static int nfs3svc_decode_getaclargs(struct svc_rqst *rqstp, __be32 *p) |
a257cdd0 | 130 | { |
026fec7e CH |
131 | struct nfsd3_getaclargs *args = rqstp->rq_argp; |
132 | ||
d40aa337 BT |
133 | p = nfs3svc_decode_fh(p, &args->fh); |
134 | if (!p) | |
a257cdd0 AG |
135 | return 0; |
136 | args->mask = ntohl(*p); p++; | |
137 | ||
138 | return xdr_argsize_check(rqstp, p); | |
139 | } | |
140 | ||
141 | ||
026fec7e | 142 | static int nfs3svc_decode_setaclargs(struct svc_rqst *rqstp, __be32 *p) |
a257cdd0 | 143 | { |
026fec7e | 144 | struct nfsd3_setaclargs *args = rqstp->rq_argp; |
a257cdd0 AG |
145 | struct kvec *head = rqstp->rq_arg.head; |
146 | unsigned int base; | |
147 | int n; | |
148 | ||
d40aa337 BT |
149 | p = nfs3svc_decode_fh(p, &args->fh); |
150 | if (!p) | |
a257cdd0 AG |
151 | return 0; |
152 | args->mask = ntohl(*p++); | |
7b8f4586 | 153 | if (args->mask & ~NFS_ACL_MASK || |
a257cdd0 AG |
154 | !xdr_argsize_check(rqstp, p)) |
155 | return 0; | |
156 | ||
157 | base = (char *)p - (char *)head->iov_base; | |
158 | n = nfsacl_decode(&rqstp->rq_arg, base, NULL, | |
159 | (args->mask & NFS_ACL) ? | |
160 | &args->acl_access : NULL); | |
161 | if (n > 0) | |
162 | n = nfsacl_decode(&rqstp->rq_arg, base + n, NULL, | |
163 | (args->mask & NFS_DFACL) ? | |
164 | &args->acl_default : NULL); | |
165 | return (n > 0); | |
166 | } | |
167 | ||
168 | /* | |
169 | * XDR encode functions | |
170 | */ | |
171 | ||
172 | /* GETACL */ | |
63f8de37 | 173 | static int nfs3svc_encode_getaclres(struct svc_rqst *rqstp, __be32 *p) |
a257cdd0 | 174 | { |
63f8de37 | 175 | struct nfsd3_getaclres *resp = rqstp->rq_resp; |
a257cdd0 AG |
176 | struct dentry *dentry = resp->fh.fh_dentry; |
177 | ||
cc028a10 | 178 | *p++ = resp->status; |
a257cdd0 | 179 | p = nfs3svc_encode_post_op_attr(rqstp, p, &resp->fh); |
2b0143b5 DH |
180 | if (resp->status == 0 && dentry && d_really_is_positive(dentry)) { |
181 | struct inode *inode = d_inode(dentry); | |
a257cdd0 AG |
182 | struct kvec *head = rqstp->rq_res.head; |
183 | unsigned int base; | |
184 | int n; | |
14d2b59e | 185 | int w; |
a257cdd0 AG |
186 | |
187 | *p++ = htonl(resp->mask); | |
188 | if (!xdr_ressize_check(rqstp, p)) | |
189 | return 0; | |
190 | base = (char *)p - (char *)head->iov_base; | |
191 | ||
14d2b59e JJ |
192 | rqstp->rq_res.page_len = w = nfsacl_size( |
193 | (resp->mask & NFS_ACL) ? resp->acl_access : NULL, | |
194 | (resp->mask & NFS_DFACL) ? resp->acl_default : NULL); | |
a257cdd0 | 195 | while (w > 0) { |
afc59400 | 196 | if (!*(rqstp->rq_next_page++)) |
a257cdd0 AG |
197 | return 0; |
198 | w -= PAGE_SIZE; | |
199 | } | |
200 | ||
201 | n = nfsacl_encode(&rqstp->rq_res, base, inode, | |
202 | resp->acl_access, | |
203 | resp->mask & NFS_ACL, 0); | |
204 | if (n > 0) | |
205 | n = nfsacl_encode(&rqstp->rq_res, base + n, inode, | |
206 | resp->acl_default, | |
207 | resp->mask & NFS_DFACL, | |
208 | NFS_ACL_DEFAULT); | |
209 | if (n <= 0) | |
210 | return 0; | |
211 | } else | |
212 | if (!xdr_ressize_check(rqstp, p)) | |
213 | return 0; | |
214 | ||
215 | return 1; | |
216 | } | |
217 | ||
218 | /* SETACL */ | |
63f8de37 | 219 | static int nfs3svc_encode_setaclres(struct svc_rqst *rqstp, __be32 *p) |
a257cdd0 | 220 | { |
63f8de37 CH |
221 | struct nfsd3_attrstat *resp = rqstp->rq_resp; |
222 | ||
cc028a10 | 223 | *p++ = resp->status; |
a257cdd0 | 224 | p = nfs3svc_encode_post_op_attr(rqstp, p, &resp->fh); |
a257cdd0 AG |
225 | return xdr_ressize_check(rqstp, p); |
226 | } | |
227 | ||
228 | /* | |
229 | * XDR release functions | |
230 | */ | |
8537488b | 231 | static void nfs3svc_release_getacl(struct svc_rqst *rqstp) |
a257cdd0 | 232 | { |
8537488b CH |
233 | struct nfsd3_getaclres *resp = rqstp->rq_resp; |
234 | ||
a257cdd0 AG |
235 | fh_put(&resp->fh); |
236 | posix_acl_release(resp->acl_access); | |
237 | posix_acl_release(resp->acl_default); | |
a257cdd0 AG |
238 | } |
239 | ||
a257cdd0 AG |
240 | struct nfsd3_voidargs { int dummy; }; |
241 | ||
a257cdd0 AG |
242 | #define ST 1 /* status*/ |
243 | #define AT 21 /* attributes */ | |
244 | #define pAT (1+AT) /* post attributes - conditional */ | |
245 | #define ACL (1+NFS_ACL_MAX_ENTRIES*3) /* Access Control List */ | |
246 | ||
ba1df797 CL |
247 | static const struct svc_procedure nfsd_acl_procedures3[3] = { |
248 | [ACLPROC3_NULL] = { | |
249 | .pc_func = nfsd3_proc_null, | |
788f7183 CL |
250 | .pc_decode = nfssvc_decode_voidarg, |
251 | .pc_encode = nfssvc_encode_voidres, | |
252 | .pc_argsize = sizeof(struct nfsd_voidargs), | |
253 | .pc_ressize = sizeof(struct nfsd_voidres), | |
ba1df797 CL |
254 | .pc_cachetype = RC_NOCACHE, |
255 | .pc_xdrressize = ST, | |
256 | }, | |
257 | [ACLPROC3_GETACL] = { | |
258 | .pc_func = nfsd3_proc_getacl, | |
259 | .pc_decode = nfs3svc_decode_getaclargs, | |
260 | .pc_encode = nfs3svc_encode_getaclres, | |
261 | .pc_release = nfs3svc_release_getacl, | |
262 | .pc_argsize = sizeof(struct nfsd3_getaclargs), | |
263 | .pc_ressize = sizeof(struct nfsd3_getaclres), | |
264 | .pc_cachetype = RC_NOCACHE, | |
265 | .pc_xdrressize = ST+1+2*(1+ACL), | |
266 | }, | |
267 | [ACLPROC3_SETACL] = { | |
268 | .pc_func = nfsd3_proc_setacl, | |
269 | .pc_decode = nfs3svc_decode_setaclargs, | |
270 | .pc_encode = nfs3svc_encode_setaclres, | |
271 | .pc_release = nfs3svc_release_fhandle, | |
272 | .pc_argsize = sizeof(struct nfsd3_setaclargs), | |
273 | .pc_ressize = sizeof(struct nfsd3_attrstat), | |
274 | .pc_cachetype = RC_NOCACHE, | |
275 | .pc_xdrressize = ST+pAT, | |
276 | }, | |
a257cdd0 AG |
277 | }; |
278 | ||
7fd38af9 | 279 | static unsigned int nfsd_acl_count3[ARRAY_SIZE(nfsd_acl_procedures3)]; |
e9679189 CH |
280 | const struct svc_version nfsd_acl_version3 = { |
281 | .vs_vers = 3, | |
282 | .vs_nproc = 3, | |
283 | .vs_proc = nfsd_acl_procedures3, | |
284 | .vs_count = nfsd_acl_count3, | |
285 | .vs_dispatch = nfsd_dispatch, | |
286 | .vs_xdrsize = NFS3_SVC_XDRSIZE, | |
a257cdd0 AG |
287 | }; |
288 |