From nobody Sun May 5 21:54:07 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1628255377; cv=none; d=zohomail.com; s=zohoarc; b=epCSZGd7HgNDP9PDmloQ/qxBp3WlmdHchlkmQ7zFhn7E9ljxU0IhrcHu976RUY6ki2FXbH21YmixUrB/8d1LxKQjTO7tdB77L7PSo3zT/ElFcoUCH94AEbp66p5jFhzokfbD3L5tQ6JL+uR5PUuDI2X52gDmrSuUr+kR/c+tIO4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1628255377; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=dwQPcLnesfAYHDPlahTLjLut3vsiO+vWn42EjRpopMs=; b=LQ9uckdKkog4eBLE9ujLtCPJDiat4siqCdVmbZfCmjFg/MD7PtO/BP181WtvrPrw8ZFfReLkMpbMdLFNqT6/4fkTDUTgCpuWvKsWsmP0P2Inzbj6JVwhquSgfDcUCQ8M9yUl1TmBlYCBTOzTwfZ277v/Di0hQDK85tyrBAHMn5w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 162825537793616.38810239470888; Fri, 6 Aug 2021 06:09:37 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-189-ishbvOB-NzWkrpnGmq0wPw-1; Fri, 06 Aug 2021 09:09:35 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EF6748B1625; Fri, 6 Aug 2021 13:09:12 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5BB8084D1F; Fri, 6 Aug 2021 13:09:12 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id ADE234BB7B; Fri, 6 Aug 2021 13:09:09 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 176D97lv001157 for ; Fri, 6 Aug 2021 09:09:07 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0EA9878C24; Fri, 6 Aug 2021 13:09:07 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.43.2.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id 39E3E78C36 for ; Fri, 6 Aug 2021 13:09:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1628255376; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=dwQPcLnesfAYHDPlahTLjLut3vsiO+vWn42EjRpopMs=; b=YCOY6ESvMSundpekN0FVAXy6AgMxts78tKjxD8WIR0PoK0hv0Xx+RtKxfmZxFCF9GplTll qxHyV/oxjaiwc4nh5nW7WqfxvEfxQ/t2i4HDnusz8ITKOR2/xbTOOUCNeXAIu9sso/YkTh 2QoQPVp6MdnAiBgYL1DVzH12bytV7tE= X-MC-Unique: ishbvOB-NzWkrpnGmq0wPw-1 From: Kristina Hanicova To: libvir-list@redhat.com Subject: [PATCH 1/3] conf: propagate xmlDocPtr and flags into virInterfaceDefParseXML() Date: Fri, 6 Aug 2021 15:08:14 +0200 Message-Id: <3242670306b88f215738656804c2b678ae816db7.1628255094.git.khanicov@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1628255378867100001 Content-Type: text/plain; charset="utf-8" We need to know if validation flag is present in order to validate given XML against schema in virInterfaceDefParseXML(). Signed-off-by: Kristina Hanicova --- src/conf/interface_conf.c | 29 +++++++++++++++---------- src/conf/interface_conf.h | 6 +++-- src/conf/virinterfaceobj.c | 2 +- src/interface/interface_backend_netcf.c | 4 ++-- src/test/test_driver.c | 4 ++-- tests/interfacexml2xmltest.c | 2 +- 6 files changed, 28 insertions(+), 19 deletions(-) diff --git a/src/conf/interface_conf.c b/src/conf/interface_conf.c index d84ec66def..7b0cfa6562 100644 --- a/src/conf/interface_conf.c +++ b/src/conf/interface_conf.c @@ -38,7 +38,8 @@ VIR_ENUM_IMPL(virInterface, ); =20 static virInterfaceDef * -virInterfaceDefParseXML(xmlXPathContextPtr ctxt, int parentIfType); +virInterfaceDefParseXML(xmlXPathContextPtr ctxt, int parentIfType, + xmlDocPtr xml, unsigned int flags); =20 static int virInterfaceDefDevFormat(virBuffer *buf, const virInterfaceDef *def, @@ -521,7 +522,7 @@ virInterfaceDefParseBridge(virInterfaceDef *def, =20 for (i =3D 0; i < nbItf; i++) { ctxt->node =3D interfaces[i]; - itf =3D virInterfaceDefParseXML(ctxt, VIR_INTERFACE_TYPE_BRIDG= E); + itf =3D virInterfaceDefParseXML(ctxt, VIR_INTERFACE_TYPE_BRIDG= E, NULL, 0); if (itf =3D=3D NULL) { ret =3D -1; def->data.bridge.nbItf =3D i; @@ -565,7 +566,7 @@ virInterfaceDefParseBondItfs(virInterfaceDef *def, =20 for (i =3D 0; i < nbItf; i++) { ctxt->node =3D interfaces[i]; - itf =3D virInterfaceDefParseXML(ctxt, VIR_INTERFACE_TYPE_BOND); + itf =3D virInterfaceDefParseXML(ctxt, VIR_INTERFACE_TYPE_BOND, NUL= L, 0); if (itf =3D=3D NULL) { def->data.bond.nbItf =3D i; goto cleanup; @@ -677,7 +678,9 @@ virInterfaceDefParseVlan(virInterfaceDef *def, =20 static virInterfaceDef * virInterfaceDefParseXML(xmlXPathContextPtr ctxt, - int parentIfType) + int parentIfType, + xmlDocPtr xml G_GNUC_UNUSED, + unsigned int flags) { virInterfaceDef *def; int type; @@ -685,6 +688,7 @@ virInterfaceDefParseXML(xmlXPathContextPtr ctxt, VIR_XPATH_NODE_AUTORESTORE(ctxt) xmlNodePtr lnk; =20 + virCheckFlags(0, NULL); =20 /* check @type */ tmp =3D virXPathString("string(./@type)", ctxt); @@ -797,7 +801,8 @@ virInterfaceDefParseXML(xmlXPathContextPtr ctxt, =20 virInterfaceDef * virInterfaceDefParseNode(xmlDocPtr xml, - xmlNodePtr root) + xmlNodePtr root, + unsigned int flags) { g_autoptr(xmlXPathContext) ctxt =3D NULL; =20 @@ -813,19 +818,20 @@ virInterfaceDefParseNode(xmlDocPtr xml, return NULL; =20 ctxt->node =3D root; - return virInterfaceDefParseXML(ctxt, VIR_INTERFACE_TYPE_LAST); + return virInterfaceDefParseXML(ctxt, VIR_INTERFACE_TYPE_LAST, xml, fla= gs); } =20 =20 static virInterfaceDef * virInterfaceDefParse(const char *xmlStr, - const char *filename) + const char *filename, + unsigned int flags) { xmlDocPtr xml; virInterfaceDef *def =3D NULL; =20 if ((xml =3D virXMLParse(filename, xmlStr, _("(interface_definition)")= ))) { - def =3D virInterfaceDefParseNode(xml, xmlDocGetRootElement(xml)); + def =3D virInterfaceDefParseNode(xml, xmlDocGetRootElement(xml), f= lags); xmlFreeDoc(xml); } =20 @@ -834,16 +840,17 @@ virInterfaceDefParse(const char *xmlStr, =20 =20 virInterfaceDef * -virInterfaceDefParseString(const char *xmlStr) +virInterfaceDefParseString(const char *xmlStr, + unsigned int flags) { - return virInterfaceDefParse(xmlStr, NULL); + return virInterfaceDefParse(xmlStr, NULL, flags); } =20 =20 virInterfaceDef * virInterfaceDefParseFile(const char *filename) { - return virInterfaceDefParse(NULL, filename); + return virInterfaceDefParse(NULL, filename, 0); } =20 =20 diff --git a/src/conf/interface_conf.h b/src/conf/interface_conf.h index f5e802736b..15819b000f 100644 --- a/src/conf/interface_conf.h +++ b/src/conf/interface_conf.h @@ -155,14 +155,16 @@ void virInterfaceDefFree(virInterfaceDef *def); =20 virInterfaceDef * -virInterfaceDefParseString(const char *xmlStr); +virInterfaceDefParseString(const char *xmlStr, + unsigned int flags); =20 virInterfaceDef * virInterfaceDefParseFile(const char *filename); =20 virInterfaceDef * virInterfaceDefParseNode(xmlDocPtr xml, - xmlNodePtr root); + xmlNodePtr root, + unsigned int flags); =20 char * virInterfaceDefFormat(const virInterfaceDef *def); diff --git a/src/conf/virinterfaceobj.c b/src/conf/virinterfaceobj.c index a73208f1fc..9439bb3d0b 100644 --- a/src/conf/virinterfaceobj.c +++ b/src/conf/virinterfaceobj.c @@ -373,7 +373,7 @@ virInterfaceObjListCloneCb(void *payload, if (!(xml =3D virInterfaceDefFormat(srcObj->def))) goto error; =20 - if (!(backup =3D virInterfaceDefParseString(xml))) + if (!(backup =3D virInterfaceDefParseString(xml, 0))) goto error; VIR_FREE(xml); =20 diff --git a/src/interface/interface_backend_netcf.c b/src/interface/interf= ace_backend_netcf.c index 416e0af36f..9f93cdd657 100644 --- a/src/interface/interface_backend_netcf.c +++ b/src/interface/interface_backend_netcf.c @@ -862,7 +862,7 @@ static char *netcfInterfaceGetXMLDesc(virInterfacePtr i= finfo, goto cleanup; } =20 - ifacedef =3D virInterfaceDefParseString(xmlstr); + ifacedef =3D virInterfaceDefParseString(xmlstr, 0); if (!ifacedef) { /* error was already reported */ goto cleanup; @@ -898,7 +898,7 @@ static virInterfacePtr netcfInterfaceDefineXML(virConne= ctPtr conn, =20 virObjectLock(driver); =20 - ifacedef =3D virInterfaceDefParseString(xml); + ifacedef =3D virInterfaceDefParseString(xml, 0); if (!ifacedef) { /* error was already reported */ goto cleanup; diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 16d70d9025..149d1afdad 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -1113,7 +1113,7 @@ testParseInterfaces(testDriver *privconn, if (!node) return -1; =20 - def =3D virInterfaceDefParseNode(ctxt->doc, node); + def =3D virInterfaceDefParseNode(ctxt->doc, node, 0); if (!def) return -1; =20 @@ -6074,7 +6074,7 @@ testInterfaceDefineXML(virConnectPtr conn, virCheckFlags(0, NULL); =20 virObjectLock(privconn); - if ((def =3D virInterfaceDefParseString(xmlStr)) =3D=3D NULL) + if ((def =3D virInterfaceDefParseString(xmlStr, flags)) =3D=3D NULL) goto cleanup; =20 if ((obj =3D virInterfaceObjListAssignDef(privconn->ifaces, def)) =3D= =3D NULL) diff --git a/tests/interfacexml2xmltest.c b/tests/interfacexml2xmltest.c index 07d179e3a3..3785467f84 100644 --- a/tests/interfacexml2xmltest.c +++ b/tests/interfacexml2xmltest.c @@ -24,7 +24,7 @@ testCompareXMLToXMLFiles(const char *xml) if (virTestLoadFile(xml, &xmlData) < 0) goto fail; =20 - if (!(dev =3D virInterfaceDefParseString(xmlData))) + if (!(dev =3D virInterfaceDefParseString(xmlData, 0))) goto fail; =20 if (!(actual =3D virInterfaceDefFormat(dev))) --=20 2.31.1 From nobody Sun May 5 21:54:07 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1628255394; cv=none; d=zohomail.com; s=zohoarc; b=Iq7s4Pzbl/7Li0GIO2+WGkKUNDkqDxxAP0x8zfURfvd8n6xardF9LaMVHVAT1eYaqSuAHpO/R1cwVjRm6rSQoAkRJ0UQBS9KU3Cl430Pi6mmfYqJOkBkPQIEYtWXN4KXm5WrffAVCBwZFOZS5qLkiW/BHwn2HevoxPko5jhgsSE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1628255394; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=7NIQLMM3JKP5Dz2H8D1hyDWJB6VLXL8VotGJtwqdsK4=; b=KqHXG7rtzhFnzRJDPGFkC6EyfqDW5kANjYTMkiM4D+RVNJB0sdLcoIgg2qm7g509qtRKPXyXBUrcinGbfTvTDPwVuvWa85OYoK32/sipEUiCC3ahQ/hnb88VxnEosHZ911rpj+YA3LGBV5rY9/6gyBjey320XrKTb7Ks/rH8qU4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1628255394633177.4175718692752; Fri, 6 Aug 2021 06:09:54 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-266-1kFYr8hBMoSIS2SGWBvd3Q-1; Fri, 06 Aug 2021 09:09:51 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7F2728A8F07; Fri, 6 Aug 2021 13:09:33 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 344EE100164C; Fri, 6 Aug 2021 13:09:33 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id D6E0C4BB7C; Fri, 6 Aug 2021 13:09:32 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 176D98Vf001168 for ; Fri, 6 Aug 2021 09:09:08 -0400 Received: by smtp.corp.redhat.com (Postfix) id D4EDC51C4C; Fri, 6 Aug 2021 13:09:07 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.43.2.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4E01778C12 for ; Fri, 6 Aug 2021 13:09:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1628255393; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=7NIQLMM3JKP5Dz2H8D1hyDWJB6VLXL8VotGJtwqdsK4=; b=Zo4TrW/6mFx/Lj0G5qV4lxIvAwCMofNPc93FSKB2xnZJSZ57XTcOcViq0nM7eJxKiumRDU sAOkj2/KlRz+IEBen45wRFUmnkHcbUe5t4tvoGbSjvQhmQV8xtXnrkAS6evKjN1fW2SOh9 DSZWzf1ygEYqYS53NGXj+2q9Sxjv5kk= X-MC-Unique: 1kFYr8hBMoSIS2SGWBvd3Q-1 From: Kristina Hanicova To: libvir-list@redhat.com Subject: [PATCH 2/3] virsh: add support for '--validate' option in define interface Date: Fri, 6 Aug 2021 15:08:15 +0200 Message-Id: <71f4dde2ebf4080991f0abeca799c27041c5ea71.1628255094.git.khanicov@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1628255396519100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Kristina Hanicova --- include/libvirt/libvirt-interface.h | 4 ++++ tools/virsh-interface.c | 10 +++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/include/libvirt/libvirt-interface.h b/include/libvirt/libvirt-= interface.h index 7591c6c7fb..e849699230 100644 --- a/include/libvirt/libvirt-interface.h +++ b/include/libvirt/libvirt-interface.h @@ -79,6 +79,10 @@ typedef enum { VIR_INTERFACE_XML_INACTIVE =3D 1 << 0 /* dump inactive interface infor= mation */ } virInterfaceXMLFlags; =20 +typedef enum { + VIR_INTERFACE_DEFINE_VALIDATE =3D (1 << 0), /* Validate the XML docume= nt against schema */ +} virInterfaceDefineFlags; + char * virInterfaceGetXMLDesc (virInterfacePtr iface, unsigned int flags); virInterfacePtr virInterfaceDefineXML (virConnectPtr conn, diff --git a/tools/virsh-interface.c b/tools/virsh-interface.c index 41acae5dcb..f72d40baab 100644 --- a/tools/virsh-interface.c +++ b/tools/virsh-interface.c @@ -525,6 +525,10 @@ static const vshCmdInfo info_interface_define[] =3D { =20 static const vshCmdOptDef opts_interface_define[] =3D { VIRSH_COMMON_OPT_FILE(N_("file containing an XML interface description= ")), + {.name =3D "validate", + .type =3D VSH_OT_BOOL, + .help =3D N_("validate the XML against the schema") + }, {.name =3D NULL} }; =20 @@ -535,15 +539,19 @@ cmdInterfaceDefine(vshControl *ctl, const vshCmd *cmd) const char *from =3D NULL; bool ret =3D true; char *buffer; + unsigned int flags =3D 0; virshControl *priv =3D ctl->privData; =20 if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0) return false; =20 + if (vshCommandOptBool(cmd, "validate")) + flags |=3D VIR_INTERFACE_DEFINE_VALIDATE; + if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) return false; =20 - iface =3D virInterfaceDefineXML(priv->conn, buffer, 0); + iface =3D virInterfaceDefineXML(priv->conn, buffer, flags); VIR_FREE(buffer); =20 if (iface !=3D NULL) { --=20 2.31.1 From nobody Sun May 5 21:54:07 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1628255403; cv=none; d=zohomail.com; s=zohoarc; b=TUR02Twxi3Pn7PbQokHO0e71G+cpFuK4ua4ZZkJOkcJ/9YzsyeW6OXHN22jhqXISrUBWhKL9fFdF7qRVscCWCh7Y/m2s5u+A0bcVVPsWlb5OHZU/M94KCsea3IkaLG5hiwONLtl6qbzlg+ZXvGXognqgFbYlCoNjJfAWdWuv/J8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1628255403; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ppvPZ+Z5tVNIf/VulRW7O5+A8FTxvBxWJCITQj5l3vs=; b=h0tm1HbWQNL1Embds6FpxoWrC+ArxvG2CBJHTbjyZ6yXKEvUjKNHUKgA438t+4PPXtSwAbnamh55cE3+ZywezQPrPPar45d2zv07RQ3lJMhfgJVu5Hq++/GBUwD6brbIN6eybBAW6lEPaAotwAWcGzf58fIcpKuMstk6Sxp9yAQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1628255403355932.9100165754246; Fri, 6 Aug 2021 06:10:03 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-564-5k76h7g_NkKGKEVecwh3RQ-1; Fri, 06 Aug 2021 09:09:58 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 89F681B2C9A2; Fri, 6 Aug 2021 13:09:36 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 648B2105C86C; Fri, 6 Aug 2021 13:09:36 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 2DC3A180BAB1; Fri, 6 Aug 2021 13:09:36 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 176D98II001173 for ; Fri, 6 Aug 2021 09:09:08 -0400 Received: by smtp.corp.redhat.com (Postfix) id B863051C5D; Fri, 6 Aug 2021 13:09:08 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.43.2.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2EA8A78C26 for ; Fri, 6 Aug 2021 13:09:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1628255401; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=ppvPZ+Z5tVNIf/VulRW7O5+A8FTxvBxWJCITQj5l3vs=; b=SlU8Pz1HpSPRG8znfymJE6So0Y42WkcZcGybMEkF0j398L0J6Rrx62ygwwi/rCfn2zY+Bt 7bHh77pkClNMkVTtSSVsjvZa1liyzP1gFsQiPFA26nvJ+jH1qNSvj+kGsYbn67p0tjkO3M MlXW5fShuuUA+bd+SHJQvIPFuYJ3kGY= X-MC-Unique: 5k76h7g_NkKGKEVecwh3RQ-1 From: Kristina Hanicova To: libvir-list@redhat.com Subject: [PATCH 3/3] interface_conf: add validation against schema in define Date: Fri, 6 Aug 2021 15:08:16 +0200 Message-Id: <5e27e2413cc96b9f60135df84385705e7d3d2fee.1628255094.git.khanicov@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1628255406089100001 Content-Type: text/plain; charset="utf-8" We need to validate the XML against schema if option '--validate' was passed to the virsh 'iface-define' command. Signed-off-by: Kristina Hanicova --- 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" =20 #define VIR_FROM_THIS VIR_FROM_INTERFACE =20 @@ -688,7 +690,14 @@ virInterfaceDefParseXML(xmlXPathContextPtr ctxt, VIR_XPATH_NODE_AUTORESTORE(ctxt) xmlNodePtr lnk; =20 - virCheckFlags(0, NULL); + if (flags & VIR_INTERFACE_DEFINE_VALIDATE) { + g_autofree char *schema =3D virFileFindResource("interface.rng", + abs_top_srcdir "/doc= s/schemas", + PKGDATADIR "/schemas= "); + if (!schema || + virXMLValidateAgainstSchema(schema, xml) < 0) + return NULL; + } =20 /* check @type */ tmp =3D virXPathString("string(./@type)", ctxt); diff --git a/src/interface/interface_backend_netcf.c b/src/interface/interf= ace_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(virCon= nectPtr conn, virInterfaceDef *ifacedef =3D NULL; virInterfacePtr ret =3D NULL; =20 - virCheckFlags(0, NULL); + virCheckFlags(VIR_INTERFACE_DEFINE_VALIDATE, NULL); =20 virObjectLock(driver); =20 - ifacedef =3D virInterfaceDefParseString(xml, 0); + ifacedef =3D virInterfaceDefParseString(xml, flags); if (!ifacedef) { /* error was already reported */ goto cleanup; --=20 2.31.1