Mark McLoughlin dc0cb0
From ae4523336ac06e3ff7cc7b416fad9e57998c6b54 Mon Sep 17 00:00:00 2001
Mark McLoughlin dc0cb0
From: Tim Waugh <twaugh@redhat.com>
Mark McLoughlin dc0cb0
Date: Fri, 3 Jul 2009 10:29:01 +0100
Mark McLoughlin dc0cb0
Subject: [PATCH 2/3] Don't unnecessarily try to change a file context
Mark McLoughlin dc0cb0
Mark McLoughlin dc0cb0
As pointed out by Tim Waugh here:
Mark McLoughlin dc0cb0
Mark McLoughlin dc0cb0
  https://bugzilla.redhat.com/507555
Mark McLoughlin dc0cb0
Mark McLoughlin dc0cb0
We shouldn't bother trying to set the context of a file if it already
Mark McLoughlin dc0cb0
matches what we want.
Mark McLoughlin dc0cb0
Mark McLoughlin dc0cb0
(Fixed to use STREQ() and not use tabs, as pointed out by danpb)
Mark McLoughlin dc0cb0
Mark McLoughlin dc0cb0
Signed-off-by: Mark McLoughlin <markmc@redhat.com>
Mark McLoughlin dc0cb0
---
Mark McLoughlin dc0cb0
 src/security_selinux.c |   11 ++++++++++-
Mark McLoughlin dc0cb0
 1 files changed, 10 insertions(+), 1 deletions(-)
Mark McLoughlin dc0cb0
Mark McLoughlin dc0cb0
diff --git a/src/security_selinux.c b/src/security_selinux.c
Mark McLoughlin dc0cb0
index db1c27d..c2015a1 100644
Mark McLoughlin dc0cb0
--- a/src/security_selinux.c
Mark McLoughlin dc0cb0
+++ b/src/security_selinux.c
Mark McLoughlin dc0cb0
@@ -280,10 +280,19 @@ static int
Mark McLoughlin dc0cb0
 SELinuxSetFilecon(virConnectPtr conn, const char *path, char *tcon)
Mark McLoughlin dc0cb0
 {
Mark McLoughlin dc0cb0
     char ebuf[1024];
Mark McLoughlin dc0cb0
+    security_context_t econ;
Mark McLoughlin dc0cb0
 
Mark McLoughlin dc0cb0
     VIR_INFO("Setting SELinux context on '%s' to '%s'", path, tcon);
Mark McLoughlin dc0cb0
 
Mark McLoughlin dc0cb0
-    if(setfilecon(path, tcon) < 0) {
Mark McLoughlin dc0cb0
+    if (setfilecon(path, tcon) < 0) {
Mark McLoughlin dc0cb0
+        if (getfilecon(path, &econ) >= 0) {
Mark McLoughlin dc0cb0
+            if (STREQ(tcon, econ)) {
Mark McLoughlin dc0cb0
+                freecon(econ);
Mark McLoughlin dc0cb0
+                /* It's alright, there's nothing to change anyway. */
Mark McLoughlin dc0cb0
+                return 0;
Mark McLoughlin dc0cb0
+            }
Mark McLoughlin dc0cb0
+            freecon(econ);
Mark McLoughlin dc0cb0
+        }
Mark McLoughlin dc0cb0
         virSecurityReportError(conn, VIR_ERR_ERROR,
Mark McLoughlin dc0cb0
                                _("%s: unable to set security context "
Mark McLoughlin dc0cb0
                                  "'\%s\' on %s: %s."), __func__,
Mark McLoughlin dc0cb0
-- 
Mark McLoughlin dc0cb0
1.6.2.5
Mark McLoughlin dc0cb0