Blob Blame History Raw
From e32502ef5a9f6bae10924426e0e2e88dbac6dca5 Mon Sep 17 00:00:00 2001
From: snir sheriber <ssheribe@redhat.com>
Date: Sun, 26 Feb 2017 12:09:17 +0200
Subject: [PATCH spice-gtk 7/8] authentication: Handle failed SASL
 authentication separately
To: spice-devel@lists.freedesktop.org

Move SASL authentication failures handling to a separate
function.

Multiple error messages asking for username\password were
removed because they are not necessarily the reason for the
failure (avoiding similar issue as in rhbz#1365736).
Letting the user know about required username\password
should be achieved by setting specific Gerror's error code
and enabling\disabling the username\password fields
accordingly by the application.

(cherry picked from commit 2dc8f0bad6558a944405404a266954fd29fd0fa2)
---
 src/spice-channel.c | 44 +++++++++++++++++++++++++++-----------------
 1 file changed, 27 insertions(+), 17 deletions(-)

diff --git a/src/spice-channel.c b/src/spice-channel.c
index 95662f3..020606b 100644
--- a/src/spice-channel.c
+++ b/src/spice-channel.c
@@ -1104,28 +1104,38 @@ static int spice_channel_read(SpiceChannel *channel, void *data, size_t length)
     return length;
 }
 
+#if HAVE_SASL
 /* coroutine context */
-static void spice_channel_failed_authentication(SpiceChannel *channel,
-                                                gboolean invalidPassword)
+static void spice_channel_failed_sasl_authentication(SpiceChannel *channel)
 {
     SpiceChannelPrivate *c = channel->priv;
+    gint err_code; /* The application should activate the authentication window fields accordingly */
 
     if (c->auth_needs_username && c->auth_needs_password)
-        g_set_error_literal(&c->error,
-                            SPICE_CLIENT_ERROR,
-                            SPICE_CLIENT_ERROR_AUTH_NEEDS_PASSWORD_AND_USERNAME,
-                            _("Authentication failed: password and username are required"));
+        err_code = SPICE_CLIENT_ERROR_AUTH_NEEDS_PASSWORD_AND_USERNAME;
     else if (c->auth_needs_username)
-        g_set_error_literal(&c->error,
-                            SPICE_CLIENT_ERROR,
-                            SPICE_CLIENT_ERROR_AUTH_NEEDS_USERNAME,
-                            _("Authentication failed: username is required"));
-    else if (c->auth_needs_password)
-        g_set_error_literal(&c->error,
-                            SPICE_CLIENT_ERROR,
-                            SPICE_CLIENT_ERROR_AUTH_NEEDS_PASSWORD,
-                            _("Authentication failed: password is required"));
-    else if (invalidPassword)
+        err_code = SPICE_CLIENT_ERROR_AUTH_NEEDS_USERNAME;
+    else
+        err_code = SPICE_CLIENT_ERROR_AUTH_NEEDS_PASSWORD;
+
+    g_set_error_literal(&c->error,
+                        SPICE_CLIENT_ERROR,
+                        err_code,
+                        _("Authentication failed"));
+
+    c->event = SPICE_CHANNEL_ERROR_AUTH;
+
+    c->has_error = TRUE; /* force disconnect */
+}
+#endif
+
+/* coroutine context */
+static void spice_channel_failed_authentication(SpiceChannel *channel,
+                                                gboolean invalidPassword)
+{
+    SpiceChannelPrivate *c = channel->priv;
+
+    if (invalidPassword)
         g_set_error_literal(&c->error,
                             SPICE_CLIENT_ERROR,
                             SPICE_CLIENT_ERROR_AUTH_NEEDS_PASSWORD,
@@ -1799,7 +1809,7 @@ error:
     if (saslconn)
         sasl_dispose(&saslconn);
 
-    spice_channel_failed_authentication(channel, FALSE);
+    spice_channel_failed_sasl_authentication(channel);
     ret = FALSE;
 
 cleanup:
-- 
2.12.1