xattr_trusted.c 1.4 KB

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