aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2020-04-27 12:41:24 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2020-04-27 12:41:24 +0200
commit20143cd6b0edf4756c556ed6626d6a6c6f22fb41 (patch)
treebcb6b8c800d55ea51179f67b19e46db5931401bf
parent5630c5fa818a38c180ee4b859539cd37a9c2b93a (diff)
gensquashfs: Add options to globally override UID/GID values
A common use case for mksquashfs is to simply pack a directory and set a magic option to force all user/group IDs to root. This commit adds similar options to gensquashfs to maek it better suited as a direct replacement for packing an input directory. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
-rw-r--r--bin/gensquashfs/mkfs.c17
-rw-r--r--bin/gensquashfs/mkfs.h5
-rw-r--r--bin/gensquashfs/options.c31
-rw-r--r--doc/gensquashfs.111
4 files changed, 63 insertions, 1 deletions
diff --git a/bin/gensquashfs/mkfs.c b/bin/gensquashfs/mkfs.c
index 9ffbb94..b1542d1 100644
--- a/bin/gensquashfs/mkfs.c
+++ b/bin/gensquashfs/mkfs.c
@@ -171,6 +171,20 @@ static int read_fstree(fstree_t *fs, options_t *opt, sqfs_xattr_writer_t *xwr,
return ret;
}
+static void override_owner_dfs(const options_t *opt, tree_node_t *n)
+{
+ if (opt->force_uid)
+ n->uid = opt->force_uid_value;
+
+ if (opt->force_gid)
+ n->gid = opt->force_gid_value;
+
+ if (S_ISDIR(n->mode)) {
+ for (n = n->data.dir.children; n != NULL; n = n->next)
+ override_owner_dfs(opt, n);
+ }
+}
+
int main(int argc, char **argv)
{
int status = EXIT_FAILURE;
@@ -195,6 +209,9 @@ int main(int argc, char **argv)
goto out;
}
+ if (opt.force_uid || opt.force_gid)
+ override_owner_dfs(&opt, sqfs.fs.root);
+
if (sehnd != NULL) {
selinux_close_context_file(sehnd);
sehnd = NULL;
diff --git a/bin/gensquashfs/mkfs.h b/bin/gensquashfs/mkfs.h
index 1b767aa..9a36d8c 100644
--- a/bin/gensquashfs/mkfs.h
+++ b/bin/gensquashfs/mkfs.h
@@ -46,6 +46,11 @@ typedef struct {
const char *packdir;
const char *selinux;
bool no_tail_packing;
+
+ unsigned int force_uid_value;
+ unsigned int force_gid_value;
+ bool force_uid;
+ bool force_gid;
} options_t;
enum {
diff --git a/bin/gensquashfs/options.c b/bin/gensquashfs/options.c
index 2369787..d029c09 100644
--- a/bin/gensquashfs/options.c
+++ b/bin/gensquashfs/options.c
@@ -6,7 +6,14 @@
*/
#include "mkfs.h"
+enum {
+ ALL_ROOT_OPTION = 1,
+};
+
static struct option long_opts[] = {
+ { "all-root", required_argument, NULL, ALL_ROOT_OPTION },
+ { "set-uid", required_argument, NULL, 'u' },
+ { "set-gid", required_argument, NULL, 'g' },
{ "compressor", required_argument, NULL, 'c' },
{ "block-size", required_argument, NULL, 'b' },
{ "dev-block-size", required_argument, NULL, 'B' },
@@ -33,7 +40,7 @@ static struct option long_opts[] = {
{ NULL, 0, NULL, 0 },
};
-static const char *short_opts = "F:D:X:c:b:B:d:j:Q:kxoefqThV"
+static const char *short_opts = "F:D:X:c:b:B:d:u:g:j:Q:kxoefqThV"
#ifdef WITH_SELINUX
"s:"
#endif
@@ -83,6 +90,14 @@ static const char *help_string =
" mode=<value> 0755 if not set.\n"
" mtime=<value> 0 if not set.\n"
"\n"
+" --set-uid, -u <number> Force the owners user ID for ALL inodes to\n"
+" this value, no matter what the pack file or\n"
+" directory entries actually specify.\n"
+" --set-gid, -g <number> Force the owners group ID for ALL inodes to\n"
+" this value, no matter what the pack file or\n"
+" directory entries actually specify.\n"
+" --all-root A short hand for `--set-uid 0 --set-gid 0`.\n"
+"\n"
#ifdef WITH_SELINUX
" --selinux, -s <file> Specify an SELinux label file to get context\n"
" attributes from.\n"
@@ -162,6 +177,20 @@ void process_command_line(options_t *opt, int argc, char **argv)
break;
switch (i) {
+ case ALL_ROOT_OPTION:
+ opt->force_uid_value = 0;
+ opt->force_gid_value = 0;
+ opt->force_uid = true;
+ opt->force_gid = true;
+ break;
+ case 'u':
+ opt->force_uid_value = strtol(optarg, NULL, 0);
+ opt->force_uid = true;
+ break;
+ case 'g':
+ opt->force_gid_value = strtol(optarg, NULL, 0);
+ opt->force_gid = true;
+ break;
case 'T':
opt->no_tail_packing = true;
break;
diff --git a/doc/gensquashfs.1 b/doc/gensquashfs.1
index 0de39bf..6214741 100644
--- a/doc/gensquashfs.1
+++ b/doc/gensquashfs.1
@@ -76,6 +76,17 @@ mtime=<value>;\fB$SOURCE\_DATE\_EPOCH\fR if set, 0 otherwise
.TE
.TP
.TP
+\fB\-\-set\-uid\fR, \fB\-u\fR <number>
+Force the owners user ID for ALL inodes to this value, no matter what the pack
+file or directory entries actually specify.
+.TP
+\fB\-\-set\-gid\fR, \fB\-g\fR <number>
+Force the owners group ID for ALL inodes to this value, no matter what the pack
+file or directory entries actually specify.
+.TP
+\fB\-\-all\-root\fR
+A short hand for `\-\-set\-uid 0 \-\-set\-gid 0`.
+.TP
\fB\-\-selinux\fR, \fB\-s\fR <file>
If built with SELinux support, use the given SELinux label file to add context
labels to the elements packed into the SquashFS image.