diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2020-04-27 12:41:24 +0200 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2020-04-27 12:41:24 +0200 |
commit | 20143cd6b0edf4756c556ed6626d6a6c6f22fb41 (patch) | |
tree | bcb6b8c800d55ea51179f67b19e46db5931401bf /bin | |
parent | 5630c5fa818a38c180ee4b859539cd37a9c2b93a (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>
Diffstat (limited to 'bin')
-rw-r--r-- | bin/gensquashfs/mkfs.c | 17 | ||||
-rw-r--r-- | bin/gensquashfs/mkfs.h | 5 | ||||
-rw-r--r-- | bin/gensquashfs/options.c | 31 |
3 files changed, 52 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; |