Andreas Gruenbacher | a257cdd | 2005-06-22 17:16:26 +0000 | [diff] [blame] | 1 | /* |
Uwe Zeisberger | f30c226 | 2006-10-03 23:01:26 +0200 | [diff] [blame] | 2 | * linux/fs/nfsd/nfs2acl.c |
Andreas Gruenbacher | a257cdd | 2005-06-22 17:16:26 +0000 | [diff] [blame] | 3 | * |
| 4 | * Process version 2 NFSACL requests. |
| 5 | * |
| 6 | * Copyright (C) 2002-2003 Andreas Gruenbacher <agruen@suse.de> |
| 7 | */ |
| 8 | |
Boaz Harrosh | 9a74af2 | 2009-12-03 20:30:56 +0200 | [diff] [blame] | 9 | #include "nfsd.h" |
| 10 | /* FIXME: nfsacl.h is a broken header */ |
Andreas Gruenbacher | a257cdd | 2005-06-22 17:16:26 +0000 | [diff] [blame] | 11 | #include <linux/nfsacl.h> |
Boaz Harrosh | 9a74af2 | 2009-12-03 20:30:56 +0200 | [diff] [blame] | 12 | #include "cache.h" |
| 13 | #include "xdr3.h" |
J. Bruce Fields | 0a3adad | 2009-11-04 18:12:35 -0500 | [diff] [blame] | 14 | #include "vfs.h" |
Andreas Gruenbacher | a257cdd | 2005-06-22 17:16:26 +0000 | [diff] [blame] | 15 | |
| 16 | #define NFSDDBG_FACILITY NFSDDBG_PROC |
| 17 | #define RETURN_STATUS(st) { resp->status = (st); return (st); } |
| 18 | |
| 19 | /* |
| 20 | * NULL call. |
| 21 | */ |
Al Viro | 7111c66 | 2006-10-19 23:28:45 -0700 | [diff] [blame] | 22 | static __be32 |
Andreas Gruenbacher | a257cdd | 2005-06-22 17:16:26 +0000 | [diff] [blame] | 23 | nfsacld_proc_null(struct svc_rqst *rqstp, void *argp, void *resp) |
| 24 | { |
| 25 | return nfs_ok; |
| 26 | } |
| 27 | |
| 28 | /* |
| 29 | * Get the Access and/or Default ACL of a file. |
| 30 | */ |
Al Viro | 7111c66 | 2006-10-19 23:28:45 -0700 | [diff] [blame] | 31 | static __be32 nfsacld_proc_getacl(struct svc_rqst * rqstp, |
Andreas Gruenbacher | a257cdd | 2005-06-22 17:16:26 +0000 | [diff] [blame] | 32 | struct nfsd3_getaclargs *argp, struct nfsd3_getaclres *resp) |
| 33 | { |
| 34 | svc_fh *fh; |
| 35 | struct posix_acl *acl; |
Al Viro | c4d987b | 2006-10-19 23:29:00 -0700 | [diff] [blame] | 36 | __be32 nfserr = 0; |
Andreas Gruenbacher | a257cdd | 2005-06-22 17:16:26 +0000 | [diff] [blame] | 37 | |
| 38 | dprintk("nfsd: GETACL(2acl) %s\n", SVCFH_fmt(&argp->fh)); |
| 39 | |
| 40 | fh = fh_copy(&resp->fh, &argp->fh); |
Miklos Szeredi | 8837abc | 2008-06-16 13:20:29 +0200 | [diff] [blame] | 41 | nfserr = fh_verify(rqstp, &resp->fh, 0, NFSD_MAY_NOP); |
| 42 | if (nfserr) |
J. Bruce Fields | ac8587d | 2007-11-12 16:05:02 -0500 | [diff] [blame] | 43 | RETURN_STATUS(nfserr); |
Andreas Gruenbacher | a257cdd | 2005-06-22 17:16:26 +0000 | [diff] [blame] | 44 | |
| 45 | if (argp->mask & ~(NFS_ACL|NFS_ACLCNT|NFS_DFACL|NFS_DFACLCNT)) |
| 46 | RETURN_STATUS(nfserr_inval); |
| 47 | resp->mask = argp->mask; |
| 48 | |
| 49 | if (resp->mask & (NFS_ACL|NFS_ACLCNT)) { |
| 50 | acl = nfsd_get_posix_acl(fh, ACL_TYPE_ACCESS); |
| 51 | if (IS_ERR(acl)) { |
| 52 | int err = PTR_ERR(acl); |
| 53 | |
| 54 | if (err == -ENODATA || err == -EOPNOTSUPP) |
| 55 | acl = NULL; |
| 56 | else { |
| 57 | nfserr = nfserrno(err); |
| 58 | goto fail; |
| 59 | } |
| 60 | } |
| 61 | if (acl == NULL) { |
| 62 | /* Solaris returns the inode's minimum ACL. */ |
| 63 | |
| 64 | struct inode *inode = fh->fh_dentry->d_inode; |
| 65 | acl = posix_acl_from_mode(inode->i_mode, GFP_KERNEL); |
| 66 | } |
| 67 | resp->acl_access = acl; |
| 68 | } |
| 69 | if (resp->mask & (NFS_DFACL|NFS_DFACLCNT)) { |
| 70 | /* Check how Solaris handles requests for the Default ACL |
| 71 | of a non-directory! */ |
| 72 | |
| 73 | acl = nfsd_get_posix_acl(fh, ACL_TYPE_DEFAULT); |
| 74 | if (IS_ERR(acl)) { |
| 75 | int err = PTR_ERR(acl); |
| 76 | |
| 77 | if (err == -ENODATA || err == -EOPNOTSUPP) |
| 78 | acl = NULL; |
| 79 | else { |
| 80 | nfserr = nfserrno(err); |
| 81 | goto fail; |
| 82 | } |
| 83 | } |
| 84 | resp->acl_default = acl; |
| 85 | } |
| 86 | |
| 87 | /* resp->acl_{access,default} are released in nfssvc_release_getacl. */ |
| 88 | RETURN_STATUS(0); |
| 89 | |
| 90 | fail: |
| 91 | posix_acl_release(resp->acl_access); |
| 92 | posix_acl_release(resp->acl_default); |
| 93 | RETURN_STATUS(nfserr); |
| 94 | } |
| 95 | |
| 96 | /* |
| 97 | * Set the Access and/or Default ACL of a file. |
| 98 | */ |
Al Viro | 7111c66 | 2006-10-19 23:28:45 -0700 | [diff] [blame] | 99 | static __be32 nfsacld_proc_setacl(struct svc_rqst * rqstp, |
Andreas Gruenbacher | a257cdd | 2005-06-22 17:16:26 +0000 | [diff] [blame] | 100 | struct nfsd3_setaclargs *argp, |
| 101 | struct nfsd_attrstat *resp) |
| 102 | { |
| 103 | svc_fh *fh; |
Al Viro | c4d987b | 2006-10-19 23:29:00 -0700 | [diff] [blame] | 104 | __be32 nfserr = 0; |
Andreas Gruenbacher | a257cdd | 2005-06-22 17:16:26 +0000 | [diff] [blame] | 105 | |
| 106 | dprintk("nfsd: SETACL(2acl) %s\n", SVCFH_fmt(&argp->fh)); |
| 107 | |
| 108 | fh = fh_copy(&resp->fh, &argp->fh); |
Miklos Szeredi | 8837abc | 2008-06-16 13:20:29 +0200 | [diff] [blame] | 109 | nfserr = fh_verify(rqstp, &resp->fh, 0, NFSD_MAY_SATTR); |
Andreas Gruenbacher | a257cdd | 2005-06-22 17:16:26 +0000 | [diff] [blame] | 110 | |
| 111 | if (!nfserr) { |
| 112 | nfserr = nfserrno( nfsd_set_posix_acl( |
| 113 | fh, ACL_TYPE_ACCESS, argp->acl_access) ); |
| 114 | } |
| 115 | if (!nfserr) { |
| 116 | nfserr = nfserrno( nfsd_set_posix_acl( |
| 117 | fh, ACL_TYPE_DEFAULT, argp->acl_default) ); |
| 118 | } |
| 119 | |
| 120 | /* argp->acl_{access,default} may have been allocated in |
| 121 | nfssvc_decode_setaclargs. */ |
| 122 | posix_acl_release(argp->acl_access); |
| 123 | posix_acl_release(argp->acl_default); |
| 124 | return nfserr; |
| 125 | } |
| 126 | |
| 127 | /* |
| 128 | * Check file attributes |
| 129 | */ |
Al Viro | 7111c66 | 2006-10-19 23:28:45 -0700 | [diff] [blame] | 130 | static __be32 nfsacld_proc_getattr(struct svc_rqst * rqstp, |
Andreas Gruenbacher | a257cdd | 2005-06-22 17:16:26 +0000 | [diff] [blame] | 131 | struct nfsd_fhandle *argp, struct nfsd_attrstat *resp) |
| 132 | { |
| 133 | dprintk("nfsd: GETATTR %s\n", SVCFH_fmt(&argp->fh)); |
| 134 | |
| 135 | fh_copy(&resp->fh, &argp->fh); |
Miklos Szeredi | 8837abc | 2008-06-16 13:20:29 +0200 | [diff] [blame] | 136 | return fh_verify(rqstp, &resp->fh, 0, NFSD_MAY_NOP); |
Andreas Gruenbacher | a257cdd | 2005-06-22 17:16:26 +0000 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | /* |
| 140 | * Check file access |
| 141 | */ |
Al Viro | 7111c66 | 2006-10-19 23:28:45 -0700 | [diff] [blame] | 142 | static __be32 nfsacld_proc_access(struct svc_rqst *rqstp, struct nfsd3_accessargs *argp, |
Andreas Gruenbacher | a257cdd | 2005-06-22 17:16:26 +0000 | [diff] [blame] | 143 | struct nfsd3_accessres *resp) |
| 144 | { |
Al Viro | c4d987b | 2006-10-19 23:29:00 -0700 | [diff] [blame] | 145 | __be32 nfserr; |
Andreas Gruenbacher | a257cdd | 2005-06-22 17:16:26 +0000 | [diff] [blame] | 146 | |
| 147 | dprintk("nfsd: ACCESS(2acl) %s 0x%x\n", |
| 148 | SVCFH_fmt(&argp->fh), |
| 149 | argp->access); |
| 150 | |
| 151 | fh_copy(&resp->fh, &argp->fh); |
| 152 | resp->access = argp->access; |
| 153 | nfserr = nfsd_access(rqstp, &resp->fh, &resp->access, NULL); |
| 154 | return nfserr; |
| 155 | } |
| 156 | |
| 157 | /* |
| 158 | * XDR decode functions |
| 159 | */ |
Al Viro | 131a21c | 2006-10-19 23:28:56 -0700 | [diff] [blame] | 160 | static int nfsaclsvc_decode_getaclargs(struct svc_rqst *rqstp, __be32 *p, |
Andreas Gruenbacher | a257cdd | 2005-06-22 17:16:26 +0000 | [diff] [blame] | 161 | struct nfsd3_getaclargs *argp) |
| 162 | { |
| 163 | if (!(p = nfs2svc_decode_fh(p, &argp->fh))) |
| 164 | return 0; |
| 165 | argp->mask = ntohl(*p); p++; |
| 166 | |
| 167 | return xdr_argsize_check(rqstp, p); |
| 168 | } |
| 169 | |
| 170 | |
Al Viro | 131a21c | 2006-10-19 23:28:56 -0700 | [diff] [blame] | 171 | static int nfsaclsvc_decode_setaclargs(struct svc_rqst *rqstp, __be32 *p, |
Andreas Gruenbacher | a257cdd | 2005-06-22 17:16:26 +0000 | [diff] [blame] | 172 | struct nfsd3_setaclargs *argp) |
| 173 | { |
| 174 | struct kvec *head = rqstp->rq_arg.head; |
| 175 | unsigned int base; |
| 176 | int n; |
| 177 | |
| 178 | if (!(p = nfs2svc_decode_fh(p, &argp->fh))) |
| 179 | return 0; |
| 180 | argp->mask = ntohl(*p++); |
| 181 | if (argp->mask & ~(NFS_ACL|NFS_ACLCNT|NFS_DFACL|NFS_DFACLCNT) || |
| 182 | !xdr_argsize_check(rqstp, p)) |
| 183 | return 0; |
| 184 | |
| 185 | base = (char *)p - (char *)head->iov_base; |
| 186 | n = nfsacl_decode(&rqstp->rq_arg, base, NULL, |
| 187 | (argp->mask & NFS_ACL) ? |
| 188 | &argp->acl_access : NULL); |
| 189 | if (n > 0) |
| 190 | n = nfsacl_decode(&rqstp->rq_arg, base + n, NULL, |
| 191 | (argp->mask & NFS_DFACL) ? |
| 192 | &argp->acl_default : NULL); |
| 193 | return (n > 0); |
| 194 | } |
| 195 | |
Al Viro | 131a21c | 2006-10-19 23:28:56 -0700 | [diff] [blame] | 196 | static int nfsaclsvc_decode_fhandleargs(struct svc_rqst *rqstp, __be32 *p, |
Andreas Gruenbacher | a257cdd | 2005-06-22 17:16:26 +0000 | [diff] [blame] | 197 | struct nfsd_fhandle *argp) |
| 198 | { |
| 199 | if (!(p = nfs2svc_decode_fh(p, &argp->fh))) |
| 200 | return 0; |
| 201 | return xdr_argsize_check(rqstp, p); |
| 202 | } |
| 203 | |
Al Viro | 131a21c | 2006-10-19 23:28:56 -0700 | [diff] [blame] | 204 | static int nfsaclsvc_decode_accessargs(struct svc_rqst *rqstp, __be32 *p, |
Andreas Gruenbacher | a257cdd | 2005-06-22 17:16:26 +0000 | [diff] [blame] | 205 | struct nfsd3_accessargs *argp) |
| 206 | { |
| 207 | if (!(p = nfs2svc_decode_fh(p, &argp->fh))) |
| 208 | return 0; |
| 209 | argp->access = ntohl(*p++); |
| 210 | |
| 211 | return xdr_argsize_check(rqstp, p); |
| 212 | } |
| 213 | |
| 214 | /* |
| 215 | * XDR encode functions |
| 216 | */ |
| 217 | |
Peter Staubach | 1b7e040 | 2009-11-02 16:59:07 -0500 | [diff] [blame] | 218 | /* |
| 219 | * There must be an encoding function for void results so svc_process |
| 220 | * will work properly. |
| 221 | */ |
| 222 | int |
| 223 | nfsaclsvc_encode_voidres(struct svc_rqst *rqstp, __be32 *p, void *dummy) |
| 224 | { |
| 225 | return xdr_ressize_check(rqstp, p); |
| 226 | } |
| 227 | |
Andreas Gruenbacher | a257cdd | 2005-06-22 17:16:26 +0000 | [diff] [blame] | 228 | /* GETACL */ |
Al Viro | 131a21c | 2006-10-19 23:28:56 -0700 | [diff] [blame] | 229 | static int nfsaclsvc_encode_getaclres(struct svc_rqst *rqstp, __be32 *p, |
Andreas Gruenbacher | a257cdd | 2005-06-22 17:16:26 +0000 | [diff] [blame] | 230 | struct nfsd3_getaclres *resp) |
| 231 | { |
| 232 | struct dentry *dentry = resp->fh.fh_dentry; |
Prasad P | aefa89d | 2007-10-24 15:14:32 -0500 | [diff] [blame] | 233 | struct inode *inode; |
Andreas Gruenbacher | a257cdd | 2005-06-22 17:16:26 +0000 | [diff] [blame] | 234 | struct kvec *head = rqstp->rq_res.head; |
| 235 | unsigned int base; |
| 236 | int n; |
Jesper Juhl | cb65a5b | 2006-12-08 02:39:39 -0800 | [diff] [blame] | 237 | int w; |
Andreas Gruenbacher | a257cdd | 2005-06-22 17:16:26 +0000 | [diff] [blame] | 238 | |
Prasad P | aefa89d | 2007-10-24 15:14:32 -0500 | [diff] [blame] | 239 | /* |
| 240 | * Since this is version 2, the check for nfserr in |
| 241 | * nfsd_dispatch actually ensures the following cannot happen. |
| 242 | * However, it seems fragile to depend on that. |
| 243 | */ |
Andreas Gruenbacher | a257cdd | 2005-06-22 17:16:26 +0000 | [diff] [blame] | 244 | if (dentry == NULL || dentry->d_inode == NULL) |
| 245 | return 0; |
| 246 | inode = dentry->d_inode; |
| 247 | |
| 248 | p = nfs2svc_encode_fattr(rqstp, p, &resp->fh); |
| 249 | *p++ = htonl(resp->mask); |
| 250 | if (!xdr_ressize_check(rqstp, p)) |
| 251 | return 0; |
| 252 | base = (char *)p - (char *)head->iov_base; |
| 253 | |
Jesper Juhl | cb65a5b | 2006-12-08 02:39:39 -0800 | [diff] [blame] | 254 | rqstp->rq_res.page_len = w = nfsacl_size( |
| 255 | (resp->mask & NFS_ACL) ? resp->acl_access : NULL, |
| 256 | (resp->mask & NFS_DFACL) ? resp->acl_default : NULL); |
Andreas Gruenbacher | a257cdd | 2005-06-22 17:16:26 +0000 | [diff] [blame] | 257 | while (w > 0) { |
NeilBrown | 4452435 | 2006-10-04 02:15:46 -0700 | [diff] [blame] | 258 | if (!rqstp->rq_respages[rqstp->rq_resused++]) |
Andreas Gruenbacher | a257cdd | 2005-06-22 17:16:26 +0000 | [diff] [blame] | 259 | return 0; |
| 260 | w -= PAGE_SIZE; |
| 261 | } |
| 262 | |
| 263 | n = nfsacl_encode(&rqstp->rq_res, base, inode, |
| 264 | resp->acl_access, |
| 265 | resp->mask & NFS_ACL, 0); |
| 266 | if (n > 0) |
| 267 | n = nfsacl_encode(&rqstp->rq_res, base + n, inode, |
| 268 | resp->acl_default, |
| 269 | resp->mask & NFS_DFACL, |
| 270 | NFS_ACL_DEFAULT); |
| 271 | if (n <= 0) |
| 272 | return 0; |
| 273 | return 1; |
| 274 | } |
| 275 | |
Al Viro | 131a21c | 2006-10-19 23:28:56 -0700 | [diff] [blame] | 276 | static int nfsaclsvc_encode_attrstatres(struct svc_rqst *rqstp, __be32 *p, |
Andreas Gruenbacher | a257cdd | 2005-06-22 17:16:26 +0000 | [diff] [blame] | 277 | struct nfsd_attrstat *resp) |
| 278 | { |
| 279 | p = nfs2svc_encode_fattr(rqstp, p, &resp->fh); |
| 280 | return xdr_ressize_check(rqstp, p); |
| 281 | } |
| 282 | |
| 283 | /* ACCESS */ |
Al Viro | 131a21c | 2006-10-19 23:28:56 -0700 | [diff] [blame] | 284 | static int nfsaclsvc_encode_accessres(struct svc_rqst *rqstp, __be32 *p, |
Andreas Gruenbacher | a257cdd | 2005-06-22 17:16:26 +0000 | [diff] [blame] | 285 | struct nfsd3_accessres *resp) |
| 286 | { |
| 287 | p = nfs2svc_encode_fattr(rqstp, p, &resp->fh); |
| 288 | *p++ = htonl(resp->access); |
| 289 | return xdr_ressize_check(rqstp, p); |
| 290 | } |
| 291 | |
| 292 | /* |
| 293 | * XDR release functions |
| 294 | */ |
Al Viro | 131a21c | 2006-10-19 23:28:56 -0700 | [diff] [blame] | 295 | static int nfsaclsvc_release_getacl(struct svc_rqst *rqstp, __be32 *p, |
Andreas Gruenbacher | a257cdd | 2005-06-22 17:16:26 +0000 | [diff] [blame] | 296 | struct nfsd3_getaclres *resp) |
| 297 | { |
| 298 | fh_put(&resp->fh); |
| 299 | posix_acl_release(resp->acl_access); |
| 300 | posix_acl_release(resp->acl_default); |
| 301 | return 1; |
| 302 | } |
| 303 | |
Greg Banks | c9ce228 | 2007-02-20 10:12:34 +1100 | [diff] [blame] | 304 | static int nfsaclsvc_release_attrstat(struct svc_rqst *rqstp, __be32 *p, |
| 305 | struct nfsd_attrstat *resp) |
Andreas Gruenbacher | a257cdd | 2005-06-22 17:16:26 +0000 | [diff] [blame] | 306 | { |
| 307 | fh_put(&resp->fh); |
| 308 | return 1; |
| 309 | } |
| 310 | |
Greg Banks | c9ce228 | 2007-02-20 10:12:34 +1100 | [diff] [blame] | 311 | static int nfsaclsvc_release_access(struct svc_rqst *rqstp, __be32 *p, |
| 312 | struct nfsd3_accessres *resp) |
| 313 | { |
| 314 | fh_put(&resp->fh); |
| 315 | return 1; |
| 316 | } |
| 317 | |
Andreas Gruenbacher | a257cdd | 2005-06-22 17:16:26 +0000 | [diff] [blame] | 318 | #define nfsaclsvc_decode_voidargs NULL |
Andreas Gruenbacher | a257cdd | 2005-06-22 17:16:26 +0000 | [diff] [blame] | 319 | #define nfsaclsvc_release_void NULL |
| 320 | #define nfsd3_fhandleargs nfsd_fhandle |
| 321 | #define nfsd3_attrstatres nfsd_attrstat |
| 322 | #define nfsd3_voidres nfsd3_voidargs |
| 323 | struct nfsd3_voidargs { int dummy; }; |
| 324 | |
| 325 | #define PROC(name, argt, rest, relt, cache, respsize) \ |
| 326 | { (svc_procfunc) nfsacld_proc_##name, \ |
| 327 | (kxdrproc_t) nfsaclsvc_decode_##argt##args, \ |
| 328 | (kxdrproc_t) nfsaclsvc_encode_##rest##res, \ |
| 329 | (kxdrproc_t) nfsaclsvc_release_##relt, \ |
| 330 | sizeof(struct nfsd3_##argt##args), \ |
| 331 | sizeof(struct nfsd3_##rest##res), \ |
| 332 | 0, \ |
| 333 | cache, \ |
| 334 | respsize, \ |
| 335 | } |
| 336 | |
| 337 | #define ST 1 /* status*/ |
| 338 | #define AT 21 /* attributes */ |
| 339 | #define pAT (1+AT) /* post attributes - conditional */ |
| 340 | #define ACL (1+NFS_ACL_MAX_ENTRIES*3) /* Access Control List */ |
| 341 | |
| 342 | static struct svc_procedure nfsd_acl_procedures2[] = { |
| 343 | PROC(null, void, void, void, RC_NOCACHE, ST), |
| 344 | PROC(getacl, getacl, getacl, getacl, RC_NOCACHE, ST+1+2*(1+ACL)), |
Greg Banks | c9ce228 | 2007-02-20 10:12:34 +1100 | [diff] [blame] | 345 | PROC(setacl, setacl, attrstat, attrstat, RC_NOCACHE, ST+AT), |
| 346 | PROC(getattr, fhandle, attrstat, attrstat, RC_NOCACHE, ST+AT), |
| 347 | PROC(access, access, access, access, RC_NOCACHE, ST+AT+1), |
Andreas Gruenbacher | a257cdd | 2005-06-22 17:16:26 +0000 | [diff] [blame] | 348 | }; |
| 349 | |
| 350 | struct svc_version nfsd_acl_version2 = { |
| 351 | .vs_vers = 2, |
| 352 | .vs_nproc = 5, |
| 353 | .vs_proc = nfsd_acl_procedures2, |
| 354 | .vs_dispatch = nfsd_dispatch, |
| 355 | .vs_xdrsize = NFS3_SVC_XDRSIZE, |
Peter Staubach | 1b7e040 | 2009-11-02 16:59:07 -0500 | [diff] [blame] | 356 | .vs_hidden = 0, |
Andreas Gruenbacher | a257cdd | 2005-06-22 17:16:26 +0000 | [diff] [blame] | 357 | }; |