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