xattr_trusted.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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(struct dentry *dentry, char *list, size_t list_size,
  15. const char *name, size_t name_len, int type)
  16. {
  17. const size_t prefix_len = XATTR_TRUSTED_PREFIX_LEN;
  18. const size_t total_len = prefix_len + name_len + 1;
  19. if (!capable(CAP_SYS_ADMIN))
  20. return 0;
  21. if (list && total_len <= list_size) {
  22. memcpy(list, XATTR_TRUSTED_PREFIX, prefix_len);
  23. memcpy(list+prefix_len, name, name_len);
  24. list[prefix_len + name_len] = '\0';
  25. }
  26. return total_len;
  27. }
  28. static int
  29. ext4_xattr_trusted_get(struct dentry *dentry, const char *name, void *buffer,
  30. size_t size, int type)
  31. {
  32. if (strcmp(name, "") == 0)
  33. return -EINVAL;
  34. return ext4_xattr_get(dentry->d_inode, EXT4_XATTR_INDEX_TRUSTED,
  35. name, buffer, size);
  36. }
  37. static int
  38. ext4_xattr_trusted_set(struct dentry *dentry, const char *name,
  39. const void *value, size_t size, int flags, int type)
  40. {
  41. if (strcmp(name, "") == 0)
  42. return -EINVAL;
  43. return ext4_xattr_set(dentry->d_inode, EXT4_XATTR_INDEX_TRUSTED,
  44. name, value, size, flags);
  45. }
  46. const struct xattr_handler ext4_xattr_trusted_handler = {
  47. .prefix = XATTR_TRUSTED_PREFIX,
  48. .list = ext4_xattr_trusted_list,
  49. .get = ext4_xattr_trusted_get,
  50. .set = ext4_xattr_trusted_set,
  51. };