security.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 *unused, struct inode *inode,
  48. const char *name, void *buffer, size_t size,
  49. int flags)
  50. {
  51. return do_jffs2_getxattr(inode, JFFS2_XPREFIX_SECURITY,
  52. name, buffer, size);
  53. }
  54. static int jffs2_security_setxattr(const struct xattr_handler *handler,
  55. struct dentry *unused, struct inode *inode,
  56. const char *name, const void *buffer,
  57. size_t size, int flags)
  58. {
  59. return do_jffs2_setxattr(inode, JFFS2_XPREFIX_SECURITY,
  60. name, buffer, size, flags);
  61. }
  62. const struct xattr_handler jffs2_security_xattr_handler = {
  63. .prefix = XATTR_SECURITY_PREFIX,
  64. .set = jffs2_security_setxattr,
  65. .get = jffs2_security_getxattr
  66. };