xattr_security.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * linux/fs/hfsplus/xattr_trusted.c
  3. *
  4. * Vyacheslav Dubeyko <slava@dubeyko.com>
  5. *
  6. * Handler for storing security labels as extended attributes.
  7. */
  8. #include <linux/security.h>
  9. #include <linux/nls.h>
  10. #include "hfsplus_fs.h"
  11. #include "xattr.h"
  12. #include "acl.h"
  13. static int hfsplus_security_getxattr(const struct xattr_handler *handler,
  14. struct dentry *unused, struct inode *inode,
  15. const char *name, void *buffer, size_t size)
  16. {
  17. return hfsplus_getxattr(inode, name, buffer, size,
  18. XATTR_SECURITY_PREFIX,
  19. XATTR_SECURITY_PREFIX_LEN);
  20. }
  21. static int hfsplus_security_setxattr(const struct xattr_handler *handler,
  22. struct dentry *unused, struct inode *inode,
  23. const char *name, const void *buffer,
  24. size_t size, int flags)
  25. {
  26. return hfsplus_setxattr(inode, name, buffer, size, flags,
  27. XATTR_SECURITY_PREFIX,
  28. XATTR_SECURITY_PREFIX_LEN);
  29. }
  30. static int hfsplus_initxattrs(struct inode *inode,
  31. const struct xattr *xattr_array,
  32. void *fs_info)
  33. {
  34. const struct xattr *xattr;
  35. char *xattr_name;
  36. int err = 0;
  37. xattr_name = kmalloc(NLS_MAX_CHARSET_SIZE * HFSPLUS_ATTR_MAX_STRLEN + 1,
  38. GFP_KERNEL);
  39. if (!xattr_name)
  40. return -ENOMEM;
  41. for (xattr = xattr_array; xattr->name != NULL; xattr++) {
  42. if (!strcmp(xattr->name, ""))
  43. continue;
  44. strcpy(xattr_name, XATTR_SECURITY_PREFIX);
  45. strcpy(xattr_name +
  46. XATTR_SECURITY_PREFIX_LEN, xattr->name);
  47. memset(xattr_name +
  48. XATTR_SECURITY_PREFIX_LEN + strlen(xattr->name), 0, 1);
  49. err = __hfsplus_setxattr(inode, xattr_name,
  50. xattr->value, xattr->value_len, 0);
  51. if (err)
  52. break;
  53. }
  54. kfree(xattr_name);
  55. return err;
  56. }
  57. int hfsplus_init_security(struct inode *inode, struct inode *dir,
  58. const struct qstr *qstr)
  59. {
  60. return security_inode_init_security(inode, dir, qstr,
  61. &hfsplus_initxattrs, NULL);
  62. }
  63. int hfsplus_init_inode_security(struct inode *inode,
  64. struct inode *dir,
  65. const struct qstr *qstr)
  66. {
  67. int err;
  68. err = hfsplus_init_posix_acl(inode, dir);
  69. if (!err)
  70. err = hfsplus_init_security(inode, dir, qstr);
  71. return err;
  72. }
  73. const struct xattr_handler hfsplus_xattr_security_handler = {
  74. .prefix = XATTR_SECURITY_PREFIX,
  75. .get = hfsplus_security_getxattr,
  76. .set = hfsplus_security_setxattr,
  77. };