2019-07-08 15:38:49 +00:00
|
|
|
/*
|
|
|
|
* remote_ssh_helper.c: a netcat replacement for proxying ssh tunnel to daemon
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#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
|
|
|
|
|
2020-11-25 17:22:51 +00:00
|
|
|
#define SSH_BUF_SIZE (1024 * 1024)
|
|
|
|
|
2019-07-08 15:38:49 +00:00
|
|
|
VIR_LOG_INIT("remote.remote_ssh_helper");
|
|
|
|
|
|
|
|
struct virRemoteSSHHelperBuffer {
|
|
|
|
size_t length;
|
|
|
|
size_t offset;
|
|
|
|
char *data;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct virRemoteSSHHelper virRemoteSSHHelper;
|
|
|
|
struct virRemoteSSHHelper {
|
|
|
|
bool quit;
|
2021-03-11 07:16:13 +00:00
|
|
|
virNetSocket *sock;
|
2020-11-25 17:22:51 +00:00
|
|
|
int sockEvents;
|
2019-07-08 15:38:49 +00:00
|
|
|
int stdinWatch;
|
2020-11-25 17:22:51 +00:00
|
|
|
int stdinEvents;
|
2019-07-08 15:38:49 +00:00
|
|
|
int stdoutWatch;
|
2020-11-25 17:22:51 +00:00
|
|
|
int stdoutEvents;
|
2019-07-08 15:38:49 +00:00
|
|
|
|
|
|
|
struct virRemoteSSHHelperBuffer sockToTerminal;
|
|
|
|
struct virRemoteSSHHelperBuffer terminalToSock;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2021-03-11 07:16:13 +00:00
|
|
|
virRemoteSSHHelperShutdown(virRemoteSSHHelper *proxy)
|
2019-07-08 15:38:49 +00:00
|
|
|
{
|
|
|
|
if (proxy->sock) {
|
|
|
|
virNetSocketRemoveIOCallback(proxy->sock);
|
|
|
|
virNetSocketClose(proxy->sock);
|
2022-01-28 17:42:45 +00:00
|
|
|
g_clear_pointer(&proxy->sock, virObjectUnref);
|
2019-07-08 15:38:49 +00:00
|
|
|
}
|
|
|
|
VIR_FREE(proxy->sockToTerminal.data);
|
|
|
|
VIR_FREE(proxy->terminalToSock.data);
|
|
|
|
if (proxy->stdinWatch != -1)
|
|
|
|
virEventRemoveHandle(proxy->stdinWatch);
|
|
|
|
if (proxy->stdoutWatch != -1)
|
|
|
|
virEventRemoveHandle(proxy->stdoutWatch);
|
|
|
|
proxy->stdinWatch = -1;
|
|
|
|
proxy->stdoutWatch = -1;
|
|
|
|
if (!proxy->quit)
|
|
|
|
proxy->quit = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-25 17:22:51 +00:00
|
|
|
static void
|
2021-03-11 07:16:13 +00:00
|
|
|
virRemoteSSHHelperUpdateEvents(virRemoteSSHHelper *proxy)
|
2020-11-25 17:22:51 +00:00
|
|
|
{
|
|
|
|
int sockEvents = 0;
|
|
|
|
int stdinEvents = 0;
|
|
|
|
int stdoutEvents = 0;
|
|
|
|
|
|
|
|
if (proxy->terminalToSock.offset != 0)
|
|
|
|
sockEvents |= VIR_EVENT_HANDLE_WRITABLE;
|
|
|
|
if (proxy->terminalToSock.offset < proxy->terminalToSock.length)
|
|
|
|
stdinEvents |= VIR_EVENT_HANDLE_READABLE;
|
|
|
|
|
|
|
|
if (proxy->sockToTerminal.offset != 0)
|
|
|
|
stdoutEvents |= VIR_EVENT_HANDLE_WRITABLE;
|
|
|
|
if (proxy->sockToTerminal.offset < proxy->sockToTerminal.length)
|
|
|
|
sockEvents |= VIR_EVENT_HANDLE_READABLE;
|
|
|
|
|
|
|
|
if (sockEvents != proxy->sockEvents) {
|
|
|
|
VIR_DEBUG("Update sock events %d -> %d", proxy->sockEvents, sockEvents);
|
|
|
|
virNetSocketUpdateIOCallback(proxy->sock, sockEvents);
|
|
|
|
proxy->sockEvents = sockEvents;
|
|
|
|
}
|
|
|
|
if (stdinEvents != proxy->stdinEvents) {
|
|
|
|
VIR_DEBUG("Update stdin events %d -> %d", proxy->stdinEvents, stdinEvents);
|
|
|
|
virEventUpdateHandle(proxy->stdinWatch, stdinEvents);
|
|
|
|
proxy->stdinEvents = stdinEvents;
|
|
|
|
}
|
|
|
|
if (stdoutEvents != proxy->stdoutEvents) {
|
|
|
|
VIR_DEBUG("Update stdout events %d -> %d", proxy->stdoutEvents, stdoutEvents);
|
|
|
|
virEventUpdateHandle(proxy->stdoutWatch, stdoutEvents);
|
|
|
|
proxy->stdoutEvents = stdoutEvents;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-08 15:38:49 +00:00
|
|
|
static void
|
2021-03-11 07:16:13 +00:00
|
|
|
virRemoteSSHHelperEventOnSocket(virNetSocket *sock,
|
2019-07-08 15:38:49 +00:00
|
|
|
int events,
|
|
|
|
void *opaque)
|
|
|
|
{
|
2021-03-11 07:16:13 +00:00
|
|
|
virRemoteSSHHelper *proxy = opaque;
|
2019-07-08 15:38:49 +00:00
|
|
|
|
|
|
|
/* we got late event after proxy was shutdown */
|
|
|
|
if (!proxy->sock)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (events & VIR_EVENT_HANDLE_READABLE) {
|
|
|
|
size_t avail = proxy->sockToTerminal.length -
|
|
|
|
proxy->sockToTerminal.offset;
|
|
|
|
int got;
|
|
|
|
|
2020-11-25 17:22:51 +00:00
|
|
|
if (avail == 0) {
|
|
|
|
VIR_DEBUG("Unexpectedly called with no space in buffer");
|
|
|
|
goto cleanup;
|
2019-07-08 15:38:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
got = virNetSocketRead(sock,
|
|
|
|
proxy->sockToTerminal.data +
|
|
|
|
proxy->sockToTerminal.offset,
|
|
|
|
avail);
|
|
|
|
if (got == -2)
|
|
|
|
return; /* blocking */
|
|
|
|
if (got == 0) {
|
|
|
|
VIR_DEBUG("EOF on socket, shutting down");
|
|
|
|
virRemoteSSHHelperShutdown(proxy);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (got < 0) {
|
|
|
|
virRemoteSSHHelperShutdown(proxy);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
proxy->sockToTerminal.offset += got;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (events & VIR_EVENT_HANDLE_WRITABLE &&
|
|
|
|
proxy->terminalToSock.offset) {
|
|
|
|
ssize_t done;
|
|
|
|
done = virNetSocketWrite(proxy->sock,
|
|
|
|
proxy->terminalToSock.data,
|
|
|
|
proxy->terminalToSock.offset);
|
|
|
|
if (done == -2)
|
|
|
|
return; /* blocking */
|
|
|
|
if (done < 0) {
|
|
|
|
virRemoteSSHHelperShutdown(proxy);
|
|
|
|
return;
|
|
|
|
}
|
2020-11-25 17:22:51 +00:00
|
|
|
|
2019-07-08 15:38:49 +00:00
|
|
|
memmove(proxy->terminalToSock.data,
|
|
|
|
proxy->terminalToSock.data + done,
|
|
|
|
proxy->terminalToSock.offset - done);
|
|
|
|
proxy->terminalToSock.offset -= done;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (events & VIR_EVENT_HANDLE_ERROR ||
|
|
|
|
events & VIR_EVENT_HANDLE_HANGUP) {
|
|
|
|
virRemoteSSHHelperShutdown(proxy);
|
2020-11-25 17:22:51 +00:00
|
|
|
return;
|
2019-07-08 15:38:49 +00:00
|
|
|
}
|
2020-11-25 17:22:51 +00:00
|
|
|
|
|
|
|
cleanup:
|
|
|
|
virRemoteSSHHelperUpdateEvents(proxy);
|
2019-07-08 15:38:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
virRemoteSSHHelperEventOnStdin(int watch G_GNUC_UNUSED,
|
|
|
|
int fd G_GNUC_UNUSED,
|
|
|
|
int events,
|
|
|
|
void *opaque)
|
|
|
|
{
|
2021-03-11 07:16:13 +00:00
|
|
|
virRemoteSSHHelper *proxy = opaque;
|
2019-07-08 15:38:49 +00:00
|
|
|
|
|
|
|
/* we got late event after console was shutdown */
|
|
|
|
if (!proxy->sock)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (events & VIR_EVENT_HANDLE_READABLE) {
|
|
|
|
size_t avail = proxy->terminalToSock.length -
|
|
|
|
proxy->terminalToSock.offset;
|
|
|
|
int got;
|
|
|
|
|
2020-11-25 17:22:51 +00:00
|
|
|
if (avail == 0) {
|
|
|
|
VIR_DEBUG("Unexpectedly called with no space in buffer");
|
|
|
|
goto cleanup;
|
2019-07-08 15:38:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
got = read(fd,
|
|
|
|
proxy->terminalToSock.data +
|
|
|
|
proxy->terminalToSock.offset,
|
|
|
|
avail);
|
|
|
|
if (got < 0) {
|
|
|
|
if (errno != EAGAIN) {
|
|
|
|
virReportSystemError(errno, "%s", _("cannot read from stdin"));
|
|
|
|
virRemoteSSHHelperShutdown(proxy);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (got == 0) {
|
|
|
|
VIR_DEBUG("EOF on stdin, shutting down");
|
|
|
|
virRemoteSSHHelperShutdown(proxy);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
proxy->terminalToSock.offset += got;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2020-11-25 17:22:51 +00:00
|
|
|
|
|
|
|
cleanup:
|
|
|
|
virRemoteSSHHelperUpdateEvents(proxy);
|
2019-07-08 15:38:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
virRemoteSSHHelperEventOnStdout(int watch G_GNUC_UNUSED,
|
|
|
|
int fd,
|
|
|
|
int events,
|
|
|
|
void *opaque)
|
|
|
|
{
|
2021-03-11 07:16:13 +00:00
|
|
|
virRemoteSSHHelper *proxy = opaque;
|
2019-07-08 15:38:49 +00:00
|
|
|
|
|
|
|
/* we got late event after console was shutdown */
|
|
|
|
if (!proxy->sock)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (events & VIR_EVENT_HANDLE_WRITABLE &&
|
|
|
|
proxy->sockToTerminal.offset) {
|
|
|
|
ssize_t done;
|
2022-02-14 15:39:00 +00:00
|
|
|
done = write(fd, /* sc_avoid_write */
|
2019-07-08 15:38:49 +00:00
|
|
|
proxy->sockToTerminal.data,
|
|
|
|
proxy->sockToTerminal.offset);
|
|
|
|
if (done < 0) {
|
|
|
|
if (errno != EAGAIN) {
|
|
|
|
virReportSystemError(errno, "%s", _("cannot write to stdout"));
|
|
|
|
virRemoteSSHHelperShutdown(proxy);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
memmove(proxy->sockToTerminal.data,
|
|
|
|
proxy->sockToTerminal.data + done,
|
|
|
|
proxy->sockToTerminal.offset - done);
|
|
|
|
proxy->sockToTerminal.offset -= done;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2020-11-25 17:22:51 +00:00
|
|
|
|
|
|
|
virRemoteSSHHelperUpdateEvents(proxy);
|
2019-07-08 15:38:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2021-03-11 07:16:13 +00:00
|
|
|
virRemoteSSHHelperRun(virNetSocket *sock)
|
2019-07-08 15:38:49 +00:00
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
virRemoteSSHHelper proxy = {
|
|
|
|
.sock = sock,
|
2020-11-25 17:22:51 +00:00
|
|
|
.sockEvents = VIR_EVENT_HANDLE_READABLE,
|
2019-07-08 15:38:49 +00:00
|
|
|
.stdinWatch = -1,
|
2020-11-25 17:22:51 +00:00
|
|
|
.stdinEvents = VIR_EVENT_HANDLE_READABLE,
|
2019-07-08 15:38:49 +00:00
|
|
|
.stdoutWatch = -1,
|
2020-11-25 17:22:51 +00:00
|
|
|
.stdoutEvents = 0,
|
|
|
|
.sockToTerminal = {
|
|
|
|
.offset = 0,
|
|
|
|
.length = SSH_BUF_SIZE,
|
|
|
|
.data = g_new0(char, SSH_BUF_SIZE),
|
|
|
|
},
|
|
|
|
.terminalToSock = {
|
|
|
|
.offset = 0,
|
|
|
|
.length = SSH_BUF_SIZE,
|
|
|
|
.data = g_new0(char, SSH_BUF_SIZE),
|
|
|
|
},
|
2019-07-08 15:38:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
virEventRegisterDefaultImpl();
|
|
|
|
|
|
|
|
if ((proxy.stdinWatch = virEventAddHandle(STDIN_FILENO,
|
|
|
|
VIR_EVENT_HANDLE_READABLE,
|
|
|
|
virRemoteSSHHelperEventOnStdin,
|
|
|
|
&proxy,
|
|
|
|
NULL)) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if ((proxy.stdoutWatch = virEventAddHandle(STDOUT_FILENO,
|
|
|
|
0,
|
|
|
|
virRemoteSSHHelperEventOnStdout,
|
|
|
|
&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() != VIR_ERR_OK)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
cleanup:
|
|
|
|
if (proxy.stdinWatch != -1)
|
|
|
|
virEventRemoveHandle(proxy.stdinWatch);
|
|
|
|
if (proxy.stdoutWatch != -1)
|
|
|
|
virEventRemoveHandle(proxy.stdoutWatch);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
const char *uri_str = NULL;
|
|
|
|
g_autoptr(virURI) uri = NULL;
|
|
|
|
g_autofree char *driver = NULL;
|
|
|
|
remoteDriverTransport transport;
|
2023-02-02 15:51:58 +00:00
|
|
|
int mode = REMOTE_DRIVER_MODE_AUTO;
|
|
|
|
const char *mode_str = NULL;
|
2019-07-08 15:38:49 +00:00
|
|
|
gboolean version = false;
|
|
|
|
gboolean readonly = false;
|
|
|
|
g_autofree char *sock_path = NULL;
|
2021-05-24 13:08:44 +00:00
|
|
|
g_autofree char *daemon_path = NULL;
|
2019-07-08 15:38:49 +00:00
|
|
|
g_autoptr(virNetSocket) sock = NULL;
|
|
|
|
GError *error = NULL;
|
|
|
|
g_autoptr(GOptionContext) context = NULL;
|
|
|
|
GOptionEntry entries[] = {
|
|
|
|
{ "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 }
|
|
|
|
};
|
2021-05-24 13:02:07 +00:00
|
|
|
unsigned int flags;
|
2023-02-02 15:51:58 +00:00
|
|
|
size_t i;
|
2019-07-08 15:38:49 +00:00
|
|
|
|
2021-12-10 10:59:33 +00:00
|
|
|
context = g_option_context_new("URI - libvirt socket proxy");
|
|
|
|
g_option_context_set_summary(context,
|
|
|
|
"Internal tool used to handle connections coming from remote\n"
|
|
|
|
"clients. Not intended to be called directly by the user.");
|
2019-07-08 15:38:49 +00:00
|
|
|
g_option_context_add_main_entries(context, entries, PACKAGE);
|
|
|
|
if (!g_option_context_parse(context, &argc, &argv, &error)) {
|
2023-03-09 12:20:48 +00:00
|
|
|
g_printerr(_("option parsing failed: %1$s\n"), error->message);
|
2019-07-08 15:38:49 +00:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (version) {
|
|
|
|
g_print("%s (%s) %s\n", argv[0], PACKAGE_NAME, PACKAGE_VERSION);
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
}
|
|
|
|
|
2021-12-10 10:59:33 +00:00
|
|
|
if (argc != 2) {
|
|
|
|
g_autofree char *help = g_option_context_get_help(context, TRUE, NULL);
|
|
|
|
g_printerr("%s", help);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
2019-07-08 15:38:49 +00:00
|
|
|
virSetErrorFunc(NULL, NULL);
|
|
|
|
virSetErrorLogPriorityFunc(NULL);
|
|
|
|
|
|
|
|
if (virGettextInitialize() < 0 ||
|
|
|
|
virErrorInitialize() < 0) {
|
2023-03-09 12:20:48 +00:00
|
|
|
g_printerr(_("%1$s: initialization failed\n"), argv[0]);
|
2019-07-08 15:38:49 +00:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
virFileActivateDirOverrideForProg(argv[0]);
|
|
|
|
|
|
|
|
/* Initialize the log system */
|
2021-12-15 15:34:16 +00:00
|
|
|
if (virLogSetFromEnv() < 0)
|
|
|
|
exit(EXIT_FAILURE);
|
2019-07-08 15:38:49 +00:00
|
|
|
|
2021-12-10 13:53:31 +00:00
|
|
|
uri_str = argv[1];
|
2019-07-08 15:38:49 +00:00
|
|
|
VIR_DEBUG("Using URI %s", uri_str);
|
|
|
|
|
|
|
|
if (!(uri = 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) {
|
2023-03-09 12:20:48 +00:00
|
|
|
g_printerr(_("%1$s: cannot parse URI transport '%2$s': %3$s\n"),
|
2019-07-08 15:38:49 +00:00
|
|
|
argv[0], uri_str, virGetLastErrorMessage());
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (transport != REMOTE_DRIVER_TRANSPORT_UNIX) {
|
2023-03-09 12:20:48 +00:00
|
|
|
g_printerr(_("%1$s: unexpected URI transport '%2$s'\n"),
|
2019-07-08 15:38:49 +00:00
|
|
|
argv[0], uri_str);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
2021-05-24 13:02:07 +00:00
|
|
|
remoteGetURIDaemonInfo(uri, transport, &flags);
|
|
|
|
if (readonly)
|
|
|
|
flags |= REMOTE_DRIVER_OPEN_RO;
|
2019-07-08 15:38:49 +00:00
|
|
|
|
2023-02-02 15:51:58 +00:00
|
|
|
for (i = 0; i < uri->paramsCount; i++) {
|
|
|
|
virURIParam *var = &uri->params[i];
|
|
|
|
|
|
|
|
if (STRCASEEQ(var->name, "mode")) {
|
|
|
|
mode_str = var->value;
|
|
|
|
continue;
|
2023-02-03 09:52:06 +00:00
|
|
|
} else if (STRCASEEQ(var->name, "socket")) {
|
|
|
|
sock_path = g_strdup(var->value);
|
|
|
|
continue;
|
2023-02-02 15:51:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mode_str &&
|
|
|
|
(mode = remoteDriverModeTypeFromString(mode_str)) < 0) {
|
2023-03-09 12:20:48 +00:00
|
|
|
g_printerr(_("%1$s: unknown remote mode '%2$s'"), argv[0], mode_str);
|
2023-02-02 15:51:58 +00:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
2023-02-03 09:52:06 +00:00
|
|
|
if (!sock_path &&
|
|
|
|
!(sock_path = remoteGetUNIXSocket(transport, mode,
|
|
|
|
driver, flags, &daemon_path))) {
|
2023-03-09 12:20:48 +00:00
|
|
|
g_printerr(_("%1$s: failed to generate UNIX socket path"), argv[0]);
|
2023-02-03 09:52:06 +00:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
2019-07-08 15:38:49 +00:00
|
|
|
|
2021-05-24 14:07:19 +00:00
|
|
|
if (virNetSocketNewConnectUNIX(sock_path, daemon_path, &sock) < 0) {
|
2023-03-09 12:20:48 +00:00
|
|
|
g_printerr(_("%1$s: cannot connect to '%2$s': %3$s\n"),
|
2019-07-08 15:38:49 +00:00
|
|
|
argv[0], sock_path, virGetLastErrorMessage());
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virRemoteSSHHelperRun(sock) < 0) {
|
2023-03-09 12:20:48 +00:00
|
|
|
g_printerr(_("%1$s: could not proxy traffic: %2$s\n"),
|
2019-07-08 15:38:49 +00:00
|
|
|
argv[0], virGetLastErrorMessage());
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
}
|