You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

100 lines
2.8 KiB

  1. From b0a2386089fd6efade6b89094325ed8a9f8c6fff Mon Sep 17 00:00:00 2001
  2. From: Christian Hesse <mail@eworm.de>
  3. Date: Sat, 22 Oct 2016 22:06:54 +0200
  4. Subject: [PATCH] sload.f2fs: allow to build without libselinux
  5. Some systems do not have libselinux. Allow to build sload.f2fs without
  6. support for selinux.
  7. Signed-off-by: Christian Hesse <mail@eworm.de>
  8. Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
  9. ---
  10. configure.ac | 4 +++-
  11. fsck/sload.c | 12 +++++++++++-
  12. 2 files changed, 14 insertions(+), 2 deletions(-)
  13. diff --git a/configure.ac b/configure.ac
  14. index f519790..7a62328 100644
  15. --- a/configure.ac
  16. +++ b/configure.ac
  17. @@ -54,7 +54,9 @@ AC_PATH_PROG([LDCONFIG], [ldconfig],
  18. # Checks for libraries.
  19. PKG_CHECK_MODULES([libuuid], [uuid])
  20. -PKG_CHECK_MODULES([libselinux], [libselinux])
  21. +PKG_CHECK_MODULES([libselinux], [libselinux],
  22. + [AC_DEFINE([HAVE_LIBSELINUX], [1], [Use libselinux])],
  23. + [AC_MSG_NOTICE([libselinux not found])])
  24. # Checks for header files.
  25. AC_CHECK_HEADERS([linux/fs.h fcntl.h mntent.h stdlib.h string.h \
  26. diff --git a/fsck/sload.c b/fsck/sload.c
  27. index ea072d1..68799c1 100644
  28. --- a/fsck/sload.c
  29. +++ b/fsck/sload.c
  30. @@ -16,8 +16,11 @@
  31. #include <libgen.h>
  32. #include <dirent.h>
  33. #include <mntent.h>
  34. +
  35. +#ifdef HAVE_LIBSELINUX
  36. #include <selinux/selinux.h>
  37. #include <selinux/label.h>
  38. +#endif
  39. #ifdef WITH_ANDROID
  40. #include <selinux/label.h>
  41. @@ -110,10 +113,12 @@ static int build_directory(struct f2fs_sb_info *sbi, const char *full_path,
  42. handle_selabel(dentries + i, S_ISDIR(stat.st_mode),
  43. target_out_dir);
  44. +#ifdef HAVE_LIBSELINUX
  45. if (sehnd && selabel_lookup(sehnd, &dentries[i].secon,
  46. dentries[i].path, stat.st_mode) < 0)
  47. ERR_MSG("Cannot lookup security context for %s\n",
  48. dentries[i].path);
  49. +#endif
  50. dentries[i].pino = dir_ino;
  51. @@ -174,6 +179,7 @@ static int build_directory(struct f2fs_sb_info *sbi, const char *full_path,
  52. MSG(1, "Error unknown file type\n");
  53. }
  54. +#ifdef HAVE_LIBSELINUX
  55. if (dentries[i].secon) {
  56. inode_set_selinux(sbi, dentries[i].ino, dentries[i].secon);
  57. MSG(1, "File = %s \n----->SELinux context = %s\n",
  58. @@ -184,10 +190,12 @@ static int build_directory(struct f2fs_sb_info *sbi, const char *full_path,
  59. dentries[i].gid, dentries[i].capabilities);
  60. }
  61. + free(dentries[i].secon);
  62. +#endif
  63. +
  64. free(dentries[i].path);
  65. free(dentries[i].full_path);
  66. free((void *)dentries[i].name);
  67. - free(dentries[i].secon);
  68. }
  69. free(dentries);
  70. @@ -218,6 +226,7 @@ int f2fs_sload(struct f2fs_sb_info *sbi, const char *from_dir,
  71. return ret;
  72. }
  73. +#ifdef HAVE_LIBSELINUX
  74. if (sehnd) {
  75. char *secontext = NULL;
  76. @@ -233,6 +242,7 @@ int f2fs_sload(struct f2fs_sb_info *sbi, const char *from_dir,
  77. }
  78. free(secontext);
  79. }
  80. +#endif
  81. /* update curseg info; can update sit->types */
  82. move_curseg_info(sbi, SM_I(sbi)->main_blkaddr);
  83. --
  84. 2.10.0