[virt-tools-list] [virt-viewer] virt-viewer: Don't connect to localhost displays with qemu+tcp://

Christophe Fergeau cfergeau at redhat.com
Tue Jun 24 07:49:54 UTC 2014


Ping ?

On Thu, Jun 19, 2014 at 06:32:40PM +0200, Christophe Fergeau wrote:
> When connecting to a remote libvirt instance, a VM may only be listening
> on localhost for SPICE/VNC connections. In such a situation, virt-viewer
> then tries to connect to localhost, which is not correct as this
> 'localhost' referred to the remote libvirt host it connected to.
> This commit adds a couple of tests on the libvirt URI used and the
> <graphics> listen address to error out in this situation.
> 
> Resolves: rhbz#1108523
> ---
>  src/virt-viewer.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 57 insertions(+)
> 
> diff --git a/src/virt-viewer.c b/src/virt-viewer.c
> index 8a1d8c5..f8f175c 100644
> --- a/src/virt-viewer.c
> +++ b/src/virt-viewer.c
> @@ -292,6 +292,55 @@ virt_viewer_replace_host(const gchar *host)
>      return ret;
>  }
>  
> +
> +static gboolean
> +virt_viewer_is_loopback(const char *host)
> +{
> +    GInetAddress *addr = NULL;
> +    gboolean is_loopback = FALSE;
> +
> +    g_return_val_if_fail(host != NULL, FALSE);
> +
> +    addr = g_inet_address_new_from_string(host);
> +    if (!addr) /* Parsing error means it was probably a hostname */
> +        return (strcmp(host, "localhost") == 0);
> +
> +    is_loopback = g_inet_address_get_is_loopback(addr);
> +    g_object_unref(addr);
> +
> +    return is_loopback;
> +}
> +
> +
> +static gboolean
> +virt_viewer_is_reachable(const gchar *host, const char *transport,
> +                         const char *transport_host)
> +{
> +    gboolean host_is_loopback;
> +    gboolean transport_is_loopback;
> +
> +    if (!host)
> +        return FALSE;
> +
> +    if (!transport)
> +        return TRUE;
> +
> +    if (strcmp(transport, "ssh") == 0)
> +        return TRUE;
> +
> +    if (strcmp(transport, "unix") == 0)
> +        return TRUE;
> +
> +    host_is_loopback = virt_viewer_is_loopback(host);
> +    transport_is_loopback = virt_viewer_is_loopback(transport_host);
> +
> +    if (transport_is_loopback && host_is_loopback)
> +        return TRUE;
> +    else
> +        return !host_is_loopback;
> +}
> +
> +
>  static gboolean
>  virt_viewer_extract_connect_info(VirtViewer *self,
>                                   virDomainPtr dom)
> @@ -377,6 +426,14 @@ virt_viewer_extract_connect_info(VirtViewer *self,
>          ghost = replacement_host;
>      }
>  
> +    if (!virt_viewer_is_reachable(ghost, transport, host)) {
> +        g_debug("graphics listen '%s' is not reachable from this machine",
> +                ghost ? ghost : "");
> +        virt_viewer_app_simple_message_dialog(app, _("Guest '%s' is not reachable"),
> +                                              priv->domkey);
> +        goto cleanup;
> +    }
> +
>      virt_viewer_app_set_connect_info(app, host, ghost, gport, gtlsport,transport, unixsock, user, port, NULL);
>  
>      retval = TRUE;
> -- 
> 1.9.3
> 
> _______________________________________________
> virt-tools-list mailing list
> virt-tools-list at redhat.com
> https://www.redhat.com/mailman/listinfo/virt-tools-list
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/virt-tools-list/attachments/20140624/82308a09/attachment.sig>


More information about the virt-tools-list mailing list