2  * linux/fs/nfsd/nfs3acl.c
 
   4  * Process version 3 NFSACL requests.
 
   6  * Copyright (C) 2002-2003 Andreas Gruenbacher <agruen@suse.de>
 
   9 #include <linux/sunrpc/svc.h>
 
  10 #include <linux/nfs3.h>
 
  11 #include <linux/nfsd/nfsd.h>
 
  12 #include <linux/nfsd/cache.h>
 
  13 #include <linux/nfsd/xdr3.h>
 
  14 #include <linux/posix_acl.h>
 
  15 #include <linux/nfsacl.h>
 
  17 #define RETURN_STATUS(st)       { resp->status = (st); return (st); }
 
  23 nfsd3_proc_null(struct svc_rqst *rqstp, void *argp, void *resp)
 
  29  * Get the Access and/or Default ACL of a file.
 
  31 static __be32 nfsd3_proc_getacl(struct svc_rqst * rqstp,
 
  32                 struct nfsd3_getaclargs *argp, struct nfsd3_getaclres *resp)
 
  35         struct posix_acl *acl;
 
  38         fh = fh_copy(&resp->fh, &argp->fh);
 
  39         nfserr = fh_verify(rqstp, &resp->fh, 0, NFSD_MAY_NOP);
 
  41                 RETURN_STATUS(nfserr);
 
  43         if (argp->mask & ~(NFS_ACL|NFS_ACLCNT|NFS_DFACL|NFS_DFACLCNT))
 
  44                 RETURN_STATUS(nfserr_inval);
 
  45         resp->mask = argp->mask;
 
  47         if (resp->mask & (NFS_ACL|NFS_ACLCNT)) {
 
  48                 acl = nfsd_get_posix_acl(fh, ACL_TYPE_ACCESS);
 
  50                         int err = PTR_ERR(acl);
 
  52                         if (err == -ENODATA || err == -EOPNOTSUPP)
 
  55                                 nfserr = nfserrno(err);
 
  60                         /* Solaris returns the inode's minimum ACL. */
 
  62                         struct inode *inode = fh->fh_dentry->d_inode;
 
  63                         acl = posix_acl_from_mode(inode->i_mode, GFP_KERNEL);
 
  65                 resp->acl_access = acl;
 
  67         if (resp->mask & (NFS_DFACL|NFS_DFACLCNT)) {
 
  68                 /* Check how Solaris handles requests for the Default ACL
 
  69                    of a non-directory! */
 
  71                 acl = nfsd_get_posix_acl(fh, ACL_TYPE_DEFAULT);
 
  73                         int err = PTR_ERR(acl);
 
  75                         if (err == -ENODATA || err == -EOPNOTSUPP)
 
  78                                 nfserr = nfserrno(err);
 
  82                 resp->acl_default = acl;
 
  85         /* resp->acl_{access,default} are released in nfs3svc_release_getacl. */
 
  89         posix_acl_release(resp->acl_access);
 
  90         posix_acl_release(resp->acl_default);
 
  91         RETURN_STATUS(nfserr);
 
  95  * Set the Access and/or Default ACL of a file.
 
  97 static __be32 nfsd3_proc_setacl(struct svc_rqst * rqstp,
 
  98                 struct nfsd3_setaclargs *argp,
 
  99                 struct nfsd3_attrstat *resp)
 
 104         fh = fh_copy(&resp->fh, &argp->fh);
 
 105         nfserr = fh_verify(rqstp, &resp->fh, 0, NFSD_MAY_SATTR);
 
 108                 nfserr = nfserrno( nfsd_set_posix_acl(
 
 109                         fh, ACL_TYPE_ACCESS, argp->acl_access) );
 
 112                 nfserr = nfserrno( nfsd_set_posix_acl(
 
 113                         fh, ACL_TYPE_DEFAULT, argp->acl_default) );
 
 116         /* argp->acl_{access,default} may have been allocated in
 
 117            nfs3svc_decode_setaclargs. */
 
 118         posix_acl_release(argp->acl_access);
 
 119         posix_acl_release(argp->acl_default);
 
 120         RETURN_STATUS(nfserr);
 
 124  * XDR decode functions
 
 126 static int nfs3svc_decode_getaclargs(struct svc_rqst *rqstp, __be32 *p,
 
 127                 struct nfsd3_getaclargs *args)
 
 129         if (!(p = nfs3svc_decode_fh(p, &args->fh)))
 
 131         args->mask = ntohl(*p); p++;
 
 133         return xdr_argsize_check(rqstp, p);
 
 137 static int nfs3svc_decode_setaclargs(struct svc_rqst *rqstp, __be32 *p,
 
 138                 struct nfsd3_setaclargs *args)
 
 140         struct kvec *head = rqstp->rq_arg.head;
 
 144         if (!(p = nfs3svc_decode_fh(p, &args->fh)))
 
 146         args->mask = ntohl(*p++);
 
 147         if (args->mask & ~(NFS_ACL|NFS_ACLCNT|NFS_DFACL|NFS_DFACLCNT) ||
 
 148             !xdr_argsize_check(rqstp, p))
 
 151         base = (char *)p - (char *)head->iov_base;
 
 152         n = nfsacl_decode(&rqstp->rq_arg, base, NULL,
 
 153                           (args->mask & NFS_ACL) ?
 
 154                           &args->acl_access : NULL);
 
 156                 n = nfsacl_decode(&rqstp->rq_arg, base + n, NULL,
 
 157                                   (args->mask & NFS_DFACL) ?
 
 158                                   &args->acl_default : NULL);
 
 163  * XDR encode functions
 
 167 static int nfs3svc_encode_getaclres(struct svc_rqst *rqstp, __be32 *p,
 
 168                 struct nfsd3_getaclres *resp)
 
 170         struct dentry *dentry = resp->fh.fh_dentry;
 
 172         p = nfs3svc_encode_post_op_attr(rqstp, p, &resp->fh);
 
 173         if (resp->status == 0 && dentry && dentry->d_inode) {
 
 174                 struct inode *inode = dentry->d_inode;
 
 175                 struct kvec *head = rqstp->rq_res.head;
 
 180                 *p++ = htonl(resp->mask);
 
 181                 if (!xdr_ressize_check(rqstp, p))
 
 183                 base = (char *)p - (char *)head->iov_base;
 
 185                 rqstp->rq_res.page_len = w = nfsacl_size(
 
 186                         (resp->mask & NFS_ACL)   ? resp->acl_access  : NULL,
 
 187                         (resp->mask & NFS_DFACL) ? resp->acl_default : NULL);
 
 189                         if (!rqstp->rq_respages[rqstp->rq_resused++])
 
 194                 n = nfsacl_encode(&rqstp->rq_res, base, inode,
 
 196                                   resp->mask & NFS_ACL, 0);
 
 198                         n = nfsacl_encode(&rqstp->rq_res, base + n, inode,
 
 200                                           resp->mask & NFS_DFACL,
 
 205                 if (!xdr_ressize_check(rqstp, p))
 
 212 static int nfs3svc_encode_setaclres(struct svc_rqst *rqstp, __be32 *p,
 
 213                 struct nfsd3_attrstat *resp)
 
 215         p = nfs3svc_encode_post_op_attr(rqstp, p, &resp->fh);
 
 217         return xdr_ressize_check(rqstp, p);
 
 221  * XDR release functions
 
 223 static int nfs3svc_release_getacl(struct svc_rqst *rqstp, __be32 *p,
 
 224                 struct nfsd3_getaclres *resp)
 
 227         posix_acl_release(resp->acl_access);
 
 228         posix_acl_release(resp->acl_default);
 
 232 #define nfs3svc_decode_voidargs         NULL
 
 233 #define nfs3svc_release_void            NULL
 
 234 #define nfsd3_setaclres                 nfsd3_attrstat
 
 235 #define nfsd3_voidres                   nfsd3_voidargs
 
 236 struct nfsd3_voidargs { int dummy; };
 
 238 #define PROC(name, argt, rest, relt, cache, respsize)   \
 
 239  { (svc_procfunc) nfsd3_proc_##name,            \
 
 240    (kxdrproc_t) nfs3svc_decode_##argt##args,    \
 
 241    (kxdrproc_t) nfs3svc_encode_##rest##res,     \
 
 242    (kxdrproc_t) nfs3svc_release_##relt,         \
 
 243    sizeof(struct nfsd3_##argt##args),           \
 
 244    sizeof(struct nfsd3_##rest##res),            \
 
 250 #define ST 1            /* status*/
 
 251 #define AT 21           /* attributes */
 
 252 #define pAT (1+AT)      /* post attributes - conditional */
 
 253 #define ACL (1+NFS_ACL_MAX_ENTRIES*3)  /* Access Control List */
 
 255 static struct svc_procedure             nfsd_acl_procedures3[] = {
 
 256   PROC(null,    void,           void,           void,     RC_NOCACHE, ST),
 
 257   PROC(getacl,  getacl,         getacl,         getacl,   RC_NOCACHE, ST+1+2*(1+ACL)),
 
 258   PROC(setacl,  setacl,         setacl,         fhandle,  RC_NOCACHE, ST+pAT),
 
 261 struct svc_version      nfsd_acl_version3 = {
 
 264                 .vs_proc        = nfsd_acl_procedures3,
 
 265                 .vs_dispatch    = nfsd_dispatch,
 
 266                 .vs_xdrsize     = NFS3_SVC_XDRSIZE,