src & network_conf: add validation against schema in define

This patch also includes propagation of flags into the
virNetworkDefParse().

Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Kristina Hanicova 2021-08-23 18:50:12 +02:00 committed by Michal Privoznik
parent 0faf5c6aa4
commit 8555dee6ba
8 changed files with 19 additions and 15 deletions

View File

@ -30522,7 +30522,7 @@ virDomainNetResolveActualType(virDomainNetDef *iface)
if (!(xml = virNetworkGetXMLDesc(net, 0))) if (!(xml = virNetworkGetXMLDesc(net, 0)))
goto cleanup; goto cleanup;
if (!(def = virNetworkDefParseString(xml, NULL))) if (!(def = virNetworkDefParseString(xml, NULL, 0)))
goto cleanup; goto cleanup;
switch ((virNetworkForwardType) def->forward.type) { switch ((virNetworkForwardType) def->forward.type) {

View File

@ -318,7 +318,7 @@ virNetworkDefCopy(virNetworkDef *def,
if (!(xml = virNetworkDefFormat(def, xmlopt, flags))) if (!(xml = virNetworkDefFormat(def, xmlopt, flags)))
return NULL; return NULL;
return virNetworkDefParseString(xml, xmlopt); return virNetworkDefParseString(xml, xmlopt, 0);
} }
@ -2085,13 +2085,15 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt,
static virNetworkDef * static virNetworkDef *
virNetworkDefParse(const char *xmlStr, virNetworkDefParse(const char *xmlStr,
const char *filename, const char *filename,
virNetworkXMLOption *xmlopt) virNetworkXMLOption *xmlopt,
unsigned int flags)
{ {
g_autoptr(xmlDoc) xml = NULL; g_autoptr(xmlDoc) xml = NULL;
virNetworkDef *def = NULL; virNetworkDef *def = NULL;
int keepBlanksDefault = xmlKeepBlanksDefault(0); int keepBlanksDefault = xmlKeepBlanksDefault(0);
if ((xml = virXMLParse(filename, xmlStr, _("(network_definition)"), NULL, false))) if ((xml = virXMLParse(filename, xmlStr, _("(network_definition)"),
"network.rng", flags & VIR_NETWORK_DEFINE_VALIDATE)))
def = virNetworkDefParseNode(xml, xmlDocGetRootElement(xml), xmlopt); def = virNetworkDefParseNode(xml, xmlDocGetRootElement(xml), xmlopt);
xmlKeepBlanksDefault(keepBlanksDefault); xmlKeepBlanksDefault(keepBlanksDefault);
@ -2101,9 +2103,10 @@ virNetworkDefParse(const char *xmlStr,
virNetworkDef * virNetworkDef *
virNetworkDefParseString(const char *xmlStr, virNetworkDefParseString(const char *xmlStr,
virNetworkXMLOption *xmlopt) virNetworkXMLOption *xmlopt,
unsigned int flags)
{ {
return virNetworkDefParse(xmlStr, NULL, xmlopt); return virNetworkDefParse(xmlStr, NULL, xmlopt, flags);
} }
@ -2111,7 +2114,7 @@ virNetworkDef *
virNetworkDefParseFile(const char *filename, virNetworkDefParseFile(const char *filename,
virNetworkXMLOption *xmlopt) virNetworkXMLOption *xmlopt)
{ {
return virNetworkDefParse(NULL, filename, xmlopt); return virNetworkDefParse(NULL, filename, xmlopt, 0);
} }

View File

@ -327,7 +327,8 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt,
virNetworkDef * virNetworkDef *
virNetworkDefParseString(const char *xmlStr, virNetworkDefParseString(const char *xmlStr,
virNetworkXMLOption *xmlopt); virNetworkXMLOption *xmlopt,
unsigned int flags);
virNetworkDef * virNetworkDef *
virNetworkDefParseFile(const char *filename, virNetworkDefParseFile(const char *filename,

View File

@ -298,7 +298,7 @@ esxNetworkDefineXMLFlags(virConnectPtr conn, const char *xml,
return NULL; return NULL;
/* Parse network XML */ /* Parse network XML */
def = virNetworkDefParseString(xml, NULL); def = virNetworkDefParseString(xml, NULL, 0);
if (!def) if (!def)
return NULL; return NULL;

View File

@ -3474,7 +3474,7 @@ networkCreateXML(virConnectPtr conn,
virNetworkPtr net = NULL; virNetworkPtr net = NULL;
virObjectEvent *event = NULL; virObjectEvent *event = NULL;
if (!(newDef = virNetworkDefParseString(xml, network_driver->xmlopt))) if (!(newDef = virNetworkDefParseString(xml, network_driver->xmlopt, 0)))
goto cleanup; goto cleanup;
if (virNetworkCreateXMLEnsureACL(conn, newDef) < 0) if (virNetworkCreateXMLEnsureACL(conn, newDef) < 0)
@ -3529,7 +3529,7 @@ networkDefineXMLFlags(virConnectPtr conn,
virCheckFlags(0, NULL); virCheckFlags(0, NULL);
if (!(def = virNetworkDefParseString(xml, network_driver->xmlopt))) if (!(def = virNetworkDefParseString(xml, network_driver->xmlopt, 0)))
goto cleanup; goto cleanup;
if (virNetworkDefineXMLFlagsEnsureACL(conn, def) < 0) if (virNetworkDefineXMLFlagsEnsureACL(conn, def) < 0)

View File

@ -4784,7 +4784,7 @@ qemuProcessGetNetworkAddress(const char *netname,
if (!xml) if (!xml)
goto cleanup; goto cleanup;
netdef = virNetworkDefParseString(xml, NULL); netdef = virNetworkDefParseString(xml, NULL, 0);
if (!netdef) if (!netdef)
goto cleanup; goto cleanup;

View File

@ -5581,7 +5581,7 @@ testNetworkCreateXML(virConnectPtr conn, const char *xml)
virNetworkPtr net = NULL; virNetworkPtr net = NULL;
virObjectEvent *event = NULL; virObjectEvent *event = NULL;
if ((newDef = virNetworkDefParseString(xml, NULL)) == NULL) if ((newDef = virNetworkDefParseString(xml, NULL, 0)) == NULL)
goto cleanup; goto cleanup;
if (!(obj = virNetworkObjAssignDef(privconn->networks, newDef, if (!(obj = virNetworkObjAssignDef(privconn->networks, newDef,
@ -5620,7 +5620,7 @@ testNetworkDefineXMLFlags(virConnectPtr conn,
virCheckFlags(0, NULL); virCheckFlags(0, NULL);
if ((newDef = virNetworkDefParseString(xml, NULL)) == NULL) if ((newDef = virNetworkDefParseString(xml, NULL, 0)) == NULL)
goto cleanup; goto cleanup;
if (!(obj = virNetworkObjAssignDef(privconn->networks, newDef, 0))) if (!(obj = virNetworkObjAssignDef(privconn->networks, newDef, 0)))

View File

@ -397,7 +397,7 @@ vboxNetworkDefineCreateXML(virConnectPtr conn, const char *xml, bool start,
VBOX_IID_INITIALIZE(&vboxnetiid); VBOX_IID_INITIALIZE(&vboxnetiid);
if (!(def = virNetworkDefParseString(xml, NULL)) || if (!(def = virNetworkDefParseString(xml, NULL, 0)) ||
(def->forward.type != VIR_NETWORK_FORWARD_NONE) || (def->forward.type != VIR_NETWORK_FORWARD_NONE) ||
(def->nips == 0 || !def->ips)) (def->nips == 0 || !def->ips))
goto cleanup; goto cleanup;