]> xenbits.xensource.com Git - libvirt.git/commitdiff
apparmor: refactor AppArmorSetSecurityImageLabel
authorChristian Ehrhardt <christian.ehrhardt@canonical.com>
Wed, 16 Oct 2019 07:32:52 +0000 (09:32 +0200)
committerChristian Ehrhardt <christian.ehrhardt@canonical.com>
Thu, 21 Nov 2019 07:26:07 +0000 (08:26 +0100)
A lot of the code in AppArmorSetSecurityImageLabel is a duplicate of
what is in reload_profile, this refactors AppArmorSetSecurityImageLabel
to use reload_profile instead.

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Acked-by: Jamie Strandboge <jamie@canonical.com>
Signed-off-by: Christian Ehrhardt <christian.ehrhardt@canonical.com>
src/security/security_apparmor.c

index c75abddef04a16d04e3d75224bb08a0d097c2636..2dd861d85054e1b2adcd5731a7d73b89ef754a13 100644 (file)
@@ -778,8 +778,6 @@ AppArmorSetSecurityImageLabel(virSecurityManagerPtr mgr,
                               virStorageSourcePtr src,
                               virSecurityDomainImageLabelFlags flags G_GNUC_UNUSED)
 {
-    int rc = -1;
-    char *profile_name = NULL;
     virSecurityLabelDefPtr secdef;
 
     if (!src->path || !virStorageSourceIsLocalStorage(src))
@@ -789,36 +787,18 @@ AppArmorSetSecurityImageLabel(virSecurityManagerPtr mgr,
     if (!secdef || !secdef->relabel)
         return 0;
 
-    if (secdef->imagelabel) {
-        /* if the device doesn't exist, error out */
-        if (!virFileExists(src->path)) {
-            virReportError(VIR_ERR_INTERNAL_ERROR,
-                           _("\'%s\' does not exist"),
-                           src->path);
-            return -1;
-        }
-
-        if ((profile_name = get_profile_name(def)) == NULL)
-            return -1;
+    if (!secdef->imagelabel)
+        return 0;
 
-        /* update the profile only if it is loaded */
-        if (profile_loaded(secdef->imagelabel) >= 0) {
-            if (load_profile(mgr, secdef->imagelabel, def,
-                             src->path, false) < 0) {
-                virReportError(VIR_ERR_INTERNAL_ERROR,
-                               _("cannot update AppArmor profile "
-                                 "\'%s\'"),
-                               secdef->imagelabel);
-                goto cleanup;
-            }
-        }
+    /* if the device doesn't exist, error out */
+    if (!virFileExists(src->path)) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("\'%s\' does not exist"),
+                       src->path);
+        return -1;
     }
-    rc = 0;
 
- cleanup:
-    VIR_FREE(profile_name);
-
-    return rc;
+    return reload_profile(mgr, def, src->path, false);
 }
 
 static int