xattr_trusted.c 1.2 KB

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