security.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*-------------------------------------------------------------------------*
  2. * File: fs/jffs2/security.c
  3. * Security Labels support on JFFS2 FileSystem
  4. *
  5. * Implemented by KaiGai Kohei <kaigai@ak.jp.nec.com>
  6. * Copyright (C) 2006 NEC Corporation
  7. *
  8. * For licensing information, see the file 'LICENCE' in the jffs2 directory.
  9. *-------------------------------------------------------------------------*/
  10. #include <linux/kernel.h>
  11. #include <linux/slab.h>
  12. #include <linux/fs.h>
  13. #include <linux/time.h>
  14. #include <linux/pagemap.h>
  15. #include <linux/highmem.h>
  16. #include <linux/crc32.h>
  17. #include <linux/jffs2.h>
  18. #include <linux/xattr.h>
  19. #include <linux/mtd/mtd.h>
  20. #include <linux/security.h>
  21. #include "nodelist.h"
  22. /* ---- Initial Security Label Attachment -------------- */
  23. int jffs2_init_security(struct inode *inode, struct inode *dir)
  24. {
  25. int rc;
  26. size_t len;
  27. void *value;
  28. char *name;
  29. rc = security_inode_init_security(inode, dir, &name, &value, &len);
  30. if (rc) {
  31. if (rc == -EOPNOTSUPP)
  32. return 0;
  33. return rc;
  34. }
  35. rc = do_jffs2_setxattr(inode, JFFS2_XPREFIX_SECURITY, name, value, len, 0);
  36. kfree(name);
  37. kfree(value);
  38. return rc;
  39. }
  40. /* ---- XATTR Handler for "security.*" ----------------- */
  41. static int jffs2_security_getxattr(struct inode *inode, const char *name,
  42. void *buffer, size_t size)
  43. {
  44. if (!strcmp(name, ""))
  45. return -EINVAL;
  46. return do_jffs2_getxattr(inode, JFFS2_XPREFIX_SECURITY, name, buffer, size);
  47. }
  48. static int jffs2_security_setxattr(struct inode *inode, const char *name, const void *buffer,
  49. size_t size, int flags)
  50. {
  51. if (!strcmp(name, ""))
  52. return -EINVAL;
  53. return do_jffs2_setxattr(inode, JFFS2_XPREFIX_SECURITY, name, buffer, size, flags);
  54. }
  55. static size_t jffs2_security_listxattr(struct inode *inode, char *list, size_t list_size,
  56. const char *name, size_t name_len)
  57. {
  58. size_t retlen = XATTR_SECURITY_PREFIX_LEN + name_len + 1;
  59. if (list && retlen <= list_size) {
  60. strcpy(list, XATTR_SECURITY_PREFIX);
  61. strcpy(list + XATTR_SECURITY_PREFIX_LEN, name);
  62. }
  63. return retlen;
  64. }
  65. struct xattr_handler jffs2_security_xattr_handler = {
  66. .prefix = XATTR_SECURITY_PREFIX,
  67. .list = jffs2_security_listxattr,
  68. .set = jffs2_security_setxattr,
  69. .get = jffs2_security_getxattr
  70. };