^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Process version 2 NFSACL requests.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2002-2003 Andreas Gruenbacher <agruen@suse.de>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include "nfsd.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) /* FIXME: nfsacl.h is a broken header */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/nfsacl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/gfp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include "cache.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include "xdr3.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include "vfs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #define NFSDDBG_FACILITY NFSDDBG_PROC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * NULL call.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) static __be32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) nfsacld_proc_null(struct svc_rqst *rqstp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) return rpc_success;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * Get the Access and/or Default ACL of a file.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) static __be32 nfsacld_proc_getacl(struct svc_rqst *rqstp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) struct nfsd3_getaclargs *argp = rqstp->rq_argp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) struct nfsd3_getaclres *resp = rqstp->rq_resp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) struct posix_acl *acl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) svc_fh *fh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) dprintk("nfsd: GETACL(2acl) %s\n", SVCFH_fmt(&argp->fh));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) fh = fh_copy(&resp->fh, &argp->fh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) resp->status = fh_verify(rqstp, &resp->fh, 0, NFSD_MAY_NOP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) if (resp->status != nfs_ok)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) inode = d_inode(fh->fh_dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) if (argp->mask & ~NFS_ACL_MASK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) resp->status = nfserr_inval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) resp->mask = argp->mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) resp->status = fh_getattr(fh, &resp->stat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) if (resp->status != nfs_ok)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) if (resp->mask & (NFS_ACL|NFS_ACLCNT)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) acl = get_acl(inode, ACL_TYPE_ACCESS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) if (acl == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) /* Solaris returns the inode's minimum ACL. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) acl = posix_acl_from_mode(inode->i_mode, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) if (IS_ERR(acl)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) resp->status = nfserrno(PTR_ERR(acl));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) resp->acl_access = acl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) if (resp->mask & (NFS_DFACL|NFS_DFACLCNT)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) /* Check how Solaris handles requests for the Default ACL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) of a non-directory! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) acl = get_acl(inode, ACL_TYPE_DEFAULT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) if (IS_ERR(acl)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) resp->status = nfserrno(PTR_ERR(acl));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) resp->acl_default = acl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) /* resp->acl_{access,default} are released in nfssvc_release_getacl. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) return rpc_success;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) posix_acl_release(resp->acl_access);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) posix_acl_release(resp->acl_default);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) * Set the Access and/or Default ACL of a file.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) static __be32 nfsacld_proc_setacl(struct svc_rqst *rqstp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) struct nfsd3_setaclargs *argp = rqstp->rq_argp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) struct nfsd_attrstat *resp = rqstp->rq_resp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) svc_fh *fh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) dprintk("nfsd: SETACL(2acl) %s\n", SVCFH_fmt(&argp->fh));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) fh = fh_copy(&resp->fh, &argp->fh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) resp->status = fh_verify(rqstp, &resp->fh, 0, NFSD_MAY_SATTR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) if (resp->status != nfs_ok)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) inode = d_inode(fh->fh_dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) error = fh_want_write(fh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) goto out_errno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) fh_lock(fh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) error = set_posix_acl(inode, ACL_TYPE_ACCESS, argp->acl_access);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) goto out_drop_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) error = set_posix_acl(inode, ACL_TYPE_DEFAULT, argp->acl_default);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) goto out_drop_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) fh_unlock(fh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) fh_drop_write(fh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) resp->status = fh_getattr(fh, &resp->stat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) /* argp->acl_{access,default} may have been allocated in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) nfssvc_decode_setaclargs. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) posix_acl_release(argp->acl_access);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) posix_acl_release(argp->acl_default);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) return rpc_success;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) out_drop_lock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) fh_unlock(fh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) fh_drop_write(fh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) out_errno:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) resp->status = nfserrno(error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) * Check file attributes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) static __be32 nfsacld_proc_getattr(struct svc_rqst *rqstp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) struct nfsd_fhandle *argp = rqstp->rq_argp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) struct nfsd_attrstat *resp = rqstp->rq_resp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) dprintk("nfsd: GETATTR %s\n", SVCFH_fmt(&argp->fh));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) fh_copy(&resp->fh, &argp->fh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) resp->status = fh_verify(rqstp, &resp->fh, 0, NFSD_MAY_NOP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) if (resp->status != nfs_ok)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) resp->status = fh_getattr(&resp->fh, &resp->stat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) return rpc_success;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) * Check file access
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) static __be32 nfsacld_proc_access(struct svc_rqst *rqstp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) struct nfsd3_accessargs *argp = rqstp->rq_argp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) struct nfsd3_accessres *resp = rqstp->rq_resp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) dprintk("nfsd: ACCESS(2acl) %s 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) SVCFH_fmt(&argp->fh),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) argp->access);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) fh_copy(&resp->fh, &argp->fh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) resp->access = argp->access;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) resp->status = nfsd_access(rqstp, &resp->fh, &resp->access, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) if (resp->status != nfs_ok)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) resp->status = fh_getattr(&resp->fh, &resp->stat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) return rpc_success;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) * XDR decode functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) static int nfsaclsvc_decode_voidarg(struct svc_rqst *rqstp, __be32 *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) static int nfsaclsvc_decode_getaclargs(struct svc_rqst *rqstp, __be32 *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) struct nfsd3_getaclargs *argp = rqstp->rq_argp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) p = nfs2svc_decode_fh(p, &argp->fh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) if (!p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) argp->mask = ntohl(*p); p++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) return xdr_argsize_check(rqstp, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) static int nfsaclsvc_decode_setaclargs(struct svc_rqst *rqstp, __be32 *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) struct nfsd3_setaclargs *argp = rqstp->rq_argp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) struct kvec *head = rqstp->rq_arg.head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) unsigned int base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) int n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) p = nfs2svc_decode_fh(p, &argp->fh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) if (!p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) argp->mask = ntohl(*p++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) if (argp->mask & ~NFS_ACL_MASK ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) !xdr_argsize_check(rqstp, p))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) base = (char *)p - (char *)head->iov_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) n = nfsacl_decode(&rqstp->rq_arg, base, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) (argp->mask & NFS_ACL) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) &argp->acl_access : NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) if (n > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) n = nfsacl_decode(&rqstp->rq_arg, base + n, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) (argp->mask & NFS_DFACL) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) &argp->acl_default : NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) return (n > 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) static int nfsaclsvc_decode_fhandleargs(struct svc_rqst *rqstp, __be32 *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) struct nfsd_fhandle *argp = rqstp->rq_argp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) p = nfs2svc_decode_fh(p, &argp->fh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) if (!p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) return xdr_argsize_check(rqstp, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) static int nfsaclsvc_decode_accessargs(struct svc_rqst *rqstp, __be32 *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) struct nfsd3_accessargs *argp = rqstp->rq_argp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) p = nfs2svc_decode_fh(p, &argp->fh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) if (!p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) argp->access = ntohl(*p++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) return xdr_argsize_check(rqstp, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) * XDR encode functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) * There must be an encoding function for void results so svc_process
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) * will work properly.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) static int nfsaclsvc_encode_voidres(struct svc_rqst *rqstp, __be32 *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) return xdr_ressize_check(rqstp, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) /* GETACL */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) static int nfsaclsvc_encode_getaclres(struct svc_rqst *rqstp, __be32 *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) struct nfsd3_getaclres *resp = rqstp->rq_resp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) struct dentry *dentry = resp->fh.fh_dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) struct kvec *head = rqstp->rq_res.head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) unsigned int base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) int n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) int w;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) *p++ = resp->status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) if (resp->status != nfs_ok)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) return xdr_ressize_check(rqstp, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) * Since this is version 2, the check for nfserr in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) * nfsd_dispatch actually ensures the following cannot happen.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) * However, it seems fragile to depend on that.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) if (dentry == NULL || d_really_is_negative(dentry))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) inode = d_inode(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) p = nfs2svc_encode_fattr(rqstp, p, &resp->fh, &resp->stat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) *p++ = htonl(resp->mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) if (!xdr_ressize_check(rqstp, p))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) base = (char *)p - (char *)head->iov_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) rqstp->rq_res.page_len = w = nfsacl_size(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) (resp->mask & NFS_ACL) ? resp->acl_access : NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) (resp->mask & NFS_DFACL) ? resp->acl_default : NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) while (w > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) if (!*(rqstp->rq_next_page++))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) w -= PAGE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) n = nfsacl_encode(&rqstp->rq_res, base, inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) resp->acl_access,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) resp->mask & NFS_ACL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) if (n > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) n = nfsacl_encode(&rqstp->rq_res, base + n, inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) resp->acl_default,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) resp->mask & NFS_DFACL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) NFS_ACL_DEFAULT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) return (n > 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) static int nfsaclsvc_encode_attrstatres(struct svc_rqst *rqstp, __be32 *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) struct nfsd_attrstat *resp = rqstp->rq_resp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) *p++ = resp->status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) if (resp->status != nfs_ok)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) p = nfs2svc_encode_fattr(rqstp, p, &resp->fh, &resp->stat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) return xdr_ressize_check(rqstp, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) /* ACCESS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) static int nfsaclsvc_encode_accessres(struct svc_rqst *rqstp, __be32 *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) struct nfsd3_accessres *resp = rqstp->rq_resp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) *p++ = resp->status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) if (resp->status != nfs_ok)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) p = nfs2svc_encode_fattr(rqstp, p, &resp->fh, &resp->stat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) *p++ = htonl(resp->access);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) return xdr_ressize_check(rqstp, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) * XDR release functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) static void nfsaclsvc_release_getacl(struct svc_rqst *rqstp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) struct nfsd3_getaclres *resp = rqstp->rq_resp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) fh_put(&resp->fh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) posix_acl_release(resp->acl_access);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) posix_acl_release(resp->acl_default);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) static void nfsaclsvc_release_attrstat(struct svc_rqst *rqstp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) struct nfsd_attrstat *resp = rqstp->rq_resp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) fh_put(&resp->fh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) static void nfsaclsvc_release_access(struct svc_rqst *rqstp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) struct nfsd3_accessres *resp = rqstp->rq_resp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) fh_put(&resp->fh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) struct nfsd3_voidargs { int dummy; };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) #define ST 1 /* status*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) #define AT 21 /* attributes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) #define pAT (1+AT) /* post attributes - conditional */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) #define ACL (1+NFS_ACL_MAX_ENTRIES*3) /* Access Control List */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) static const struct svc_procedure nfsd_acl_procedures2[5] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) [ACLPROC2_NULL] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) .pc_func = nfsacld_proc_null,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) .pc_decode = nfsaclsvc_decode_voidarg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) .pc_encode = nfsaclsvc_encode_voidres,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) .pc_argsize = sizeof(struct nfsd3_voidargs),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) .pc_ressize = sizeof(struct nfsd3_voidargs),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) .pc_cachetype = RC_NOCACHE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) .pc_xdrressize = ST,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) [ACLPROC2_GETACL] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) .pc_func = nfsacld_proc_getacl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) .pc_decode = nfsaclsvc_decode_getaclargs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) .pc_encode = nfsaclsvc_encode_getaclres,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) .pc_release = nfsaclsvc_release_getacl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) .pc_argsize = sizeof(struct nfsd3_getaclargs),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) .pc_ressize = sizeof(struct nfsd3_getaclres),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) .pc_cachetype = RC_NOCACHE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) .pc_xdrressize = ST+1+2*(1+ACL),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) [ACLPROC2_SETACL] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) .pc_func = nfsacld_proc_setacl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) .pc_decode = nfsaclsvc_decode_setaclargs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) .pc_encode = nfsaclsvc_encode_attrstatres,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) .pc_release = nfsaclsvc_release_attrstat,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) .pc_argsize = sizeof(struct nfsd3_setaclargs),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) .pc_ressize = sizeof(struct nfsd_attrstat),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) .pc_cachetype = RC_NOCACHE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) .pc_xdrressize = ST+AT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) [ACLPROC2_GETATTR] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) .pc_func = nfsacld_proc_getattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) .pc_decode = nfsaclsvc_decode_fhandleargs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) .pc_encode = nfsaclsvc_encode_attrstatres,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) .pc_release = nfsaclsvc_release_attrstat,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) .pc_argsize = sizeof(struct nfsd_fhandle),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) .pc_ressize = sizeof(struct nfsd_attrstat),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) .pc_cachetype = RC_NOCACHE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) .pc_xdrressize = ST+AT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) [ACLPROC2_ACCESS] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) .pc_func = nfsacld_proc_access,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) .pc_decode = nfsaclsvc_decode_accessargs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) .pc_encode = nfsaclsvc_encode_accessres,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) .pc_release = nfsaclsvc_release_access,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) .pc_argsize = sizeof(struct nfsd3_accessargs),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) .pc_ressize = sizeof(struct nfsd3_accessres),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) .pc_cachetype = RC_NOCACHE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) .pc_xdrressize = ST+AT+1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) static unsigned int nfsd_acl_count2[ARRAY_SIZE(nfsd_acl_procedures2)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) const struct svc_version nfsd_acl_version2 = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) .vs_vers = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) .vs_nproc = 5,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) .vs_proc = nfsd_acl_procedures2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) .vs_count = nfsd_acl_count2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) .vs_dispatch = nfsd_dispatch,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) .vs_xdrsize = NFS3_SVC_XDRSIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) };