From patchwork Thu Jul 26 17:59:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cole Robinson X-Patchwork-Id: 142991 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp749884ljj; Thu, 26 Jul 2018 10:59:21 -0700 (PDT) X-Google-Smtp-Source: AAOMgpelZRjX3cAKWwZep+h34bGvQL/80z3YQKzAbtsG+wNyur/b/cvuAQF/CnHvwYryJMEN2Ftl X-Received: by 2002:aed:3de2:: with SMTP id j31-v6mr2829671qtf.3.1532627961869; Thu, 26 Jul 2018 10:59:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532627961; cv=none; d=google.com; s=arc-20160816; b=ES5NmxQXwF7PAIrmOwndhpJPYEubOpy0uFxtYAYoGPhHZeR2Hcs686EebFsYVlcalG 9TEotZxeP0spy6IkYTOLM5JEBP0hZ4LZtYxwzZX3fwZ8B3ckpDJejuZ9H2bHVgZFxUDC 437DCWx/+r3UzyNutZov01QF5uqeQUl6Wnenh2eXcdNIvPRZvSHZnaRxD2bwaOy1NE+Q Ypsxlt1sUddQE2qU7r6nmeoE65jfa+TmOwRY2+e3FQxradinBL2kZ8FHOkVRJ4vHjqZC beXFtF7avaM/5MORMrAapvURelSid5pSaQ6ofVYBQjRM50aBO7+VgTXQ4lT6QPy0f4Rd q3yg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:sender:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:message-id:date:to:from:delivered-to :arc-authentication-results; bh=WpjQWF0KKSEF0GTSm0sFvina/DeTRgnvIn+fax8qvg8=; b=IGcAVD+kSlpbqKvRlsYXfuc5W0LRkZs+157LhJhD0dRb3d32EKgmqDB1jaiQvj8CYG 5oWLB+Wng2aO24yaukcwLgRa06VeWF5aSKVY2K8MY7wYZDKvG8HFVObTCsz7H1cVVyNh co6Le7aVfzY6ibDPe2JpaV+FzMN1k2JmLtCboUREPOV54W75FltoHZW4nIRazcr58Phe 5ZO4PvBCe0qVwPTWA8WNmA/1T5Jz+r/ib8EWej0yZwRtumA1mcloptxRHi/1cvXrXkvY 1gGGXDakleeOAE/+JJjxcx0RRQBUYi7uaUuVySXJiHwcHDivFkzoqPXPzWDuUZPaM+rG OH3g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id h47-v6si1896145qth.404.2018.07.26.10.59.21 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 26 Jul 2018 10:59:21 -0700 (PDT) Received-SPF: pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B66FF307C71B; Thu, 26 Jul 2018 17:59:19 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1E21A3083332; Thu, 26 Jul 2018 17:59:19 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 61D3C4A463; Thu, 26 Jul 2018 17:59:17 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6QHxF1R030517 for ; Thu, 26 Jul 2018 13:59:15 -0400 Received: by smtp.corp.redhat.com (Postfix) id 978471C5A2; Thu, 26 Jul 2018 17:59:15 +0000 (UTC) Delivered-To: libvirt-list@redhat.com Received: from worklaptop.bos.redhat.com (dhcp-17-157.bos.redhat.com [10.18.17.157]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7C83C7C4B; Thu, 26 Jul 2018 17:59:13 +0000 (UTC) From: Cole Robinson To: libvirt-list@redhat.com Date: Thu, 26 Jul 2018 13:59:12 -0400 Message-Id: <1e02bd9e528e85a5bc0ef564f63a50c1cd25bfde.1532627952.git.crobinso@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH] audit: Share virtType fallback logic X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Thu, 26 Jul 2018 17:59:20 +0000 (UTC) Signed-off-by: Cole Robinson --- src/conf/domain_audit.c | 91 +++++++++++++---------------------------- 1 file changed, 28 insertions(+), 63 deletions(-) -- 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list Reviewed-by: John Ferlan diff --git a/src/conf/domain_audit.c b/src/conf/domain_audit.c index d9be638f05..fc13338d64 100644 --- a/src/conf/domain_audit.c +++ b/src/conf/domain_audit.c @@ -68,6 +68,21 @@ virDomainAuditGetRdev(const char *path ATTRIBUTE_UNUSED) #endif +static const char * +virDomainAuditGetVirtType(virDomainDefPtr def) +{ + const char *virt; + + if (!(virt = virDomainVirtTypeToString(def->virtType))) { + VIR_WARN("Unexpected virt type %d while encoding audit message", + def->virtType); + virt = "?"; + } + + return virt; +} + + static void virDomainAuditGenericDev(virDomainObjPtr vm, const char *type, @@ -82,7 +97,7 @@ virDomainAuditGenericDev(virDomainObjPtr vm, char *vmname = NULL; char *oldsrc = NULL; char *newsrc = NULL; - const char *virt; + const char *virt = virDomainAuditGetVirtType(vm->def); /* if both new and old source aren't provided don't log anything */ if (!newsrcpath && !oldsrcpath) @@ -99,12 +114,6 @@ virDomainAuditGenericDev(virDomainObjPtr vm, if (!(vmname = virAuditEncode("vm", vm->def->name))) goto no_memory; - if (!(virt = virDomainVirtTypeToString(vm->def->virtType))) { - VIR_WARN("Unexpected virt type %d while encoding audit message", - vm->def->virtType); - virt = "?"; - } - if (!(newsrc = virAuditEncode(newdev, VIR_AUDIT_STR(newsrcpath)))) goto no_memory; @@ -312,7 +321,7 @@ virDomainAuditNetDevice(virDomainDefPtr vmDef, virDomainNetDefPtr netDef, char *vmname; char *dev_name = NULL; char *rdev; - const char *virt; + const char *virt = virDomainAuditGetVirtType(vmDef); virUUIDFormat(vmDef->uuid, uuidstr); virMacAddrFormat(&netDef->mac, macstr); @@ -324,11 +333,6 @@ virDomainAuditNetDevice(virDomainDefPtr vmDef, virDomainNetDefPtr netDef, goto cleanup; } - if (!(virt = virDomainVirtTypeToString(vmDef->virtType))) { - VIR_WARN("Unexpected virt type %d while encoding audit message", vmDef->virtType); - virt = "?"; - } - VIR_AUDIT(VIR_AUDIT_RECORD_RESOURCE, success, "virt=%s resrc=net reason=open %s uuid=%s net=%s %s rdev=%s", virt, vmname, uuidstr, macstr, dev_name, VIR_AUDIT_STR(rdev)); @@ -356,7 +360,8 @@ virDomainAuditHostdev(virDomainObjPtr vm, virDomainHostdevDefPtr hostdev, char *vmname; char *address = NULL; char *device = NULL; - const char *virt; + const char *virt = virDomainAuditGetVirtType(vm->def); + virDomainHostdevSubsysUSBPtr usbsrc = &hostdev->source.subsys.u.usb; virDomainHostdevSubsysPCIPtr pcisrc = &hostdev->source.subsys.u.pci; virDomainHostdevSubsysSCSIPtr scsisrc = &hostdev->source.subsys.u.scsi; @@ -369,11 +374,6 @@ virDomainAuditHostdev(virDomainObjPtr vm, virDomainHostdevDefPtr hostdev, return; } - if (!(virt = virDomainVirtTypeToString(vm->def->virtType))) { - VIR_WARN("Unexpected virt type %d while encoding audit message", vm->def->virtType); - virt = "?"; - } - switch ((virDomainHostdevMode) hostdev->mode) { case VIR_DOMAIN_HOSTDEV_MODE_SUBSYS: switch ((virDomainHostdevSubsysType) hostdev->source.subsys.type) { @@ -509,7 +509,7 @@ virDomainAuditRedirdev(virDomainObjPtr vm, virDomainRedirdevDefPtr redirdev, char *vmname; char *address = NULL; char *device = NULL; - const char *virt; + const char *virt = virDomainAuditGetVirtType(vm->def); virUUIDFormat(vm->def->uuid, uuidstr); if (!(vmname = virAuditEncode("vm", vm->def->name))) { @@ -517,11 +517,6 @@ virDomainAuditRedirdev(virDomainObjPtr vm, virDomainRedirdevDefPtr redirdev, return; } - if (!(virt = virDomainVirtTypeToString(vm->def->virtType))) { - VIR_WARN("Unexpected virt type %d while encoding audit message", vm->def->virtType); - virt = "?"; - } - switch (redirdev->bus) { case VIR_DOMAIN_REDIRDEV_BUS_USB: if (VIR_STRDUP_QUIET(address, "USB redirdev") < 0) { @@ -571,7 +566,7 @@ virDomainAuditTPM(virDomainObjPtr vm, virDomainTPMDefPtr tpm, char *vmname; char *path = NULL; char *device = NULL; - const char *virt; + const char *virt = virDomainAuditGetVirtType(vm->def); virUUIDFormat(vm->def->uuid, uuidstr); if (!(vmname = virAuditEncode("vm", vm->def->name))) { @@ -579,11 +574,6 @@ virDomainAuditTPM(virDomainObjPtr vm, virDomainTPMDefPtr tpm, return; } - if (!(virt = virDomainVirtTypeToString(vm->def->virtType))) { - VIR_WARN("Unexpected virt type %d while encoding audit message", vm->def->virtType); - virt = "?"; - } - switch (tpm->type) { case VIR_DOMAIN_TPM_TYPE_PASSTHROUGH: path = tpm->data.passthrough.source.data.file.path; @@ -639,7 +629,7 @@ virDomainAuditCgroup(virDomainObjPtr vm, virCgroupPtr cgroup, char *vmname; char *controller = NULL; char *detail; - const char *virt; + const char *virt = virDomainAuditGetVirtType(vm->def); virUUIDFormat(vm->def->uuid, uuidstr); if (!(vmname = virAuditEncode("vm", vm->def->name))) { @@ -647,11 +637,6 @@ virDomainAuditCgroup(virDomainObjPtr vm, virCgroupPtr cgroup, return; } - if (!(virt = virDomainVirtTypeToString(vm->def->virtType))) { - VIR_WARN("Unexpected virt type %d while encoding audit message", vm->def->virtType); - virt = "?"; - } - ignore_value(virCgroupPathOfController(cgroup, VIR_CGROUP_CONTROLLER_DEVICES, NULL, &controller)); @@ -757,7 +742,7 @@ virDomainAuditResource(virDomainObjPtr vm, const char *resource, { char uuidstr[VIR_UUID_STRING_BUFLEN]; char *vmname; - const char *virt; + const char *virt = virDomainAuditGetVirtType(vm->def); virUUIDFormat(vm->def->uuid, uuidstr); if (!(vmname = virAuditEncode("vm", vm->def->name))) { @@ -765,11 +750,6 @@ virDomainAuditResource(virDomainObjPtr vm, const char *resource, return; } - if (!(virt = virDomainVirtTypeToString(vm->def->virtType))) { - VIR_WARN("Unexpected virt type %d while encoding audit message", vm->def->virtType); - virt = "?"; - } - VIR_AUDIT(VIR_AUDIT_RECORD_RESOURCE, success, "virt=%s resrc=%s reason=%s %s uuid=%s old-%s=%lld new-%s=%lld", virt, resource, reason, vmname, uuidstr, @@ -809,7 +789,7 @@ virDomainAuditLifecycle(virDomainObjPtr vm, const char *op, { char uuidstr[VIR_UUID_STRING_BUFLEN]; char *vmname; - const char *virt; + const char *virt = virDomainAuditGetVirtType(vm->def); virUUIDFormat(vm->def->uuid, uuidstr); @@ -818,11 +798,6 @@ virDomainAuditLifecycle(virDomainObjPtr vm, const char *op, return; } - if (!(virt = virDomainVirtTypeToString(vm->def->virtType))) { - VIR_WARN("Unexpected virt type %d while encoding audit message", vm->def->virtType); - virt = "?"; - } - VIR_AUDIT(VIR_AUDIT_RECORD_MACHINE_CONTROL, success, "virt=%s op=%s reason=%s %s uuid=%s vm-pid=%lld", virt, op, reason, vmname, uuidstr, (long long)vm->pid); @@ -909,7 +884,7 @@ virDomainAuditInit(virDomainObjPtr vm, { char uuidstr[VIR_UUID_STRING_BUFLEN]; char *vmname; - const char *virt; + const char *virt = virDomainAuditGetVirtType(vm->def); virUUIDFormat(vm->def->uuid, uuidstr); @@ -918,11 +893,6 @@ virDomainAuditInit(virDomainObjPtr vm, return; } - if (!(virt = virDomainVirtTypeToString(vm->def->virtType))) { - VIR_WARN("Unexpected virt type %d while encoding audit message", vm->def->virtType); - virt = "?"; - } - VIR_AUDIT(VIR_AUDIT_RECORD_MACHINE_CONTROL, true, "virt=%s op=init %s uuid=%s vm-pid=%lld init-pid=%lld pid-ns=%lld", virt, vmname, uuidstr, (long long)vm->pid, (long long)initpid, @@ -942,8 +912,8 @@ virDomainAuditSecurityLabel(virDomainObjPtr vm, bool success) { char uuidstr[VIR_UUID_STRING_BUFLEN]; char *vmname; - const char *virt; size_t i; + const char *virt = virDomainAuditGetVirtType(vm->def); virUUIDFormat(vm->def->uuid, uuidstr); if (!(vmname = virAuditEncode("vm", vm->def->name))) { @@ -951,11 +921,6 @@ virDomainAuditSecurityLabel(virDomainObjPtr vm, bool success) return; } - if (!(virt = virDomainVirtTypeToString(vm->def->virtType))) { - VIR_WARN("Unexpected virt type %d while encoding audit message", vm->def->virtType); - virt = "?"; - } - for (i = 0; i < vm->def->nseclabels; i++) { VIR_AUDIT(VIR_AUDIT_RECORD_MACHINE_ID, success, "virt=%s %s uuid=%s vm-ctx=%s img-ctx=%s model=%s", @@ -976,7 +941,7 @@ virDomainAuditShmem(virDomainObjPtr vm, char uuidstr[VIR_UUID_STRING_BUFLEN]; char *vmname = virAuditEncode("vm", vm->def->name); const char *srcpath = virDomainChrSourceDefGetPath(&def->server.chr); - const char *virt = virDomainVirtTypeToString(vm->def->virtType); + const char *virt = virDomainAuditGetVirtType(vm->def); char *shmpath = NULL; virUUIDFormat(vm->def->uuid, uuidstr); @@ -1018,7 +983,7 @@ virDomainAuditInput(virDomainObjPtr vm, { char uuidstr[VIR_UUID_STRING_BUFLEN]; char *vmname; - const char *virt = virDomainVirtTypeToString(vm->def->virtType); + const char *virt = virDomainAuditGetVirtType(vm->def); virUUIDFormat(vm->def->uuid, uuidstr);