[PATCH v2 31/39] security_selinux: Simplify virSecuritySELinuxSetImageLabelInternal

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This function calls virSecuritySELinuxSetFilecon() or
virSecuritySELinuxSetFileconOptional() from a lot of places.
It works, because in all places we're passing src->path which is
what we wanted. But not anymore. We will want to be able to pass
a different path and thus the function must be reworked a bit.

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
ACKed-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/security/security_selinux.c | 34 ++++++++++++---------------------
 1 file changed, 12 insertions(+), 22 deletions(-)

diff --git a/src/security/security_selinux.c b/src/security/security_selinux.c
index e879fa39ab..3a00666d26 100644
--- a/src/security/security_selinux.c
+++ b/src/security/security_selinux.c
@@ -1823,7 +1823,9 @@ virSecuritySELinuxSetImageLabelInternal(virSecurityManagerPtr mgr,
     virSecurityDeviceLabelDefPtr disk_seclabel;
     virSecurityDeviceLabelDefPtr parent_seclabel = NULL;
     bool remember;
-    int ret;
+    const char *path = src->path;
+    const char *tcon = NULL;
+    int ret = -1;
 
     if (!src->path || !virStorageSourceIsLocalStorage(src))
         return 0;
@@ -1856,40 +1858,28 @@ virSecuritySELinuxSetImageLabelInternal(virSecurityManagerPtr mgr,
         if (!disk_seclabel->relabel)
             return 0;
 
-        ret = virSecuritySELinuxSetFilecon(mgr, src->path,
-                                           disk_seclabel->label, remember);
+        tcon = disk_seclabel->label;
     } else if (parent_seclabel && (!parent_seclabel->relabel || parent_seclabel->label)) {
         if (!parent_seclabel->relabel)
             return 0;
 
-        ret = virSecuritySELinuxSetFilecon(mgr, src->path,
-                                           parent_seclabel->label, remember);
+        tcon = parent_seclabel->label;
     } else if (!parent || parent == src) {
         if (src->shared) {
-            ret = virSecuritySELinuxSetFilecon(mgr,
-                                               src->path,
-                                               data->file_context,
-                                               remember);
+            tcon = data->file_context;
         } else if (src->readonly) {
-            ret = virSecuritySELinuxSetFilecon(mgr,
-                                               src->path,
-                                               data->content_context,
-                                               remember);
+            tcon = data->content_context;
         } else if (secdef->imagelabel) {
-            ret = virSecuritySELinuxSetFilecon(mgr,
-                                               src->path,
-                                               secdef->imagelabel,
-                                               remember);
+            tcon = secdef->imagelabel;
         } else {
-            ret = 0;
+            return 0;
         }
     } else {
-        ret = virSecuritySELinuxSetFilecon(mgr,
-                                           src->path,
-                                           data->content_context,
-                                           remember);
+        tcon = data->content_context;
     }
 
+    ret = virSecuritySELinuxSetFilecon(mgr, path, tcon, remember);
+
     if (ret == 1 && !disk_seclabel) {
         /* If we failed to set a label, but virt_use_nfs let us
          * proceed anyway, then we don't need to relabel later.  */
-- 
2.21.0

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux