summaryrefslogtreecommitdiff
path: root/lib/fstree/selinux.c
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-06-10 22:41:34 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-06-10 22:41:34 +0200
commit0742ee3943192434d69092f11946f791f0f25502 (patch)
tree64a88d77e911d040c0b24741a4d6506e0cf37707 /lib/fstree/selinux.c
parent69de75de97c17ef7370b26944ee286e4b3dc6266 (diff)
Add generic function to produce a full path from an fstree node
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/fstree/selinux.c')
-rw-r--r--lib/fstree/selinux.c45
1 files changed, 4 insertions, 41 deletions
diff --git a/lib/fstree/selinux.c b/lib/fstree/selinux.c
index ef858f2..ec14a93 100644
--- a/lib/fstree/selinux.c
+++ b/lib/fstree/selinux.c
@@ -10,45 +10,6 @@
#define XATTR_NAME_SELINUX "security.selinux"
#define XATTR_VALUE_SELINUX "system_u:object_r:unlabeled_t:s0"
-static char *get_path(tree_node_t *node)
-{
- tree_node_t *it;
- char *str, *ptr;
- size_t len = 0;
-
- if (node->parent == NULL) {
- str = strdup("/");
-
- if (str == NULL)
- goto fail_alloc;
- return str;
- }
-
- for (it = node; it != NULL && it->parent != NULL; it = it->parent) {
- len += strlen(it->name) + 1;
- }
-
- str = malloc(len + 1);
- if (str == NULL)
- goto fail_alloc;
-
- ptr = str + len;
- *ptr = '\0';
-
- for (it = node; it != NULL && it->parent != NULL; it = it->parent) {
- len = strlen(it->name);
- ptr -= len;
-
- memcpy(ptr, it->name, len);
- *(--ptr) = '/';
- }
-
- return str;
-fail_alloc:
- perror("relabeling files");
- return NULL;
-}
-
static int relable_node(fstree_t *fs, struct selabel_handle *sehnd,
tree_node_t *node)
{
@@ -56,9 +17,11 @@ static int relable_node(fstree_t *fs, struct selabel_handle *sehnd,
tree_node_t *it;
int ret;
- path = get_path(node);
- if (path == NULL)
+ path = fstree_get_path(node);
+ if (path == NULL) {
+ perror("relabeling files");
return -1;
+ }
if (selabel_lookup(sehnd, &context, path, node->mode) < 0) {
free(path);