xattr_trusted.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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/module.h>
  8. #include <linux/string.h>
  9. #include <linux/capability.h>
  10. #include <linux/fs.h>
  11. #include "ext4_jbd2.h"
  12. #include "ext4.h"
  13. #include "xattr.h"
  14. static size_t
  15. ext4_xattr_trusted_list(struct dentry *dentry, char *list, size_t list_size,
  16. const char *name, size_t name_len, int type)
  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(struct dentry *dentry, const char *name, void *buffer,
  31. size_t size, int type)
  32. {
  33. if (strcmp(name, "") == 0)
  34. return -EINVAL;
  35. return ext4_xattr_get(dentry->d_inode, EXT4_XATTR_INDEX_TRUSTED,
  36. name, buffer, size);
  37. }
  38. static int
  39. ext4_xattr_trusted_set(struct dentry *dentry, const char *name,
  40. const void *value, size_t size, int flags, int type)
  41. {
  42. if (strcmp(name, "") == 0)
  43. return -EINVAL;
  44. return ext4_xattr_set(dentry->d_inode, EXT4_XATTR_INDEX_TRUSTED,
  45. name, value, size, flags);
  46. }
  47. const struct xattr_handler ext4_xattr_trusted_handler = {
  48. .prefix = XATTR_TRUSTED_PREFIX,
  49. .list = ext4_xattr_trusted_list,
  50. .get = ext4_xattr_trusted_get,
  51. .set = ext4_xattr_trusted_set,
  52. };