xattr_trusted.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * linux/fs/ext2/xattr_trusted.c
  3. * Handler for trusted extended attributes.
  4. *
  5. * Copyright (C) 2003 by Andreas Gruenbacher, <a.gruenbacher@computer.org>
  6. */
  7. #include "ext2.h"
  8. #include "xattr.h"
  9. static size_t
  10. ext2_xattr_trusted_list(const struct xattr_handler *handler,
  11. struct dentry *dentry, char *list, size_t list_size,
  12. const char *name, size_t name_len)
  13. {
  14. const int prefix_len = XATTR_TRUSTED_PREFIX_LEN;
  15. const size_t total_len = prefix_len + name_len + 1;
  16. if (!capable(CAP_SYS_ADMIN))
  17. return 0;
  18. if (list && total_len <= list_size) {
  19. memcpy(list, XATTR_TRUSTED_PREFIX, prefix_len);
  20. memcpy(list+prefix_len, name, name_len);
  21. list[prefix_len + name_len] = '\0';
  22. }
  23. return total_len;
  24. }
  25. static int
  26. ext2_xattr_trusted_get(const struct xattr_handler *handler,
  27. struct dentry *dentry, const char *name,
  28. void *buffer, size_t size)
  29. {
  30. if (strcmp(name, "") == 0)
  31. return -EINVAL;
  32. return ext2_xattr_get(d_inode(dentry), EXT2_XATTR_INDEX_TRUSTED, name,
  33. buffer, size);
  34. }
  35. static int
  36. ext2_xattr_trusted_set(const struct xattr_handler *handler,
  37. struct dentry *dentry, const char *name,
  38. const void *value, size_t size, int flags)
  39. {
  40. if (strcmp(name, "") == 0)
  41. return -EINVAL;
  42. return ext2_xattr_set(d_inode(dentry), EXT2_XATTR_INDEX_TRUSTED, name,
  43. value, size, flags);
  44. }
  45. const struct xattr_handler ext2_xattr_trusted_handler = {
  46. .prefix = XATTR_TRUSTED_PREFIX,
  47. .list = ext2_xattr_trusted_list,
  48. .get = ext2_xattr_trusted_get,
  49. .set = ext2_xattr_trusted_set,
  50. };