daemon: auth session changes to support timeout, and identity info.
authorAmarnath Valluri <amarnath.valluri@linux.intel.com>
Thu, 7 Mar 2013 08:39:17 +0000 (10:39 +0200)
committerJussi Laako <jussi.laako@linux.intel.com>
Tue, 19 Mar 2013 14:17:58 +0000 (16:17 +0200)
src/daemon/dbus/gsignond-dbus-auth-session-adapter.c
src/daemon/dbus/gsignond-dbus-identity-adapter.c
src/daemon/gsignond-auth-session.c
src/daemon/gsignond-auth-session.h
src/daemon/gsignond-identity.c

index 282dc5d..fcc714b 100644 (file)
@@ -71,7 +71,7 @@ gsignond_dbus_auth_session_adapter_set_property (GObject *object,
                 if (self->priv->parent) {
                     g_signal_handler_disconnect (self->priv->parent, self->priv->state_changed_handler_id);
                 }
-                self->priv->parent = GSIGNOND_AUTH_SESSION_IFACE (g_object_ref (iface));
+                self->priv->parent = GSIGNOND_AUTH_SESSION_IFACE (iface);
                 self->priv->state_changed_handler_id = 
                        g_signal_connect (self->priv->parent, "state-changed", 
                                          G_CALLBACK (_emit_state_changed), self);
@@ -93,7 +93,7 @@ gsignond_dbus_auth_session_adapter_get_property (GObject *object,
 
     switch (property_id) {
         case PROP_IMPL: {
-            g_value_set_instance (value, self->priv->parent);
+            g_value_set_pointer (value, self->priv->parent);
             break;
         }
         default:
@@ -115,9 +115,6 @@ gsignond_dbus_auth_session_adapter_dispose (GObject *object)
             g_signal_handler_disconnect (self->priv->parent, self->priv->process_error_handler_id);
         if (self->priv->process_result_handler_id)
             g_signal_handler_disconnect (self->priv->parent, self->priv->process_result_handler_id);
-    
-        g_object_unref (self->priv->parent);
-        self->priv->parent = NULL;
     }
 
     if (self->priv->connection) {
@@ -133,12 +130,13 @@ gsignond_dbus_auth_session_adapter_finalize (GObject *object)
 {
     GSignondDbusAuthSessionAdapter *self = GSIGNOND_DBUS_AUTH_SESSION_ADAPTER (object);
 
-    g_dbus_interface_skeleton_unexport (G_DBUS_INTERFACE_SKELETON (object));
-
     if (self->priv->parent) {
         self->priv->parent = NULL;
     }
 
+    DBG("(-)'%s' object unexported", g_dbus_interface_skeleton_get_object_path (G_DBUS_INTERFACE_SKELETON(object)));
+    g_dbus_interface_skeleton_unexport (G_DBUS_INTERFACE_SKELETON (object));
+
     G_OBJECT_CLASS (gsignond_dbus_auth_session_adapter_parent_class)->finalize (object);
 }
 
@@ -191,7 +189,7 @@ gsignond_dbus_auth_session_adapter_init (GSignondDbusAuthSessionAdapter *self)
         g_free (object_path);
         return ;
     }
-
+    DBG("(+) '%s' object exported", object_path);
     g_free (object_path);
 
     g_signal_connect (self, "handle-query-available-mechanisms", G_CALLBACK (_handle_query_available_mechanisms), NULL);
index 67ce875..521de18 100644 (file)
@@ -48,7 +48,6 @@ struct _GSignondDbusIdentityAdapterPrivate
 {
     GDBusConnection       *connection;
     GSignondIdentityIface *identity;
-    gchar *object_path;
     gchar *app_context;
     GSignondSecurityContext sec_context;
     /* signal handler ids */
@@ -183,13 +182,6 @@ gsignond_dbus_identity_adapter_finalize (GObject *object)
 {
     GSignondDbusIdentityAdapter *self = GSIGNOND_DBUS_IDENTITY_ADAPTER (object);
 
-    g_dbus_interface_skeleton_unexport (G_DBUS_INTERFACE_SKELETON (object));
-
-    if (self->priv->object_path) {
-        g_free (self->priv->object_path);
-        self->priv->object_path = NULL;
-    }
-
     if (self->priv->app_context) {
         g_free (self->priv->app_context);
         self->priv->app_context = NULL;
@@ -199,6 +191,9 @@ gsignond_dbus_identity_adapter_finalize (GObject *object)
         self->priv->identity = NULL;
     }
 
+    DBG("(-)'%s' object unexported", g_dbus_interface_skeleton_get_object_path (G_DBUS_INTERFACE_SKELETON(object)));
+    g_dbus_interface_skeleton_unexport (G_DBUS_INTERFACE_SKELETON (object));
+
     G_OBJECT_CLASS (gsignond_dbus_identity_adapter_parent_class)->finalize (object);
 }
 
@@ -259,6 +254,7 @@ gsignond_dbus_identity_adapter_init (GSignondDbusIdentityAdapter *self)
         g_free (object_path);
         return ;
     }
+    DBG("(+)'%s' object exported", object_path);
     g_free (object_path);
 
     g_signal_connect (self, "handle-request-credentials-update", G_CALLBACK (_handle_request_credentials_update), NULL);
index 9de2fff..0d0993d 100644 (file)
@@ -26,6 +26,8 @@
 #include "gsignond-auth-session-iface.h"
 #include "gsignond/gsignond-error.h"
 #include "gsignond/gsignond-log.h"
+#include "gsignond/gsignond-session-data.h"
+#include "gsignond/gsignond-identity-info.h"
 #include "dbus/gsignond-dbus.h"
 #include "dbus/gsignond-dbus-auth-session-adapter.h"
 #include "gsignond-auth-session.h"
@@ -47,6 +49,7 @@ struct _GSignondAuthSessionPrivate
     GSignondDbusAuthSessionAdapter *session_adapter;
     GSignondPluginProxy *proxy;
     GSequence *plugin_mechanisms;
+    GSignondIdentityInfo *identity_info;
 };
 
 static void gsignond_auth_session_iface_init (gpointer g_iface);
@@ -73,7 +76,7 @@ _query_available_mechanisms (GSignondAuthSessionIface *iface,
                              const gchar **wanted_mechanisms,
                              GError **error)
 {
-    if (G_LIKELY ((iface && GSIGNOND_IS_AUTH_SESSION (iface)) == 0)) {
+    if (!iface || !GSIGNOND_IS_AUTH_SESSION (iface)) {
         WARN ("assertion G_LIKELY ((iface && GSIGNOND_IS_AUTH_SESSION (iface)) == 0) failed");
         if (error) *error = gsignond_get_gerror_for_id (GSIGNOND_ERROR_UNKNOWN, "Unknown error");
         return NULL;
@@ -101,7 +104,7 @@ _query_available_mechanisms (GSignondAuthSessionIface *iface,
     iter = mechanisms;
     for (src_iter = wanted_mechanisms; *src_iter != NULL; src_iter++) {
         GSequenceIter *pos = g_sequence_lookup (self->priv->plugin_mechanisms,
-                                                *src_iter,
+                                                (gpointer)*src_iter,
                                                 _sort_cmp,
                                                 NULL);
         if (pos) {
@@ -126,6 +129,16 @@ _process (GSignondAuthSessionIface *iface, GSignondSessionData *session_data,
     }
     GSignondAuthSession *self = GSIGNOND_AUTH_SESSION (iface);
 
+    if (session_data && 
+        !gsignond_session_data_get_username (session_data) 
+        && self->priv->identity_info) {
+        const gchar *username = gsignond_identity_info_get_username (self->priv->identity_info);
+
+        if (username) {
+            gsignond_session_data_set_username (session_data, username);
+        }
+    }
+
     gsignond_plugin_proxy_process(self->priv->proxy, iface, session_data,
                                   mechanism);
 
@@ -212,6 +225,11 @@ _dispose (GObject *object)
         self->priv->proxy = NULL;
     }
 
+    if (self->priv->identity_info) {
+        g_hash_table_unref ((GHashTable *)self->priv->identity_info);
+        self->priv->identity_info = NULL;
+    }
+
     G_OBJECT_CLASS (gsignond_auth_session_parent_class)->dispose (object);
 }
 
@@ -319,7 +337,8 @@ gboolean gsignond_auth_session_set_id(GSignondAuthSession *session, gint id)
 
 /**
  * gsignond_auth_session_new:
- * @owner: instance of #GSignondIdentityIface
+ * @info: instance of #GSignondIdentityInfo
+ * @app_context: application security
  * @method: authentication method
  *
  * Creates instance of #GSignondAuthSession.
@@ -327,9 +346,12 @@ gboolean gsignond_auth_session_set_id(GSignondAuthSession *session, gint id)
  * Returns: (transfer full) newly created object 
  */
 GSignondAuthSession * 
-gsignond_auth_session_new (gint id, const gchar *method)
+gsignond_auth_session_new (GSignondIdentityInfo *info, const gchar *app_context, const gchar *method, gint timeout)
 {
     GSignondPluginProxy* proxy;
+    guint id = 0;
+
+    if (info) id = gsignond_identity_info_get_id (info);
     
     if (id == 0) {
         proxy = gsignond_plugin_proxy_new(gsignond_get_config(), method);
@@ -340,10 +362,11 @@ gsignond_auth_session_new (gint id, const gchar *method)
         if (!proxy) return NULL;
         g_object_ref(proxy);
     }
-    
+
     GSignondAuthSession *auth_session =
-        g_object_new (GSIGNOND_TYPE_AUTH_SESSION, "method", method, NULL);
+        g_object_new (GSIGNOND_TYPE_AUTH_SESSION, "method", method, "timeout", timeout, NULL);
     auth_session->priv->proxy = proxy;
+    auth_session->priv->identity_info = g_hash_table_ref ((GHashTable *)info);
 
     return auth_session;
 }
index 7f95640..ecbbaa8 100644 (file)
@@ -28,7 +28,7 @@
 
 #include <glib-object.h>
 
-#include "gsignond-identity-iface.h"
+#include <gsignond/gsignond-identity-info.h>
 #include "gsignond-disposable.h"
 
 G_BEGIN_DECLS
@@ -77,8 +77,10 @@ gsignond_auth_session_get_object_path (GSignondAuthSession *session);
 gboolean gsignond_auth_session_set_id(GSignondAuthSession *session, gint id);
 
 GSignondAuthSession * 
-gsignond_auth_session_new (gint id,
-                           const gchar *method);
+gsignond_auth_session_new (GSignondIdentityInfo *info,
+                           const gchar *app_context,
+                           const gchar *method,
+                           gint timeout);
 
 G_END_DECLS
 
index 47600ca..db4e0a4 100644 (file)
@@ -36,6 +36,7 @@
 #include "gsignond-auth-session.h"
 #include "plugins/gsignond-plugin-proxy-factory.h"
 #include "gsignond-daemon.h"
+#include "gsignond/gsignond-config-dbus.h"
 
 enum 
 {
@@ -381,8 +382,6 @@ _on_session_close (gpointer data, GObject *session)
 {
     GSignondIdentity *identity = GSIGNOND_IDENTITY (data);
 
-    g_object_weak_unref (session, _on_session_close, data);
-
     identity->priv->auth_sessions = g_list_remove (identity->priv->auth_sessions, session);
     
     if (g_list_length (identity->priv->auth_sessions) == 0) {
@@ -404,6 +403,8 @@ _get_auth_session (GSignondIdentityIface *iface, const gchar *method, const GSig
     const gchar *object_path = NULL;
     GHashTable *supported_methods = NULL;
     gboolean method_available = FALSE;
+    gchar *app_context = NULL;
+    gint timeout = 0;
 
     if (!method) {
         WARN ("assertion (method) failed");
@@ -443,8 +444,13 @@ _get_auth_session (GSignondIdentityIface *iface, const gchar *method, const GSig
 
     VALIDATE_IDENTITY_READ_ACCESS (identity, ctx, NULL);
 
-    session = gsignond_auth_session_new (gsignond_identity_info_get_id(
-        identity->priv->info), method);
+    timeout = gsignond_config_get_integer (gsignond_get_config(), GSIGNOND_CONFIG_DBUS_AUTH_SESSION_TIMEOUT);
+    g_object_get (identity->priv->identity_adapter, "app-context", &app_context, NULL);
+    session = gsignond_auth_session_new (identity->priv->info,
+                                         app_context, 
+                                         method,
+                                         timeout);
+    g_free (app_context);
 
     if (!session) {
         if (error) *error = gsignond_get_gerror_for_id (GSIGNOND_ERROR_UNKNOWN, "Unknown error");