xattr_trusted.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #include <linux/reiserfs_fs.h>
  2. #include <linux/capability.h>
  3. #include <linux/errno.h>
  4. #include <linux/fs.h>
  5. #include <linux/pagemap.h>
  6. #include <linux/xattr.h>
  7. #include <linux/reiserfs_xattr.h>
  8. #include <asm/uaccess.h>
  9. static int
  10. trusted_get(struct dentry *dentry, const char *name, void *buffer, size_t size,
  11. int handler_flags)
  12. {
  13. if (strlen(name) < sizeof(XATTR_TRUSTED_PREFIX))
  14. return -EINVAL;
  15. if (!capable(CAP_SYS_ADMIN) || IS_PRIVATE(dentry->d_inode))
  16. return -EPERM;
  17. return reiserfs_xattr_get(dentry->d_inode, name, buffer, size);
  18. }
  19. static int
  20. trusted_set(struct dentry *dentry, const char *name, const void *buffer,
  21. size_t size, int flags, int handler_flags)
  22. {
  23. if (strlen(name) < sizeof(XATTR_TRUSTED_PREFIX))
  24. return -EINVAL;
  25. if (!capable(CAP_SYS_ADMIN) || IS_PRIVATE(dentry->d_inode))
  26. return -EPERM;
  27. return reiserfs_xattr_set(dentry->d_inode, name, buffer, size, flags);
  28. }
  29. static size_t trusted_list(struct dentry *dentry, char *list, size_t list_size,
  30. const char *name, size_t name_len, int handler_flags)
  31. {
  32. const size_t len = name_len + 1;
  33. if (!capable(CAP_SYS_ADMIN) || IS_PRIVATE(dentry->d_inode))
  34. return 0;
  35. if (list && len <= list_size) {
  36. memcpy(list, name, name_len);
  37. list[name_len] = '\0';
  38. }
  39. return len;
  40. }
  41. const struct xattr_handler reiserfs_xattr_trusted_handler = {
  42. .prefix = XATTR_TRUSTED_PREFIX,
  43. .get = trusted_get,
  44. .set = trusted_set,
  45. .list = trusted_list,
  46. };