diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2023-10-20 11:18:40 +0200 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2023-10-20 11:26:53 +0200 |
commit | 084deb943d0326df532f8a0f901a5756162d0507 (patch) | |
tree | e583decf02af0dee3cdb228e791b3f8ec50f7d44 /bin/gensquashfs/src | |
parent | 2eec954d10396fba1755261f3d911701818755d8 (diff) |
gensquashfs: apply xattr file also when using a pack file
When reading a directory tree from a description file, we already scan
do selinux relabeling if applicable. The same code path can be used to
apply xattr from an xattr file, if present.
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'bin/gensquashfs/src')
-rw-r--r-- | bin/gensquashfs/src/mkfs.c | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/bin/gensquashfs/src/mkfs.c b/bin/gensquashfs/src/mkfs.c index 248eb74..39bc605 100644 --- a/bin/gensquashfs/src/mkfs.c +++ b/bin/gensquashfs/src/mkfs.c @@ -94,7 +94,8 @@ static int pack_files(sqfs_block_processor_t *data, fstree_t *fs, } static int relabel_tree_dfs(const char *filename, sqfs_xattr_writer_t *xwr, - tree_node_t *n, void *selinux_handle) + tree_node_t *n, void *selinux_handle, + void *xattrmap) { char *path = fstree_get_path(n); int ret; @@ -110,24 +111,28 @@ static int relabel_tree_dfs(const char *filename, sqfs_xattr_writer_t *xwr, return -1; } - if (selinux_relable_node(selinux_handle, xwr, n, path)) { - free(path); - 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); - ret = sqfs_xattr_writer_end(xwr, &n->xattr_idx); if (ret) { sqfs_perror(filename, "flushing completed key-value pairs", ret); return -1; } - free(path); - if (S_ISDIR(n->mode)) { for (n = n->data.children; n != NULL; n = n->next) { - if (relabel_tree_dfs(filename, xwr, n, selinux_handle)) + if (relabel_tree_dfs(filename, xwr, n, + selinux_handle, xattrmap)) { return -1; + } } } @@ -135,15 +140,15 @@ static int relabel_tree_dfs(const char *filename, sqfs_xattr_writer_t *xwr, } static int read_fstree(fstree_t *fs, options_t *opt, sqfs_xattr_writer_t *xwr, - void *selinux_handle) + void *selinux_handle, void *xattrmap) { int ret; ret = fstree_from_file(fs, opt->infile, opt->packdir); - if (ret == 0 && selinux_handle != NULL) + if (ret == 0 && (selinux_handle != NULL || xattrmap != NULL)) ret = relabel_tree_dfs(opt->cfg.filename, xwr, - fs->root, selinux_handle); + fs->root, selinux_handle, xattrmap); return ret; } @@ -214,7 +219,7 @@ int main(int argc, char **argv) if (ret != 0) goto out; } else { - if (read_fstree(&sqfs.fs, &opt, sqfs.xwr, sehnd)) + if (read_fstree(&sqfs.fs, &opt, sqfs.xwr, sehnd, xattrmap)) goto out; } |