xattr_security.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 "hfsplus_fs.h"
  10. #include "xattr.h"
  11. static int hfsplus_security_getxattr(struct dentry *dentry, const char *name,
  12. void *buffer, size_t size, int type)
  13. {
  14. char xattr_name[HFSPLUS_ATTR_MAX_STRLEN + 1] = {0};
  15. size_t len = strlen(name);
  16. if (!strcmp(name, ""))
  17. return -EINVAL;
  18. if (len + XATTR_SECURITY_PREFIX_LEN > HFSPLUS_ATTR_MAX_STRLEN)
  19. return -EOPNOTSUPP;
  20. strcpy(xattr_name, XATTR_SECURITY_PREFIX);
  21. strcpy(xattr_name + XATTR_SECURITY_PREFIX_LEN, name);
  22. return hfsplus_getxattr(dentry, xattr_name, buffer, size);
  23. }
  24. static int hfsplus_security_setxattr(struct dentry *dentry, const char *name,
  25. const void *buffer, size_t size, int flags, int type)
  26. {
  27. char xattr_name[HFSPLUS_ATTR_MAX_STRLEN + 1] = {0};
  28. size_t len = strlen(name);
  29. if (!strcmp(name, ""))
  30. return -EINVAL;
  31. if (len + XATTR_SECURITY_PREFIX_LEN > HFSPLUS_ATTR_MAX_STRLEN)
  32. return -EOPNOTSUPP;
  33. strcpy(xattr_name, XATTR_SECURITY_PREFIX);
  34. strcpy(xattr_name + XATTR_SECURITY_PREFIX_LEN, name);
  35. return hfsplus_setxattr(dentry, xattr_name, buffer, size, flags);
  36. }
  37. static size_t hfsplus_security_listxattr(struct dentry *dentry, char *list,
  38. size_t list_size, const char *name, size_t name_len, int type)
  39. {
  40. /*
  41. * This method is not used.
  42. * It is used hfsplus_listxattr() instead of generic_listxattr().
  43. */
  44. return -EOPNOTSUPP;
  45. }
  46. static int hfsplus_initxattrs(struct inode *inode,
  47. const struct xattr *xattr_array,
  48. void *fs_info)
  49. {
  50. const struct xattr *xattr;
  51. char xattr_name[HFSPLUS_ATTR_MAX_STRLEN + 1] = {0};
  52. size_t xattr_name_len;
  53. int err = 0;
  54. for (xattr = xattr_array; xattr->name != NULL; xattr++) {
  55. xattr_name_len = strlen(xattr->name);
  56. if (xattr_name_len == 0)
  57. continue;
  58. if (xattr_name_len + XATTR_SECURITY_PREFIX_LEN >
  59. HFSPLUS_ATTR_MAX_STRLEN)
  60. return -EOPNOTSUPP;
  61. strcpy(xattr_name, XATTR_SECURITY_PREFIX);
  62. strcpy(xattr_name +
  63. XATTR_SECURITY_PREFIX_LEN, xattr->name);
  64. memset(xattr_name +
  65. XATTR_SECURITY_PREFIX_LEN + xattr_name_len, 0, 1);
  66. err = __hfsplus_setxattr(inode, xattr_name,
  67. xattr->value, xattr->value_len, 0);
  68. if (err)
  69. break;
  70. }
  71. return err;
  72. }
  73. int hfsplus_init_security(struct inode *inode, struct inode *dir,
  74. const struct qstr *qstr)
  75. {
  76. return security_inode_init_security(inode, dir, qstr,
  77. &hfsplus_initxattrs, NULL);
  78. }
  79. const struct xattr_handler hfsplus_xattr_security_handler = {
  80. .prefix = XATTR_SECURITY_PREFIX,
  81. .list = hfsplus_security_listxattr,
  82. .get = hfsplus_security_getxattr,
  83. .set = hfsplus_security_setxattr,
  84. };