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 <linux/string.h>
  8. #include <linux/capability.h>
  9. #include <linux/fs.h>
  10. #include <linux/ext2_fs.h>
  11. #include "xattr.h"
  12. static size_t
  13. ext2_xattr_trusted_list(struct dentry *dentry, char *list, size_t list_size,
  14. const char *name, size_t name_len, int type)
  15. {
  16. const int prefix_len = XATTR_TRUSTED_PREFIX_LEN;
  17. const size_t total_len = prefix_len + name_len + 1;
  18. if (!capable(CAP_SYS_ADMIN))
  19. return 0;
  20. if (list && total_len <= list_size) {
  21. memcpy(list, XATTR_TRUSTED_PREFIX, prefix_len);
  22. memcpy(list+prefix_len, name, name_len);
  23. list[prefix_len + name_len] = '\0';
  24. }
  25. return total_len;
  26. }
  27. static int
  28. ext2_xattr_trusted_get(struct dentry *dentry, const char *name,
  29. void *buffer, size_t size, int type)
  30. {
  31. if (strcmp(name, "") == 0)
  32. return -EINVAL;
  33. return ext2_xattr_get(dentry->d_inode, EXT2_XATTR_INDEX_TRUSTED, name,
  34. buffer, size);
  35. }
  36. static int
  37. ext2_xattr_trusted_set(struct dentry *dentry, const char *name,
  38. const void *value, size_t size, int flags, int type)
  39. {
  40. if (strcmp(name, "") == 0)
  41. return -EINVAL;
  42. return ext2_xattr_set(dentry->d_inode, 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. };