We need to validate the XML against schema if option '--validate' was passed to the virsh 'iface-define' command. Signed-off-by: Kristina Hanicova <khanicov@xxxxxxxxxx> --- src/conf/interface_conf.c | 11 ++++++++++- src/interface/interface_backend_netcf.c | 4 ++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/conf/interface_conf.c b/src/conf/interface_conf.c index 7b0cfa6562..ddecd96c8b 100644 --- a/src/conf/interface_conf.c +++ b/src/conf/interface_conf.c @@ -29,6 +29,8 @@ #include "viruuid.h" #include "virbuffer.h" #include "virstring.h" +#include "virfile.h" +#include "configmake.h" #define VIR_FROM_THIS VIR_FROM_INTERFACE @@ -688,7 +690,14 @@ virInterfaceDefParseXML(xmlXPathContextPtr ctxt, VIR_XPATH_NODE_AUTORESTORE(ctxt) xmlNodePtr lnk; - virCheckFlags(0, NULL); + if (flags & VIR_INTERFACE_DEFINE_VALIDATE) { + g_autofree char *schema = virFileFindResource("interface.rng", + abs_top_srcdir "/docs/schemas", + PKGDATADIR "/schemas"); + if (!schema || + virXMLValidateAgainstSchema(schema, xml) < 0) + return NULL; + } /* check @type */ tmp = virXPathString("string(./@type)", ctxt); diff --git a/src/interface/interface_backend_netcf.c b/src/interface/interface_backend_netcf.c index 9f93cdd657..78fd4f9bc7 100644 --- a/src/interface/interface_backend_netcf.c +++ b/src/interface/interface_backend_netcf.c @@ -894,11 +894,11 @@ static virInterfacePtr netcfInterfaceDefineXML(virConnectPtr conn, virInterfaceDef *ifacedef = NULL; virInterfacePtr ret = NULL; - virCheckFlags(0, NULL); + virCheckFlags(VIR_INTERFACE_DEFINE_VALIDATE, NULL); virObjectLock(driver); - ifacedef = virInterfaceDefParseString(xml, 0); + ifacedef = virInterfaceDefParseString(xml, flags); if (!ifacedef) { /* error was already reported */ goto cleanup; -- 2.31.1