From nobody Sun Feb 8 07:07:59 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.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 ARC-Seal: i=1; a=rsa-sha256; t=1563897945; cv=none; d=zoho.com; s=zohoarc; b=VYM6Kc0DDnXce1kzzmj+YihwTUdtavLiZlkit42oRbQIjUBY2U0Dn4BrPa25RQRIEGmTXlRAKCvh/B8JBFnJiERLjXXhyGTSZ35m6RtLm8yQLu5X4xHHU0mDL3lnlTSwIrESDdZ0A+EVaz74rZsRdTR8OH+IhMXCWkINwAk1lO4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563897945; 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:ARC-Authentication-Results; bh=LTRYfv1mg/yPZ77WUBjyGvrdgo8y4Zx09KVdqsujBSI=; b=e45Qxym0JYoSy3eomOQv/w29fZGh52RFMvYiaP4b8bvT2yGS0uRKIU8F2nKSQ60zaGdGT5ZDNlUYwWbawgkvZBPYb7KafUPrLpg2f9lB85M3PyhXHtTbUTiuhd/AdVeuYJUGCzWexPcW4BRhgfEja9d4A0nLj5JRPX6N+wGDwXw= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1563897945031945.3856977732509; Tue, 23 Jul 2019 09:05:45 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DE908C0A4F6F; Tue, 23 Jul 2019 16:05:43 +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 AF2D25C28C; Tue, 23 Jul 2019 16:05:43 +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 6E6CD18045D1; Tue, 23 Jul 2019 16:05:43 +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 x6NG5YhX025427 for ; Tue, 23 Jul 2019 12:05:34 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8F4705C28C; Tue, 23 Jul 2019 16:05:34 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.36.112.10]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6D3305C25A; Tue, 23 Jul 2019 16:05:32 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Tue, 23 Jul 2019 17:03:17 +0100 Message-Id: <20190723160319.18153-40-berrange@redhat.com> In-Reply-To: <20190723160319.18153-1-berrange@redhat.com> References: <20190723160319.18153-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 39/41] remote: refactor the code for choosing the UNIX socket path 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 23 Jul 2019 16:05:44 +0000 (UTC) The ssh, libssh, libssh2 & unix transports all need to use a UNIX socket path, and duplicate some of the same logic for error checking. Pull this out into a separate method to increase code sharing. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/remote/remote_driver.c | 111 ++++++++++++------------------------- 1 file changed, 36 insertions(+), 75 deletions(-) diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index 0500998502..6dc282c139 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -739,34 +739,35 @@ remoteConnectSupportsFeatureUnlocked(virConnectPtr co= nn, } =20 =20 -#ifndef WIN32 -static char *remoteGetUNIXSocketNonRoot(void) +static char * +remoteGetUNIXSocket(remoteDriverTransport transport, + unsigned int flags) { char *sockname =3D NULL; - char *userdir =3D virGetUserRuntimeDirectory(); - - if (!userdir) - return NULL; + VIR_AUTOFREE(char *userdir); + + if (flags & VIR_DRV_OPEN_REMOTE_USER) { + if (transport !=3D REMOTE_DRIVER_TRANSPORT_UNIX) { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, + _("Connecting to session instance without " + "socket path is not supported by the %s " + "transport"), + remoteDriverTransportTypeToString(transport)); + return NULL; + } + if (!(userdir =3D virGetUserRuntimeDirectory())) + return NULL; =20 - if (virAsprintf(&sockname, "%s/" LIBVIRTD_USER_UNIX_SOCKET, userdir) <= 0) { - VIR_FREE(userdir); - return NULL; + if (virAsprintf(&sockname, + "%s/" LIBVIRTD_USER_UNIX_SOCKET, userdir) < 0) + return NULL; + } else { + if (VIR_STRDUP(sockname, + flags & VIR_DRV_OPEN_REMOTE_RO ? + LIBVIRTD_PRIV_UNIX_SOCKET_RO : + LIBVIRTD_PRIV_UNIX_SOCKET) < 0) + return NULL; } - VIR_FREE(userdir); - - VIR_DEBUG("Chosen UNIX sockname %s", sockname); - return sockname; -} -#endif /* WIN32 */ - -static char *remoteGetUNIXSocketRoot(unsigned int flags) -{ - char *sockname =3D NULL; - - if (VIR_STRDUP(sockname, - flags & VIR_DRV_OPEN_REMOTE_RO ? - LIBVIRTD_PRIV_UNIX_SOCKET_RO : LIBVIRTD_PRIV_UNIX_SOCKE= T) < 0) - return NULL; =20 VIR_DEBUG("Chosen UNIX sockname %s", sockname); return sockname; @@ -964,6 +965,17 @@ doRemoteOpen(virConnectPtr conn, } =20 VIR_DEBUG("Connecting with transport %d", transport); + + if ((transport =3D=3D REMOTE_DRIVER_TRANSPORT_UNIX || + transport =3D=3D REMOTE_DRIVER_TRANSPORT_SSH || + transport =3D=3D REMOTE_DRIVER_TRANSPORT_LIBSSH || + transport =3D=3D REMOTE_DRIVER_TRANSPORT_LIBSSH2) && + !sockname && + !(sockname =3D remoteGetUNIXSocket(transport, flags))) + goto failed; + + VIR_DEBUG("Chosen UNIX socket %s", NULLSTR(sockname)); + /* Connect to the remote service. */ switch (transport) { case REMOTE_DRIVER_TRANSPORT_TLS: @@ -1005,20 +1017,6 @@ doRemoteOpen(virConnectPtr conn, break; =20 case REMOTE_DRIVER_TRANSPORT_LIBSSH2: - if (!sockname) { - /* Right now we don't support default session connections */ - if (flags & VIR_DRV_OPEN_REMOTE_USER) { - virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", - _("Connecting to session instance without " - "socket path is not supported by the libs= sh2 " - "connection driver")); - goto failed; - } - - if (!(sockname =3D remoteGetUNIXSocketRoot(flags))) - goto failed; - } - VIR_DEBUG("Starting LibSSH2 session"); =20 priv->client =3D virNetClientNewLibSSH2(priv->hostname, @@ -1040,20 +1038,6 @@ doRemoteOpen(virConnectPtr conn, break; =20 case REMOTE_DRIVER_TRANSPORT_LIBSSH: - if (!sockname) { - /* Right now we don't support default session connections */ - if (flags & VIR_DRV_OPEN_REMOTE_USER) { - virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", - _("Connecting to session instance without " - "socket path is not supported by the libs= sh " - "connection driver")); - goto failed; - } - - if (!(sockname =3D remoteGetUNIXSocketRoot(flags))) - goto failed; - } - VIR_DEBUG("Starting libssh session"); =20 priv->client =3D virNetClientNewLibssh(priv->hostname, @@ -1076,15 +1060,6 @@ doRemoteOpen(virConnectPtr conn, =20 #ifndef WIN32 case REMOTE_DRIVER_TRANSPORT_UNIX: - if (!sockname) { - if (flags & VIR_DRV_OPEN_REMOTE_USER) - sockname =3D remoteGetUNIXSocketNonRoot(); - else - sockname =3D remoteGetUNIXSocketRoot(flags); - if (!sockname) - goto failed; - } - if ((flags & VIR_DRV_OPEN_REMOTE_AUTOSTART) && !(daemonPath =3D virFileFindResourceFull("libvirtd", NULL, NULL, @@ -1105,20 +1080,6 @@ doRemoteOpen(virConnectPtr conn, if (!command && VIR_STRDUP(command, "ssh") < 0) goto failed; =20 - if (!sockname) { - /* Right now we don't support default session connections */ - if (flags & VIR_DRV_OPEN_REMOTE_USER) { - virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", - _("Connecting to session instance without " - "socket path is not supported by the ssh " - "connection driver")); - goto failed; - } - - if (!(sockname =3D remoteGetUNIXSocketRoot(flags))) - goto failed; - } - if (!(priv->client =3D virNetClientNewSSH(priv->hostname, port, command, --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list