xattr_security.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * linux/fs/ext4/xattr_security.c
  3. * Handler for storing security labels as extended attributes.
  4. */
  5. #include <linux/string.h>
  6. #include <linux/fs.h>
  7. #include <linux/security.h>
  8. #include <linux/slab.h>
  9. #include "ext4_jbd2.h"
  10. #include "ext4.h"
  11. #include "xattr.h"
  12. static int
  13. ext4_xattr_security_get(const struct xattr_handler *handler,
  14. struct dentry *unused, struct inode *inode,
  15. const char *name, void *buffer, size_t size)
  16. {
  17. return ext4_xattr_get(inode, EXT4_XATTR_INDEX_SECURITY,
  18. name, buffer, size);
  19. }
  20. static int
  21. ext4_xattr_security_set(const struct xattr_handler *handler,
  22. struct dentry *unused, struct inode *inode,
  23. const char *name, const void *value,
  24. size_t size, int flags)
  25. {
  26. return ext4_xattr_set(inode, EXT4_XATTR_INDEX_SECURITY,
  27. name, value, size, flags);
  28. }
  29. static int
  30. ext4_initxattrs(struct inode *inode, const struct xattr *xattr_array,
  31. void *fs_info)
  32. {
  33. const struct xattr *xattr;
  34. handle_t *handle = fs_info;
  35. int err = 0;
  36. for (xattr = xattr_array; xattr->name != NULL; xattr++) {
  37. err = ext4_xattr_set_handle(handle, inode,
  38. EXT4_XATTR_INDEX_SECURITY,
  39. xattr->name, xattr->value,
  40. xattr->value_len, 0);
  41. if (err < 0)
  42. break;
  43. }
  44. return err;
  45. }
  46. int
  47. ext4_init_security(handle_t *handle, struct inode *inode, struct inode *dir,
  48. const struct qstr *qstr)
  49. {
  50. return security_inode_init_security(inode, dir, qstr,
  51. &ext4_initxattrs, handle);
  52. }
  53. const struct xattr_handler ext4_xattr_security_handler = {
  54. .prefix = XATTR_SECURITY_PREFIX,
  55. .get = ext4_xattr_security_get,
  56. .set = ext4_xattr_security_set,
  57. };