51 lines
1.6 KiB
Diff
51 lines
1.6 KiB
Diff
From 2f71384f233aa544cf0cf50be7e83c7762ad1c15 Mon Sep 17 00:00:00 2001
|
|
From: Vit Mojzis <vmojzis@redhat.com>
|
|
Date: Mon, 31 Oct 2022 17:46:17 +0100
|
|
Subject: [PATCH] libselinux: Ignore missing directories when -i is used
|
|
|
|
Currently "-i" only ignores a file whose parent directory exists. Start also
|
|
ignoring paths with missing components.
|
|
|
|
Fixes:
|
|
# restorecon -i -v -R /var/log/missingdir/missingfile; echo $?
|
|
255
|
|
restorecon: SELinux: Could not get canonical path for /var/log/missingdir/missingfile restorecon: No such file or directory.
|
|
|
|
Signed-off-by: Vit Mojzis <vmojzis@redhat.com>
|
|
Acked-by: James Carter <jwcart2@gmail.com>
|
|
|
|
Reference:https://github.com/SELinuxProject/selinux/commit/2f71384f233aa544cf0cf50be7e83c7762ad1c15
|
|
Confilct: modify state.flags. to flags.
|
|
---
|
|
libselinux/src/selinux_restorecon.c | 7 +++++++
|
|
1 file changed, 7 insertions(+)
|
|
|
|
diff --git a/src/selinux_restorecon.c b/src/selinux_restorecon.c
|
|
index 2d24559f..6b5f6921 100644
|
|
--- a/src/selinux_restorecon.c
|
|
+++ b/src/selinux_restorecon.c
|
|
@@ -1108,6 +1108,10 @@ static int selinux_restorecon_common(const char *pathname_orig,
|
|
pathname = realpath(pathname_orig, NULL);
|
|
if (!pathname) {
|
|
free(basename_cpy);
|
|
+ /* missing parent directory */
|
|
+ if (flags.ignore_noent && errno == ENOENT) {
|
|
+ return 0;
|
|
+ }
|
|
goto realpatherr;
|
|
}
|
|
} else {
|
|
@@ -1121,6 +1125,9 @@ static int selinux_restorecon_common(const char *pathname_orig,
|
|
free(dirname_cpy);
|
|
if (!pathdnamer) {
|
|
free(basename_cpy);
|
|
+ if (flags.ignore_noent && errno == ENOENT) {
|
|
+ return 0;
|
|
+ }
|
|
goto realpatherr;
|
|
}
|
|
if (!strcmp(pathdnamer, "/"))
|
|
--
|
|
2.27.0
|
|
|