xattr_security.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 *dentry, const char *name,
  11. void *buffer, size_t size)
  12. {
  13. return ext2_xattr_get(d_inode(dentry), 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 *dentry, const char *name,
  19. const void *value, size_t size, int flags)
  20. {
  21. return ext2_xattr_set(d_inode(dentry), EXT2_XATTR_INDEX_SECURITY, name,
  22. value, size, flags);
  23. }
  24. static int ext2_initxattrs(struct inode *inode, const struct xattr *xattr_array,
  25. void *fs_info)
  26. {
  27. const struct xattr *xattr;
  28. int err = 0;
  29. for (xattr = xattr_array; xattr->name != NULL; xattr++) {
  30. err = ext2_xattr_set(inode, EXT2_XATTR_INDEX_SECURITY,
  31. xattr->name, xattr->value,
  32. xattr->value_len, 0);
  33. if (err < 0)
  34. break;
  35. }
  36. return err;
  37. }
  38. int
  39. ext2_init_security(struct inode *inode, struct inode *dir,
  40. const struct qstr *qstr)
  41. {
  42. return security_inode_init_security(inode, dir, qstr,
  43. &ext2_initxattrs, NULL);
  44. }
  45. const struct xattr_handler ext2_xattr_security_handler = {
  46. .prefix = XATTR_SECURITY_PREFIX,
  47. .get = ext2_xattr_security_get,
  48. .set = ext2_xattr_security_set,
  49. };