security.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * JFFS2 -- Journalling Flash File System, Version 2.
  3. *
  4. * Copyright © 2006 NEC Corporation
  5. *
  6. * Created by KaiGai Kohei <kaigai@ak.jp.nec.com>
  7. *
  8. * For licensing information, see the file 'LICENCE' in this directory.
  9. *
  10. */
  11. #include <linux/kernel.h>
  12. #include <linux/slab.h>
  13. #include <linux/fs.h>
  14. #include <linux/time.h>
  15. #include <linux/pagemap.h>
  16. #include <linux/highmem.h>
  17. #include <linux/crc32.h>
  18. #include <linux/jffs2.h>
  19. #include <linux/xattr.h>
  20. #include <linux/mtd/mtd.h>
  21. #include <linux/security.h>
  22. #include "nodelist.h"
  23. /* ---- Initial Security Label(s) Attachment callback --- */
  24. static int jffs2_initxattrs(struct inode *inode,
  25. const struct xattr *xattr_array, void *fs_info)
  26. {
  27. const struct xattr *xattr;
  28. int err = 0;
  29. for (xattr = xattr_array; xattr->name != NULL; xattr++) {
  30. err = do_jffs2_setxattr(inode, JFFS2_XPREFIX_SECURITY,
  31. xattr->name, xattr->value,
  32. xattr->value_len, 0);
  33. if (err < 0)
  34. break;
  35. }
  36. return err;
  37. }
  38. /* ---- Initial Security Label(s) Attachment ----------- */
  39. int jffs2_init_security(struct inode *inode, struct inode *dir,
  40. const struct qstr *qstr)
  41. {
  42. return security_inode_init_security(inode, dir, qstr,
  43. &jffs2_initxattrs, NULL);
  44. }
  45. /* ---- XATTR Handler for "security.*" ----------------- */
  46. static int jffs2_security_getxattr(const struct xattr_handler *handler,
  47. struct dentry *dentry, const char *name,
  48. void *buffer, size_t size)
  49. {
  50. if (!strcmp(name, ""))
  51. return -EINVAL;
  52. return do_jffs2_getxattr(d_inode(dentry), JFFS2_XPREFIX_SECURITY,
  53. name, buffer, size);
  54. }
  55. static int jffs2_security_setxattr(const struct xattr_handler *handler,
  56. struct dentry *dentry, const char *name,
  57. const void *buffer, size_t size, int flags)
  58. {
  59. if (!strcmp(name, ""))
  60. return -EINVAL;
  61. return do_jffs2_setxattr(d_inode(dentry), JFFS2_XPREFIX_SECURITY,
  62. name, buffer, size, flags);
  63. }
  64. static size_t jffs2_security_listxattr(const struct xattr_handler *handler,
  65. struct dentry *dentry, char *list,
  66. size_t list_size, const char *name,
  67. size_t name_len)
  68. {
  69. size_t retlen = XATTR_SECURITY_PREFIX_LEN + name_len + 1;
  70. if (list && retlen <= list_size) {
  71. strcpy(list, XATTR_SECURITY_PREFIX);
  72. strcpy(list + XATTR_SECURITY_PREFIX_LEN, name);
  73. }
  74. return retlen;
  75. }
  76. const struct xattr_handler jffs2_security_xattr_handler = {
  77. .prefix = XATTR_SECURITY_PREFIX,
  78. .list = jffs2_security_listxattr,
  79. .set = jffs2_security_setxattr,
  80. .get = jffs2_security_getxattr
  81. };