[virt-tools-list] [PATCH 1/2] Return full response from virt_viewer_auth_collect_credentials()

Pavel Grunt pgrunt at redhat.com
Fri Jun 2 11:16:06 UTC 2017


On Fri, 2017-06-02 at 12:40 +0200, Victor Toso wrote:
> From: Victor Toso <me at victortoso.com>
> 
> Who is trying to collect the credentials might need to know if a
> given
> failure is due bad user input of credentionals or if the user has
> cancel/closed the dialog (which is also consider failure prior this
> patch)
> 
> Related: https://bugzilla.redhat.com/show_bug.cgi?id=1446161
> Signed-off-by: Victor Toso <victortoso at redhat.com>
> ---
>  src/remote-viewer.c             | 14 +++++++-------
>  src/virt-viewer-auth.c          |  2 +-
>  src/virt-viewer-auth.h          | 10 +++++-----
>  src/virt-viewer-session-spice.c | 22 +++++++++++-----------
>  src/virt-viewer-session-vnc.c   | 10 +++++-----
>  src/virt-viewer.c               | 10 ++++++----
>  6 files changed, 35 insertions(+), 33 deletions(-)
> 
> diff --git a/src/remote-viewer.c b/src/remote-viewer.c
> index 2db76bc..ab563bb 100644
> --- a/src/remote-viewer.c
> +++ b/src/remote-viewer.c
> @@ -737,7 +737,7 @@ authenticate_cb(RestProxy *proxy, G_GNUC_UNUSED
> RestProxyAuth *auth,
>      gchar *username = NULL;
>      gchar *password = NULL;
>      VirtViewerWindow *window;
> -    gboolean success = FALSE;
> +    gint response;

it is enum GtkResponseType, better to use that (same for the function
definition and declaration).

Besides that it looks ok
Pavel

>  
>      g_object_get(proxy,
>                   "username", &username,
> @@ -747,11 +747,11 @@ authenticate_cb(RestProxy *proxy,
> G_GNUC_UNUSED RestProxyAuth *auth,
>          username = g_strdup(g_get_user_name());
>  
>      window =
> virt_viewer_app_get_main_window(VIRT_VIEWER_APP(user_data));
> -    success =
> virt_viewer_auth_collect_credentials(virt_viewer_window_get_window(w
> indow),
> -                                                   "oVirt",
> -                                                   NULL,
> -                                                   &username,
> &password);
> -    if (success) {
> +    response =
> virt_viewer_auth_collect_credentials(virt_viewer_window_get_window(w
> indow),
> +                                                    "oVirt",
> +                                                    NULL,
> +                                                    &username,
> &password);
> +    if (response == GTK_RESPONSE_OK) {
>          g_object_set(G_OBJECT(proxy),
>                       "username", username,
>                       "password", password,
> @@ -764,7 +764,7 @@ authenticate_cb(RestProxy *proxy, G_GNUC_UNUSED
> RestProxyAuth *auth,
>  
>      g_free(username);
>      g_free(password);
> -    return success;
> +    return (response == GTK_RESPONSE_OK);
>  }
>  
>  static void
> diff --git a/src/virt-viewer-auth.c b/src/virt-viewer-auth.c
> index 67c770c..96cda8a 100644
> --- a/src/virt-viewer-auth.c
> +++ b/src/virt-viewer-auth.c
> @@ -113,7 +113,7 @@ virt_viewer_auth_collect_credentials(GtkWindow
> *window,
>      gtk_widget_destroy(GTK_WIDGET(dialog));
>      g_object_unref(G_OBJECT(creds));
>  
> -    return response == GTK_RESPONSE_OK;
> +    return response;
>  }
>  
>  /*
> diff --git a/src/virt-viewer-auth.h b/src/virt-viewer-auth.h
> index 25463fc..ebe09e5 100644
> --- a/src/virt-viewer-auth.h
> +++ b/src/virt-viewer-auth.h
> @@ -27,11 +27,11 @@
>  
>  #include "virt-viewer-session.h"
>  
> -gboolean virt_viewer_auth_collect_credentials(GtkWindow *window,
> -                                              const char *type,
> -                                              const char *address,
> -                                              char **username,
> -                                              char **password);
> +gint virt_viewer_auth_collect_credentials(GtkWindow *window,
> +                                          const char *type,
> +                                          const char *address,
> +                                          char **username,
> +                                          char **password);
>  
>  #endif
>  /*
> diff --git a/src/virt-viewer-session-spice.c b/src/virt-viewer-
> session-spice.c
> index 5f326aa..a87d4cd 100644
> --- a/src/virt-viewer-session-spice.c
> +++ b/src/virt-viewer-session-spice.c
> @@ -668,7 +668,7 @@
> virt_viewer_session_spice_main_channel_event(SpiceChannel *channel,
>  {
>      VirtViewerSessionSpice *self =
> VIRT_VIEWER_SESSION_SPICE(session);
>      gchar *password = NULL, *user = NULL;
> -    gboolean ret;
> +    gint response;
>      static gboolean username_required = FALSE;
>  
>      g_return_if_fail(self != NULL);
> @@ -717,13 +717,13 @@
> virt_viewer_session_spice_main_channel_event(SpiceChannel *channel,
>          }
>  
>          g_object_get(self->priv->session, "host", &host, NULL);
> -        ret = virt_viewer_auth_collect_credentials(self->priv-
> >main_window,
> -                                                   "SPICE",
> -                                                   host,
> -                                                   username_require
> d ? &user : NULL,
> -                                                   &password);
> +        response = virt_viewer_auth_collect_credentials(self->priv-
> >main_window,
> +                                                        "SPICE",
> +                                                        host,
> +                                                        username_re
> quired ? &user : NULL,
> +                                                        &password);
>          g_free(host);
> -        if (!ret) {
> +        if (response != GTK_RESPONSE_OK) {
>              g_signal_emit_by_name(session, "session-cancelled");
>          } else {
>              gboolean openfd;
> @@ -750,10 +750,10 @@
> virt_viewer_session_spice_main_channel_event(SpiceChannel *channel,
>              SpiceURI *proxy = spice_session_get_proxy_uri(self-
> >priv->session);
>              g_warn_if_fail(proxy != NULL);
>  
> -            ret = virt_viewer_auth_collect_credentials(self->priv-
> >main_window,
> -                                                       "proxy",
> spice_uri_get_hostname(proxy),
> -                                                       &user,
> &password);
> -            if (!ret) {
> +            response = virt_viewer_auth_collect_credentials(self-
> >priv->main_window,
> +                                                            "proxy"
> , spice_uri_get_hostname(proxy),
> +                                                            &user,
> &password);
> +            if (response != GTK_RESPONSE_OK) {
>                  g_signal_emit_by_name(session, "session-
> cancelled");
>              } else {
>                  spice_uri_set_user(proxy, user);
> diff --git a/src/virt-viewer-session-vnc.c b/src/virt-viewer-
> session-vnc.c
> index 26fb405..5287460 100644
> --- a/src/virt-viewer-session-vnc.c
> +++ b/src/virt-viewer-session-vnc.c
> @@ -307,12 +307,12 @@
> virt_viewer_session_vnc_auth_credential(GtkWidget *src
> G_GNUC_UNUSED,
>      }
>  
>      if (wantUsername || wantPassword) {
> -        gboolean ret = virt_viewer_auth_collect_credentials(self-
> >priv->main_window,
> -                                                            "VNC",
> NULL,
> -                                                            wantUse
> rname ? &username : NULL,
> -                                                            wantPas
> sword ? &password : NULL);
> +        gint response = virt_viewer_auth_collect_credentials(self-
> >priv->main_window,
> +                                                             "VNC",
> NULL,
> +                                                             wantUs
> ername ? &username : NULL,
> +                                                             wantPa
> ssword ? &password : NULL);
>  
> -        if (!ret) {
> +        if (response != GTK_RESPONSE_OK) {
>              vnc_display_close(self->priv->vnc);
>              g_signal_emit_by_name(self, "session-cancelled");
>              goto cleanup;
> diff --git a/src/virt-viewer.c b/src/virt-viewer.c
> index 5c321db..eef1103 100644
> --- a/src/virt-viewer.c
> +++ b/src/virt-viewer.c
> @@ -988,14 +988,16 @@
> virt_viewer_auth_libvirt_credentials(virConnectCredentialPtr cred,
>      if (username || password) {
>          VirtViewerWindow *vwin =
> virt_viewer_app_get_main_window(VIRT_VIEWER_APP(app));
>          GtkWindow *win = virt_viewer_window_get_window(vwin);
> +        gint response;
>  
>          if (username && (*username == NULL || **username == '\0'))
>              *username = g_strdup(g_get_user_name());
>  
> -        priv->auth_cancelled =
> !virt_viewer_auth_collect_credentials(win,
> -                                                                   
>   "libvirt",
> -                                                                   
>   app->priv->uri,
> -                                                                   
>   username, password);
> +        response = virt_viewer_auth_collect_credentials(win,
> +                                                        "libvirt",
> +                                                        app->priv-
> >uri,
> +                                                        username,
> password);
> +        priv->auth_cancelled = (response != GTK_RESPONSE_OK);
>          if (priv->auth_cancelled) {
>              ret = -1;
>              goto cleanup;




More information about the virt-tools-list mailing list