[Spice-commits] 5 commits - gtk/spice-channel-priv.h gtk/spice-channel.c gtk/spice-client.h gtk/spice-session-priv.h gtk/spice-session.c m4/manywarnings.m4 po/POTFILES.in

Christophe Fergau teuf at kemper.freedesktop.org
Fri Oct 10 03:40:21 PDT 2014


 gtk/spice-channel-priv.h |    1 
 gtk/spice-channel.c      |   47 +++++++++-
 gtk/spice-client.h       |    6 +
 gtk/spice-session-priv.h |    2 
 gtk/spice-session.c      |   56 +++++++++++-
 m4/manywarnings.m4       |  213 ++++++++++++++++++++++++++++++-----------------
 po/POTFILES.in           |    1 
 7 files changed, 241 insertions(+), 85 deletions(-)

New commits:
commit af733ed71f118e11c39d0aeb5c0ed12f015b9ad8
Author: Cole Robinson <crobinso at redhat.com>
Date:   Thu Oct 2 18:17:53 2014 +0200

    m4: Update manywarnings from gnulib
    
    Fixes these noisy errors on Fedora 21:
    
    gcc: warning: switch '-Wmudflap' is no longer supported

diff --git a/m4/manywarnings.m4 b/m4/manywarnings.m4
index fd0e372..3e6dd21 100644
--- a/m4/manywarnings.m4
+++ b/m4/manywarnings.m4
@@ -1,5 +1,5 @@
-# manywarnings.m4 serial 3
-dnl Copyright (C) 2008-2012 Free Software Foundation, Inc.
+# manywarnings.m4 serial 7
+dnl Copyright (C) 2008-2014 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
 dnl with or without modifications, as long as this notice is preserved.
@@ -35,14 +35,12 @@ AC_DEFUN([gl_MANYWARN_COMPLEMENT],
 # make sure your gcc understands it.
 AC_DEFUN([gl_MANYWARN_ALL_GCC],
 [
-  dnl First, check if -Wno-missing-field-initializers is needed.
-  dnl -Wmissing-field-initializers is implied by -W, but that issues
-  dnl warnings with GCC version before 4.7, for the common idiom
-  dnl of initializing types on the stack to zero, using { 0, }
+  dnl First, check for some issues that only occur when combining multiple
+  dnl gcc warning categories.
   AC_REQUIRE([AC_PROG_CC])
   if test -n "$GCC"; then
 
-    dnl First, check -W -Werror -Wno-missing-field-initializers is supported
+    dnl Check if -W -Werror -Wno-missing-field-initializers is supported
     dnl with the current $CC $CFLAGS $CPPFLAGS.
     AC_MSG_CHECKING([whether -Wno-missing-field-initializers is supported])
     AC_CACHE_VAL([gl_cv_cc_nomfi_supported], [
@@ -77,108 +75,171 @@ AC_DEFUN([gl_MANYWARN_ALL_GCC],
       ])
       AC_MSG_RESULT([$gl_cv_cc_nomfi_needed])
     fi
+
+    dnl Next, check if -Werror -Wuninitialized is useful with the
+    dnl user's choice of $CFLAGS; some versions of gcc warn that it
+    dnl has no effect if -O is not also used
+    AC_MSG_CHECKING([whether -Wuninitialized is supported])
+    AC_CACHE_VAL([gl_cv_cc_uninitialized_supported], [
+      gl_save_CFLAGS="$CFLAGS"
+      CFLAGS="$CFLAGS -Werror -Wuninitialized"
+      AC_COMPILE_IFELSE(
+        [AC_LANG_PROGRAM([[]], [[]])],
+        [gl_cv_cc_uninitialized_supported=yes],
+        [gl_cv_cc_uninitialized_supported=no])
+      CFLAGS="$gl_save_CFLAGS"])
+    AC_MSG_RESULT([$gl_cv_cc_uninitialized_supported])
+
   fi
 
+  # List all gcc warning categories.
+  # To compare this list to your installed GCC's, run this Bash command:
+  #
+  # comm -3 \
+  #  <(sed -n 's/^  *\(-[^ ]*\) .*/\1/p' manywarnings.m4 | sort) \
+  #  <(gcc --help=warnings | sed -n 's/^  \(-[^ ]*\) .*/\1/p' | sort |
+  #      grep -v -x -f <(
+  #         awk '/^[^#]/ {print $1}' ../build-aux/gcc-warning.spec))
+
   gl_manywarn_set=
   for gl_manywarn_item in \
-    -Wall \
     -W \
-    -Wformat-y2k \
-    -Wformat-nonliteral \
-    -Wformat-security \
-    -Winit-self \
-    -Wmissing-include-dirs \
-    -Wswitch-default \
-    -Wswitch-enum \
-    -Wunused \
-    -Wunknown-pragmas \
-    -Wstrict-aliasing \
-    -Wstrict-overflow \
-    -Wsystem-headers \
-    -Wfloat-equal \
-    -Wtraditional \
-    -Wtraditional-conversion \
-    -Wdeclaration-after-statement \
-    -Wundef \
-    -Wshadow \
-    -Wunsafe-loop-optimizations \
-    -Wpointer-arith \
+    -Wabi \
+    -Waddress \
+    -Waggressive-loop-optimizations \
+    -Wall \
+    -Warray-bounds \
+    -Wattributes \
     -Wbad-function-cast \
-    -Wc++-compat \
-    -Wcast-qual \
-    -Wcast-align \
-    -Wwrite-strings \
-    -Wconversion \
-    -Wsign-conversion \
-    -Wlogical-op \
-    -Waggregate-return \
-    -Wstrict-prototypes \
-    -Wold-style-definition \
-    -Wmissing-prototypes \
-    -Wmissing-declarations \
-    -Wmissing-noreturn \
-    -Wmissing-format-attribute \
-    -Wpacked \
-    -Wpadded \
-    -Wredundant-decls \
-    -Wnested-externs \
-    -Wunreachable-code \
-    -Winline \
-    -Winvalid-pch \
-    -Wlong-long \
-    -Wvla \
-    -Wvolatile-register-var \
-    -Wdisabled-optimization \
-    -Wstack-protector \
-    -Woverlength-strings \
     -Wbuiltin-macro-redefined \
-    -Wmudflap \
-    -Wpacked-bitfield-compat \
-    -Wsync-nand \
-    ; do
-    gl_manywarn_set="$gl_manywarn_set $gl_manywarn_item"
-  done
-  # The following are not documented in the manual but are included in
-  # output from gcc --help=warnings.
-  for gl_manywarn_item in \
-    -Wattributes \
+    -Wcast-align \
+    -Wchar-subscripts \
+    -Wclobbered \
+    -Wcomment \
+    -Wcomments \
     -Wcoverage-mismatch \
-    -Wmultichar \
-    -Wunused-macros \
-    ; do
-    gl_manywarn_set="$gl_manywarn_set $gl_manywarn_item"
-  done
-  # More warnings from gcc 4.6.2 --help=warnings.
-  for gl_manywarn_item in \
-    -Wabi \
     -Wcpp \
+    -Wdate-time \
     -Wdeprecated \
     -Wdeprecated-declarations \
+    -Wdisabled-optimization \
     -Wdiv-by-zero \
     -Wdouble-promotion \
+    -Wempty-body \
     -Wendif-labels \
+    -Wenum-compare \
     -Wextra \
     -Wformat-contains-nul \
     -Wformat-extra-args \
+    -Wformat-nonliteral \
+    -Wformat-security \
+    -Wformat-y2k \
     -Wformat-zero-length \
-    -Wformat=2 \
+    -Wfree-nonheap-object \
+    -Wignored-qualifiers \
+    -Wimplicit \
+    -Wimplicit-function-declaration \
+    -Wimplicit-int \
+    -Winit-self \
+    -Winline \
+    -Wint-to-pointer-cast \
+    -Winvalid-memory-model \
+    -Winvalid-pch \
+    -Wjump-misses-init \
+    -Wlogical-op \
+    -Wmain \
+    -Wmaybe-uninitialized \
+    -Wmissing-braces \
+    -Wmissing-declarations \
+    -Wmissing-field-initializers \
+    -Wmissing-include-dirs \
+    -Wmissing-parameter-type \
+    -Wmissing-prototypes \
     -Wmultichar \
-    -Wnormalized=nfc \
+    -Wnarrowing \
+    -Wnested-externs \
+    -Wnonnull \
+    -Wold-style-declaration \
+    -Wold-style-definition \
+    -Wopenmp-simd \
     -Woverflow \
+    -Woverlength-strings \
+    -Woverride-init \
+    -Wpacked \
+    -Wpacked-bitfield-compat \
+    -Wparentheses \
+    -Wpointer-arith \
+    -Wpointer-sign \
     -Wpointer-to-int-cast \
     -Wpragmas \
+    -Wreturn-local-addr \
+    -Wreturn-type \
+    -Wsequence-point \
+    -Wshadow \
+    -Wsizeof-pointer-memaccess \
+    -Wstack-protector \
+    -Wstrict-aliasing \
+    -Wstrict-overflow \
+    -Wstrict-prototypes \
     -Wsuggest-attribute=const \
+    -Wsuggest-attribute=format \
     -Wsuggest-attribute=noreturn \
     -Wsuggest-attribute=pure \
+    -Wswitch \
+    -Wswitch-default \
+    -Wsync-nand \
+    -Wsystem-headers \
     -Wtrampolines \
+    -Wtrigraphs \
+    -Wtype-limits \
+    -Wuninitialized \
+    -Wunknown-pragmas \
+    -Wunsafe-loop-optimizations \
+    -Wunused \
+    -Wunused-but-set-parameter \
+    -Wunused-but-set-variable \
+    -Wunused-function \
+    -Wunused-label \
+    -Wunused-local-typedefs \
+    -Wunused-macros \
+    -Wunused-parameter \
+    -Wunused-result \
+    -Wunused-value \
+    -Wunused-variable \
+    -Wvarargs \
+    -Wvariadic-macros \
+    -Wvector-operation-performance \
+    -Wvla \
+    -Wvolatile-register-var \
+    -Wwrite-strings \
+    \
     ; do
     gl_manywarn_set="$gl_manywarn_set $gl_manywarn_item"
   done
 
-  # Disable the missing-field-initializers warning if needed
+  # gcc --help=warnings outputs an unusual form for this option; list
+  # it here so that the above 'comm' command doesn't report a false match.
+  gl_manywarn_set="$gl_manywarn_set -Wnormalized=nfc"
+
+  # These are needed for older GCC versions.
+  if test -n "$GCC"; then
+    case `($CC --version) 2>/dev/null` in
+      'gcc (GCC) '[[0-3]].* | \
+      'gcc (GCC) '4.[[0-7]].*)
+        gl_manywarn_set="$gl_manywarn_set -fdiagnostics-show-option"
+        gl_manywarn_set="$gl_manywarn_set -funit-at-a-time"
+          ;;
+    esac
+  fi
+
+  # Disable specific options as needed.
   if test "$gl_cv_cc_nomfi_needed" = yes; then
     gl_manywarn_set="$gl_manywarn_set -Wno-missing-field-initializers"
   fi
 
+  if test "$gl_cv_cc_uninitialized_supported" = no; then
+    gl_manywarn_set="$gl_manywarn_set -Wno-uninitialized"
+  fi
+
   $1=$gl_manywarn_set
 ])
commit fce9201f2f27d90b0224f3dd5845a74e526b5480
Author: Fabiano Fidêncio <fidencio at redhat.com>
Date:   Wed Oct 8 14:15:28 2014 +0200

    Add support to handle username when connecting with SASL
    
    Based on a patch from Dietmar Maurer <dietmar at proxmox.com>
    http://lists.freedesktop.org/archives/spice-devel/2013-October/015138.html

diff --git a/gtk/spice-channel-priv.h b/gtk/spice-channel-priv.h
index 03eed38..6067abc 100644
--- a/gtk/spice-channel-priv.h
+++ b/gtk/spice-channel-priv.h
@@ -136,6 +136,7 @@ struct _SpiceChannelPrivate {
     GSList                      *flushing;
 
     gboolean                    disable_channel_msg;
+    gboolean                    auth_needs_username_and_password;
     GError                      *error;
 };
 
diff --git a/gtk/spice-channel.c b/gtk/spice-channel.c
index 5d1a86e..cd031e4 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>
@@ -107,6 +109,7 @@ static void spice_channel_init(SpiceChannel *channel)
     c->out_serial = 1;
     c->in_serial = 1;
     c->fd = -1;
+    c->auth_needs_username_and_password = FALSE;
     strcpy(c->name, "?");
     c->caps = g_array_new(FALSE, TRUE, sizeof(guint32));
     c->common_caps = g_array_new(FALSE, TRUE, sizeof(guint32));
@@ -1242,6 +1245,7 @@ spice_channel_gather_sasl_credentials(SpiceChannel *channel,
 {
     SpiceChannelPrivate *c;
     int ninteract;
+    gboolean ret = TRUE;
 
     g_return_val_if_fail(channel != NULL, FALSE);
     g_return_val_if_fail(channel->priv != NULL, FALSE);
@@ -1254,12 +1258,22 @@ spice_channel_gather_sasl_credentials(SpiceChannel *channel,
         switch (interact[ninteract].id) {
         case SASL_CB_AUTHNAME:
         case SASL_CB_USER:
-            g_warn_if_reached();
+            c->auth_needs_username_and_password = TRUE;
+            if (spice_session_get_username(c->session) == NULL)
+                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)
-                return FALSE;
+            if (spice_session_get_password(c->session) == NULL) {
+                /* Even if we reach this point, we have to continue looking for
+                 * SASL_CB_AUTHNAME|SASL_CB_USER, otherwise we would return a
+                 * wrong error to the applications */
+                ret = FALSE;
+                continue;
+            }
 
             interact[ninteract].result =  spice_session_get_password(c->session);
             interact[ninteract].len = strlen(interact[ninteract].result);
@@ -1269,7 +1283,7 @@ spice_channel_gather_sasl_credentials(SpiceChannel *channel,
 
     CHANNEL_DEBUG(channel, "Filled SASL interact");
 
-    return TRUE;
+    return ret;
 }
 
 /*
@@ -1308,6 +1322,22 @@ spice_channel_gather_sasl_credentials(SpiceChannel *channel,
 #define SASL_MAX_MECHNAME_LEN 100
 #define SASL_MAX_DATA_LEN (1024 * 1024)
 
+static void spice_channel_set_detailed_authentication_error(SpiceChannel *channel)
+{
+    SpiceChannelPrivate *c = channel->priv;
+
+    if (c->auth_needs_username_and_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"));
+    else
+        g_set_error_literal(&c->error,
+                            SPICE_CLIENT_ERROR,
+                            SPICE_CLIENT_ERROR_AUTH_NEEDS_PASSWORD,
+                            _("Authentication failed: password is required"));
+}
+
 /* Perform the SASL authentication process
  */
 static gboolean spice_channel_perform_auth_sasl(SpiceChannel *channel)
@@ -1323,6 +1353,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 },
     };
@@ -1624,8 +1656,10 @@ restart:
 complete:
     CHANNEL_DEBUG(channel, "%s", "SASL authentication complete");
     spice_channel_read(channel, &len, sizeof(len));
-    if (len != SPICE_LINK_ERR_OK)
+    if (len != SPICE_LINK_ERR_OK) {
+        spice_channel_set_detailed_authentication_error(channel);
         g_coroutine_signal_emit(channel, signals[SPICE_CHANNEL_EVENT], 0, SPICE_CHANNEL_ERROR_AUTH);
+    }
     ret = len == SPICE_LINK_ERR_OK;
     /* This must come *after* check-auth-result, because the former
      * is defined to be sent unencrypted, and setting saslconn turns
@@ -1636,6 +1670,7 @@ complete:
 error:
     if (saslconn)
         sasl_dispose(&saslconn);
+    spice_channel_set_detailed_authentication_error(channel);
     g_coroutine_signal_emit(channel, signals[SPICE_CHANNEL_EVENT], 0, SPICE_CHANNEL_ERROR_AUTH);
     c->has_error = TRUE; /* force disconnect */
     ret = FALSE;
@@ -2552,6 +2587,8 @@ static void channel_reset(SpiceChannel *channel, gboolean migrating)
 
     c->fd = -1;
 
+    c->auth_needs_username_and_password = FALSE;
+
     g_free(c->peer_msg);
     c->peer_msg = NULL;
     c->peer_pos = 0;
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 8809121..3375ab5 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -2,6 +2,7 @@ data/spice-mime.xml.in
 data/spicy.desktop.in.in
 gtk/channel-usbredir.c
 gtk/desktop-integration.c
+gtk/spice-channel.c
 gtk/spice-cmdline.c
 gtk/spice-option.c
 gtk/spicy-screenshot.c
commit 0fe5be04ef762a8ae4057f45e64cfdf6ba426102
Author: Fabiano Fidêncio <fidencio at redhat.com>
Date:   Wed Oct 8 14:15:27 2014 +0200

    Add errors related to the SASL auth
    
    SPICE_CLIENT_ERROR_AUTH_* will be used to set more detailed errors
    with respect to the main channel event SPICE_CHANNEL_ERROR_AUTH.

diff --git a/gtk/spice-client.h b/gtk/spice-client.h
index f1a7fb3..c2474d1 100644
--- a/gtk/spice-client.h
+++ b/gtk/spice-client.h
@@ -58,6 +58,8 @@ G_BEGIN_DECLS
  * @SPICE_CLIENT_ERROR_FAILED: generic error code
  * @SPICE_CLIENT_USB_DEVICE_REJECTED: usb device rejected by host
  * @SPICE_CLIENT_USB_DEVICE_LOST: usb device disconnected (fatal IO error)
+ * @SPICE_CLIENT_ERROR_AUTH_NEEDS_PASSWORD: password is required
+ * @SPICE_CLIENT_ERROR_AUTH_NEEDS_PASSWORD_AND_USERNAME: password and username are required
  *
  * Error codes returned by spice-client API.
  */
@@ -66,6 +68,8 @@ typedef enum
     SPICE_CLIENT_ERROR_FAILED,
     SPICE_CLIENT_USB_DEVICE_REJECTED,
     SPICE_CLIENT_USB_DEVICE_LOST,
+    SPICE_CLIENT_ERROR_AUTH_NEEDS_PASSWORD,
+    SPICE_CLIENT_ERROR_AUTH_NEEDS_PASSWORD_AND_USERNAME,
 } SpiceClientError;
 
 GQuark spice_client_error_quark(void);
commit af3ee8043e2e04a81858e4d4f10df4c26ada9d51
Author: Fabiano Fidêncio <fidencio at redhat.com>
Date:   Wed Oct 8 14:15:26 2014 +0200

    Add missing doc for SPICE_CLIENT_USB* errors

diff --git a/gtk/spice-client.h b/gtk/spice-client.h
index 0e1e49d..f1a7fb3 100644
--- a/gtk/spice-client.h
+++ b/gtk/spice-client.h
@@ -56,6 +56,8 @@ G_BEGIN_DECLS
 /**
  * SpiceClientError:
  * @SPICE_CLIENT_ERROR_FAILED: generic error code
+ * @SPICE_CLIENT_USB_DEVICE_REJECTED: usb device rejected by host
+ * @SPICE_CLIENT_USB_DEVICE_LOST: usb device disconnected (fatal IO error)
  *
  * Error codes returned by spice-client API.
  */
commit 04e2741c687ec9f73f07429202e0d7da9c90cfcf
Author: Dietmar Maurer <dietmar at proxmox.com>
Date:   Wed Oct 8 15:20:11 2014 +0200

    Add "username" property to SpiceSession

diff --git a/gtk/spice-session-priv.h b/gtk/spice-session-priv.h
index 4b2c151..da43866 100644
--- a/gtk/spice-session-priv.h
+++ b/gtk/spice-session-priv.h
@@ -45,6 +45,7 @@ struct _SpiceSessionPrivate {
     char              *host;
     char              *port;
     char              *tls_port;
+    char              *username;
     char              *password;
     char              *ca_file;
     char              *ciphers;
@@ -146,6 +147,7 @@ void spice_session_set_migration_state(SpiceSession *session, SpiceSessionMigrat
 void spice_session_set_port(SpiceSession *session, int port, gboolean tls);
 void spice_session_get_pubkey(SpiceSession *session, guint8 **pubkey, guint *size);
 guint spice_session_get_verify(SpiceSession *session);
+const gchar* spice_session_get_username(SpiceSession *session);
 const gchar* spice_session_get_password(SpiceSession *session);
 const gchar* spice_session_get_host(SpiceSession *session);
 const gchar* spice_session_get_cert_subject(SpiceSession *session);
diff --git a/gtk/spice-session.c b/gtk/spice-session.c
index 49afc97..0663380 100644
--- a/gtk/spice-session.c
+++ b/gtk/spice-session.c
@@ -111,7 +111,8 @@ enum {
     PROP_CA,
     PROP_PROXY,
     PROP_SECURE_CHANNELS,
-    PROP_SHARED_DIR
+    PROP_SHARED_DIR,
+    PROP_USERNAME
 };
 
 /* signals */
@@ -217,6 +218,7 @@ spice_session_finalize(GObject *gobject)
     g_free(s->host);
     g_free(s->port);
     g_free(s->tls_port);
+    g_free(s->username);
     g_free(s->password);
     g_free(s->ca_file);
     g_free(s->ciphers);
@@ -262,11 +264,12 @@ static int spice_uri_create(SpiceSession *session, char *dest, int len)
 static int spice_parse_uri(SpiceSession *session, const char *original_uri)
 {
     SpiceSessionPrivate *s = session->priv;
-    gchar *host = NULL, *port = NULL, *tls_port = NULL, *uri = NULL, *password = NULL;
+    gchar *host = NULL, *port = NULL, *tls_port = NULL, *uri = NULL, *username = NULL, *password = NULL;
     gchar *path = NULL;
     gchar *unescaped_path = NULL;
     gchar *authority = NULL;
     gchar *query = NULL;
+    gchar *tmp = NULL;
 
     g_return_val_if_fail(original_uri != NULL, -1);
 
@@ -281,6 +284,15 @@ static int spice_parse_uri(SpiceSession *session, const char *original_uri)
         goto fail;
     }
     authority = uri + strlen(URI_SCHEME_SPICE);
+
+    tmp = strchr(authority, '@');
+    if (tmp) {
+        tmp[0] = '\0';
+        username = g_uri_unescape_string(authority, NULL);
+        authority = ++tmp;
+        tmp = NULL;
+    }
+
     path = strchr(authority, '/');
     if (path) {
         path[0] = '\0';
@@ -303,7 +315,7 @@ static int spice_parse_uri(SpiceSession *session, const char *original_uri)
     /* Now process the individual parts */
 
     if (authority[0] == '[') {
-        gchar *tmp = strchr(authority, ']');
+        tmp = strchr(authority, ']');
         if (!tmp) {
             g_warning("Missing closing ']' in authority for URI '%s'", uri);
             goto fail;
@@ -314,7 +326,7 @@ static int spice_parse_uri(SpiceSession *session, const char *original_uri)
         if (tmp[0] == ':')
             port = g_strdup(tmp + 1);
     } else {
-        gchar *tmp = strchr(authority, ':');
+        tmp = strchr(authority, ':');
         if (tmp) {
             *tmp = '\0';
             tmp++;
@@ -375,10 +387,12 @@ static int spice_parse_uri(SpiceSession *session, const char *original_uri)
     g_free(s->host);
     g_free(s->port);
     g_free(s->tls_port);
+    g_free(s->username);
     g_free(s->password);
     s->host = host;
     s->port = port;
     s->tls_port = tls_port;
+    s->username = username;
     s->password = password;
     return 0;
 
@@ -388,6 +402,7 @@ fail:
     g_free(host);
     g_free(port);
     g_free(tls_port);
+    g_free(username);
     g_free(password);
     return -1;
 }
@@ -412,6 +427,9 @@ static void spice_session_get_property(GObject    *gobject,
     case PROP_TLS_PORT:
         g_value_set_string(value, s->tls_port);
 	break;
+    case PROP_USERNAME:
+        g_value_set_string(value, s->username);
+	break;
     case PROP_PASSWORD:
         g_value_set_string(value, s->password);
 	break;
@@ -522,6 +540,10 @@ static void spice_session_set_property(GObject      *gobject,
         g_free(s->tls_port);
         s->tls_port = g_value_dup_string(value);
         break;
+    case PROP_USERNAME:
+        g_free(s->username);
+        s->username = g_value_dup_string(value);
+        break;
     case PROP_PASSWORD:
         g_free(s->password);
         s->password = g_value_dup_string(value);
@@ -688,6 +710,21 @@ static void spice_session_class_init(SpiceSessionClass *klass)
                              G_PARAM_STATIC_STRINGS));
 
     /**
+     * SpiceSession:username:
+     *
+     * Username to use
+     *
+     **/
+    g_object_class_install_property
+        (gobject_class, PROP_USERNAME,
+         g_param_spec_string("username",
+                             "Username",
+                             "Username used for SASL connections",
+                             NULL,
+                             G_PARAM_READWRITE |
+                             G_PARAM_STATIC_STRINGS));
+
+    /**
      * SpiceSession:password:
      *
      * TLS password to use
@@ -1214,6 +1251,7 @@ SpiceSession *spice_session_new_from_session(SpiceSession *session)
 
     g_warn_if_fail(c->host == NULL);
     g_warn_if_fail(c->tls_port == NULL);
+    g_warn_if_fail(c->username == NULL);
     g_warn_if_fail(c->password == NULL);
     g_warn_if_fail(c->ca_file == NULL);
     g_warn_if_fail(c->ciphers == NULL);
@@ -1225,6 +1263,7 @@ SpiceSession *spice_session_new_from_session(SpiceSession *session)
     g_object_get(session,
                  "host", &c->host,
                  "tls-port", &c->tls_port,
+                 "username", &c->username,
                  "password", &c->password,
                  "ca-file", &c->ca_file,
                  "ciphers", &c->ciphers,
@@ -2073,6 +2112,15 @@ void spice_session_set_migration_state(SpiceSession *session, SpiceSessionMigrat
 }
 
 G_GNUC_INTERNAL
+const gchar* spice_session_get_username(SpiceSession *session)
+{
+    SpiceSessionPrivate *s = session->priv;
+
+    g_return_val_if_fail(s != NULL, NULL);
+    return s->username;
+}
+
+G_GNUC_INTERNAL
 const gchar* spice_session_get_password(SpiceSession *session)
 {
     SpiceSessionPrivate *s = session->priv;


More information about the Spice-commits mailing list