xattr_trusted.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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(struct dentry *dentry, char *list, size_t list_size,
  11. const char *name, size_t name_len, int type)
  12. {
  13. const int prefix_len = XATTR_TRUSTED_PREFIX_LEN;
  14. const size_t total_len = prefix_len + name_len + 1;
  15. if (!capable(CAP_SYS_ADMIN))
  16. return 0;
  17. if (list && total_len <= list_size) {
  18. memcpy(list, XATTR_TRUSTED_PREFIX, prefix_len);
  19. memcpy(list+prefix_len, name, name_len);
  20. list[prefix_len + name_len] = '\0';
  21. }
  22. return total_len;
  23. }
  24. static int
  25. ext2_xattr_trusted_get(struct dentry *dentry, const char *name,
  26. void *buffer, size_t size, int type)
  27. {
  28. if (strcmp(name, "") == 0)
  29. return -EINVAL;
  30. return ext2_xattr_get(d_inode(dentry), EXT2_XATTR_INDEX_TRUSTED, name,
  31. buffer, size);
  32. }
  33. static int
  34. ext2_xattr_trusted_set(struct dentry *dentry, const char *name,
  35. const void *value, size_t size, int flags, int type)
  36. {
  37. if (strcmp(name, "") == 0)
  38. return -EINVAL;
  39. return ext2_xattr_set(d_inode(dentry), EXT2_XATTR_INDEX_TRUSTED, name,
  40. value, size, flags);
  41. }
  42. const struct xattr_handler ext2_xattr_trusted_handler = {
  43. .prefix = XATTR_TRUSTED_PREFIX,
  44. .list = ext2_xattr_trusted_list,
  45. .get = ext2_xattr_trusted_get,
  46. .set = ext2_xattr_trusted_set,
  47. };