xattr_trusted.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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/module.h>
  8. #include <linux/string.h>
  9. #include <linux/capability.h>
  10. #include <linux/fs.h>
  11. #include <linux/smp_lock.h>
  12. #include <linux/ext2_fs.h>
  13. #include "xattr.h"
  14. #define XATTR_TRUSTED_PREFIX "trusted."
  15. static size_t
  16. ext2_xattr_trusted_list(struct inode *inode, char *list, size_t list_size,
  17. const char *name, size_t name_len)
  18. {
  19. const int prefix_len = sizeof(XATTR_TRUSTED_PREFIX)-1;
  20. const size_t total_len = prefix_len + name_len + 1;
  21. if (!capable(CAP_SYS_ADMIN))
  22. return 0;
  23. if (list && total_len <= list_size) {
  24. memcpy(list, XATTR_TRUSTED_PREFIX, prefix_len);
  25. memcpy(list+prefix_len, name, name_len);
  26. list[prefix_len + name_len] = '\0';
  27. }
  28. return total_len;
  29. }
  30. static int
  31. ext2_xattr_trusted_get(struct inode *inode, const char *name,
  32. void *buffer, size_t size)
  33. {
  34. if (strcmp(name, "") == 0)
  35. return -EINVAL;
  36. return ext2_xattr_get(inode, EXT2_XATTR_INDEX_TRUSTED, name,
  37. buffer, size);
  38. }
  39. static int
  40. ext2_xattr_trusted_set(struct inode *inode, const char *name,
  41. const void *value, size_t size, int flags)
  42. {
  43. if (strcmp(name, "") == 0)
  44. return -EINVAL;
  45. return ext2_xattr_set(inode, EXT2_XATTR_INDEX_TRUSTED, name,
  46. value, size, flags);
  47. }
  48. struct xattr_handler ext2_xattr_trusted_handler = {
  49. .prefix = XATTR_TRUSTED_PREFIX,
  50. .list = ext2_xattr_trusted_list,
  51. .get = ext2_xattr_trusted_get,
  52. .set = ext2_xattr_trusted_set,
  53. };