xattr_trusted.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #include "reiserfs.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 "xattr.h"
  8. #include <linux/uaccess.h>
  9. static int
  10. trusted_get(const struct xattr_handler *handler, struct dentry *unused,
  11. struct inode *inode, const char *name, void *buffer, size_t size)
  12. {
  13. if (!capable(CAP_SYS_ADMIN) || IS_PRIVATE(inode))
  14. return -EPERM;
  15. return reiserfs_xattr_get(inode, xattr_full_name(handler, name),
  16. buffer, size);
  17. }
  18. static int
  19. trusted_set(const struct xattr_handler *handler, struct dentry *unused,
  20. struct inode *inode, const char *name, const void *buffer,
  21. size_t size, int flags)
  22. {
  23. if (!capable(CAP_SYS_ADMIN) || IS_PRIVATE(inode))
  24. return -EPERM;
  25. return reiserfs_xattr_set(inode,
  26. xattr_full_name(handler, name),
  27. buffer, size, flags);
  28. }
  29. static bool trusted_list(struct dentry *dentry)
  30. {
  31. return capable(CAP_SYS_ADMIN) && !IS_PRIVATE(d_inode(dentry));
  32. }
  33. const struct xattr_handler reiserfs_xattr_trusted_handler = {
  34. .prefix = XATTR_TRUSTED_PREFIX,
  35. .get = trusted_get,
  36. .set = trusted_set,
  37. .list = trusted_list,
  38. };