]> xenbits.xensource.com Git - libvirt.git/commitdiff
virt-aa-helper: use 'include if exists' on .files
authorGeorgia Garcia <georgia.garcia@canonical.com>
Tue, 4 Jun 2024 17:34:56 +0000 (14:34 -0300)
committerMichal Privoznik <mprivozn@redhat.com>
Tue, 11 Jun 2024 07:46:19 +0000 (09:46 +0200)
Change the 'include' in the AppArmor policy to use 'include if exists'
when including <uuid>.files. Note that 'if exists' is only available
after AppArmor 3.0, therefore a #ifdef check must be added.

When the <uuid>.files is not present, there are some failures in the
AppArmor tools like the following, since they expect the file to exist
when using 'include':

ERROR: Include file /etc/apparmor.d/libvirt/libvirt-8534a409-a460-4fab-a2dd-0e1dce4ff273.files not found

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/security/virt-aa-helper.c

index 0374581f07c69b5fcb91ea82d1ea3113948e0f23..402cbd960245258ab218e65f6b1a0bd873414ddc 100644 (file)
@@ -1564,7 +1564,12 @@ main(int argc, char **argv)
         /* create the profile from TEMPLATE */
         if (ctl->cmd == 'c' || purged) {
             char *tmp = NULL;
-            tmp = g_strdup_printf("  #include <libvirt/%s.files>\n", ctl->uuid);
+#if defined(WITH_APPARMOR_3)
+            const char *ifexists = "if exists ";
+#else
+            const char *ifexists = "";
+#endif
+            tmp = g_strdup_printf("  #include %s<libvirt/%s.files>\n", ifexists, ctl->uuid);
 
             if (ctl->dryrun) {
                 vah_info(profile);