aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2023-10-24 10:10:52 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2023-10-24 15:57:18 +0200
commitd17f308b24a332d1767888e086ece9a2e71a891d (patch)
tree765ab17e800cd4c5d9f2c2e3716d93e1aaac2c0b /bin
parentdce63f71c4b901e776686cca351d4ff55badb425 (diff)
Cleanup: gensquashfs: remove tree walk for force-uid/gid
If the --force-uid or --force-gid flags are used, don't do a recursive tree walk after the fact, instead simply apply the settings at the source (e.g. tree iterator). Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'bin')
-rw-r--r--bin/gensquashfs/src/fstree_from_file.c27
-rw-r--r--bin/gensquashfs/src/mkfs.c24
-rw-r--r--bin/gensquashfs/src/mkfs.h7
-rw-r--r--bin/gensquashfs/src/options.c10
-rw-r--r--bin/gensquashfs/test/fstree_from_file.c6
-rw-r--r--bin/gensquashfs/test/fstree_from_file2.c5
-rw-r--r--bin/gensquashfs/test/fstree_glob1.c10
-rw-r--r--bin/gensquashfs/test/sort_file.c5
8 files changed, 47 insertions, 47 deletions
diff --git a/bin/gensquashfs/src/fstree_from_file.c b/bin/gensquashfs/src/fstree_from_file.c
index a5c6e53..97773b6 100644
--- a/bin/gensquashfs/src/fstree_from_file.c
+++ b/bin/gensquashfs/src/fstree_from_file.c
@@ -100,11 +100,11 @@ static const struct callback_t {
#define NUM_HOOKS (sizeof(file_list_hooks) / sizeof(file_list_hooks[0]))
static int handle_line(fstree_t *fs, const char *filename, size_t line_num,
- split_line_t *line, const char *basepath)
+ split_line_t *line, const options_t *opt)
{
+ sqfs_u64 uid = 0, gid = 0, mode = 0;
const struct callback_t *cb = NULL;
unsigned int glob_flags = 0;
- sqfs_u64 uid, gid, mode;
sqfs_dir_entry_t *ent = NULL;
const char *msg = NULL;
bool is_glob = false;
@@ -137,7 +137,6 @@ static int handle_line(fstree_t *fs, const char *filename, size_t line_num,
goto fail_root;
if (is_glob && !strcmp(line->args[2], "*")) {
- mode = 0;
glob_flags |= DIR_SCAN_KEEP_MODE;
} else {
if (parse_uint_oct(line->args[2], -1, NULL, 0, 07777, &mode))
@@ -145,21 +144,25 @@ static int handle_line(fstree_t *fs, const char *filename, size_t line_num,
}
if (is_glob && !strcmp(line->args[3], "*")) {
- uid = 0;
- glob_flags |= DIR_SCAN_KEEP_UID;
+ glob_flags |= (opt->dirscan_flags & DIR_SCAN_KEEP_UID);
} else {
if (parse_uint(line->args[3], -1, NULL, 0, 0x0FFFFFFFF, &uid))
goto fail_uid_gid;
}
+ if (!(opt->dirscan_flags & DIR_SCAN_KEEP_UID))
+ uid = opt->force_uid_value;
+
if (is_glob && !strcmp(line->args[4], "*")) {
- gid = 0;
- glob_flags |= DIR_SCAN_KEEP_GID;
+ glob_flags |= (opt->dirscan_flags & DIR_SCAN_KEEP_GID);
} else {
if (parse_uint(line->args[4], -1, NULL, 0, 0x0FFFFFFFF, &gid))
goto fail_uid_gid;
}
+ if (!(opt->dirscan_flags & DIR_SCAN_KEEP_GID))
+ gid = opt->force_gid_value;
+
if (!is_glob && cb->need_extra && line->count <= 5)
goto fail_no_extra;
@@ -178,7 +181,7 @@ static int handle_line(fstree_t *fs, const char *filename, size_t line_num,
if (is_glob) {
ret = glob_files(fs, filename, line_num, ent,
- basepath, glob_flags, line);
+ opt->packdir, glob_flags, line);
} else {
ret = cb->callback(fs, filename, line_num, ent, line);
}
@@ -217,7 +220,7 @@ out_desc:
}
int fstree_from_file_stream(fstree_t *fs, sqfs_istream_t *fp,
- const char *basepath)
+ const options_t *opt)
{
const char *filename;
size_t line_num = 1;
@@ -249,7 +252,7 @@ int fstree_from_file_stream(fstree_t *fs, sqfs_istream_t *fp,
default: goto fail_split;
}
- ret = handle_line(fs, filename, line_num, sep, basepath);
+ ret = handle_line(fs, filename, line_num, sep, opt);
free(sep);
free(line);
++line_num;
@@ -278,7 +281,7 @@ fail_line:
return -1;
}
-int fstree_from_file(fstree_t *fs, const char *filename, const char *basepath)
+int fstree_from_file(fstree_t *fs, const char *filename, const options_t *opt)
{
sqfs_istream_t *fp;
int ret;
@@ -289,7 +292,7 @@ int fstree_from_file(fstree_t *fs, const char *filename, const char *basepath)
return -1;
}
- ret = fstree_from_file_stream(fs, fp, basepath);
+ ret = fstree_from_file_stream(fs, fp, opt);
sqfs_drop(fp);
return ret;
diff --git a/bin/gensquashfs/src/mkfs.c b/bin/gensquashfs/src/mkfs.c
index f5164ce..320e250 100644
--- a/bin/gensquashfs/src/mkfs.c
+++ b/bin/gensquashfs/src/mkfs.c
@@ -93,20 +93,6 @@ static int pack_files(sqfs_block_processor_t *data, fstree_t *fs,
return 0;
}
-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.children; n != NULL; n = n->next)
- override_owner_dfs(opt, n);
- }
-}
-
int main(int argc, char **argv)
{
int status = EXIT_FAILURE;
@@ -146,9 +132,10 @@ int main(int argc, char **argv)
int ret;
memset(&cfg, 0, sizeof(cfg));
- cfg.flags = opt.dirscan_flags | DIR_SCAN_KEEP_UID |
- DIR_SCAN_KEEP_GID | DIR_SCAN_KEEP_MODE;
cfg.def_mtime = sqfs.fs.defaults.mtime;
+ cfg.def_uid = opt.force_uid_value;
+ cfg.def_gid = opt.force_gid_value;
+ cfg.flags = opt.dirscan_flags;
dir = dir_tree_iterator_create(opt.packdir, &cfg);
if (dir == NULL)
@@ -159,13 +146,10 @@ int main(int argc, char **argv)
if (ret != 0)
goto out;
} else {
- if (fstree_from_file(&sqfs.fs, opt.infile, opt.packdir))
+ if (fstree_from_file(&sqfs.fs, opt.infile, &opt))
goto out;
}
- if (opt.force_uid || opt.force_gid)
- override_owner_dfs(&opt, sqfs.fs.root);
-
if (fstree_post_process(&sqfs.fs))
goto out;
diff --git a/bin/gensquashfs/src/mkfs.h b/bin/gensquashfs/src/mkfs.h
index 55ea2d5..437198b 100644
--- a/bin/gensquashfs/src/mkfs.h
+++ b/bin/gensquashfs/src/mkfs.h
@@ -56,8 +56,6 @@ typedef struct {
unsigned int force_uid_value;
unsigned int force_gid_value;
- bool force_uid;
- bool force_gid;
bool scan_xattr;
} options_t;
@@ -101,11 +99,10 @@ void selinux_close_context_file(void *sehnd);
Returns 0 on success.
*/
-int fstree_from_file(fstree_t *fs, const char *filename,
- const char *basepath);
+int fstree_from_file(fstree_t *fs, const char *filename, const options_t *opt);
int fstree_from_file_stream(fstree_t *fs, sqfs_istream_t *file,
- const char *basepath);
+ const options_t *opt);
/*
Recursively scan a directory to build a file system tree.
diff --git a/bin/gensquashfs/src/options.c b/bin/gensquashfs/src/options.c
index c8bf64b..6915f20 100644
--- a/bin/gensquashfs/src/options.c
+++ b/bin/gensquashfs/src/options.c
@@ -204,6 +204,8 @@ void process_command_line(options_t *opt, int argc, char **argv)
memset(opt, 0, sizeof(*opt));
sqfs_writer_cfg_init(&opt->cfg);
+ opt->dirscan_flags = DIR_SCAN_KEEP_UID | DIR_SCAN_KEEP_GID |
+ DIR_SCAN_KEEP_MODE;
for (;;) {
i = getopt_long(argc, argv, short_opts, long_opts, NULL);
@@ -214,16 +216,16 @@ void process_command_line(options_t *opt, int argc, char **argv)
case ALL_ROOT_OPTION:
opt->force_uid_value = 0;
opt->force_gid_value = 0;
- opt->force_uid = true;
- opt->force_gid = true;
+ opt->dirscan_flags &= ~DIR_SCAN_KEEP_UID;
+ opt->dirscan_flags &= ~DIR_SCAN_KEEP_GID;
break;
case 'u':
opt->force_uid_value = strtol(optarg, NULL, 0);
- opt->force_uid = true;
+ opt->dirscan_flags &= ~DIR_SCAN_KEEP_UID;
break;
case 'g':
opt->force_gid_value = strtol(optarg, NULL, 0);
- opt->force_gid = true;
+ opt->dirscan_flags &= ~DIR_SCAN_KEEP_GID;
break;
case 'T':
opt->no_tail_packing = true;
diff --git a/bin/gensquashfs/test/fstree_from_file.c b/bin/gensquashfs/test/fstree_from_file.c
index a5500dc..bbd1c09 100644
--- a/bin/gensquashfs/test/fstree_from_file.c
+++ b/bin/gensquashfs/test/fstree_from_file.c
@@ -27,15 +27,19 @@ int main(int argc, char **argv)
fstree_defaults_t fsd;
sqfs_istream_t *file;
tree_node_t *n;
+ options_t opt;
fstree_t fs;
(void)argc; (void)argv;
+ memset(&opt, 0, sizeof(opt));
+ opt.dirscan_flags = DIR_SCAN_KEEP_UID | DIR_SCAN_KEEP_GID;
+
file = istream_memory_create("memfile", 7, listing, strlen(listing));
TEST_NOT_NULL(file);
TEST_ASSERT(parse_fstree_defaults(&fsd, NULL) == 0);
TEST_ASSERT(fstree_init(&fs, &fsd) == 0);
- TEST_ASSERT(fstree_from_file_stream(&fs, file, NULL) == 0);
+ TEST_ASSERT(fstree_from_file_stream(&fs, file, &opt) == 0);
sqfs_drop(file);
fstree_post_process(&fs);
diff --git a/bin/gensquashfs/test/fstree_from_file2.c b/bin/gensquashfs/test/fstree_from_file2.c
index ab372c9..3f9561b 100644
--- a/bin/gensquashfs/test/fstree_from_file2.c
+++ b/bin/gensquashfs/test/fstree_from_file2.c
@@ -22,15 +22,18 @@ int main(int argc, char **argv)
fstree_defaults_t fsd;
sqfs_istream_t *file;
tree_node_t *n;
+ options_t opt;
fstree_t fs;
(void)argc; (void)argv;
+ memset(&opt, 0, sizeof(opt));
+
file = istream_memory_create("memfile", 7, listing, strlen(listing));
TEST_NOT_NULL(file);
TEST_ASSERT(parse_fstree_defaults(&fsd, NULL) == 0);
TEST_ASSERT(fstree_init(&fs, &fsd) == 0);
- TEST_ASSERT(fstree_from_file_stream(&fs, file, NULL) == 0);
+ TEST_ASSERT(fstree_from_file_stream(&fs, file, &opt) == 0);
sqfs_drop(file);
fstree_post_process(&fs);
diff --git a/bin/gensquashfs/test/fstree_glob1.c b/bin/gensquashfs/test/fstree_glob1.c
index 315ab74..58686fd 100644
--- a/bin/gensquashfs/test/fstree_glob1.c
+++ b/bin/gensquashfs/test/fstree_glob1.c
@@ -269,17 +269,21 @@ static void check_hierarchy(tree_node_t *root, bool subdir, bool recursive)
int main(int argc, char **argv)
{
fstree_defaults_t fsd;
+ options_t opt;
fstree_t fs;
int ret;
(void)argc; (void)argv;
TEST_ASSERT(parse_fstree_defaults(&fsd, NULL) == 0);
+ memset(&opt, 0, sizeof(opt));
+ opt.packdir = (char *)TEST_PATH;
+
/* first test case, directory tree only */
ret = fstree_init(&fs, &fsd);
TEST_EQUAL_I(ret, 0);
- ret = fstree_from_file(&fs, TEST_PATH "/fstree_glob1.txt", TEST_PATH);
+ ret = fstree_from_file(&fs, TEST_PATH "/fstree_glob1.txt", &opt);
TEST_EQUAL_I(ret, 0);
fstree_post_process(&fs);
@@ -290,7 +294,7 @@ int main(int argc, char **argv)
ret = fstree_init(&fs, &fsd);
TEST_EQUAL_I(ret, 0);
- ret = fstree_from_file(&fs, TEST_PATH "/fstree_glob2.txt", TEST_PATH);
+ ret = fstree_from_file(&fs, TEST_PATH "/fstree_glob2.txt", &opt);
TEST_EQUAL_I(ret, 0);
fstree_post_process(&fs);
@@ -301,7 +305,7 @@ int main(int argc, char **argv)
ret = fstree_init(&fs, &fsd);
TEST_EQUAL_I(ret, 0);
- ret = fstree_from_file(&fs, TEST_PATH "/fstree_glob3.txt", TEST_PATH);
+ ret = fstree_from_file(&fs, TEST_PATH "/fstree_glob3.txt", &opt);
TEST_EQUAL_I(ret, 0);
fstree_post_process(&fs);
diff --git a/bin/gensquashfs/test/sort_file.c b/bin/gensquashfs/test/sort_file.c
index 063f95d..828548a 100644
--- a/bin/gensquashfs/test/sort_file.c
+++ b/bin/gensquashfs/test/sort_file.c
@@ -114,17 +114,20 @@ int main(int argc, char **argv)
sqfs_istream_t *memstream;
fstree_defaults_t fsd;
tree_node_t *n;
+ options_t opt;
fstree_t fs;
size_t i;
(void)argc; (void)argv;
+ memset(&opt, 0, sizeof(opt));
+
memstream = istream_memory_create("listing.txt", 1024,
listing, strlen(listing));
TEST_NOT_NULL(memstream);
TEST_ASSERT(parse_fstree_defaults(&fsd, NULL) == 0);
TEST_ASSERT(fstree_init(&fs, &fsd) == 0);
- TEST_ASSERT(fstree_from_file_stream(&fs, memstream, NULL) == 0);
+ TEST_ASSERT(fstree_from_file_stream(&fs, memstream, &opt) == 0);
sqfs_drop(memstream);
fstree_post_process(&fs);