From 28b24512622785d1634a089f7d1d5c25edfb7577 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Sat, 11 May 2019 00:35:29 +0200 Subject: Add SELinux option to gensquashfs Signed-off-by: David Oberhollenzer --- mkfs/Makemodule.am | 2 ++ mkfs/mkfs.c | 9 +++++++++ mkfs/mkfs.h | 1 + mkfs/options.c | 16 ++++++++++++++++ 4 files changed, 28 insertions(+) diff --git a/mkfs/Makemodule.am b/mkfs/Makemodule.am index 33471fc..d8e75a2 100644 --- a/mkfs/Makemodule.am +++ b/mkfs/Makemodule.am @@ -1,6 +1,7 @@ gensquashfs_SOURCES = mkfs/mkfs.c mkfs/mkfs.h mkfs/block.c gensquashfs_SOURCES += mkfs/options.c mkfs/meta.c gensquashfs_LDADD = libsquashfs.a libfstree.a libcompress.a libutil.a +gensquashfs_CPPFLAGS = $(AM_CPPFLAGS) if WITH_XZ gensquashfs_LDADD += $(XZ_LIBS) @@ -19,6 +20,7 @@ gensquashfs_LDADD += $(LZ4_LIBS) endif if WITH_SELINUX +gensquashfs_CPPFLAGS += -DWITH_SELINUX gensquashfs_LDADD += $(LIBSELINUX_LIBS) endif diff --git a/mkfs/mkfs.c b/mkfs/mkfs.c index ae6210b..d028a9d 100644 --- a/mkfs/mkfs.c +++ b/mkfs/mkfs.c @@ -72,6 +72,15 @@ int main(int argc, char **argv) if (fstree_from_file(&info.fs, info.opt.infile)) goto out_fstree; +#ifdef WITH_SELINUX + if (info.opt.selinux != NULL) { + if (fstree_relabel_selinux(&info.fs, info.opt.selinux)) + goto out_fstree; + } +#endif + + fstree_xattr_deduplicate(&info.fs); + fstree_sort(&info.fs); info.cmp = compressor_create(info.super.compression_id, true, diff --git a/mkfs/mkfs.h b/mkfs/mkfs.h index c689848..33e9970 100644 --- a/mkfs/mkfs.h +++ b/mkfs/mkfs.h @@ -28,6 +28,7 @@ typedef struct { bool quiet; const char *infile; const char *outfile; + const char *selinux; } options_t; typedef struct { diff --git a/mkfs/options.c b/mkfs/options.c index 0a556eb..d7bdf16 100644 --- a/mkfs/options.c +++ b/mkfs/options.c @@ -18,11 +18,18 @@ static struct option long_opts[] = { { "defaults", required_argument, NULL, 'd' }, { "force", no_argument, NULL, 'f' }, { "quiet", no_argument, NULL, 'q' }, +#ifdef WITH_SELINUX + { "selinux", required_argument, NULL, 's' }, +#endif { "version", no_argument, NULL, 'V' }, { "help", no_argument, NULL, 'h' }, }; +#ifdef WITH_SELINUX +static const char *short_opts = "s:c:b:B:d:fqhV"; +#else static const char *short_opts = "c:b:B:d:fqhV"; +#endif enum { DEF_UID = 0, @@ -97,6 +104,10 @@ static const char *help_string = " mode= 0755 if not set.\n" " mtime= 0 if not set.\n" "\n" +#ifdef WITH_SELINUX +" --selinux, s Specify an SELinux label file to get context\n" +" attributes from.\n" +#endif " --force, -f Overwrite the output file if it exists.\n" " --quiet, -q Do not print out progress reports.\n" " --help, -h Print help text and exit.\n" @@ -265,6 +276,11 @@ void process_command_line(options_t *opt, int argc, char **argv) case 'q': opt->quiet = true; break; +#ifdef WITH_SELINUX + case 's': + opt->selinux = optarg; + break; +#endif case 'h': printf(help_string, __progname, SQFS_DEFAULT_BLOCK_SIZE, SQFS_DEVBLK_SIZE); -- cgit v1.2.3