nfs3acl.c 6.3 KB

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