9p-xattr-user.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * 9p user. 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. /*
  14. * Not so fast! You might want to read the 9p developer docs first:
  15. * https://wiki.qemu.org/Documentation/9p
  16. */
  17. #include "qemu/osdep.h"
  18. #include "9p.h"
  19. #include "fsdev/file-op-9p.h"
  20. #include "9p-xattr.h"
  21. static ssize_t mp_user_getxattr(FsContext *ctx, const char *path,
  22. const char *name, void *value, size_t size)
  23. {
  24. if (strncmp(name, "user.virtfs.", 12) == 0) {
  25. /*
  26. * Don't allow fetch of user.virtfs namespace
  27. * in case of mapped security
  28. */
  29. errno = ENOATTR;
  30. return -1;
  31. }
  32. return local_getxattr_nofollow(ctx, path, name, value, size);
  33. }
  34. static ssize_t mp_user_listxattr(FsContext *ctx, const char *path,
  35. char *name, void *value, size_t size)
  36. {
  37. int name_size = strlen(name) + 1;
  38. if (strncmp(name, "user.virtfs.", 12) == 0) {
  39. /* check if it is a mapped posix acl */
  40. if (strncmp(name, "user.virtfs.system.posix_acl_", 29) == 0) {
  41. /* adjust the name and size */
  42. name += 12;
  43. name_size -= 12;
  44. } else {
  45. /*
  46. * Don't allow fetch of user.virtfs namespace
  47. * in case of mapped security
  48. */
  49. return 0;
  50. }
  51. }
  52. if (!value) {
  53. return name_size;
  54. }
  55. if (size < name_size) {
  56. errno = ERANGE;
  57. return -1;
  58. }
  59. /* name_size includes the trailing NUL. */
  60. memcpy(value, name, name_size);
  61. return name_size;
  62. }
  63. static int mp_user_setxattr(FsContext *ctx, const char *path, const char *name,
  64. void *value, size_t size, int flags)
  65. {
  66. if (strncmp(name, "user.virtfs.", 12) == 0) {
  67. /*
  68. * Don't allow fetch of user.virtfs namespace
  69. * in case of mapped security
  70. */
  71. errno = EACCES;
  72. return -1;
  73. }
  74. return local_setxattr_nofollow(ctx, path, name, value, size, flags);
  75. }
  76. static int mp_user_removexattr(FsContext *ctx,
  77. const char *path, const char *name)
  78. {
  79. if (strncmp(name, "user.virtfs.", 12) == 0) {
  80. /*
  81. * Don't allow fetch of user.virtfs namespace
  82. * in case of mapped security
  83. */
  84. errno = EACCES;
  85. return -1;
  86. }
  87. return local_removexattr_nofollow(ctx, path, name);
  88. }
  89. XattrOperations mapped_user_xattr = {
  90. .name = "user.",
  91. .getxattr = mp_user_getxattr,
  92. .setxattr = mp_user_setxattr,
  93. .listxattr = mp_user_listxattr,
  94. .removexattr = mp_user_removexattr,
  95. };
  96. XattrOperations passthrough_user_xattr = {
  97. .name = "user.",
  98. .getxattr = pt_getxattr,
  99. .setxattr = pt_setxattr,
  100. .listxattr = pt_listxattr,
  101. .removexattr = pt_removexattr,
  102. };