From nobody Sun Feb 8 11:26:00 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 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=1596711139; cv=none; d=zohomail.com; s=zohoarc; b=IquX4Nq3vfX7KuoM2H7DTcdWS9W8U8g8nMEVuCEYO8DDI3oWfQAgvjLKveyfRaYiJff8xX9fZ0HXCVTXNAoMWD71C1EpEJI1LGNXfQmYwDc2Ni3Jz9B+v8Syv5mQuBdR8U7T1/p5vu7sD8DDp2FnedGu4P7VX1UMBMJBPS6zgj8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1596711139; 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=rWyaVudclO3HWYGtyFpDKX6ft9qPd4b/Ub5gkvip3t4=; b=WSnx3xUBSIK4Tiksyu9PxCVoabYljnGiB17qPwi2q9cOh2EbKKZEAJ7UFlCD6QGucbQiYZFJhvuXxss2o8f52BFZVluD8u37omAZ1Za3A/dx5qenErobiu98Q/Nktp+CNBwAVdS7/VUu+LG9H4+VVFj3pcQwo9twtp/OtQaiCq4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 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-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1596711139460260.2099803693802; Thu, 6 Aug 2020 03:52:19 -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-61-BcDHjWuENr66-IBHqbtGNg-1; Thu, 06 Aug 2020 06:52:15 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B0E4118C63E2; Thu, 6 Aug 2020 10:52:08 +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 8E2581A7CF; Thu, 6 Aug 2020 10:52: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 5D0CB96936; Thu, 6 Aug 2020 10:52:08 +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 076Ak31U031733 for ; Thu, 6 Aug 2020 06:46:03 -0400 Received: by smtp.corp.redhat.com (Postfix) id A3E747C0E5; Thu, 6 Aug 2020 10:46:03 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.36.110.44]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8F95D7B925; Thu, 6 Aug 2020 10:46:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1596711138; 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=rWyaVudclO3HWYGtyFpDKX6ft9qPd4b/Ub5gkvip3t4=; b=RNXmWfbayhbDwmoy5FRmXIf07xKZ27VJplQ1gztVoGj2y/Yv3aldBMe6QXCFP2uyMI3GNx XZ9lgkfT+iVnDKRCmGy5Bf7k246G2njTzudEymEYwFXtWyAcrLzst7pEvSnM5sGhUCTur0 wD0vNZsDUo5Hvy7BW3hlpE4SrvAQ5D0= X-MC-Unique: BcDHjWuENr66-IBHqbtGNg-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Subject: [libvirt PATCH v3 08/10] remote: introduce virt-ssh-helper binary Date: Thu, 6 Aug 2020 11:45:43 +0100 Message-Id: <20200806104545.73447-9-berrange@redhat.com> In-Reply-To: <20200806104545.73447-1-berrange@redhat.com> References: <20200806104545.73447-1-berrange@redhat.com> 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.84 on 10.5.11.23 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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) When accessing libvirtd over a SSH tunnel, the remote driver needs a way to proxy the SSH input/output stream to a suitable libvirt daemon. Tihs is currently done by spawning netcat, pointing it to the libvirtd socket path. This is problematic for a number of reasons: - The socket path varies according to the --prefix chosen at build time. The remote client is seeing the local prefix, but what we need is the remote prefix - The socket path varies according to remote env variables, such as the XDG_RUNTIME_DIR location. Again we see the local XDG_RUNTIME_DIR value, but what we need is the remote value (if any) - The remote driver doesn't know whether it must connect to the legacy libvirtd or the modular daemons, so must always assume legacy libvirtd for back-compat. This means we'll always end up using the virtproxyd daemon adding an extra hop in the RPC layer. - We can not able to autospawn the libvirtd daemon for session mode access To address these problems this patch introduces the 'virtd-ssh-helper' program which takes the URI for the remote driver as a CLI parameter. It then figures out which daemon to connect to and its socket path, using the same code that the remote driver client would on the remote host's build of libvirt. Signed-off-by: Daniel P. Berrang=C3=A9 --- build-aux/syntax-check.mk | 2 +- libvirt.spec.in | 2 + po/POTFILES.in | 1 + src/remote/meson.build | 17 ++ src/remote/remote_ssh_helper.c | 425 +++++++++++++++++++++++++++++++++ src/rpc/virnetsocket.h | 1 + 6 files changed, 447 insertions(+), 1 deletion(-) create mode 100644 src/remote/remote_ssh_helper.c diff --git a/build-aux/syntax-check.mk b/build-aux/syntax-check.mk index 6eb59cf90e..151f7a4767 100644 --- a/build-aux/syntax-check.mk +++ b/build-aux/syntax-check.mk @@ -1864,7 +1864,7 @@ sc_group-qemu-caps: # List all syntax-check exemptions: exclude_file_name_regexp--sc_avoid_strcase =3D ^tools/vsh\.h$$ =20 -_src1=3Dlibvirt-stream|qemu/qemu_monitor|util/vir(command|file|fdstream)|r= pc/virnetsocket|lxc/lxc_controller|locking/lock_daemon|logging/log_daemon +_src1=3Dlibvirt-stream|qemu/qemu_monitor|util/vir(command|file|fdstream)|r= pc/virnetsocket|lxc/lxc_controller|locking/lock_daemon|logging/log_daemon|r= emote/remote_ssh_helper _test1=3Dshunloadtest|virnettlscontexttest|virnettlssessiontest|vircgroupm= ock|commandhelper exclude_file_name_regexp--sc_avoid_write =3D \ ^(src/($(_src1))|tools/virsh-console|tests/($(_test1)))\.c$$ diff --git a/libvirt.spec.in b/libvirt.spec.in index e64cfdb561..35125e4f8e 100644 --- a/libvirt.spec.in +++ b/libvirt.spec.in @@ -1561,6 +1561,8 @@ exit 0 =20 %attr(0755, root, root) %{_libexecdir}/libvirt_iohelper =20 +%attr(0755, root, root) %{_bindir}/virt-ssh-helper + %attr(0755, root, root) %{_sbindir}/libvirtd %attr(0755, root, root) %{_sbindir}/virtproxyd %attr(0755, root, root) %{_sbindir}/virtlogd diff --git a/po/POTFILES.in b/po/POTFILES.in index c4197604ef..1ab94972c7 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -182,6 +182,7 @@ @SRCDIR@src/remote/remote_daemon_stream.c @SRCDIR@src/remote/remote_driver.c @SRCDIR@src/remote/remote_sockets.c +@SRCDIR@src/remote/remote_ssh_helper.c @SRCDIR@src/rpc/virkeepalive.c @SRCDIR@src/rpc/virnetclient.c @SRCDIR@src/rpc/virnetclientprogram.c diff --git a/src/remote/meson.build b/src/remote/meson.build index 91dd587cba..9ad2f6ab1c 100644 --- a/src/remote/meson.build +++ b/src/remote/meson.build @@ -51,6 +51,15 @@ remote_daemon_sources =3D files( =20 remote_daemon_generated =3D [] =20 +virt_ssh_helper_sources =3D files( + 'remote_sockets.c', + 'remote_ssh_helper.c', +) + +virt_ssh_helper_dep =3D [ + src_dep, +] + foreach name : [ 'remote', 'qemu', 'lxc' ] protocol_x =3D '@0@_protocol.x'.format(name) dispatch_h =3D '@0@_daemon_dispatch_stubs.h'.format(name) @@ -278,6 +287,14 @@ if conf.has('WITH_REMOTE') rename: [ '50-libvirt.rules' ], ) endif + + virt_helpers +=3D { + 'name': 'virt-ssh-helper', + 'sources': [ + virt_ssh_helper_sources + ], + 'install_dir': bindir, + } endif endif =20 diff --git a/src/remote/remote_ssh_helper.c b/src/remote/remote_ssh_helper.c new file mode 100644 index 0000000000..0da55c1d1f --- /dev/null +++ b/src/remote/remote_ssh_helper.c @@ -0,0 +1,425 @@ +/* + * remote_ssh_helper.c: a netcat replacement for proxying ssh tunnel to da= emon + * + * Copyright (C) 2020 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + */ + +#include + +#include + +#include "rpc/virnetsocket.h" +#include "viralloc.h" +#include "virlog.h" +#include "virgettext.h" +#include "virfile.h" + +#include "remote_sockets.h" + +#define VIR_FROM_THIS VIR_FROM_REMOTE + +VIR_LOG_INIT("remote.remote_ssh_helper"); + +struct virRemoteSSHHelperBuffer { + size_t length; + size_t offset; + char *data; +}; + +typedef struct virRemoteSSHHelper virRemoteSSHHelper; +typedef virRemoteSSHHelper *virRemoteSSHHelperPtr; +struct virRemoteSSHHelper { + bool quit; + virNetSocketPtr sock; + int stdinWatch; + int stdoutWatch; + + struct virRemoteSSHHelperBuffer sockToTerminal; + struct virRemoteSSHHelperBuffer terminalToSock; +}; + + +static void +virRemoteSSHHelperShutdown(virRemoteSSHHelperPtr proxy) +{ + if (proxy->sock) { + virNetSocketRemoveIOCallback(proxy->sock); + virNetSocketClose(proxy->sock); + virObjectUnref(proxy->sock); + proxy->sock =3D NULL; + } + VIR_FREE(proxy->sockToTerminal.data); + VIR_FREE(proxy->terminalToSock.data); + if (proxy->stdinWatch !=3D -1) + virEventRemoveHandle(proxy->stdinWatch); + if (proxy->stdoutWatch !=3D -1) + virEventRemoveHandle(proxy->stdoutWatch); + proxy->stdinWatch =3D -1; + proxy->stdoutWatch =3D -1; + if (!proxy->quit) + proxy->quit =3D true; +} + + +static void +virRemoteSSHHelperEventOnSocket(virNetSocketPtr sock, + int events, + void *opaque) +{ + virRemoteSSHHelperPtr proxy =3D opaque; + + /* we got late event after proxy was shutdown */ + if (!proxy->sock) + return; + + if (events & VIR_EVENT_HANDLE_READABLE) { + size_t avail =3D proxy->sockToTerminal.length - + proxy->sockToTerminal.offset; + int got; + + if (avail < 1024) { + if (VIR_REALLOC_N(proxy->sockToTerminal.data, + proxy->sockToTerminal.length + 1024) < 0) { + virRemoteSSHHelperShutdown(proxy); + return; + } + proxy->sockToTerminal.length +=3D 1024; + avail +=3D 1024; + } + + got =3D virNetSocketRead(sock, + proxy->sockToTerminal.data + + proxy->sockToTerminal.offset, + avail); + if (got =3D=3D -2) + return; /* blocking */ + if (got =3D=3D 0) { + VIR_DEBUG("EOF on socket, shutting down"); + virRemoteSSHHelperShutdown(proxy); + return; + } + if (got < 0) { + virRemoteSSHHelperShutdown(proxy); + return; + } + proxy->sockToTerminal.offset +=3D got; + if (proxy->sockToTerminal.offset) + virEventUpdateHandle(proxy->stdoutWatch, + VIR_EVENT_HANDLE_WRITABLE); + } + + if (events & VIR_EVENT_HANDLE_WRITABLE && + proxy->terminalToSock.offset) { + ssize_t done; + size_t avail; + done =3D virNetSocketWrite(proxy->sock, + proxy->terminalToSock.data, + proxy->terminalToSock.offset); + if (done =3D=3D -2) + return; /* blocking */ + if (done < 0) { + virRemoteSSHHelperShutdown(proxy); + return; + } + memmove(proxy->terminalToSock.data, + proxy->terminalToSock.data + done, + proxy->terminalToSock.offset - done); + proxy->terminalToSock.offset -=3D done; + + avail =3D proxy->terminalToSock.length - proxy->terminalToSock.off= set; + if (avail > 1024) { + ignore_value(VIR_REALLOC_N(proxy->terminalToSock.data, + proxy->terminalToSock.offset + 1024= )); + proxy->terminalToSock.length =3D proxy->terminalToSock.offset = + 1024; + } + } + if (!proxy->terminalToSock.offset) + virNetSocketUpdateIOCallback(proxy->sock, + VIR_EVENT_HANDLE_READABLE); + + if (events & VIR_EVENT_HANDLE_ERROR || + events & VIR_EVENT_HANDLE_HANGUP) { + virRemoteSSHHelperShutdown(proxy); + } +} + + +static void +virRemoteSSHHelperEventOnStdin(int watch G_GNUC_UNUSED, + int fd G_GNUC_UNUSED, + int events, + void *opaque) +{ + virRemoteSSHHelperPtr proxy =3D opaque; + + /* we got late event after console was shutdown */ + if (!proxy->sock) + return; + + if (events & VIR_EVENT_HANDLE_READABLE) { + size_t avail =3D proxy->terminalToSock.length - + proxy->terminalToSock.offset; + int got; + + if (avail < 1024) { + if (VIR_REALLOC_N(proxy->terminalToSock.data, + proxy->terminalToSock.length + 1024) < 0) { + virRemoteSSHHelperShutdown(proxy); + return; + } + proxy->terminalToSock.length +=3D 1024; + avail +=3D 1024; + } + + got =3D read(fd, + proxy->terminalToSock.data + + proxy->terminalToSock.offset, + avail); + if (got < 0) { + if (errno !=3D EAGAIN) { + virReportSystemError(errno, "%s", _("cannot read from stdi= n")); + virRemoteSSHHelperShutdown(proxy); + } + return; + } + if (got =3D=3D 0) { + VIR_DEBUG("EOF on stdin, shutting down"); + virRemoteSSHHelperShutdown(proxy); + return; + } + + proxy->terminalToSock.offset +=3D got; + if (proxy->terminalToSock.offset) + virNetSocketUpdateIOCallback(proxy->sock, + VIR_EVENT_HANDLE_READABLE | + VIR_EVENT_HANDLE_WRITABLE); + } + + if (events & VIR_EVENT_HANDLE_ERROR) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("IO error on stdin"= )); + virRemoteSSHHelperShutdown(proxy); + return; + } + + if (events & VIR_EVENT_HANDLE_HANGUP) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("EOF on stdin")); + virRemoteSSHHelperShutdown(proxy); + return; + } +} + + +static void +virRemoteSSHHelperEventOnStdout(int watch G_GNUC_UNUSED, + int fd, + int events, + void *opaque) +{ + virRemoteSSHHelperPtr proxy =3D opaque; + + /* we got late event after console was shutdown */ + if (!proxy->sock) + return; + + if (events & VIR_EVENT_HANDLE_WRITABLE && + proxy->sockToTerminal.offset) { + ssize_t done; + size_t avail; + done =3D write(fd, + proxy->sockToTerminal.data, + proxy->sockToTerminal.offset); + if (done < 0) { + if (errno !=3D EAGAIN) { + virReportSystemError(errno, "%s", _("cannot write to stdou= t")); + virRemoteSSHHelperShutdown(proxy); + } + return; + } + memmove(proxy->sockToTerminal.data, + proxy->sockToTerminal.data + done, + proxy->sockToTerminal.offset - done); + proxy->sockToTerminal.offset -=3D done; + + avail =3D proxy->sockToTerminal.length - proxy->sockToTerminal.off= set; + if (avail > 1024) { + ignore_value(VIR_REALLOC_N(proxy->sockToTerminal.data, + proxy->sockToTerminal.offset + 1024= )); + proxy->sockToTerminal.length =3D proxy->sockToTerminal.offset = + 1024; + } + } + + if (!proxy->sockToTerminal.offset) + virEventUpdateHandle(proxy->stdoutWatch, 0); + + if (events & VIR_EVENT_HANDLE_ERROR) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("IO error stdout")); + virRemoteSSHHelperShutdown(proxy); + return; + } + + if (events & VIR_EVENT_HANDLE_HANGUP) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("EOF on stdout")); + virRemoteSSHHelperShutdown(proxy); + return; + } +} + + +static int +virRemoteSSHHelperRun(virNetSocketPtr sock) +{ + int ret =3D -1; + virRemoteSSHHelper proxy =3D { + .sock =3D sock, + .stdinWatch =3D -1, + .stdoutWatch =3D -1, + }; + + virEventRegisterDefaultImpl(); + + if ((proxy.stdinWatch =3D virEventAddHandle(STDIN_FILENO, + VIR_EVENT_HANDLE_READABLE, + virRemoteSSHHelperEventOnStd= in, + &proxy, + NULL)) < 0) + goto cleanup; + + if ((proxy.stdoutWatch =3D virEventAddHandle(STDOUT_FILENO, + 0, + virRemoteSSHHelperEventOnSt= dout, + &proxy, + NULL)) < 0) + goto cleanup; + + if (virNetSocketAddIOCallback(proxy.sock, + VIR_EVENT_HANDLE_READABLE, + virRemoteSSHHelperEventOnSocket, + &proxy, + NULL) < 0) + goto cleanup; + + while (!proxy.quit) + virEventRunDefaultImpl(); + + if (virGetLastErrorCode() !=3D VIR_ERR_OK) + goto cleanup; + + ret =3D 0; + cleanup: + if (proxy.stdinWatch !=3D -1) + virEventRemoveHandle(proxy.stdinWatch); + if (proxy.stdoutWatch !=3D -1) + virEventRemoveHandle(proxy.stdoutWatch); + return ret; +} + +int main(int argc, char **argv) +{ + const char *uri_str =3D NULL; + g_autoptr(virURI) uri =3D NULL; + g_autofree char *driver =3D NULL; + remoteDriverTransport transport; + bool user =3D false; + bool autostart =3D false; + gboolean version =3D false; + gboolean readonly =3D false; + g_autofree char *sock_path =3D NULL; + g_autofree char *daemon_name =3D NULL; + g_autoptr(virNetSocket) sock =3D NULL; + GError *error =3D NULL; + g_autoptr(GOptionContext) context =3D NULL; + GOptionEntry entries[] =3D { + { "readonly", 'r', 0, G_OPTION_ARG_NONE, &readonly, "Connect read-= only", NULL }, + { "version", 'V', 0, G_OPTION_ARG_NONE, &version, "Display version= information", NULL }, + { NULL, '\0', 0, 0, NULL, NULL, NULL } + }; + + context =3D g_option_context_new("- libvirt socket proxy"); + g_option_context_add_main_entries(context, entries, PACKAGE); + if (!g_option_context_parse(context, &argc, &argv, &error)) { + g_printerr(_("option parsing failed: %s\n"), error->message); + exit(EXIT_FAILURE); + } + + if (version) { + g_print("%s (%s) %s\n", argv[0], PACKAGE_NAME, PACKAGE_VERSION); + exit(EXIT_SUCCESS); + } + + virSetErrorFunc(NULL, NULL); + virSetErrorLogPriorityFunc(NULL); + + if (virGettextInitialize() < 0 || + virErrorInitialize() < 0) { + g_printerr(_("%s: initialization failed\n"), argv[0]); + exit(EXIT_FAILURE); + } + + virFileActivateDirOverrideForProg(argv[0]); + + /* Initialize the log system */ + virLogSetFromEnv(); + + if (optind !=3D (argc - 1)) { + g_printerr("%s: expected a URI\n", argv[0]); + exit(EXIT_FAILURE); + } + + uri_str =3D argv[optind]; + VIR_DEBUG("Using URI %s", uri_str); + + if (!(uri =3D virURIParse(uri_str))) { + g_printerr(("%s: cannot parse '%s': %s\n"), + argv[0], uri_str, virGetLastErrorMessage()); + exit(EXIT_FAILURE); + } + + if (remoteSplitURIScheme(uri, &driver, &transport) < 0) { + g_printerr(_("%s: cannot parse URI transport '%s': %s\n"), + argv[0], uri_str, virGetLastErrorMessage()); + exit(EXIT_FAILURE); + } + + if (transport !=3D REMOTE_DRIVER_TRANSPORT_UNIX) { + g_printerr(_("%s: unexpected URI transport '%s'\n"), + argv[0], uri_str); + exit(EXIT_FAILURE); + } + + remoteGetURIDaemonInfo(uri, transport, &user, &autostart); + + sock_path =3D remoteGetUNIXSocket(transport, + REMOTE_DRIVER_MODE_AUTO, + driver, + !!readonly, + user, + &daemon_name); + + if (virNetSocketNewConnectUNIX(sock_path, autostart, daemon_name, &soc= k) < 0) { + g_printerr(_("%s: cannot connect to '%s': %s\n"), + argv[0], sock_path, virGetLastErrorMessage()); + exit(EXIT_FAILURE); + } + + if (virRemoteSSHHelperRun(sock) < 0) { + g_printerr(_("%s: could not proxy traffic: %s\n"), + argv[0], virGetLastErrorMessage()); + exit(EXIT_FAILURE); + } + + exit(EXIT_SUCCESS); +} diff --git a/src/rpc/virnetsocket.h b/src/rpc/virnetsocket.h index d39b270480..3996d264fb 100644 --- a/src/rpc/virnetsocket.h +++ b/src/rpc/virnetsocket.h @@ -34,6 +34,7 @@ typedef struct _virNetSocket virNetSocket; typedef virNetSocket *virNetSocketPtr; =20 +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virNetSocket, virObjectUnref); =20 typedef void (*virNetSocketIOFunc)(virNetSocketPtr sock, int events, --=20 2.26.2