[Spice-devel] [spice-gtk 3/5] Add SpiceSession::auth-file

Christophe Fergeau cfergeau at redhat.com
Tue Jun 4 07:19:12 PDT 2013


This property is parsed from the 'authfile' parameter in SPICE URI, and
points to a file containing credentials to use when establishing the SPICE
connection, see http://libvirt.org/auth.html
---
 gtk/spice-session-priv.h |  2 ++
 gtk/spice-session.c      | 44 +++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 45 insertions(+), 1 deletion(-)

diff --git a/gtk/spice-session-priv.h b/gtk/spice-session-priv.h
index 5ed48dd..218f5c3 100644
--- a/gtk/spice-session-priv.h
+++ b/gtk/spice-session-priv.h
@@ -38,6 +38,7 @@ struct _SpiceSessionPrivate {
     char              *port;
     char              *tls_port;
     char              *password;
+    char              *auth_file;
     char              *ca_file;
     char              *ciphers;
     GByteArray        *pubkey;
@@ -136,6 +137,7 @@ 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_password(SpiceSession *session);
+const gchar* spice_session_get_auth_file(SpiceSession *session);
 const gchar* spice_session_get_host(SpiceSession *session);
 const gchar* spice_session_get_cert_subject(SpiceSession *session);
 const gchar* spice_session_get_ciphers(SpiceSession *session);
diff --git a/gtk/spice-session.c b/gtk/spice-session.c
index 83b91db..9746051 100644
--- a/gtk/spice-session.c
+++ b/gtk/spice-session.c
@@ -108,7 +108,8 @@ enum {
     PROP_NAME,
     PROP_CA,
     PROP_PROXY,
-    PROP_SECURE_CHANNELS
+    PROP_SECURE_CHANNELS,
+    PROP_AUTH_FILE,
 };
 
 /* signals */
@@ -266,6 +267,7 @@ spice_session_finalize(GObject *gobject)
     g_free(s->smartcard_db);
     g_strfreev(s->disable_effects);
     g_strfreev(s->secure_channels);
+    g_free(s->auth_file);
 
     spice_session_palettes_clear(session);
     spice_session_images_clear(session);
@@ -303,6 +305,7 @@ static int spice_uri_parse(SpiceSession *session, const char *original_uri)
 {
     SpiceSessionPrivate *s = SPICE_SESSION_GET_PRIVATE(session);
     gchar *host = NULL, *port = NULL, *tls_port = NULL, *uri = NULL, *password = NULL;
+    gchar *auth_file = NULL;
     gchar *path = NULL;
     gchar *unescaped_path = NULL;
     gchar *authority = NULL;
@@ -384,6 +387,8 @@ static int spice_uri_parse(SpiceSession *session, const char *original_uri)
             target_key = &port;
         } else if (g_str_equal(key, "tls-port")) {
             target_key = &tls_port;
+        } else if (g_str_equal(key, "authfile")) {
+            target_key = &auth_file;
         } else if (g_str_equal(key, "password")) {
             target_key = &password;
             g_warning("password may be visible in process listings");
@@ -412,10 +417,12 @@ static int spice_uri_parse(SpiceSession *session, const char *original_uri)
     g_free(s->port);
     g_free(s->tls_port);
     g_free(s->password);
+    g_free(s->auth_file);
     s->host = host;
     s->port = port;
     s->tls_port = tls_port;
     s->password = password;
+    s->auth_file = auth_file;
     return 0;
 
 fail:
@@ -425,6 +432,7 @@ fail:
     g_free(port);
     g_free(tls_port);
     g_free(password);
+    g_free(auth_file);
     return -1;
 }
 
@@ -527,6 +535,9 @@ static void spice_session_get_property(GObject    *gobject,
     case PROP_PROXY:
         g_value_take_string(value, spice_proxy_to_string(s->proxy));
 	break;
+    case PROP_AUTH_FILE:
+        g_value_set_string(value, s->auth_file);
+        break;
     default:
 	G_OBJECT_WARN_INVALID_PROPERTY_ID(gobject, prop_id, pspec);
 	break;
@@ -649,6 +660,10 @@ static void spice_session_set_property(GObject      *gobject,
     case PROP_PROXY:
         update_proxy(session, g_value_get_string(value));
         break;
+    case PROP_AUTH_FILE:
+        g_free(s->auth_file);
+        s->auth_file = g_value_dup_string(value);
+        break;
     default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID(gobject, prop_id, pspec);
         break;
@@ -1193,6 +1208,22 @@ static void spice_session_class_init(SpiceSessionClass *klass)
                              G_PARAM_READWRITE |
                              G_PARAM_STATIC_STRINGS));
 
+    /**
+     * SpiceSession:auth-file:
+     *
+     * File containing authentication credentials, see
+     * http://libvirt.org/auth.html
+     *
+     **/
+    g_object_class_install_property
+        (gobject_class, PROP_AUTH_FILE,
+         g_param_spec_string("auth-file",
+                             "Auth configuration file",
+                             "",
+                             NULL,
+                             G_PARAM_READWRITE |
+                             G_PARAM_STATIC_STRINGS));
+
     g_type_class_add_private(klass, sizeof(SpiceSessionPrivate));
 }
 
@@ -1231,11 +1262,13 @@ SpiceSession *spice_session_new_from_session(SpiceSession *session)
     g_warn_if_fail(c->pubkey == NULL);
     g_warn_if_fail(c->pubkey == NULL);
     g_warn_if_fail(c->proxy == NULL);
+    g_warn_if_fail(c->auth_file == NULL);
 
     g_object_get(session,
                  "host", &c->host,
                  "tls-port", &c->tls_port,
                  "password", &c->password,
+                 "auth-file", &c->auth_file,
                  "ca-file", &c->ca_file,
                  "ciphers", &c->ciphers,
                  "cert-subject", &c->cert_subject,
@@ -2067,6 +2100,15 @@ const gchar* spice_session_get_password(SpiceSession *session)
 }
 
 G_GNUC_INTERNAL
+const gchar* spice_session_get_auth_file(SpiceSession *session)
+{
+    SpiceSessionPrivate *s = SPICE_SESSION_GET_PRIVATE(session);
+
+    g_return_val_if_fail(s != NULL, NULL);
+    return s->auth_file;
+}
+
+G_GNUC_INTERNAL
 const gchar* spice_session_get_host(SpiceSession *session)
 {
     SpiceSessionPrivate *s = SPICE_SESSION_GET_PRIVATE(session);
-- 
1.8.2.1



More information about the Spice-devel mailing list