]> xenbits.xensource.com Git - libvirt.git/commitdiff
conf: virDomainGraphicsDefValidate: validate attribute 'network' for listen type...
authorAmneesh Singh <natto@weirdnatto.in>
Wed, 13 Apr 2022 16:31:37 +0000 (22:01 +0530)
committerMartin Kletzander <mkletzan@redhat.com>
Wed, 4 May 2022 12:33:02 +0000 (14:33 +0200)
Related: https://gitlab.com/libvirt/libvirt/-/issues/93
Signed-off-by: Amneesh Singh <natto@weirdnatto.in>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
src/conf/domain_validate.c

index 3f03feee4ff9ceb472ac6c64bd699cbd38f3c6b9..7219e95e294b18d37b09237c16b660d8698dd438 100644 (file)
@@ -2381,10 +2381,35 @@ virDomainAudioDefValidate(const virDomainDef *def,
     return 0;
 }
 
+static int
+virDomainGraphicsDefListensValidate(const virDomainGraphicsDef *def)
+{
+    size_t i;
+
+    for (i = 0; i < def->nListens; i++) {
+        if (def->listens[i].type == VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NETWORK &&
+            !def->listens[i].network) {
+            virReportError(VIR_ERR_XML_ERROR, "%s",
+                           _("'network' attribute is required for "
+                             "listen type 'network'"));
+            return -1;
+        }
+    }
+
+    return 0;
+}
+
 static int
 virDomainGraphicsDefValidate(const virDomainDef *def,
                              const virDomainGraphicsDef *graphics)
 {
+    if (graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC ||
+        graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_SPICE ||
+        graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_RDP) {
+        if (virDomainGraphicsDefListensValidate(graphics) < 0)
+            return -1;
+    }
+
     if (graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC)
         return virDomainEnsureAudioID(def, graphics->data.vnc.audioId);