xattr_security.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 *dentry, const char *name,
  15. void *buffer, size_t size)
  16. {
  17. return hfsplus_getxattr(dentry, 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 *dentry, const char *name,
  23. const void *buffer, size_t size, int flags)
  24. {
  25. return hfsplus_setxattr(dentry, name, buffer, size, flags,
  26. XATTR_SECURITY_PREFIX,
  27. XATTR_SECURITY_PREFIX_LEN);
  28. }
  29. static int hfsplus_initxattrs(struct inode *inode,
  30. const struct xattr *xattr_array,
  31. void *fs_info)
  32. {
  33. const struct xattr *xattr;
  34. char *xattr_name;
  35. int err = 0;
  36. xattr_name = kmalloc(NLS_MAX_CHARSET_SIZE * HFSPLUS_ATTR_MAX_STRLEN + 1,
  37. GFP_KERNEL);
  38. if (!xattr_name)
  39. return -ENOMEM;
  40. for (xattr = xattr_array; xattr->name != NULL; xattr++) {
  41. if (!strcmp(xattr->name, ""))
  42. continue;
  43. strcpy(xattr_name, XATTR_SECURITY_PREFIX);
  44. strcpy(xattr_name +
  45. XATTR_SECURITY_PREFIX_LEN, xattr->name);
  46. memset(xattr_name +
  47. XATTR_SECURITY_PREFIX_LEN + strlen(xattr->name), 0, 1);
  48. err = __hfsplus_setxattr(inode, xattr_name,
  49. xattr->value, xattr->value_len, 0);
  50. if (err)
  51. break;
  52. }
  53. kfree(xattr_name);
  54. return err;
  55. }
  56. int hfsplus_init_security(struct inode *inode, struct inode *dir,
  57. const struct qstr *qstr)
  58. {
  59. return security_inode_init_security(inode, dir, qstr,
  60. &hfsplus_initxattrs, NULL);
  61. }
  62. int hfsplus_init_inode_security(struct inode *inode,
  63. struct inode *dir,
  64. const struct qstr *qstr)
  65. {
  66. int err;
  67. err = hfsplus_init_posix_acl(inode, dir);
  68. if (!err)
  69. err = hfsplus_init_security(inode, dir, qstr);
  70. return err;
  71. }
  72. const struct xattr_handler hfsplus_xattr_security_handler = {
  73. .prefix = XATTR_SECURITY_PREFIX,
  74. .get = hfsplus_security_getxattr,
  75. .set = hfsplus_security_setxattr,
  76. };