File coreutils-chcon-skip-validation-if-selinux-disabled.patch of Package coreutils.39338

From: Kamil Dudka <kdudka@redhat.com>
Date: Mon, 2 Dec 2019 14:02:02 +0100
Subject: chcon: do not validate security context if SELinux is disabled
References: bsc#1212999
Git-commit: 5118a2e392c8cffb3c26eaffbb75e2b1ef7607f9
Patch-mainline: v8.32

* src/chcon.c (main): Skip call of security_check_context()
in case SELinux is disabled to avoid unnecessary failure.

Bug: https://bugzilla.redhat.com/1777831
---
 src/chcon.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

--- coreutils-8.25.orig/src/chcon.c
+++ coreutils-8.25/src/chcon.c
@@ -18,6 +18,7 @@
 #include <stdio.h>
 #include <sys/types.h>
 #include <getopt.h>
+#include <selinux/selinux.h>
 
 #include "system.h"
 #include "dev-ino.h"
@@ -556,7 +557,8 @@ main (int argc, char **argv)
   else
     {
       specified_context = argv[optind++];
-      if (security_check_context (se_const (specified_context)) < 0)
+      if (0 < is_selinux_enabled ()
+          && security_check_context (se_const (specified_context)) < 0)
         error (EXIT_FAILURE, errno, _("invalid context: %s"),
                quote (specified_context));
     }
openSUSE Build Service is sponsored by