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