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