summaryrefslogtreecommitdiff
path: root/bin/gensquashfs/mkfs.c
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 /bin/gensquashfs/mkfs.c
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>
Diffstat (limited to 'bin/gensquashfs/mkfs.c')
-rw-r--r--bin/gensquashfs/mkfs.c17
1 files changed, 17 insertions, 0 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;