xattr_security.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * linux/fs/ext2/xattr_security.c
  3. * Handler for storing security labels as extended attributes.
  4. */
  5. #include "ext2.h"
  6. #include <linux/security.h>
  7. #include "xattr.h"
  8. static int
  9. ext2_xattr_security_get(const struct xattr_handler *handler,
  10. struct dentry *unused, struct inode *inode,
  11. const char *name, void *buffer, size_t size)
  12. {
  13. return ext2_xattr_get(inode, EXT2_XATTR_INDEX_SECURITY, name,
  14. buffer, size);
  15. }
  16. static int
  17. ext2_xattr_security_set(const struct xattr_handler *handler,
  18. struct dentry *unused, struct inode *inode,
  19. const char *name, const void *value,
  20. size_t size, int flags)
  21. {
  22. return ext2_xattr_set(inode, EXT2_XATTR_INDEX_SECURITY, name,
  23. value, size, flags);
  24. }
  25. static int ext2_initxattrs(struct inode *inode, const struct xattr *xattr_array,
  26. void *fs_info)
  27. {
  28. const struct xattr *xattr;
  29. int err = 0;
  30. for (xattr = xattr_array; xattr->name != NULL; xattr++) {
  31. err = ext2_xattr_set(inode, EXT2_XATTR_INDEX_SECURITY,
  32. xattr->name, xattr->value,
  33. xattr->value_len, 0);
  34. if (err < 0)
  35. break;
  36. }
  37. return err;
  38. }
  39. int
  40. ext2_init_security(struct inode *inode, struct inode *dir,
  41. const struct qstr *qstr)
  42. {
  43. return security_inode_init_security(inode, dir, qstr,
  44. &ext2_initxattrs, NULL);
  45. }
  46. const struct xattr_handler ext2_xattr_security_handler = {
  47. .prefix = XATTR_SECURITY_PREFIX,
  48. .get = ext2_xattr_security_get,
  49. .set = ext2_xattr_security_set,
  50. };