xattr_trusted.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. #define XATTR_TRUSTED_PREFIX "trusted."
  10. static int
  11. trusted_get(struct inode *inode, const char *name, void *buffer, size_t size)
  12. {
  13. if (strlen(name) < sizeof(XATTR_TRUSTED_PREFIX))
  14. return -EINVAL;
  15. if (!reiserfs_xattrs(inode->i_sb))
  16. return -EOPNOTSUPP;
  17. if (!(capable(CAP_SYS_ADMIN) || is_reiserfs_priv_object(inode)))
  18. return -EPERM;
  19. return reiserfs_xattr_get(inode, name, buffer, size);
  20. }
  21. static int
  22. trusted_set(struct inode *inode, const char *name, const void *buffer,
  23. size_t size, int flags)
  24. {
  25. if (strlen(name) < sizeof(XATTR_TRUSTED_PREFIX))
  26. return -EINVAL;
  27. if (!reiserfs_xattrs(inode->i_sb))
  28. return -EOPNOTSUPP;
  29. if (!(capable(CAP_SYS_ADMIN) || is_reiserfs_priv_object(inode)))
  30. return -EPERM;
  31. return reiserfs_xattr_set(inode, name, buffer, size, flags);
  32. }
  33. static int trusted_del(struct inode *inode, const char *name)
  34. {
  35. if (strlen(name) < sizeof(XATTR_TRUSTED_PREFIX))
  36. return -EINVAL;
  37. if (!reiserfs_xattrs(inode->i_sb))
  38. return -EOPNOTSUPP;
  39. if (!(capable(CAP_SYS_ADMIN) || is_reiserfs_priv_object(inode)))
  40. return -EPERM;
  41. return 0;
  42. }
  43. static int
  44. trusted_list(struct inode *inode, const char *name, int namelen, char *out)
  45. {
  46. int len = namelen;
  47. if (!reiserfs_xattrs(inode->i_sb))
  48. return 0;
  49. if (!(capable(CAP_SYS_ADMIN) || is_reiserfs_priv_object(inode)))
  50. return 0;
  51. if (out)
  52. memcpy(out, name, len);
  53. return len;
  54. }
  55. struct reiserfs_xattr_handler trusted_handler = {
  56. .prefix = XATTR_TRUSTED_PREFIX,
  57. .get = trusted_get,
  58. .set = trusted_set,
  59. .del = trusted_del,
  60. .list = trusted_list,
  61. };