From nobody Sat Feb 7 08:27:19 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 149322919748489.8552380751122; Wed, 26 Apr 2017 10:53:17 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EFBF36AADF; Wed, 26 Apr 2017 17:53:08 +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 C12C818A47; Wed, 26 Apr 2017 17:53:08 +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 61D3318523DA; Wed, 26 Apr 2017 17:53:08 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v3QHr0tB009026 for ; Wed, 26 Apr 2017 13:53:00 -0400 Received: by smtp.corp.redhat.com (Postfix) id 14D4D18039; Wed, 26 Apr 2017 17:53:00 +0000 (UTC) Received: from angien.brq.redhat.com (dhcp129-47.brq.redhat.com [10.34.129.47]) by smtp.corp.redhat.com (Postfix) with ESMTP id 445D74D743; Wed, 26 Apr 2017 17:52:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com EFBF36AADF Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com EFBF36AADF From: Peter Krempa To: libvir-list@redhat.com Date: Wed, 26 Apr 2017 19:52:41 +0200 Message-Id: <3591ef202df5354e2fdf1238f803cbcfe5bb6f26.1493229124.git.pkrempa@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH 11/14] conf: Add support for cookies for HTTP based disks 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 26 Apr 2017 17:53:09 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Add possibility to specify one or more cookies for http based disks. This patch adds the config parser, storage and validation of the cookies. --- docs/formatdomain.html.in | 9 ++ docs/schemas/domaincommon.rng | 39 +++++-- src/conf/domain_conf.c | 108 +++++++++++++++++- src/util/virstoragefile.c | 124 +++++++++++++++++= ++++ src/util/virstoragefile.h | 14 +++ .../generic-disk-network-http.xml | 4 + 6 files changed, 289 insertions(+), 9 deletions(-) diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in index e31a271a5..ab70edff3 100644 --- a/docs/formatdomain.html.in +++ b/docs/formatdomain.html.in @@ -2245,6 +2245,9 @@ <driver name=3D'qemu' type=3D'raw'/> <source protocol=3D"http" name=3D"url_path"> <host name=3D"hostname" port=3D"80"/> + <cookies> + <cookie name=3D"test">somevalue</cookie> + </cookies> </source> <target dev=3D'hde' bus=3D'ide' tray=3D'open'/> <readonly/> @@ -2593,6 +2596,12 @@ protocol. Supported for 'rbd' since 1.2.= 11 (QEMU only). +
cookies
+
+ For http and https accessed storage = it's + possible to pass one or more cookies. The cookie name and value + must conform to the HTTP specification. +

diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng index 0c51f5151..b2fa72381 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -1556,16 +1556,39 @@ + + + + + + + [!#$%&'*+\-.0-9A-Z\^_`a-z|~]+ + + + + [!#$%&'()*+\-./0-9:>=3D<?@A-= Z\^_`\[\]a-z|~]+ + + + + + + + - - - http - https - - - - + + + + http + https + + + + + + + + diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 5a736c853..b1a357174 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -7520,6 +7520,78 @@ virDomainDiskSourcePoolDefParse(xmlNodePtr node, } +static virStorageNetCookieDefPtr +virDomainStorageCookieParse(xmlNodePtr node, + xmlXPathContextPtr ctxt) +{ + virStorageNetCookieDefPtr cookie =3D NULL; + virStorageNetCookieDefPtr ret =3D NULL; + xmlNodePtr oldnode =3D ctxt->node; + + ctxt->node =3D node; + + if (VIR_ALLOC(cookie) < 0) + goto cleanup; + + if (!(cookie->name =3D virXPathString("string(./@name)", ctxt))) { + virReportError(VIR_ERR_XML_ERROR, "%s", _("missing cookie name")); + goto cleanup; + } + + if (!(cookie->value =3D virXPathString("string(.)", ctxt))) { + virReportError(VIR_ERR_XML_ERROR, _("missing value for cookie '%s'= "), + cookie->name); + goto cleanup; + } + + VIR_STEAL_PTR(ret, cookie); + + cleanup: + ctxt->node =3D oldnode; + virStorageNetCookieDefFree(cookie); + return ret; +} + + +static int +virDomainStorageCookiesParse(xmlNodePtr node, + xmlXPathContextPtr ctxt, + virStorageSourcePtr src) +{ + xmlNodePtr oldnode =3D ctxt->node; + xmlNodePtr *nodes =3D NULL; + ssize_t nnodes; + size_t i; + int ret =3D -1; + + ctxt->node =3D node; + + if ((nnodes =3D virXPathNodeSet("./cookie", ctxt, &nodes)) < 0) + goto cleanup; + + if (VIR_ALLOC_N(src->cookies, nnodes) < 0) + goto cleanup; + + src->ncookies =3D nnodes; + + for (i =3D 0; i < nnodes; i++) { + if (!(src->cookies[i] =3D virDomainStorageCookieParse(nodes[i], ct= xt))) + goto cleanup; + } + + if (virStorageSourceNetCookiesValidate(src) < 0) + goto cleanup; + + ret =3D 0; + + cleanup: + VIR_FREE(nodes); + ctxt->node =3D oldnode; + + return ret; +} + + int virDomainDiskSourceParse(xmlNodePtr node, xmlXPathContextPtr ctxt, @@ -7528,6 +7600,7 @@ virDomainDiskSourceParse(xmlNodePtr node, int ret =3D -1; char *protocol =3D NULL; xmlNodePtr saveNode =3D ctxt->node; + xmlNodePtr tmpnode; ctxt->node =3D node; @@ -7590,6 +7663,12 @@ virDomainDiskSourceParse(xmlNodePtr node, if (virDomainStorageHostParse(node, &src->hosts, &src->nhosts) < 0) goto cleanup; + + if (src->protocol =3D=3D VIR_STORAGE_NET_PROTOCOL_HTTP && + (tmpnode =3D virXPathNode("./cookies", ctxt))) { + if (virDomainStorageCookiesParse(tmpnode, ctxt, src) < 0) + goto cleanup; + } break; case VIR_STORAGE_TYPE_VOLUME: if (virDomainDiskSourcePoolDefParse(node, &src->srcpool) < 0) @@ -20769,6 +20848,30 @@ virDomainSourceDefFormatSeclabel(virBufferPtr buf, static int +virDomainDiskSourceFormatNetworkCookies(virBufferPtr buf, + virStorageSourcePtr src) +{ + size_t i; + + if (src->ncookies =3D=3D 0) + return 0; + + virBufferAddLit(buf, "\n"); + virBufferAdjustIndent(buf, 2); + + for (i =3D 0; i < src->ncookies; i++) { + virBufferEscapeString(buf, "", src->cookies[i]= ->name); + virBufferEscapeString(buf, "%s\n", src->cookies[i]->value= ); + } + + virBufferAdjustIndent(buf, -2); + virBufferAddLit(buf, "\n"); + + return 0; +} + + +static int virDomainDiskSourceFormatNetwork(virBufferPtr buf, virStorageSourcePtr src) { @@ -20787,7 +20890,7 @@ virDomainDiskSourceFormatNetwork(virBufferPtr buf, VIR_FREE(path); - if (src->nhosts =3D=3D 0 && !src->snapshot && !src->configFile) { + if (src->nhosts =3D=3D 0 && !src->snapshot && !src->configFile && src-= >ncookies =3D=3D 0) { virBufferAddLit(buf, "/>\n"); } else { virBufferAddLit(buf, ">\n"); @@ -20809,6 +20912,9 @@ virDomainDiskSourceFormatNetwork(virBufferPtr buf, virBufferEscapeString(buf, "\n", src->snaps= hot); virBufferEscapeString(buf, "\n", src->configF= ile); + if (virDomainDiskSourceFormatNetworkCookies(buf, src) < 0) + return -1; + virBufferAdjustIndent(buf, -2); virBufferAddLit(buf, "\n"); } diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index 94a77ce86..fe03a3009 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -1948,6 +1948,126 @@ virStorageSourceSeclabelsCopy(virStorageSourcePtr t= o, } +void +virStorageNetCookieDefFree(virStorageNetCookieDefPtr def) +{ + if (!def) + return; + + VIR_FREE(def->name); + VIR_FREE(def->value); + + VIR_FREE(def); +} + + +static void +virStorageSourceCookiesClear(virStorageSourcePtr src) +{ + size_t i; + + if (!src || !src->cookies) + return; + + for (i =3D 0; i < src->ncookies; i++) + virStorageNetCookieDefFree(src->cookies[i]); + + VIR_FREE(src->cookies); + src->ncookies =3D 0; +} + + +static int +virStorageSourceNetCookiesCopy(virStorageSourcePtr to, + const virStorageSource *from) +{ + size_t i; + + if (from->ncookies =3D=3D 0) + return 0; + + if (VIR_ALLOC_N(to->cookies, from->ncookies) < 0) + return -1; + to->ncookies =3D from->ncookies; + + for (i =3D 0; i < from->ncookies; i++) { + if (VIR_STRDUP(to->cookies[i]->name, from->cookies[i]->name) < 0 || + VIR_STRDUP(to->cookies[i]->value, from->cookies[i]->value) < 0) + goto error; + } + + return 0; + + error: + virStorageSourceCookiesClear(to); + return -1; +} + + +/* see https://tools.ietf.org/html/rfc6265#section-4.1.1 */ +static const char virStorageSourceCookieValueInvalidChars[] =3D + "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F" + "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F" + " \",;\\"; + +/* in addition cookie name can't contain these */ +static const char virStorageSourceCookieNameInvalidChars[] =3D + "()<>@:/[]?=3D{}"; + +static int +virStorageSourceNetCookieValidate(virStorageNetCookieDefPtr def) +{ + /* name must have at least 1 character */ + if (*(def->name) =3D=3D '\0') { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("cookie name must not be empty")); + return -1; + } + + /* check invalid characters in name */ + if (virStringHasChars(def->name, virStorageSourceCookieValueInvalidCha= rs) || + virStringHasChars(def->name, virStorageSourceCookieNameInvalidChar= s)) { + virReportError(VIR_ERR_XML_ERROR, + _("cookie name '%s' contains invalid characters"), + def->name); + return -1; + } + + /* check invalid characters in value */ + if (virStringHasChars(def->value, virStorageSourceCookieValueInvalidCh= ars)) { + virReportError(VIR_ERR_XML_ERROR, + _("value of cookie '%s' contains invalid characters= "), + def->name); + return -1; + } + + return 0; +} + + +int +virStorageSourceNetCookiesValidate(virStorageSourcePtr src) +{ + size_t i; + size_t j; + + for (i =3D 0; i < src->ncookies; i++) { + if (virStorageSourceNetCookieValidate(src->cookies[i]) < 0) + return -1; + + for (j =3D i + 1; j < src->ncookies; j++) { + if (STREQ(src->cookies[i]->name, src->cookies[j]->name)) { + virReportError(VIR_ERR_XML_ERROR, _("duplicate cookie '%s'= "), + src->cookies[i]->name); + return -1; + } + } + } + + return 0; +} + + static virStorageTimestampsPtr virStorageTimestampsCopy(const virStorageTimestamps *src) { @@ -2060,6 +2180,9 @@ virStorageSourceCopy(const virStorageSource *src, ret->nhosts =3D src->nhosts; } + if (virStorageSourceNetCookiesCopy(ret, src) < 0) + goto error; + if (src->srcpool && !(ret->srcpool =3D virStorageSourcePoolDefCopy(src->srcpool))) goto error; @@ -2258,6 +2381,7 @@ virStorageSourceClear(virStorageSourcePtr def) VIR_FREE(def->volume); VIR_FREE(def->snapshot); VIR_FREE(def->configFile); + virStorageSourceCookiesClear(def); virStorageSourcePoolDefFree(def->srcpool); VIR_FREE(def->driverName); virBitmapFree(def->features); diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h index 9ebfc1108..42d9eac61 100644 --- a/src/util/virstoragefile.h +++ b/src/util/virstoragefile.h @@ -160,6 +160,16 @@ struct _virStorageNetHostDef { char *socket; /* path to unix socket */ }; +typedef struct _virStorageNetCookieDef virStorageNetCookieDef; +typedef virStorageNetCookieDef *virStorageNetCookieDefPtr; +struct _virStorageNetCookieDef { + char *name; + char *value; +}; + +void virStorageNetCookieDefFree(virStorageNetCookieDefPtr def); + + /* Information for a storage volume from a virStoragePool */ /* @@ -235,6 +245,8 @@ struct _virStorageSource { the source definition */ size_t nhosts; virStorageNetHostDefPtr hosts; + size_t ncookies; + virStorageNetCookieDefPtr *cookies; virStorageSourcePoolDefPtr srcpool; virStorageAuthDefPtr auth; virStorageEncryptionPtr encryption; @@ -371,6 +383,8 @@ int virStorageSourceUpdateCapacity(virStorageSourcePtr = src, char *buf, ssize_t len, bool probe); +int virStorageSourceNetCookiesValidate(virStorageSourcePtr src); + virStorageSourcePtr virStorageSourceNewFromBacking(virStorageSourcePtr par= ent); virStorageSourcePtr virStorageSourceCopy(const virStorageSource *src, bool backingChain) diff --git a/tests/genericxml2xmlindata/generic-disk-network-http.xml b/tes= ts/genericxml2xmlindata/generic-disk-network-http.xml index 51c779502..fc5ac6e5e 100644 --- a/tests/genericxml2xmlindata/generic-disk-network-http.xml +++ b/tests/genericxml2xmlindata/generic-disk-network-http.xml @@ -32,6 +32,10 @@ + + testcookievalue + blurb + --=20 2.12.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list