Blame SOURCES/0044-policycoreutils-Improve-error-message-when-selabel_o.patch

e0b08f
From 69da6239d8505a9d6ca547187f71a351df17f157 Mon Sep 17 00:00:00 2001
e0b08f
From: Vit Mojzis <vmojzis@redhat.com>
e0b08f
Date: Mon, 10 Jan 2022 18:35:27 +0100
e0b08f
Subject: [PATCH] policycoreutils: Improve error message when selabel_open
e0b08f
 fails
e0b08f
e0b08f
When selabel_open fails to locate file_context files and
e0b08f
selabel_opt_path is not specified (e.g. when the policy type is
e0b08f
missconfigured in /etc/selinux/config), perror only prints
e0b08f
"No such file or directory".
e0b08f
This can be confusing in case of "restorecon" since it's
e0b08f
not apparent that the issue is in policy store.
e0b08f
e0b08f
Before:
e0b08f
  \# restorecon -v /tmp/foo.txt
e0b08f
  No such file or directory
e0b08f
After:
e0b08f
  \# restorecon -v /tmp/foo.txt
e0b08f
  /etc/selinux/yolo/contexts/files/file_contexts: No such file or directory
e0b08f
e0b08f
Signed-off-by: Vit Mojzis <vmojzis@redhat.com>
e0b08f
---
e0b08f
 policycoreutils/setfiles/restore.c | 2 +-
e0b08f
 1 file changed, 1 insertion(+), 1 deletion(-)
e0b08f
e0b08f
diff --git a/policycoreutils/setfiles/restore.c b/policycoreutils/setfiles/restore.c
e0b08f
index d3335d1a..ba2668b3 100644
e0b08f
--- a/policycoreutils/setfiles/restore.c
e0b08f
+++ b/policycoreutils/setfiles/restore.c
e0b08f
@@ -29,7 +29,7 @@ void restore_init(struct restore_opts *opts)
e0b08f
 
e0b08f
 	opts->hnd = selabel_open(SELABEL_CTX_FILE, selinux_opts, 3);
e0b08f
 	if (!opts->hnd) {
e0b08f
-		perror(opts->selabel_opt_path);
e0b08f
+		perror(opts->selabel_opt_path ? opts->selabel_opt_path : selinux_file_context_path());
e0b08f
 		exit(1);
e0b08f
 	}
e0b08f
 
e0b08f
-- 
e0b08f
2.30.2
e0b08f