From nobody Mon Feb 9 14:17:12 2026 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=1618496951; cv=none; d=zohomail.com; s=zohoarc; b=Y3HPLJp7uSv0e6ARbJuz6Xitvkkhbc9LupRF0SFgwRTETstn1zaONu+vphlVrIN3OlVEAtk3IDWZy69WK+Kv/T4UodhhF5EXHD74HDbGqgSJrxa+jzSW2GZV2f2tWY56fA4uzSHXfvA7Zgcy3QXxp+37AgajAVvP2wv32cgVJRI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1618496951; 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=gWAqJST7Le2waBvBmRKNKKII+wt2sYfw6Us+0b2N2b4=; b=Rf42VAwbCX8P/0m5NZyQ96OWNMWfJxjs/JV/5GmLnXAWQy/cHMmW0qS0hhRRkSS3TEo4pRK5xxSBLRvhd/wRNRrwwaDfrDXOTgxOShoPJ+evlRwAJl3qfBro2PtNSCsivbeFCraOFerBf2XUbCMUK7o9Jjsbtf/l+kEyUxg3nqc= 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) header.from= 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 1618496951515562.1924912958457; Thu, 15 Apr 2021 07:29:11 -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-501-nWi_GDS2N_Cmd050vP44HA-1; Thu, 15 Apr 2021 10:29:07 -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 16B0418A08DC; Thu, 15 Apr 2021 14:27:57 +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 EB7B56A035; Thu, 15 Apr 2021 14:27:56 +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 B42E544A60; Thu, 15 Apr 2021 14:27:56 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 13FERpjX024410 for ; Thu, 15 Apr 2021 10:27:51 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7588460917; Thu, 15 Apr 2021 14:27:51 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.40.196.1]) by smtp.corp.redhat.com (Postfix) with ESMTP id DE6E753CC3 for ; Thu, 15 Apr 2021 14:27:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1618496950; 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=gWAqJST7Le2waBvBmRKNKKII+wt2sYfw6Us+0b2N2b4=; b=hut8aTNq4IHRshnrIbCWZ+xYyX/zTtHAuSkXp1YRK7WnUEXMsMicW4nXBN/ysSfNPfw8aQ 1WWiWwhkDDOAVjNhPEdWw7FcX92IOs0lvT0fV8rtxBnEZ3tVR/dUJFIeSs3nyf3oMKfDIj ZgNCOEUoGvm41z09CZ4NTmp4f2LFsJ0= X-MC-Unique: nWi_GDS2N_Cmd050vP44HA-1 From: Kristina Hanicova To: libvir-list@redhat.com Subject: [PATCH 17/21] Refactoring virDomainSmartcardDefParseXML() to use XPath Date: Thu, 15 Apr 2021 16:26:32 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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) Content-Type: text/plain; charset="utf-8" Signed-off-by: Kristina Hanicova --- src/conf/domain_conf.c | 59 ++++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 34 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 8d53b30917..ece34403a7 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -12221,12 +12221,14 @@ virDomainSmartcardDefParseXML(virDomainXMLOption = *xmlopt, xmlXPathContextPtr ctxt, unsigned int flags) { - xmlNodePtr cur; g_autoptr(virDomainSmartcardDef) def =3D NULL; - size_t i; g_autofree char *mode =3D NULL; g_autofree char *type =3D NULL; + g_autofree xmlNodePtr *certificates =3D NULL; + int n =3D 0; + VIR_XPATH_NODE_AUTORESTORE(ctxt) =20 + ctxt->node =3D node; def =3D g_new0(virDomainSmartcardDef, 1); =20 mode =3D virXMLPropString(node, "mode"); @@ -12247,42 +12249,32 @@ virDomainSmartcardDefParseXML(virDomainXMLOption = *xmlopt, break; =20 case VIR_DOMAIN_SMARTCARD_TYPE_HOST_CERTIFICATES: - i =3D 0; - cur =3D node->children; - while (cur) { - if (cur->type =3D=3D XML_ELEMENT_NODE && - virXMLNodeNameEqual(cur, "certificate")) { - if (i =3D=3D 3) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("host-certificates mode needs " - "exactly three certificates")); - return NULL; - } - if (!(def->data.cert.file[i] =3D virXMLNodeContentString(c= ur))) - return NULL; - - i++; - } else if (cur->type =3D=3D XML_ELEMENT_NODE && - virXMLNodeNameEqual(cur, "database") && - !def->data.cert.database) { - if (!(def->data.cert.database =3D virXMLNodeContentString(= cur))) - return NULL; - - if (*def->data.cert.database !=3D '/') { - virReportError(VIR_ERR_XML_ERROR, - _("expecting absolute path: %s"), - def->data.cert.database); - return NULL; - } - } - cur =3D cur->next; - } - if (i < 3) { + n =3D virXPathNodeSet("./certificate", ctxt, &certificates); + if (n !=3D VIR_DOMAIN_SMARTCARD_NUM_CERTIFICATES) { virReportError(VIR_ERR_XML_ERROR, "%s", _("host-certificates mode needs " "exactly three certificates")); return NULL; } + + if (!(def->data.cert.file[0] =3D virXMLNodeContentString(certifica= tes[0])) || + !(def->data.cert.file[1] =3D virXMLNodeContentString(certifica= tes[1])) || + !(def->data.cert.file[2] =3D virXMLNodeContentString(certifica= tes[2]))) + return NULL; + + if (virXPathNode("./database", ctxt) && + !def->data.cert.database) { + if (!(def->data.cert.database =3D + virXPathString("string(./database/text())", ctxt))) + return NULL; + + if (*def->data.cert.database !=3D '/') { + virReportError(VIR_ERR_XML_ERROR, + _("expecting absolute path: %s"), + def->data.cert.database); + return NULL; + } + } break; =20 case VIR_DOMAIN_SMARTCARD_TYPE_PASSTHROUGH: @@ -12304,7 +12296,6 @@ virDomainSmartcardDefParseXML(virDomainXMLOption *x= mlopt, return NULL; } =20 - cur =3D node->children; if (virDomainChrSourceDefParseXML(def->data.passthru, node, flags, NULL, ctxt) < 0) return NULL; --=20 2.30.2