acl.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * Copyright IBM Corporation, 2010
  3. * Author Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of version 2.1 of the GNU Lesser General Public License
  7. * as published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it would be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  12. *
  13. */
  14. #include <linux/module.h>
  15. #include <linux/fs.h>
  16. #include <net/9p/9p.h>
  17. #include <net/9p/client.h>
  18. #include <linux/slab.h>
  19. #include <linux/posix_acl_xattr.h>
  20. #include "xattr.h"
  21. #include "acl.h"
  22. static struct posix_acl *__v9fs_get_acl(struct p9_fid *fid, char *name)
  23. {
  24. ssize_t size;
  25. void *value = NULL;
  26. struct posix_acl *acl = NULL;;
  27. size = v9fs_fid_xattr_get(fid, name, NULL, 0);
  28. if (size > 0) {
  29. value = kzalloc(size, GFP_NOFS);
  30. if (!value)
  31. return ERR_PTR(-ENOMEM);
  32. size = v9fs_fid_xattr_get(fid, name, value, size);
  33. if (size > 0) {
  34. acl = posix_acl_from_xattr(value, size);
  35. if (IS_ERR(acl))
  36. goto err_out;
  37. }
  38. } else if (size == -ENODATA || size == 0 ||
  39. size == -ENOSYS || size == -EOPNOTSUPP) {
  40. acl = NULL;
  41. } else
  42. acl = ERR_PTR(-EIO);
  43. err_out:
  44. kfree(value);
  45. return acl;
  46. }
  47. int v9fs_get_acl(struct inode *inode, struct p9_fid *fid)
  48. {
  49. int retval = 0;
  50. struct posix_acl *pacl, *dacl;
  51. /* get the default/access acl values and cache them */
  52. dacl = __v9fs_get_acl(fid, POSIX_ACL_XATTR_DEFAULT);
  53. pacl = __v9fs_get_acl(fid, POSIX_ACL_XATTR_ACCESS);
  54. if (!IS_ERR(dacl) && !IS_ERR(pacl)) {
  55. set_cached_acl(inode, ACL_TYPE_DEFAULT, dacl);
  56. set_cached_acl(inode, ACL_TYPE_ACCESS, pacl);
  57. posix_acl_release(dacl);
  58. posix_acl_release(pacl);
  59. } else
  60. retval = -EIO;
  61. return retval;
  62. }
  63. static struct posix_acl *v9fs_get_cached_acl(struct inode *inode, int type)
  64. {
  65. struct posix_acl *acl;
  66. /*
  67. * 9p Always cache the acl value when
  68. * instantiating the inode (v9fs_inode_from_fid)
  69. */
  70. acl = get_cached_acl(inode, type);
  71. BUG_ON(acl == ACL_NOT_CACHED);
  72. return acl;
  73. }
  74. int v9fs_check_acl(struct inode *inode, int mask)
  75. {
  76. struct posix_acl *acl = v9fs_get_cached_acl(inode, ACL_TYPE_ACCESS);
  77. if (IS_ERR(acl))
  78. return PTR_ERR(acl);
  79. if (acl) {
  80. int error = posix_acl_permission(inode, acl, mask);
  81. posix_acl_release(acl);
  82. return error;
  83. }
  84. return -EAGAIN;
  85. }