xattr_trusted.c 1.6 KB

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