From nobody Wed May 14 08:08:27 2025 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.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1524158069660328.000409492667; Thu, 19 Apr 2018 10:14:29 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 58D8731327DD; Thu, 19 Apr 2018 17:14:28 +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 2570118B1C; Thu, 19 Apr 2018 17:14:28 +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 D3458180BAD6; Thu, 19 Apr 2018 17:14:27 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w3JHAHAI015160 for ; Thu, 19 Apr 2018 13:10:17 -0400 Received: by smtp.corp.redhat.com (Postfix) id 87E6A21A468D; Thu, 19 Apr 2018 17:10:17 +0000 (UTC) Received: from t460.redhat.com (unknown [10.33.36.22]) by smtp.corp.redhat.com (Postfix) with ESMTP id C98D82026E04; Thu, 19 Apr 2018 17:10:16 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Thu, 19 Apr 2018 18:09:58 +0100 Message-Id: <20180419171002.17117-11-berrange@redhat.com> In-Reply-To: <20180419171002.17117-1-berrange@redhat.com> References: <20180419171002.17117-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 10/14] remote: split URI scheme into driver and transport upfront 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: , Content-Type: text/plain; charset="utf-8" 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Thu, 19 Apr 2018 17:14:28 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Currently the remote driver extracts the transport from URI scheme and plays games to temporarily hide the driver part when formatting URIs. Refactor the code to split the URI scheme upfront so the two pieces are easily available where needed. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/remote/remote_driver.c | 73 ++++++++++++++++++++++++++----------------= ---- 1 file changed, 42 insertions(+), 31 deletions(-) diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index d3b588c374..436324d252 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -24,7 +24,6 @@ #include =20 #include -#include =20 #include "virnetclient.h" #include "virnetclientprogram.h" @@ -162,7 +161,26 @@ static void make_nonnull_domain_snapshot(remote_nonnul= l_domain_snapshot *snapsho /*----------------------------------------------------------------------*/ =20 /* Helper functions for remoteOpen. */ -static char *get_transport_from_scheme(char *scheme); +static int remoteSplitURIScheme(virURIPtr uri, + char **driver, + char **transport) +{ + char *p =3D strchr(uri->scheme, '+'); + + *driver =3D *transport =3D NULL; + + if (VIR_STRNDUP(*driver, uri->scheme, p ? p - uri->scheme : -1) < 0) + return -1; + + if (p && + VIR_STRDUP(*transport, p + 1) < 0) { + VIR_FREE(*driver); + return -1; + } + + return 0; +} + =20 static int remoteStateInitialize(bool privileged ATTRIBUTE_UNUSED, @@ -715,11 +733,12 @@ remoteConnectSupportsFeatureUnlocked(virConnectPtr co= nn, static int doRemoteOpen(virConnectPtr conn, struct private_data *priv, + const char *driver_str, + const char *transport_str, virConnectAuthPtr auth ATTRIBUTE_UNUSED, virConfPtr conf, unsigned int flags) { - char *transport_str =3D NULL; enum { trans_tls, trans_unix, @@ -738,8 +757,6 @@ doRemoteOpen(virConnectPtr conn, * URIs we don't care about */ =20 if (conn->uri) { - transport_str =3D get_transport_from_scheme(conn->uri->scheme); - if (!transport_str) { if (conn->uri->server) transport =3D trans_tls; @@ -873,26 +890,16 @@ doRemoteOpen(virConnectPtr conn, goto failed; } else { virURI tmpuri =3D { - .scheme =3D conn->uri->scheme, + .scheme =3D (char *)driver_str, .query =3D virURIFormatParams(conn->uri), .path =3D conn->uri->path, .fragment =3D conn->uri->fragment, }; =20 - /* Evil, blank out transport scheme temporarily */ - if (transport_str) { - assert(transport_str[-1] =3D=3D '+'); - transport_str[-1] =3D '\0'; - } - name =3D virURIFormat(&tmpuri); =20 VIR_FREE(tmpuri.query); =20 - /* Restore transport scheme */ - if (transport_str) - transport_str[-1] =3D '+'; - if (!name) goto failed; } @@ -1297,14 +1304,23 @@ remoteConnectOpen(virConnectPtr conn, unsigned int flags) { struct private_data *priv; - int ret, rflags =3D 0; + int ret =3D VIR_DRV_OPEN_ERROR; + int rflags =3D 0; const char *autostart =3D virGetEnvBlockSUID("LIBVIRT_AUTOSTART"); + char *driver =3D NULL; + char *transport =3D NULL; =20 - if (inside_daemon && (!conn->uri || !conn->uri->server)) - return VIR_DRV_OPEN_DECLINED; + if (conn->uri && + remoteSplitURIScheme(conn->uri, &driver, &transport) < 0) + goto cleanup; + + if (inside_daemon && (!conn->uri || !conn->uri->server)) { + ret =3D VIR_DRV_OPEN_DECLINED; + goto cleanup; + } =20 if (!(priv =3D remoteAllocPrivateData())) - return VIR_DRV_OPEN_ERROR; + goto cleanup; =20 if (flags & VIR_CONNECT_RO) rflags |=3D VIR_DRV_OPEN_REMOTE_RO; @@ -1319,8 +1335,7 @@ remoteConnectOpen(virConnectPtr conn, !conn->uri->server && conn->uri->path && conn->uri->scheme && - ((strchr(conn->uri->scheme, '+') =3D=3D 0)|| - (strstr(conn->uri->scheme, "+unix") !=3D NULL)) && + (transport =3D=3D NULL || STREQ(transport, "unix")) && (STREQ(conn->uri->path, "/session") || STRPREFIX(conn->uri->scheme, "test+")) && geteuid() > 0) { @@ -1348,7 +1363,7 @@ remoteConnectOpen(virConnectPtr conn, } } =20 - ret =3D doRemoteOpen(conn, priv, auth, conf, rflags); + ret =3D doRemoteOpen(conn, priv, driver, transport, auth, conf, rflags= ); if (ret !=3D VIR_DRV_OPEN_SUCCESS) { conn->privateData =3D NULL; remoteDriverUnlock(priv); @@ -1357,18 +1372,14 @@ remoteConnectOpen(virConnectPtr conn, conn->privateData =3D priv; remoteDriverUnlock(priv); } + + cleanup: + VIR_FREE(driver); + VIR_FREE(transport); return ret; } =20 =20 -/* In a string "driver+transport" return a pointer to "transport". */ -static char * -get_transport_from_scheme(char *scheme) -{ - char *p =3D strchr(scheme, '+'); - return p ? p + 1 : NULL; -} - /*----------------------------------------------------------------------*/ =20 =20 --=20 2.14.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list