security.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 Attachment -------------- */
  24. int jffs2_init_security(struct inode *inode, struct inode *dir,
  25. const struct qstr *qstr)
  26. {
  27. int rc;
  28. size_t len;
  29. void *value;
  30. char *name;
  31. rc = security_inode_init_security(inode, dir, qstr, &name, &value, &len);
  32. if (rc) {
  33. if (rc == -EOPNOTSUPP)
  34. return 0;
  35. return rc;
  36. }
  37. rc = do_jffs2_setxattr(inode, JFFS2_XPREFIX_SECURITY, name, value, len, 0);
  38. kfree(name);
  39. kfree(value);
  40. return rc;
  41. }
  42. /* ---- XATTR Handler for "security.*" ----------------- */
  43. static int jffs2_security_getxattr(struct dentry *dentry, const char *name,
  44. void *buffer, size_t size, int type)
  45. {
  46. if (!strcmp(name, ""))
  47. return -EINVAL;
  48. return do_jffs2_getxattr(dentry->d_inode, JFFS2_XPREFIX_SECURITY,
  49. name, buffer, size);
  50. }
  51. static int jffs2_security_setxattr(struct dentry *dentry, const char *name,
  52. const void *buffer, size_t size, int flags, int type)
  53. {
  54. if (!strcmp(name, ""))
  55. return -EINVAL;
  56. return do_jffs2_setxattr(dentry->d_inode, JFFS2_XPREFIX_SECURITY,
  57. name, buffer, size, flags);
  58. }
  59. static size_t jffs2_security_listxattr(struct dentry *dentry, char *list,
  60. size_t list_size, const char *name, size_t name_len, int type)
  61. {
  62. size_t retlen = XATTR_SECURITY_PREFIX_LEN + name_len + 1;
  63. if (list && retlen <= list_size) {
  64. strcpy(list, XATTR_SECURITY_PREFIX);
  65. strcpy(list + XATTR_SECURITY_PREFIX_LEN, name);
  66. }
  67. return retlen;
  68. }
  69. const struct xattr_handler jffs2_security_xattr_handler = {
  70. .prefix = XATTR_SECURITY_PREFIX,
  71. .list = jffs2_security_listxattr,
  72. .set = jffs2_security_setxattr,
  73. .get = jffs2_security_getxattr
  74. };