9p-posix-acl.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /*
  2. * 9p system.posix* xattr callback
  3. *
  4. * Copyright IBM, Corp. 2010
  5. *
  6. * Authors:
  7. * Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
  8. *
  9. * This work is licensed under the terms of the GNU GPL, version 2. See
  10. * the COPYING file in the top-level directory.
  11. *
  12. */
  13. #include "qemu/osdep.h"
  14. #include "qemu/xattr.h"
  15. #include "9p.h"
  16. #include "fsdev/file-op-9p.h"
  17. #include "9p-xattr.h"
  18. #define MAP_ACL_ACCESS "user.virtfs.system.posix_acl_access"
  19. #define MAP_ACL_DEFAULT "user.virtfs.system.posix_acl_default"
  20. #define ACL_ACCESS "system.posix_acl_access"
  21. #define ACL_DEFAULT "system.posix_acl_default"
  22. static ssize_t mp_pacl_getxattr(FsContext *ctx, const char *path,
  23. const char *name, void *value, size_t size)
  24. {
  25. return local_getxattr_nofollow(ctx, path, MAP_ACL_ACCESS, value, size);
  26. }
  27. static ssize_t mp_pacl_listxattr(FsContext *ctx, const char *path,
  28. char *name, void *value, size_t osize)
  29. {
  30. ssize_t len = sizeof(ACL_ACCESS);
  31. if (!value) {
  32. return len;
  33. }
  34. if (osize < len) {
  35. errno = ERANGE;
  36. return -1;
  37. }
  38. /* len includes the trailing NUL */
  39. memcpy(value, ACL_ACCESS, len);
  40. return 0;
  41. }
  42. static int mp_pacl_setxattr(FsContext *ctx, const char *path, const char *name,
  43. void *value, size_t size, int flags)
  44. {
  45. return local_setxattr_nofollow(ctx, path, MAP_ACL_ACCESS, value, size,
  46. flags);
  47. }
  48. static int mp_pacl_removexattr(FsContext *ctx,
  49. const char *path, const char *name)
  50. {
  51. int ret;
  52. ret = local_removexattr_nofollow(ctx, path, MAP_ACL_ACCESS);
  53. if (ret == -1 && errno == ENODATA) {
  54. /*
  55. * We don't get ENODATA error when trying to remove a
  56. * posix acl that is not present. So don't throw the error
  57. * even in case of mapped security model
  58. */
  59. errno = 0;
  60. ret = 0;
  61. }
  62. return ret;
  63. }
  64. static ssize_t mp_dacl_getxattr(FsContext *ctx, const char *path,
  65. const char *name, void *value, size_t size)
  66. {
  67. return local_getxattr_nofollow(ctx, path, MAP_ACL_DEFAULT, value, size);
  68. }
  69. static ssize_t mp_dacl_listxattr(FsContext *ctx, const char *path,
  70. char *name, void *value, size_t osize)
  71. {
  72. ssize_t len = sizeof(ACL_DEFAULT);
  73. if (!value) {
  74. return len;
  75. }
  76. if (osize < len) {
  77. errno = ERANGE;
  78. return -1;
  79. }
  80. /* len includes the trailing NUL */
  81. memcpy(value, ACL_DEFAULT, len);
  82. return 0;
  83. }
  84. static int mp_dacl_setxattr(FsContext *ctx, const char *path, const char *name,
  85. void *value, size_t size, int flags)
  86. {
  87. return local_setxattr_nofollow(ctx, path, MAP_ACL_DEFAULT, value, size,
  88. flags);
  89. }
  90. static int mp_dacl_removexattr(FsContext *ctx,
  91. const char *path, const char *name)
  92. {
  93. int ret;
  94. ret = local_removexattr_nofollow(ctx, path, MAP_ACL_DEFAULT);
  95. if (ret == -1 && errno == ENODATA) {
  96. /*
  97. * We don't get ENODATA error when trying to remove a
  98. * posix acl that is not present. So don't throw the error
  99. * even in case of mapped security model
  100. */
  101. errno = 0;
  102. ret = 0;
  103. }
  104. return ret;
  105. }
  106. XattrOperations mapped_pacl_xattr = {
  107. .name = "system.posix_acl_access",
  108. .getxattr = mp_pacl_getxattr,
  109. .setxattr = mp_pacl_setxattr,
  110. .listxattr = mp_pacl_listxattr,
  111. .removexattr = mp_pacl_removexattr,
  112. };
  113. XattrOperations mapped_dacl_xattr = {
  114. .name = "system.posix_acl_default",
  115. .getxattr = mp_dacl_getxattr,
  116. .setxattr = mp_dacl_setxattr,
  117. .listxattr = mp_dacl_listxattr,
  118. .removexattr = mp_dacl_removexattr,
  119. };
  120. XattrOperations passthrough_acl_xattr = {
  121. .name = "system.posix_acl_",
  122. .getxattr = pt_getxattr,
  123. .setxattr = pt_setxattr,
  124. .listxattr = pt_listxattr,
  125. .removexattr = pt_removexattr,
  126. };
  127. XattrOperations none_acl_xattr = {
  128. .name = "system.posix_acl_",
  129. .getxattr = notsup_getxattr,
  130. .setxattr = notsup_setxattr,
  131. .listxattr = notsup_listxattr,
  132. .removexattr = notsup_removexattr,
  133. };