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 |
a6beb732 | 21 | nfsd3_proc_null(struct svc_rqst *rqstp) |
a257cdd0 AG |
22 | { |
23 | return nfs_ok; | |
24 | } | |
25 | ||
26 | /* | |
27 | * Get the Access and/or Default ACL of a file. | |
28 | */ | |
a6beb732 | 29 | static __be32 nfsd3_proc_getacl(struct svc_rqst *rqstp) |
a257cdd0 | 30 | { |
a6beb732 CH |
31 | struct nfsd3_getaclargs *argp = rqstp->rq_argp; |
32 | struct nfsd3_getaclres *resp = rqstp->rq_resp; | |
a257cdd0 | 33 | struct posix_acl *acl; |
4ac7249e CH |
34 | struct inode *inode; |
35 | svc_fh *fh; | |
c4d987ba | 36 | __be32 nfserr = 0; |
a257cdd0 AG |
37 | |
38 | fh = fh_copy(&resp->fh, &argp->fh); | |
8837abca MS |
39 | nfserr = fh_verify(rqstp, &resp->fh, 0, NFSD_MAY_NOP); |
40 | if (nfserr) | |
ac8587dc | 41 | RETURN_STATUS(nfserr); |
a257cdd0 | 42 | |
2b0143b5 | 43 | inode = d_inode(fh->fh_dentry); |
4ac7249e | 44 | |
7b8f4586 | 45 | if (argp->mask & ~NFS_ACL_MASK) |
a257cdd0 AG |
46 | RETURN_STATUS(nfserr_inval); |
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 KM |
55 | if (IS_ERR(acl)) { |
56 | nfserr = nfserrno(PTR_ERR(acl)); | |
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)) { |
4ac7249e CH |
66 | nfserr = nfserrno(PTR_ERR(acl)); |
67 | goto fail; | |
a257cdd0 AG |
68 | } |
69 | resp->acl_default = acl; | |
70 | } | |
71 | ||
72 | /* resp->acl_{access,default} are released in nfs3svc_release_getacl. */ | |
73 | RETURN_STATUS(0); | |
74 | ||
75 | fail: | |
76 | posix_acl_release(resp->acl_access); | |
77 | posix_acl_release(resp->acl_default); | |
78 | RETURN_STATUS(nfserr); | |
79 | } | |
80 | ||
81 | /* | |
82 | * Set the Access and/or Default ACL of a file. | |
83 | */ | |
a6beb732 | 84 | static __be32 nfsd3_proc_setacl(struct svc_rqst *rqstp) |
a257cdd0 | 85 | { |
a6beb732 CH |
86 | struct nfsd3_setaclargs *argp = rqstp->rq_argp; |
87 | struct nfsd3_attrstat *resp = rqstp->rq_resp; | |
4ac7249e | 88 | struct inode *inode; |
a257cdd0 | 89 | svc_fh *fh; |
c4d987ba | 90 | __be32 nfserr = 0; |
4ac7249e | 91 | int error; |
a257cdd0 AG |
92 | |
93 | fh = fh_copy(&resp->fh, &argp->fh); | |
8837abca | 94 | nfserr = fh_verify(rqstp, &resp->fh, 0, NFSD_MAY_SATTR); |
4ac7249e CH |
95 | if (nfserr) |
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 | ||
106 | error = set_posix_acl(inode, ACL_TYPE_ACCESS, argp->acl_access); | |
4ac7249e | 107 | if (error) |
99965378 BH |
108 | goto out_drop_lock; |
109 | error = set_posix_acl(inode, ACL_TYPE_DEFAULT, argp->acl_default); | |
4ac7249e | 110 | |
99965378 BH |
111 | out_drop_lock: |
112 | fh_unlock(fh); | |
4ac7249e CH |
113 | fh_drop_write(fh); |
114 | out_errno: | |
115 | nfserr = nfserrno(error); | |
116 | out: | |
a257cdd0 AG |
117 | /* argp->acl_{access,default} may have been allocated in |
118 | nfs3svc_decode_setaclargs. */ | |
119 | posix_acl_release(argp->acl_access); | |
120 | posix_acl_release(argp->acl_default); | |
121 | RETURN_STATUS(nfserr); | |
122 | } | |
123 | ||
124 | /* | |
125 | * XDR decode functions | |
126 | */ | |
026fec7e | 127 | static int nfs3svc_decode_getaclargs(struct svc_rqst *rqstp, __be32 *p) |
a257cdd0 | 128 | { |
026fec7e CH |
129 | struct nfsd3_getaclargs *args = rqstp->rq_argp; |
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 | ||
026fec7e | 140 | static int nfs3svc_decode_setaclargs(struct svc_rqst *rqstp, __be32 *p) |
a257cdd0 | 141 | { |
026fec7e | 142 | struct nfsd3_setaclargs *args = rqstp->rq_argp; |
a257cdd0 AG |
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 */ | |
63f8de37 | 171 | static int nfs3svc_encode_getaclres(struct svc_rqst *rqstp, __be32 *p) |
a257cdd0 | 172 | { |
63f8de37 | 173 | struct nfsd3_getaclres *resp = rqstp->rq_resp; |
a257cdd0 AG |
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 */ | |
63f8de37 | 216 | static int nfs3svc_encode_setaclres(struct svc_rqst *rqstp, __be32 *p) |
a257cdd0 | 217 | { |
63f8de37 CH |
218 | struct nfsd3_attrstat *resp = rqstp->rq_resp; |
219 | ||
a257cdd0 AG |
220 | p = nfs3svc_encode_post_op_attr(rqstp, p, &resp->fh); |
221 | ||
222 | return xdr_ressize_check(rqstp, p); | |
223 | } | |
224 | ||
225 | /* | |
226 | * XDR release functions | |
227 | */ | |
8537488b | 228 | static void nfs3svc_release_getacl(struct svc_rqst *rqstp) |
a257cdd0 | 229 | { |
8537488b CH |
230 | struct nfsd3_getaclres *resp = rqstp->rq_resp; |
231 | ||
a257cdd0 AG |
232 | fh_put(&resp->fh); |
233 | posix_acl_release(resp->acl_access); | |
234 | posix_acl_release(resp->acl_default); | |
a257cdd0 AG |
235 | } |
236 | ||
237 | #define nfs3svc_decode_voidargs NULL | |
238 | #define nfs3svc_release_void NULL | |
239 | #define nfsd3_setaclres nfsd3_attrstat | |
240 | #define nfsd3_voidres nfsd3_voidargs | |
241 | struct nfsd3_voidargs { int dummy; }; | |
242 | ||
f7235b6b CH |
243 | #define PROC(name, argt, rest, relt, cache, respsize) \ |
244 | { \ | |
a6beb732 | 245 | .pc_func = nfsd3_proc_##name, \ |
026fec7e | 246 | .pc_decode = nfs3svc_decode_##argt##args, \ |
63f8de37 | 247 | .pc_encode = nfs3svc_encode_##rest##res, \ |
8537488b | 248 | .pc_release = nfs3svc_release_##relt, \ |
f7235b6b CH |
249 | .pc_argsize = sizeof(struct nfsd3_##argt##args), \ |
250 | .pc_ressize = sizeof(struct nfsd3_##rest##res), \ | |
251 | .pc_cachetype = cache, \ | |
252 | .pc_xdrressize = respsize, \ | |
253 | } | |
a257cdd0 AG |
254 | |
255 | #define ST 1 /* status*/ | |
256 | #define AT 21 /* attributes */ | |
257 | #define pAT (1+AT) /* post attributes - conditional */ | |
258 | #define ACL (1+NFS_ACL_MAX_ENTRIES*3) /* Access Control List */ | |
259 | ||
260 | static struct svc_procedure nfsd_acl_procedures3[] = { | |
261 | PROC(null, void, void, void, RC_NOCACHE, ST), | |
262 | PROC(getacl, getacl, getacl, getacl, RC_NOCACHE, ST+1+2*(1+ACL)), | |
263 | PROC(setacl, setacl, setacl, fhandle, RC_NOCACHE, ST+pAT), | |
264 | }; | |
265 | ||
266 | struct svc_version nfsd_acl_version3 = { | |
267 | .vs_vers = 3, | |
268 | .vs_nproc = 3, | |
269 | .vs_proc = nfsd_acl_procedures3, | |
270 | .vs_dispatch = nfsd_dispatch, | |
271 | .vs_xdrsize = NFS3_SVC_XDRSIZE, | |
272 | }; | |
273 |