aboutsummaryrefslogtreecommitdiff
path: root/bin/gensquashfs/src
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2023-10-20 11:44:27 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2023-10-20 11:48:17 +0200
commitdce63f71c4b901e776686cca351d4ff55badb425 (patch)
treedf04f269b8376d2c3a95988aa7190cbb5bec1b6e /bin/gensquashfs/src
parent084deb943d0326df532f8a0f901a5756162d0507 (diff)
Cleanup: gensquashfs: merge xattr scanning code
The fstree from file and directory xattr scanning code essentially do the same thing now. Except the later also _optionally_ reads xattrs from a directory source. Merge the two code paths. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'bin/gensquashfs/src')
-rw-r--r--bin/gensquashfs/src/apply_xattr.c (renamed from bin/gensquashfs/src/dirscan_xattr.c)6
-rw-r--r--bin/gensquashfs/src/mkfs.c70
-rw-r--r--bin/gensquashfs/src/mkfs.h4
3 files changed, 9 insertions, 71 deletions
diff --git a/bin/gensquashfs/src/dirscan_xattr.c b/bin/gensquashfs/src/apply_xattr.c
index 1bc829f..cc03eab 100644
--- a/bin/gensquashfs/src/dirscan_xattr.c
+++ b/bin/gensquashfs/src/apply_xattr.c
@@ -1,6 +1,6 @@
/* SPDX-License-Identifier: GPL-3.0-or-later */
/*
- * dirscan_xattr.c
+ * apply_xattr.c
*
* Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
*/
@@ -207,8 +207,8 @@ out:
return ret;
}
-int xattrs_from_dir(fstree_t *fs, const char *path, void *selinux_handle,
- void *xattr_map, sqfs_xattr_writer_t *xwr, bool scan_xattr)
+int apply_xattrs(fstree_t *fs, const char *path, void *selinux_handle,
+ void *xattr_map, sqfs_xattr_writer_t *xwr, bool scan_xattr)
{
if (xwr == NULL)
return 0;
diff --git a/bin/gensquashfs/src/mkfs.c b/bin/gensquashfs/src/mkfs.c
index 39bc605..f5164ce 100644
--- a/bin/gensquashfs/src/mkfs.c
+++ b/bin/gensquashfs/src/mkfs.c
@@ -93,66 +93,6 @@ static int pack_files(sqfs_block_processor_t *data, fstree_t *fs,
return 0;
}
-static int relabel_tree_dfs(const char *filename, sqfs_xattr_writer_t *xwr,
- tree_node_t *n, void *selinux_handle,
- void *xattrmap)
-{
- char *path = fstree_get_path(n);
- int ret;
-
- if (path == NULL) {
- perror("getting absolute node path for SELinux relabeling");
- return -1;
- }
-
- ret = sqfs_xattr_writer_begin(xwr, 0);
- if (ret) {
- sqfs_perror(filename, "recording xattr key-value pairs", ret);
- return -1;
- }
-
- if (xattrmap != NULL)
- ret = xattr_apply_map_file(path, xattrmap, xwr);
-
- if (ret == 0 && selinux_handle != NULL)
- ret = selinux_relable_node(selinux_handle, xwr, n, path);
-
- free(path);
- if (ret == 0)
- ret = sqfs_xattr_writer_end(xwr, &n->xattr_idx);
-
- if (ret) {
- sqfs_perror(filename, "flushing completed key-value pairs",
- ret);
- return -1;
- }
-
- if (S_ISDIR(n->mode)) {
- for (n = n->data.children; n != NULL; n = n->next) {
- if (relabel_tree_dfs(filename, xwr, n,
- selinux_handle, xattrmap)) {
- return -1;
- }
- }
- }
-
- return 0;
-}
-
-static int read_fstree(fstree_t *fs, options_t *opt, sqfs_xattr_writer_t *xwr,
- void *selinux_handle, void *xattrmap)
-{
- int ret;
-
- ret = fstree_from_file(fs, opt->infile, opt->packdir);
-
- if (ret == 0 && (selinux_handle != NULL || xattrmap != NULL))
- ret = relabel_tree_dfs(opt->cfg.filename, xwr,
- fs->root, selinux_handle, xattrmap);
-
- return ret;
-}
-
static void override_owner_dfs(const options_t *opt, tree_node_t *n)
{
if (opt->force_uid)
@@ -219,7 +159,7 @@ int main(int argc, char **argv)
if (ret != 0)
goto out;
} else {
- if (read_fstree(&sqfs.fs, &opt, sqfs.xwr, sehnd, xattrmap))
+ if (fstree_from_file(&sqfs.fs, opt.infile, opt.packdir))
goto out;
}
@@ -229,11 +169,9 @@ int main(int argc, char **argv)
if (fstree_post_process(&sqfs.fs))
goto out;
- if (opt.infile == NULL) {
- if (xattrs_from_dir(&sqfs.fs, opt.packdir, sehnd, xattrmap,
- sqfs.xwr, opt.scan_xattr)) {
- goto out;
- }
+ if (apply_xattrs(&sqfs.fs, opt.packdir, sehnd, xattrmap,
+ sqfs.xwr, opt.infile == NULL && opt.scan_xattr)) {
+ goto out;
}
if (sortfile != NULL) {
diff --git a/bin/gensquashfs/src/mkfs.h b/bin/gensquashfs/src/mkfs.h
index 5c5f02c..55ea2d5 100644
--- a/bin/gensquashfs/src/mkfs.h
+++ b/bin/gensquashfs/src/mkfs.h
@@ -74,8 +74,8 @@ struct XattrMap {
void process_command_line(options_t *opt, int argc, char **argv);
-int xattrs_from_dir(fstree_t *fs, const char *path, void *selinux_handle,
- void *xattr_map, sqfs_xattr_writer_t *xwr, bool scan_xattr);
+int apply_xattrs(fstree_t *fs, const char *path, void *selinux_handle,
+ void *xattr_map, sqfs_xattr_writer_t *xwr, bool scan_xattr);
void *xattr_open_map_file(const char *path);