Blame SOURCES/0033-Don-t-connect-to-localhost-when-using-direct.patch

4ab194
From 7d8b1c5665e9f27533bea7c1e0876ffb784cd1b6 Mon Sep 17 00:00:00 2001
4ab194
From: Christophe Fergeau <cfergeau@redhat.com>
4ab194
Date: Thu, 3 Apr 2014 14:06:22 +0200
4ab194
Subject: [PATCH] Don't connect to localhost when using --direct
4ab194
4ab194
Trying to connect to a remote virtual machine using
4ab194
virt-viewer -c qemu+ssh://example.com/system --direct $vm_name
4ab194
will currently fail with an error message saying it's not possible to
4ab194
localhost. This happens with VMs which listen on a wildcard address (eg
4ab194
'0.0.0.0').
4ab194
This was introduced by commit 74b1b62 which changes the host to connect to
4ab194
to 'localhost' when trying to connect through ssh to a VM listening on a
4ab194
wildcard address. This is only valid when using a ssh tunnel, and should
4ab194
not be done with --direct. The fallback code which uses the hostname from
4ab194
the libvirt URI is what makes the most sense in this situation (wildcard
4ab194
listen address + --direct).
4ab194
This commit introduces a virt_viewer_app_get_direct() so that this can be
4ab194
implemented.
4ab194
4ab194
Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1079211
4ab194
---
4ab194
 src/virt-viewer-app.c | 7 +++++++
4ab194
 src/virt-viewer-app.h | 1 +
4ab194
 src/virt-viewer.c     | 3 ++-
4ab194
 3 files changed, 10 insertions(+), 1 deletion(-)
4ab194
4ab194
diff --git a/src/virt-viewer-app.c b/src/virt-viewer-app.c
4ab194
index 033a594..27e5164 100644
4ab194
--- a/src/virt-viewer-app.c
4ab194
+++ b/src/virt-viewer-app.c
4ab194
@@ -1838,6 +1838,13 @@ virt_viewer_app_set_direct(VirtViewerApp *self, gboolean direct)
4ab194
     self->priv->direct = direct;
4ab194
 }
4ab194
 
4ab194
+gboolean virt_viewer_app_get_direct(VirtViewerApp *self)
4ab194
+{
4ab194
+    g_return_val_if_fail(VIRT_VIEWER_IS_APP(self), FALSE);
4ab194
+
4ab194
+    return self->priv->direct;
4ab194
+}
4ab194
+
4ab194
 void
4ab194
 virt_viewer_app_clear_hotkeys(VirtViewerApp *self)
4ab194
 {
4ab194
diff --git a/src/virt-viewer-app.h b/src/virt-viewer-app.h
4ab194
index 7c77957..f03369b 100644
4ab194
--- a/src/virt-viewer-app.h
4ab194
+++ b/src/virt-viewer-app.h
4ab194
@@ -75,6 +75,7 @@ gboolean virt_viewer_app_activate(VirtViewerApp *self, GError **error);
4ab194
 gboolean virt_viewer_app_initial_connect(VirtViewerApp *self, GError **error);
4ab194
 void virt_viewer_app_start_reconnect_poll(VirtViewerApp *self);
4ab194
 void virt_viewer_app_set_zoom_level(VirtViewerApp *self, gint zoom_level);
4ab194
+gboolean virt_viewer_app_get_direct(VirtViewerApp *self);
4ab194
 void virt_viewer_app_set_direct(VirtViewerApp *self, gboolean direct);
4ab194
 void virt_viewer_app_set_hotkeys(VirtViewerApp *self, const gchar *hotkeys);
4ab194
 void virt_viewer_app_set_attach(VirtViewerApp *self, gboolean attach);
4ab194
diff --git a/src/virt-viewer.c b/src/virt-viewer.c
4ab194
index 01a9a51..739b817 100644
4ab194
--- a/src/virt-viewer.c
4ab194
+++ b/src/virt-viewer.c
4ab194
@@ -365,7 +365,8 @@ virt_viewer_extract_connect_info(VirtViewer *self,
4ab194
      */
4ab194
     if (virt_viewer_replace_host(ghost)) {
4ab194
         gchar *replacement_host = NULL;
4ab194
-        if (g_strcmp0(transport, "ssh") == 0) {
4ab194
+        if ((g_strcmp0(transport, "ssh") == 0)
4ab194
+                && !virt_viewer_app_get_direct(app)) {
4ab194
             replacement_host = g_strdup("localhost");
4ab194
         } else {
4ab194
             replacement_host = g_strdup(host);