linux/fs/nfsd/nfs3acl.c
<<
>>
Prefs
   1/*
   2 * Process version 3 NFSACL requests.
   3 *
   4 * Copyright (C) 2002-2003 Andreas Gruenbacher <agruen@suse.de>
   5 */
   6
   7#include "nfsd.h"
   8/* FIXME: nfsacl.h is a broken header */
   9#include <linux/nfsacl.h>
  10#include <linux/gfp.h>
  11#include "cache.h"
  12#include "xdr3.h"
  13#include "vfs.h"
  14
  15#define RETURN_STATUS(st)       { resp->status = (st); return (st); }
  16
  17/*
  18 * NULL call.
  19 */
  20static __be32
  21nfsd3_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 */
  29static __be32 nfsd3_proc_getacl(struct svc_rqst * rqstp,
  30                struct nfsd3_getaclargs *argp, struct nfsd3_getaclres *resp)
  31{
  32        svc_fh *fh;
  33        struct posix_acl *acl;
  34        __be32 nfserr = 0;
  35
  36        fh = fh_copy(&resp->fh, &argp->fh);
  37        nfserr = fh_verify(rqstp, &resp->fh, 0, NFSD_MAY_NOP);
  38        if (nfserr)
  39                RETURN_STATUS(nfserr);
  40
  41        if (argp->mask & ~NFS_ACL_MASK)
  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
  86fail:
  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 */
  95static __be32 nfsd3_proc_setacl(struct svc_rqst * rqstp,
  96                struct nfsd3_setaclargs *argp,
  97                struct nfsd3_attrstat *resp)
  98{
  99        svc_fh *fh;
 100        __be32 nfserr = 0;
 101
 102        fh = fh_copy(&resp->fh, &argp->fh);
 103        nfserr = fh_verify(rqstp, &resp->fh, 0, NFSD_MAY_SATTR);
 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 */
 124static int nfs3svc_decode_getaclargs(struct svc_rqst *rqstp, __be32 *p,
 125                struct nfsd3_getaclargs *args)
 126{
 127        p = nfs3svc_decode_fh(p, &args->fh);
 128        if (!p)
 129                return 0;
 130        args->mask = ntohl(*p); p++;
 131
 132        return xdr_argsize_check(rqstp, p);
 133}
 134
 135
 136static int nfs3svc_decode_setaclargs(struct svc_rqst *rqstp, __be32 *p,
 137                struct nfsd3_setaclargs *args)
 138{
 139        struct kvec *head = rqstp->rq_arg.head;
 140        unsigned int base;
 141        int n;
 142
 143        p = nfs3svc_decode_fh(p, &args->fh);
 144        if (!p)
 145                return 0;
 146        args->mask = ntohl(*p++);
 147        if (args->mask & ~NFS_ACL_MASK ||
 148            !xdr_argsize_check(rqstp, p))
 149                return 0;
 150
 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);
 155        if (n > 0)
 156                n = nfsacl_decode(&rqstp->rq_arg, base + n, NULL,
 157                                  (args->mask & NFS_DFACL) ?
 158                                  &args->acl_default : NULL);
 159        return (n > 0);
 160}
 161
 162/*
 163 * XDR encode functions
 164 */
 165
 166/* GETACL */
 167static int nfs3svc_encode_getaclres(struct svc_rqst *rqstp, __be32 *p,
 168                struct nfsd3_getaclres *resp)
 169{
 170        struct dentry *dentry = resp->fh.fh_dentry;
 171
 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;
 176                unsigned int base;
 177                int n;
 178                int w;
 179
 180                *p++ = htonl(resp->mask);
 181                if (!xdr_ressize_check(rqstp, p))
 182                        return 0;
 183                base = (char *)p - (char *)head->iov_base;
 184
 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);
 188                while (w > 0) {
 189                        if (!*(rqstp->rq_next_page++))
 190                                return 0;
 191                        w -= PAGE_SIZE;
 192                }
 193
 194                n = nfsacl_encode(&rqstp->rq_res, base, inode,
 195                                  resp->acl_access,
 196                                  resp->mask & NFS_ACL, 0);
 197                if (n > 0)
 198                        n = nfsacl_encode(&rqstp->rq_res, base + n, inode,
 199                                          resp->acl_default,
 200                                          resp->mask & NFS_DFACL,
 201                                          NFS_ACL_DEFAULT);
 202                if (n <= 0)
 203                        return 0;
 204        } else
 205                if (!xdr_ressize_check(rqstp, p))
 206                        return 0;
 207
 208        return 1;
 209}
 210
 211/* SETACL */
 212static int nfs3svc_encode_setaclres(struct svc_rqst *rqstp, __be32 *p,
 213                struct nfsd3_attrstat *resp)
 214{
 215        p = nfs3svc_encode_post_op_attr(rqstp, p, &resp->fh);
 216
 217        return xdr_ressize_check(rqstp, p);
 218}
 219
 220/*
 221 * XDR release functions
 222 */
 223static int nfs3svc_release_getacl(struct svc_rqst *rqstp, __be32 *p,
 224                struct nfsd3_getaclres *resp)
 225{
 226        fh_put(&resp->fh);
 227        posix_acl_release(resp->acl_access);
 228        posix_acl_release(resp->acl_default);
 229        return 1;
 230}
 231
 232#define nfs3svc_decode_voidargs         NULL
 233#define nfs3svc_release_void            NULL
 234#define nfsd3_setaclres                 nfsd3_attrstat
 235#define nfsd3_voidres                   nfsd3_voidargs
 236struct nfsd3_voidargs { int dummy; };
 237
 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),            \
 245   0,                                           \
 246   cache,                                       \
 247   respsize,                                    \
 248 }
 249
 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 */
 254
 255static 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),
 259};
 260
 261struct svc_version      nfsd_acl_version3 = {
 262                .vs_vers        = 3,
 263                .vs_nproc       = 3,
 264                .vs_proc        = nfsd_acl_procedures3,
 265                .vs_dispatch    = nfsd_dispatch,
 266                .vs_xdrsize     = NFS3_SVC_XDRSIZE,
 267                .vs_hidden      = 0,
 268};
 269
 270