conf: virDomainGraphicsDefValidate: validate attribute 'network' for listen type 'network'

Related: https://gitlab.com/libvirt/libvirt/-/issues/93
Signed-off-by: Amneesh Singh <natto@weirdnatto.in>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
This commit is contained in:
Amneesh Singh 2022-04-13 22:01:37 +05:30 committed by Martin Kletzander
parent d9f175379c
commit 871a071abb

View 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);