9p-xattr-user.c 2.8 KB

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