xattr_trusted.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 inode *inode, const char *name, void *buffer, size_t size)
  11. {
  12. if (strlen(name) < sizeof(XATTR_TRUSTED_PREFIX))
  13. return -EINVAL;
  14. if (!capable(CAP_SYS_ADMIN) || IS_PRIVATE(inode))
  15. return -EPERM;
  16. return reiserfs_xattr_get(inode, name, buffer, size);
  17. }
  18. static int
  19. trusted_set(struct inode *inode, const char *name, const void *buffer,
  20. size_t size, int flags)
  21. {
  22. if (strlen(name) < sizeof(XATTR_TRUSTED_PREFIX))
  23. return -EINVAL;
  24. if (!capable(CAP_SYS_ADMIN) || IS_PRIVATE(inode))
  25. return -EPERM;
  26. return reiserfs_xattr_set(inode, name, buffer, size, flags);
  27. }
  28. static size_t trusted_list(struct inode *inode, char *list, size_t list_size,
  29. const char *name, size_t name_len)
  30. {
  31. const size_t len = name_len + 1;
  32. if (!capable(CAP_SYS_ADMIN) || IS_PRIVATE(inode))
  33. return 0;
  34. if (list && len <= list_size) {
  35. memcpy(list, name, name_len);
  36. list[name_len] = '\0';
  37. }
  38. return len;
  39. }
  40. struct xattr_handler reiserfs_xattr_trusted_handler = {
  41. .prefix = XATTR_TRUSTED_PREFIX,
  42. .get = trusted_get,
  43. .set = trusted_set,
  44. .list = trusted_list,
  45. };