acl.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * Copyright (C) 2007 Red Hat. All rights reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public
  6. * License v2 as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. * General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public
  14. * License along with this program; if not, write to the
  15. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  16. * Boston, MA 021110-1307, USA.
  17. */
  18. #include <linux/fs.h>
  19. #include <linux/string.h>
  20. #include <linux/xattr.h>
  21. #include <linux/posix_acl_xattr.h>
  22. #include "ctree.h"
  23. #include "xattr.h"
  24. static int btrfs_xattr_set_acl(struct inode *inode, int type,
  25. const void *value, size_t size)
  26. {
  27. int ret = 0;
  28. struct posix_acl *acl;
  29. if (!is_owner_or_cap(inode))
  30. return -EPERM;
  31. if (value) {
  32. acl = posix_acl_from_xattr(value, size);
  33. if (acl == NULL) {
  34. value = NULL;
  35. size = 0;
  36. } else if (IS_ERR(acl)) {
  37. ret = PTR_ERR(acl);
  38. } else {
  39. ret = posix_acl_valid(acl);
  40. posix_acl_release(acl);
  41. }
  42. if (ret)
  43. return ret;
  44. }
  45. return btrfs_xattr_set(inode, type, "", value, size, 0);
  46. }
  47. static int btrfs_xattr_get_acl(struct inode *inode, int type,
  48. void *value, size_t size)
  49. {
  50. return btrfs_xattr_get(inode, type, "", value, size);
  51. }
  52. static int btrfs_xattr_acl_access_get(struct inode *inode, const char *name,
  53. void *value, size_t size)
  54. {
  55. if (*name != '\0')
  56. return -EINVAL;
  57. return btrfs_xattr_get_acl(inode, BTRFS_XATTR_INDEX_POSIX_ACL_ACCESS,
  58. value, size);
  59. }
  60. static int btrfs_xattr_acl_access_set(struct inode *inode, const char *name,
  61. const void *value, size_t size, int flags)
  62. {
  63. if (*name != '\0')
  64. return -EINVAL;
  65. return btrfs_xattr_set_acl(inode, BTRFS_XATTR_INDEX_POSIX_ACL_ACCESS,
  66. value, size);
  67. }
  68. static int btrfs_xattr_acl_default_get(struct inode *inode, const char *name,
  69. void *value, size_t size)
  70. {
  71. if (*name != '\0')
  72. return -EINVAL;
  73. return btrfs_xattr_get_acl(inode, BTRFS_XATTR_INDEX_POSIX_ACL_DEFAULT,
  74. value, size);
  75. }
  76. static int btrfs_xattr_acl_default_set(struct inode *inode, const char *name,
  77. const void *value, size_t size, int flags)
  78. {
  79. if (*name != '\0')
  80. return -EINVAL;
  81. return btrfs_xattr_set_acl(inode, BTRFS_XATTR_INDEX_POSIX_ACL_DEFAULT,
  82. value, size);
  83. }
  84. struct xattr_handler btrfs_xattr_acl_default_handler = {
  85. .prefix = POSIX_ACL_XATTR_DEFAULT,
  86. .list = btrfs_xattr_generic_list,
  87. .get = btrfs_xattr_acl_default_get,
  88. .set = btrfs_xattr_acl_default_set,
  89. };
  90. struct xattr_handler btrfs_xattr_acl_access_handler = {
  91. .prefix = POSIX_ACL_XATTR_ACCESS,
  92. .list = btrfs_xattr_generic_list,
  93. .get = btrfs_xattr_acl_access_get,
  94. .set = btrfs_xattr_acl_access_set,
  95. };