nfs3acl.c 6.3 KB

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