[PATCH 5/7] src & network_conf: add validation against schema in define

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

Signed-off-by: Kristina Hanicova <khanicov@xxxxxxxxxx>
---
 src/conf/domain_conf.c       |  2 +-
 src/conf/network_conf.c      | 15 +++++++++------
 src/conf/network_conf.h      |  3 ++-
 src/esx/esx_network_driver.c |  2 +-
 src/network/bridge_driver.c  |  4 ++--
 src/qemu/qemu_process.c      |  2 +-
 src/test/test_driver.c       |  4 ++--
 src/vbox/vbox_network.c      |  2 +-
 8 files changed, 19 insertions(+), 15 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 10effdce69..0328447f87 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -30522,7 +30522,7 @@ virDomainNetResolveActualType(virDomainNetDef *iface)
     if (!(xml = virNetworkGetXMLDesc(net, 0)))
         goto cleanup;
 
-    if (!(def = virNetworkDefParseString(xml, NULL)))
+    if (!(def = virNetworkDefParseString(xml, NULL, 0)))
         goto cleanup;
 
     switch ((virNetworkForwardType) def->forward.type) {
diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
index fbd939a1f1..f23599abac 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
@@ -318,7 +318,7 @@ virNetworkDefCopy(virNetworkDef *def,
     if (!(xml = virNetworkDefFormat(def, xmlopt, flags)))
        return NULL;
 
-    return virNetworkDefParseString(xml, xmlopt);
+    return virNetworkDefParseString(xml, xmlopt, 0);
 }
 
 
@@ -2085,13 +2085,15 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt,
 static virNetworkDef *
 virNetworkDefParse(const char *xmlStr,
                    const char *filename,
-                   virNetworkXMLOption *xmlopt)
+                   virNetworkXMLOption *xmlopt,
+                   unsigned int flags)
 {
     g_autoptr(xmlDoc) xml = NULL;
     virNetworkDef *def = NULL;
     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);
 
     xmlKeepBlanksDefault(keepBlanksDefault);
@@ -2101,9 +2103,10 @@ virNetworkDefParse(const char *xmlStr,
 
 virNetworkDef *
 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,
                        virNetworkXMLOption *xmlopt)
 {
-    return virNetworkDefParse(NULL, filename, xmlopt);
+    return virNetworkDefParse(NULL, filename, xmlopt, 0);
 }
 
 
diff --git a/src/conf/network_conf.h b/src/conf/network_conf.h
index 6199f3f588..34007e1969 100644
--- a/src/conf/network_conf.h
+++ b/src/conf/network_conf.h
@@ -327,7 +327,8 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt,
 
 virNetworkDef *
 virNetworkDefParseString(const char *xmlStr,
-                         virNetworkXMLOption *xmlopt);
+                         virNetworkXMLOption *xmlopt,
+                         unsigned int flags);
 
 virNetworkDef *
 virNetworkDefParseFile(const char *filename,
diff --git a/src/esx/esx_network_driver.c b/src/esx/esx_network_driver.c
index 72b5a4f235..8a0cfa3729 100644
--- a/src/esx/esx_network_driver.c
+++ b/src/esx/esx_network_driver.c
@@ -298,7 +298,7 @@ esxNetworkDefineXMLFlags(virConnectPtr conn, const char *xml,
         return NULL;
 
     /* Parse network XML */
-    def = virNetworkDefParseString(xml, NULL);
+    def = virNetworkDefParseString(xml, NULL, 0);
 
     if (!def)
         return NULL;
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index 0f27b1d180..207163cde2 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -3474,7 +3474,7 @@ networkCreateXML(virConnectPtr conn,
     virNetworkPtr net = NULL;
     virObjectEvent *event = NULL;
 
-    if (!(newDef = virNetworkDefParseString(xml, network_driver->xmlopt)))
+    if (!(newDef = virNetworkDefParseString(xml, network_driver->xmlopt, 0)))
         goto cleanup;
 
     if (virNetworkCreateXMLEnsureACL(conn, newDef) < 0)
@@ -3529,7 +3529,7 @@ networkDefineXMLFlags(virConnectPtr conn,
 
     virCheckFlags(0, NULL);
 
-    if (!(def = virNetworkDefParseString(xml, network_driver->xmlopt)))
+    if (!(def = virNetworkDefParseString(xml, network_driver->xmlopt, 0)))
         goto cleanup;
 
     if (virNetworkDefineXMLFlagsEnsureACL(conn, def) < 0)
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 77da9992f4..df3bd66c0c 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -4784,7 +4784,7 @@ qemuProcessGetNetworkAddress(const char *netname,
     if (!xml)
         goto cleanup;
 
-    netdef = virNetworkDefParseString(xml, NULL);
+    netdef = virNetworkDefParseString(xml, NULL, 0);
     if (!netdef)
         goto cleanup;
 
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index d9203c9568..117d1e6ba9 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -5581,7 +5581,7 @@ testNetworkCreateXML(virConnectPtr conn, const char *xml)
     virNetworkPtr net = NULL;
     virObjectEvent *event = NULL;
 
-    if ((newDef = virNetworkDefParseString(xml, NULL)) == NULL)
+    if ((newDef = virNetworkDefParseString(xml, NULL, 0)) == NULL)
         goto cleanup;
 
     if (!(obj = virNetworkObjAssignDef(privconn->networks, newDef,
@@ -5620,7 +5620,7 @@ testNetworkDefineXMLFlags(virConnectPtr conn,
 
     virCheckFlags(0, NULL);
 
-    if ((newDef = virNetworkDefParseString(xml, NULL)) == NULL)
+    if ((newDef = virNetworkDefParseString(xml, NULL, 0)) == NULL)
         goto cleanup;
 
     if (!(obj = virNetworkObjAssignDef(privconn->networks, newDef, 0)))
diff --git a/src/vbox/vbox_network.c b/src/vbox/vbox_network.c
index cce43ee5af..804f9f0b01 100644
--- a/src/vbox/vbox_network.c
+++ b/src/vbox/vbox_network.c
@@ -397,7 +397,7 @@ vboxNetworkDefineCreateXML(virConnectPtr conn, const char *xml, bool start,
 
     VBOX_IID_INITIALIZE(&vboxnetiid);
 
-    if (!(def = virNetworkDefParseString(xml, NULL)) ||
+    if (!(def = virNetworkDefParseString(xml, NULL, 0)) ||
         (def->forward.type != VIR_NETWORK_FORWARD_NONE) ||
         (def->nips == 0 || !def->ips))
         goto cleanup;
-- 
2.31.1




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux