security.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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(struct dentry *dentry, const char *name,
  47. void *buffer, size_t size, int type)
  48. {
  49. if (!strcmp(name, ""))
  50. return -EINVAL;
  51. return do_jffs2_getxattr(d_inode(dentry), JFFS2_XPREFIX_SECURITY,
  52. name, buffer, size);
  53. }
  54. static int jffs2_security_setxattr(struct dentry *dentry, const char *name,
  55. const void *buffer, size_t size, int flags, int type)
  56. {
  57. if (!strcmp(name, ""))
  58. return -EINVAL;
  59. return do_jffs2_setxattr(d_inode(dentry), JFFS2_XPREFIX_SECURITY,
  60. name, buffer, size, flags);
  61. }
  62. static size_t jffs2_security_listxattr(struct dentry *dentry, char *list,
  63. size_t list_size, const char *name, size_t name_len, int type)
  64. {
  65. size_t retlen = XATTR_SECURITY_PREFIX_LEN + name_len + 1;
  66. if (list && retlen <= list_size) {
  67. strcpy(list, XATTR_SECURITY_PREFIX);
  68. strcpy(list + XATTR_SECURITY_PREFIX_LEN, name);
  69. }
  70. return retlen;
  71. }
  72. const struct xattr_handler jffs2_security_xattr_handler = {
  73. .prefix = XATTR_SECURITY_PREFIX,
  74. .list = jffs2_security_listxattr,
  75. .set = jffs2_security_setxattr,
  76. .get = jffs2_security_getxattr
  77. };