xattr_trusted.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * linux/fs/ext3/xattr_trusted.c
  3. * Handler for trusted extended attributes.
  4. *
  5. * Copyright (C) 2003 by Andreas Gruenbacher, <a.gruenbacher@computer.org>
  6. */
  7. #include <linux/module.h>
  8. #include <linux/string.h>
  9. #include <linux/capability.h>
  10. #include <linux/fs.h>
  11. #include <linux/smp_lock.h>
  12. #include <linux/ext3_jbd.h>
  13. #include <linux/ext3_fs.h>
  14. #include "xattr.h"
  15. #define XATTR_TRUSTED_PREFIX "trusted."
  16. static size_t
  17. ext3_xattr_trusted_list(struct inode *inode, char *list, size_t list_size,
  18. const char *name, size_t name_len)
  19. {
  20. const size_t prefix_len = sizeof(XATTR_TRUSTED_PREFIX)-1;
  21. const size_t total_len = prefix_len + name_len + 1;
  22. if (!capable(CAP_SYS_ADMIN))
  23. return 0;
  24. if (list && total_len <= list_size) {
  25. memcpy(list, XATTR_TRUSTED_PREFIX, prefix_len);
  26. memcpy(list+prefix_len, name, name_len);
  27. list[prefix_len + name_len] = '\0';
  28. }
  29. return total_len;
  30. }
  31. static int
  32. ext3_xattr_trusted_get(struct inode *inode, const char *name,
  33. void *buffer, size_t size)
  34. {
  35. if (strcmp(name, "") == 0)
  36. return -EINVAL;
  37. return ext3_xattr_get(inode, EXT3_XATTR_INDEX_TRUSTED, name,
  38. buffer, size);
  39. }
  40. static int
  41. ext3_xattr_trusted_set(struct inode *inode, const char *name,
  42. const void *value, size_t size, int flags)
  43. {
  44. if (strcmp(name, "") == 0)
  45. return -EINVAL;
  46. return ext3_xattr_set(inode, EXT3_XATTR_INDEX_TRUSTED, name,
  47. value, size, flags);
  48. }
  49. struct xattr_handler ext3_xattr_trusted_handler = {
  50. .prefix = XATTR_TRUSTED_PREFIX,
  51. .list = ext3_xattr_trusted_list,
  52. .get = ext3_xattr_trusted_get,
  53. .set = ext3_xattr_trusted_set,
  54. };