xattr_security.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 *dentry, const char *name,
  15. void *buffer, size_t size)
  16. {
  17. return ext4_xattr_get(d_inode(dentry), 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 *dentry, const char *name,
  23. const void *value, size_t size, int flags)
  24. {
  25. return ext4_xattr_set(d_inode(dentry), EXT4_XATTR_INDEX_SECURITY,
  26. name, value, size, flags);
  27. }
  28. static int
  29. ext4_initxattrs(struct inode *inode, const struct xattr *xattr_array,
  30. void *fs_info)
  31. {
  32. const struct xattr *xattr;
  33. handle_t *handle = fs_info;
  34. int err = 0;
  35. for (xattr = xattr_array; xattr->name != NULL; xattr++) {
  36. err = ext4_xattr_set_handle(handle, inode,
  37. EXT4_XATTR_INDEX_SECURITY,
  38. xattr->name, xattr->value,
  39. xattr->value_len, 0);
  40. if (err < 0)
  41. break;
  42. }
  43. return err;
  44. }
  45. int
  46. ext4_init_security(handle_t *handle, struct inode *inode, struct inode *dir,
  47. const struct qstr *qstr)
  48. {
  49. return security_inode_init_security(inode, dir, qstr,
  50. &ext4_initxattrs, handle);
  51. }
  52. const struct xattr_handler ext4_xattr_security_handler = {
  53. .prefix = XATTR_SECURITY_PREFIX,
  54. .get = ext4_xattr_security_get,
  55. .set = ext4_xattr_security_set,
  56. };