[Spice-devel] [PATCH 3/3] Add support to handle username when connecting with SASL

Fabiano Fidêncio fidencio at redhat.com
Wed Oct 1 07:36:46 PDT 2014


From: Dietmar Maurer <dietmar at proxmox.com>

---
 gtk/spice-channel.c | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/gtk/spice-channel.c b/gtk/spice-channel.c
index a8b4e35..fe04707 100644
--- a/gtk/spice-channel.c
+++ b/gtk/spice-channel.c
@@ -26,6 +26,8 @@
 #include "spice-marshal.h"
 #include "bio-gio.h"
 
+#include <glib/gi18n.h>
+
 #include <openssl/rsa.h>
 #include <openssl/evp.h>
 #include <openssl/x509.h>
@@ -1265,12 +1267,26 @@ spice_channel_gather_sasl_credentials(SpiceChannel *channel,
         switch (interact[ninteract].id) {
         case SASL_CB_AUTHNAME:
         case SASL_CB_USER:
-            g_warn_if_reached();
+            if (spice_session_get_username(c->session) == NULL) {
+                g_set_error_literal(&c->error,
+                                    SPICE_CHANNEL_ERROR,
+                                    SPICE_CHANNEL_ERROR_AUTH_NEEDS_PASSWORD_AND_USERNAME,
+                                    _("Authentication failed: password and username are required"));
+                return FALSE;
+            }
+
+            interact[ninteract].result =  spice_session_get_username(c->session);
+            interact[ninteract].len = strlen(interact[ninteract].result);
             break;
 
         case SASL_CB_PASS:
-            if (spice_session_get_password(c->session) == NULL)
+            if (spice_session_get_password(c->session) == NULL) {
+                g_set_error_literal(&c->error,
+                                    SPICE_CHANNEL_ERROR,
+                                    SPICE_CHANNEL_ERROR_AUTH_NEEDS_PASSWORD,
+                                    _("Authentication failed: password is required"));
                 return FALSE;
+            }
 
             interact[ninteract].result =  spice_session_get_password(c->session);
             interact[ninteract].len = strlen(interact[ninteract].result);
@@ -1334,6 +1350,8 @@ static gboolean spice_channel_perform_auth_sasl(SpiceChannel *channel)
     const void *val;
     sasl_ssf_t ssf;
     static const sasl_callback_t saslcb[] = {
+        { .id = SASL_CB_USER },
+        { .id = SASL_CB_AUTHNAME },
         { .id = SASL_CB_PASS },
         { .id = 0 },
     };
-- 
1.9.3



More information about the Spice-devel mailing list