daemon: fixed more memory leaks
authorImran Zaman <imran.zaman@linux.intel.com>
Mon, 29 Apr 2013 13:06:25 +0000 (16:06 +0300)
committerImran Zaman <imran.zaman@linux.intel.com>
Mon, 29 Apr 2013 13:06:25 +0000 (16:06 +0300)
src/common/gsignond-identity-info.c
src/daemon/db/Makefile.am
src/daemon/db/gsignond-db-secret-cache.c [deleted file]
src/daemon/db/gsignond-db-secret-cache.h [deleted file]
src/daemon/dbus/gsignond-dbus-auth-service-adapter.c
src/daemon/dbus/gsignond-dbus-auth-session-adapter.c
src/daemon/dbus/gsignond-dbus-identity-adapter.c
src/daemon/gsignond-identity.c
src/daemon/main.c
test/db/dbtest.c

index f92aca2..95ca256 100644 (file)
@@ -795,8 +795,8 @@ gsignond_identity_info_get_mechanisms (
                 g_free (vmechanisms);
                 break;
             }
-            g_free (vmethod);
-            g_free (vmechanisms);
+            g_free (vmethod); vmethod = NULL;
+            g_strfreev (vmechanisms); vmechanisms = NULL;
         }
     }
     return mechanisms;
@@ -818,16 +818,17 @@ gsignond_identity_info_remove_method (
     g_assert (info != NULL);
 
     GHashTable *methods = NULL;
+    gboolean ret = FALSE;
 
     g_return_val_if_fail (method != NULL, FALSE);
 
     methods = gsignond_identity_info_get_methods (info);
     if (methods && g_hash_table_remove (methods, method)) {
-        return gsignond_identity_info_set_methods (info, methods);
+        ret = gsignond_identity_info_set_methods (info, methods);
     }
     if (methods)
         g_hash_table_unref (methods);
-    return FALSE;
+    return ret;
 }
 
 /**
@@ -1059,6 +1060,7 @@ gsignond_identity_info_check_method_mechanism (
     split_mechs = g_strsplit (mechanism, space, 0);
     if (g_strv_length (split_mechs) <= 1 ) {
         g_sequence_free (mechanisms);
+        if (split_mechs) g_strfreev (split_mechs);
         return FALSE;
     }
 
index f583231..80dee4b 100644 (file)
@@ -11,7 +11,6 @@ libgsignond_db_la_LIBADD =    \
         $(GSIGNOND_LIBS)
 
 libgsignond_db_la_SOURCES = \
-   gsignond-db-secret-cache.c \
    gsignond-db-credentials-database.c \
    gsignond-db-metadata-database.c
 
diff --git a/src/daemon/db/gsignond-db-secret-cache.c b/src/daemon/db/gsignond-db-secret-cache.c
deleted file mode 100644 (file)
index 931bab7..0000000
+++ /dev/null
@@ -1,358 +0,0 @@
-/* vi: set et sw=4 ts=4 cino=t0,(0: */
-/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * This file is part of gsignond
- *
- * Copyright (C) 2012 Intel Corporation.
- *
- * Contact: Imran Zaman <imran.zaman@linux.intel.com>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA
- */
-#include "gsignond/gsignond-log.h"
-#include "common/db/gsignond-db-error.h"
-#include "gsignond-db-secret-cache.h"
-
-#define GSIGNOND_DB_SECRET_CACHE_GET_PRIVATE(obj) \
-                                          (G_TYPE_INSTANCE_GET_PRIVATE ((obj),\
-                                           GSIGNOND_DB_TYPE_SECRET_CACHE, \
-                                           GSignondDbSecretCachePrivate))
-
-G_DEFINE_TYPE (GSignondDbSecretCache, gsignond_db_secret_cache,
-        G_TYPE_OBJECT);
-
-typedef struct {
-    GSignondCredentials *creds;
-    gboolean store_password;
-    GHashTable *blob_data;
-} AuthCache;
-
-struct _GSignondDbSecretCachePrivate {
-    GHashTable *cache;
-};
-
-static AuthCache*
-_gsignond_db_auth_cache_new (void)
-{
-    AuthCache *auth_cache = NULL;
-    auth_cache = (AuthCache *)g_malloc0 (sizeof (AuthCache));
-    auth_cache->blob_data = NULL;
-    auth_cache->creds = NULL;
-    return auth_cache;
-}
-
-static void
-_gsignond_db_auth_cache_free (AuthCache *auth_cache)
-{
-    g_return_if_fail (auth_cache != NULL);
-
-    if (auth_cache->creds) {
-        g_object_unref (auth_cache->creds);
-        auth_cache->creds = NULL;
-    }
-    if (auth_cache->blob_data) {
-        g_hash_table_unref (auth_cache->blob_data);
-        auth_cache->blob_data = NULL;
-    }
-    g_free (auth_cache);
-    auth_cache = NULL;
-}
-
-
-static void
-_gsignond_db_secret_cache_dispose (
-        GObject *gobject)
-{
-    g_return_if_fail (GSIGNOND_DB_IS_SECRET_CACHE (gobject));
-    GSignondDbSecretCache *self = GSIGNOND_DB_SECRET_CACHE (gobject);
-
-    /* dispose might be called multiple times, so we must guard against
-      * calling g_object_unref() on an invalid GObject.
-    */
-    if (self->priv->cache) {
-        g_hash_table_unref (self->priv->cache);
-        self->priv->cache = NULL;
-    }
-
-    /* Chain up to the parent class */
-    G_OBJECT_CLASS (gsignond_db_secret_cache_parent_class)->dispose (
-            gobject);
-}
-
-static void
-_gsignond_db_secret_cache_finalize (GObject *gobject)
-{
-    /* Chain up to the parent class */
-    G_OBJECT_CLASS (gsignond_db_secret_cache_parent_class)->finalize (
-            gobject);
-}
-
-static void
-gsignond_db_secret_cache_class_init (GSignondDbSecretCacheClass *klass)
-{
-    GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
-
-    gobject_class->dispose = _gsignond_db_secret_cache_dispose;
-    gobject_class->finalize = _gsignond_db_secret_cache_finalize;
-
-    g_type_class_add_private (klass, sizeof (GSignondDbSecretCachePrivate));
-}
-
-static void
-gsignond_db_secret_cache_init (GSignondDbSecretCache *self)
-{
-    self->priv = GSIGNOND_DB_SECRET_CACHE_GET_PRIVATE (self);
-    self->priv->cache =  g_hash_table_new_full ((GHashFunc)g_int_hash,
-                            (GEqualFunc)g_int_equal,
-                            (GDestroyNotify)g_free,
-                            (GDestroyNotify)_gsignond_db_auth_cache_free);
-}
-
-/**
- * gsignond_db_secret_cache_new:
- *
- * Creates new #GSignondDbSecretCache object
- *
- * Returns : (transfer full) the #GSignondDbSecretCache object
- */
-GSignondDbSecretCache *
-gsignond_db_secret_cache_new ()
-{
-    return GSIGNOND_DB_SECRET_CACHE (
-            g_object_new (GSIGNOND_DB_TYPE_SECRET_CACHE,
-                         NULL));
-}
-
-/**
- * gsignond_db_secret_cache_get_credentials:
- *
- * @self: instance of #GSignondSecretCache
- * @id: the identity whose credentials are being fetched.
- *
- * Gets the credentials from the cache.
- *
- * Returns: (transfer none) #GSignondCredentials if successful,
- * NULL otherwise. When done use g_object_unref (creds) to release the
- * reference.
- */
-GSignondCredentials*
-gsignond_db_secret_cache_get_credentials (
-        GSignondDbSecretCache *self,
-        const guint32 id)
-{
-    AuthCache *value = NULL;
-
-    g_return_val_if_fail (GSIGNOND_DB_IS_SECRET_CACHE (self), NULL);
-
-    value = (AuthCache *) g_hash_table_lookup (self->priv->cache, &id);
-    if (value) {
-        return g_object_ref (value->creds);
-    }
-    return NULL;
-}
-
-/**
- * gsignond_db_secret_cache_update_credentials:
- * @self: instance of #GSignondSecretCache
- * @creds: (transfer full) the credentials to be updated.
- * @store_password: flag to store the password or not.
- *
- * Updates the credentials for the given identity to the cache.
- *
- * Returns: TRUE if successful, FALSE otherwise.
- */
-gboolean
-gsignond_db_secret_cache_update_credentials (
-        GSignondDbSecretCache *self,
-        GSignondCredentials *creds,
-        gboolean store_password)
-{
-    guint32 id = 0;
-    AuthCache *value = NULL;
-
-    g_return_val_if_fail (GSIGNOND_DB_IS_SECRET_CACHE (self), FALSE);
-    g_return_val_if_fail (creds != NULL, FALSE);
-
-    id = gsignond_credentials_get_id(creds);
-    if (id == 0) {
-        INFO ("Not adding credentials to SecretCache as id is 0");
-        return TRUE;
-    }
-
-    value = (AuthCache *) g_hash_table_lookup (self->priv->cache, &id);
-    if (value) {
-        DBG ("Removing existing credentials");
-        if (value->creds) g_object_unref (value->creds);
-        value->creds = g_object_ref (creds);
-    } else {
-        guint32 *cred_id = NULL;
-        value = _gsignond_db_auth_cache_new ();
-        value->creds = g_object_ref (creds);
-        cred_id = g_malloc (sizeof (guint32));
-        *cred_id = id;
-        g_hash_table_insert (self->priv->cache, cred_id, value);
-    }
-    value->store_password = store_password;
-    return TRUE;
-}
-
-/**
- * gsignond_db_secret_cache_get_data:
- *
- * @self: instance of #GSignondSecretCache
- * @id: the identity whose credentials are being fetched.
- * @method: the authentication method the data is used for.
- *
- * Gets the data from the cache.
- *
- * Returns: (transfer none) #GHashTable  (gchar*, GBytes*) dictionary with the
- * data; returns NULL if fails. When done use g_hash_table_unref (data) to
- * release the reference
- */
-GHashTable *
-gsignond_db_secret_cache_get_data (
-        GSignondDbSecretCache *self,
-        const guint32 id,
-        const guint32 method)
-{
-    AuthCache *value = NULL;
-    GHashTable *blob = NULL;
-
-    g_return_val_if_fail (GSIGNOND_DB_IS_SECRET_CACHE (self), NULL);
-
-    value = (AuthCache *) g_hash_table_lookup (self->priv->cache, &id);
-    if (value && value->blob_data) {
-        DBG ("Credentials exist - check method blob");
-        blob = (GHashTable *) g_hash_table_lookup (value->blob_data, &method);
-        if (blob) {
-            return g_hash_table_ref (blob);
-        }
-    }
-    return NULL;
-}
-
-/**
- * gsignond_db_secret_cache_update_data:
- * @self: instance of #GSignondSecretCache
- * @id: the identity whose credentials are being fetched.
- * @method: the authentication method the data is used for.
- * @data: (transfer full) #GHashTable (gchar*, GBytes*) dictionary with the data
- *
- * Updates the data to the cache.
- *
- * Returns: TRUE if successful, FALSE otherwise.
- */
-gboolean
-gsignond_db_secret_cache_update_data (
-        GSignondDbSecretCache *self,
-        const guint32 id,
-        const guint32 method,
-        GHashTable *data)
-{
-    AuthCache *value = NULL;
-    guint32 *methodid = NULL;
-
-    g_return_val_if_fail (GSIGNOND_DB_IS_SECRET_CACHE (self), FALSE);
-    g_return_val_if_fail (data != NULL, FALSE);
-
-    if (id == 0) {
-        INFO ("Not adding data to SecretCache as id is 0");
-        return TRUE;
-    }
-
-    value = (AuthCache *) g_hash_table_lookup (self->priv->cache,
-            &id);
-    methodid = (guint32 *)g_malloc (sizeof (guint32));
-    *methodid = method;
-    if (value && !value->blob_data) {
-        DBG ("Create new as no blob data exists for the identity");
-        value->blob_data = g_hash_table_new_full ((GHashFunc)g_int_hash,
-                                    (GEqualFunc)g_int_equal,
-                                    (GDestroyNotify)g_free,
-                                    (GDestroyNotify)g_hash_table_unref);
-    }
-    if (value == NULL) {
-        DBG ("Create new cache entry as it does not exist already");
-        guint32 *cacheid = NULL;
-        value = _gsignond_db_auth_cache_new ();
-        g_hash_table_insert (value->blob_data, methodid,
-                g_hash_table_ref (data));
-        cacheid = (guint32 *)g_malloc (sizeof (guint32));
-        *cacheid = id;
-        g_hash_table_insert (self->priv->cache, cacheid, value);
-    } else {
-        g_hash_table_replace (value->blob_data, methodid,
-                g_hash_table_ref (data));
-    }
-    return TRUE;
-}
-
-/**
- * gsignond_db_secret_cache_write_to_storage:
- * @self: instance of #GSignondDbSqlDatabase
- *
- * Writes the cache to secret storage.
- *
- * Returns: TRUE if successful, FALSE otherwise.
- */
-gboolean
-gsignond_db_secret_cache_write_to_storage (
-        GSignondDbSecretCache *self,
-        GSignondSecretStorage *storage)
-{
-    GHashTableIter iter, iter1;
-    guint32 id, method;
-    AuthCache *auth_cache = NULL;
-    GHashTable *blob = NULL;
-
-    g_return_val_if_fail (GSIGNOND_DB_IS_SECRET_CACHE (self), FALSE);
-
-    g_hash_table_iter_init (&iter, self->priv->cache);
-    while (g_hash_table_iter_next (&iter,(gpointer *) &id,
-            (gpointer *) &auth_cache)) {
-
-        /* Store the credentials */
-        gsignond_secret_storage_update_credentials(storage,
-                auth_cache->creds);
-
-        /* Store any binary blobs */
-        g_hash_table_iter_init (&iter1, auth_cache->blob_data);
-        while (g_hash_table_iter_next (&iter1,(gpointer *) &method,
-                (gpointer *) &blob)) {
-            gsignond_secret_storage_update_data(storage,
-                    id, method, blob);
-        }
-    }
-    return TRUE;
-}
-
-/**
- * gsignond_db_secret_cache_clear:
- * @self: instance of #GSignondDbSqlDatabase
- *
- * Clears the cache.
- *
- * Returns: TRUE if successful, FALSE otherwise.
- */
-gboolean
-gsignond_db_secret_cache_clear (GSignondDbSecretCache *self)
-{
-    g_return_val_if_fail (GSIGNOND_DB_IS_SECRET_CACHE (self), FALSE);
-    g_hash_table_remove_all (self->priv->cache);
-    return TRUE;
-}
-
-
diff --git a/src/daemon/db/gsignond-db-secret-cache.h b/src/daemon/db/gsignond-db-secret-cache.h
deleted file mode 100644 (file)
index 9f73b65..0000000
+++ /dev/null
@@ -1,112 +0,0 @@
-/* vi: set et sw=4 ts=4 cino=t0,(0: */
-/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * This file is part of gsignond
- *
- * Copyright (C) 2012 Intel Corporation.
- *
- * Contact: Imran Zaman <imran.zaman@linux.intel.com>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA
- */
-
-#ifndef __GSIGNOND_DB_SECRET_CACHE_H__
-#define __GSIGNOND_DB_SECRET_CACHE_H__
-
-#include <glib.h>
-#include <glib-object.h>
-
-#include <gsignond/gsignond-credentials.h>
-#include <gsignond/gsignond-secret-storage.h>
-
-G_BEGIN_DECLS
-
-#define GSIGNOND_DB_TYPE_SECRET_CACHE   \
-                                       (gsignond_db_secret_cache_get_type ())
-#define GSIGNOND_DB_SECRET_CACHE(obj)  (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
-                                           GSIGNOND_DB_TYPE_SECRET_CACHE, \
-                                           GSignondDbSecretCache))
-#define GSIGNOND_DB_IS_SECRET_CACHE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj),\
-                                           GSIGNOND_DB_TYPE_SECRET_CACHE))
-#define GSIGNOND_DB_SECRET_CACHE_CLASS(klass) \
-                                            (G_TYPE_CHECK_CLASS_CAST ((klass), \
-                                             GSIGNOND_DB_TYPE_SECRET_CACHE, \
-                                             GSignondDbSecretCacheClass))
-#define GSIGNOND_DB_IS_SECRET_CACHE_CLASS(klass) \
-                                            (G_TYPE_CHECK_CLASS_TYPE ((klass), \
-                                             GSIGNOND_DB_TYPE_SECRET_CACHE))
-#define GSIGNOND_DB_SECRET_CACHE_GET_CLASS(obj) \
-                                            (G_TYPE_INSTANCE_GET_CLASS ((obj), \
-                                             GSIGNOND_DB_TYPE_SECRET_CACHE, \
-                                             GSignondDbSecretCacheClass))
-
-typedef struct _GSignondDbSecretCachePrivate GSignondDbSecretCachePrivate;
-
-typedef struct
-{
-    GObject parent_instance;
-
-    /*< private >*/
-    GSignondDbSecretCachePrivate *priv;
-} GSignondDbSecretCache;
-
-typedef struct {
-    GObjectClass parent_class;
-
-} GSignondDbSecretCacheClass;
-
-/* used by GSIGNOND_DB_TYPE_SECRET_CACHE */
-GType
-gsignond_db_secret_cache_get_type (void);
-
-GSignondDbSecretCache*
-gsignond_db_secret_cache_new (void);
-
-GSignondCredentials*
-gsignond_db_secret_cache_get_credentials (
-        GSignondDbSecretCache *self,
-        const guint32 id);
-
-gboolean
-gsignond_db_secret_cache_update_credentials (
-        GSignondDbSecretCache *self,
-        GSignondCredentials *creds,
-        gboolean store_password);
-
-GHashTable*
-gsignond_db_secret_cache_get_data (
-        GSignondDbSecretCache *self,
-        const guint32 id,
-        const guint32 method);
-
-gboolean
-gsignond_db_secret_cache_update_data (
-        GSignondDbSecretCache *self,
-        const guint32 id,
-        const guint32 method,
-        GHashTable *data);
-
-gboolean
-gsignond_db_secret_cache_write_to_storage (
-        GSignondDbSecretCache *self,
-        GSignondSecretStorage *storage);
-
-gboolean
-gsignond_db_secret_cache_clear (GSignondDbSecretCache *self);
-
-G_END_DECLS
-
-#endif /* __GSIGNOND_DB_SECRET_CACHE_H__ */
index e635c4a..d2f6cd2 100644 (file)
@@ -309,12 +309,12 @@ _handle_register_new_identity (GSignondDbusAuthServiceAdapter *self,
                                const gchar *app_context,
                                gpointer user_data)
 {
-    GSignondSecurityContext sec_context = {0, 0};
     GSignondIdentity *identity = NULL;
     GError *error = NULL;
     GDBusConnection *connection = NULL;
     const gchar *sender = NULL;
     int fd = -1;
+    GSignondSecurityContext *sec_context = gsignond_security_context_new ();
 
     g_return_val_if_fail (self && GSIGNOND_IS_DBUS_AUTH_SERVICE_ADAPTER(self), FALSE);
 
@@ -327,12 +327,12 @@ _handle_register_new_identity (GSignondDbusAuthServiceAdapter *self,
 
     gsignond_access_control_manager_security_context_of_peer(
             gsignond_daemon_get_access_control_manager (self->priv->auth_service),
-            &sec_context,
+            sec_context,
             fd,
             sender,
             app_context);
 
-    identity = gsignond_daemon_register_new_identity (self->priv->auth_service, &sec_context, &error);
+    identity = gsignond_daemon_register_new_identity (self->priv->auth_service, sec_context, &error);
 
     if (identity) {
         GSignondDbusIdentityAdapter *dbus_identity = _create_and_cache_dbus_identity (self, identity, app_context, connection, sender);
@@ -346,6 +346,7 @@ _handle_register_new_identity (GSignondDbusAuthServiceAdapter *self,
         
         gsignond_disposable_set_keep_in_use (GSIGNOND_DISPOSABLE (self));
     }
+    gsignond_security_context_free (sec_context);
 
     return TRUE;
 }
@@ -357,12 +358,12 @@ _handle_get_identity (GSignondDbusAuthServiceAdapter *self,
                       const gchar *app_context,
                       gpointer user_data)
 {
-    GSignondSecurityContext sec_context = {0, 0};
     GSignondIdentity *identity = NULL;
     GError *error = NULL;
     GDBusConnection *connection = NULL;
     const gchar *sender =  NULL;
     int fd = -1;
+    GSignondSecurityContext *sec_context = gsignond_security_context_new ();
 
     connection = g_dbus_method_invocation_get_connection (invocation);
 #ifdef USE_P2P
@@ -372,12 +373,12 @@ _handle_get_identity (GSignondDbusAuthServiceAdapter *self,
 #endif
     gsignond_access_control_manager_security_context_of_peer(
             gsignond_daemon_get_access_control_manager (self->priv->auth_service),
-            &sec_context,
+            sec_context,
             fd,
             sender,
             app_context);
 
-    identity = gsignond_daemon_get_identity (self->priv->auth_service, id, &sec_context, &error);
+    identity = gsignond_daemon_get_identity (self->priv->auth_service, id, sec_context, &error);
 
     if (identity) {
         GSignondIdentityInfo *info = NULL;
@@ -394,6 +395,7 @@ _handle_get_identity (GSignondDbusAuthServiceAdapter *self,
 
         gsignond_disposable_set_keep_in_use (GSIGNOND_DISPOSABLE (self));
     }
+    gsignond_security_context_free (sec_context);
 
     return TRUE;
 }
index bfa5623..2c8afef 100644 (file)
@@ -46,7 +46,7 @@ struct _GSignondDbusAuthSessionAdapterPrivate
     GSignondAuthSession *session;
     gchar *app_context;
     gboolean is_process_active;
-    GSignondSecurityContext ctx;
+    GSignondSecurityContext *ctx;
 };
 
 G_DEFINE_TYPE (GSignondDbusAuthSessionAdapter, gsignond_dbus_auth_session_adapter, GSIGNOND_TYPE_DISPOSABLE)
@@ -67,7 +67,7 @@ G_DEFINE_TYPE (GSignondDbusAuthSessionAdapter, gsignond_dbus_auth_session_adapte
     }\
     gsignond_access_control_manager_security_context_of_peer( \
             acm, \
-            &priv->ctx, \
+            priv->ctx, \
             fd, \
             sender, \
             priv->app_context); \
@@ -166,6 +166,11 @@ gsignond_dbus_auth_session_adapter_finalize (GObject *object)
 {
     GSignondDbusAuthSessionAdapter *self = GSIGNOND_DBUS_AUTH_SESSION_ADAPTER (object);
 
+    if (self->priv->ctx) {
+        gsignond_security_context_free (self->priv->ctx);
+        self->priv->ctx = NULL;
+    }
+
     if (self->priv->app_context) {
         g_free (self->priv->app_context);
         self->priv->app_context = NULL;
@@ -221,6 +226,7 @@ gsignond_dbus_auth_session_adapter_init (GSignondDbusAuthSessionAdapter *self)
     self->priv->app_context = 0;
     self->priv->is_process_active = FALSE;
     self->priv->dbus_auth_session = gsignond_dbus_auth_session_skeleton_new ();
+    self->priv->ctx = gsignond_security_context_new ();
 
     g_signal_connect_swapped (self->priv->dbus_auth_session,
         "handle-query-available-mechanisms", 
@@ -243,7 +249,7 @@ _handle_query_available_mechanisms (GSignondDbusAuthSessionAdapter *self,
     PREPARE_SECURITY_CONTEXT (self, invocation);
 
     mechanisms = gsignond_auth_session_query_available_mechanisms (
-        self->priv->session, wanted_mechanisms, &self->priv->ctx, &error);
+        self->priv->session, wanted_mechanisms, self->priv->ctx, &error);
 
     if (mechanisms) {
         gsignond_dbus_auth_session_complete_query_available_mechanisms (
@@ -340,7 +346,7 @@ _handle_process (GSignondDbusAuthSessionAdapter *self,
     info = _auth_session_dbus_info_new (self, invocation);
     self->priv->is_process_active = TRUE;
     if (!gsignond_auth_session_process (self->priv->session, data, mechanisms, 
-                &self->priv->ctx, _on_process_done, 
+                self->priv->ctx, _on_process_done,
                 _emit_state_changed, info, &error)) {
         g_dbus_method_invocation_return_gerror (invocation, error);
         g_error_free (error);
@@ -371,7 +377,7 @@ _handle_cancel (GSignondDbusAuthSessionAdapter *self,
     
     PREPARE_SECURITY_CONTEXT (self, invocation);
 
-    if (gsignond_auth_session_cancel (self->priv->session, &self->priv->ctx, &error))
+    if (gsignond_auth_session_cancel (self->priv->session, self->priv->ctx, &error))
         gsignond_dbus_auth_session_complete_cancel (self->priv->dbus_auth_session, invocation);
     else {
         g_dbus_method_invocation_return_gerror (invocation, error);
index fd338cc..d4339f1 100644 (file)
@@ -76,7 +76,7 @@ struct _GSignondDbusIdentityAdapterPrivate
     GSignondDbusIdentity *dbus_identity;
     GSignondIdentity  *identity;
     gchar *app_context;
-    GSignondSecurityContext sec_context;
+    GSignondSecurityContext *sec_context;
     GList *sessions;
     /* signal handler ids */
     guint info_updated_handler_id;
@@ -104,7 +104,7 @@ G_DEFINE_TYPE (GSignondDbusIdentityAdapter, gsignond_dbus_identity_adapter, GSIG
         }\
         gsignond_access_control_manager_security_context_of_peer( \
             acm, \
-            &priv->sec_context, \
+            priv->sec_context, \
             fd, \
             sender, \
             priv->app_context); \
@@ -261,6 +261,11 @@ gsignond_dbus_identity_adapter_finalize (GObject *object)
 {
     GSignondDbusIdentityAdapter *self = GSIGNOND_DBUS_IDENTITY_ADAPTER (object);
 
+    if (self->priv->sec_context) {
+        gsignond_security_context_free (self->priv->sec_context);
+        self->priv->sec_context = NULL;
+    }
+
     if (self->priv->sessions) {
         g_list_free (self->priv->sessions);
         self->priv->sessions = NULL;
@@ -319,6 +324,7 @@ gsignond_dbus_identity_adapter_init (GSignondDbusIdentityAdapter *self)
     self->priv->identity = 0;
     self->priv->app_context = 0;
     self->priv->dbus_identity = gsignond_dbus_identity_skeleton_new();
+    self->priv->sec_context = gsignond_security_context_new ();
 
     g_signal_connect_swapped (self->priv->dbus_identity,
             "handle-request-credentials-update", G_CALLBACK (_handle_request_credentials_update), self);
@@ -378,7 +384,7 @@ _handle_request_credentials_update (GSignondDbusIdentityAdapter *self,
 
     PREPARE_SECURITY_CONTEXT (self, invocation);
     
-    gsignond_identity_request_credentials_update (self->priv->identity, message, &self->priv->sec_context, &error);
+    gsignond_identity_request_credentials_update (self->priv->identity, message, self->priv->sec_context, &error);
     if (error) {
         g_dbus_method_invocation_return_gerror (invocation, error);
         g_error_free (error);
@@ -407,7 +413,7 @@ _handle_get_info (GSignondDbusIdentityAdapter *self,
     PREPARE_SECURITY_CONTEXT (self, invocation);
     
     identity_data = gsignond_identity_get_info (self->priv->identity, 
-        &self->priv->sec_context, &error);
+        self->priv->sec_context, &error);
 
     if (identity_data) {
         gsignond_dbus_identity_complete_get_info (
@@ -450,7 +456,7 @@ _handle_get_auth_session (GSignondDbusIdentityAdapter *self,
 
     PREPARE_SECURITY_CONTEXT (self, invocation);
 
-    session = gsignond_identity_get_auth_session (self->priv->identity, method, &self->priv->sec_context, &error);
+    session = gsignond_identity_get_auth_session (self->priv->identity, method, self->priv->sec_context, &error);
 
     if (session) {
         guint timeout =gsignond_identity_get_auth_session_timeout (self->priv->identity);
@@ -513,7 +519,7 @@ _handle_verify_user (GSignondDbusIdentityAdapter *self,
 
     PREPARE_SECURITY_CONTEXT (self, invocation);
 
-    gsignond_identity_verify_user (self->priv->identity, params, &self->priv->sec_context, &error);
+    gsignond_identity_verify_user (self->priv->identity, params, self->priv->sec_context, &error);
 
     if (error) {
         g_dbus_method_invocation_return_gerror (invocation, error);
@@ -570,7 +576,7 @@ _handle_verify_secret (GSignondDbusIdentityAdapter *self,
 
     PREPARE_SECURITY_CONTEXT (self, invocation);
     
-    gsignond_identity_verify_secret (self->priv->identity, secret, &self->priv->sec_context, &error);
+    gsignond_identity_verify_secret (self->priv->identity, secret, self->priv->sec_context, &error);
 
     if (error) {
         g_dbus_method_invocation_return_gerror (invocation, error);
@@ -600,7 +606,7 @@ _handle_remove (GSignondDbusIdentityAdapter   *self,
 
     PREPARE_SECURITY_CONTEXT (self, invocation);
 
-    if (!gsignond_identity_remove (self->priv->identity, &self->priv->sec_context, &error)) {
+    if (!gsignond_identity_remove (self->priv->identity, self->priv->sec_context, &error)) {
         g_dbus_method_invocation_return_gerror (invocation, error);
         g_error_free (error);
 
@@ -627,7 +633,7 @@ _handle_sign_out (GSignondDbusIdentityAdapter *self,
 
     PREPARE_SECURITY_CONTEXT (self, invocation);
 
-    res = gsignond_identity_sign_out (self->priv->identity, &self->priv->sec_context, &error);
+    res = gsignond_identity_sign_out (self->priv->identity, self->priv->sec_context, &error);
 
     if (!error) {
         gsignond_dbus_identity_complete_sign_out (self->priv->dbus_identity, invocation, res);
@@ -655,7 +661,7 @@ _handle_store (GSignondDbusIdentityAdapter *self,
 
     PREPARE_SECURITY_CONTEXT (self, invocation);
 
-    id = gsignond_identity_store (self->priv->identity, info, &self->priv->sec_context, &error);
+    id = gsignond_identity_store (self->priv->identity, info, self->priv->sec_context, &error);
 
     if (id) {
         gsignond_dbus_identity_complete_store (self->priv->dbus_identity, invocation, id);
@@ -682,7 +688,7 @@ _handle_add_reference (GSignondDbusIdentityAdapter *self,
 
     PREPARE_SECURITY_CONTEXT (self, invocation);
 
-    id = gsignond_identity_add_reference (self->priv->identity, reference, &self->priv->sec_context, &error);
+    id = gsignond_identity_add_reference (self->priv->identity, reference, self->priv->sec_context, &error);
 
     if (id) {
         gsignond_dbus_identity_complete_add_reference (self->priv->dbus_identity, invocation, id);
@@ -710,7 +716,7 @@ _handle_remove_reference (GSignondDbusIdentityAdapter *self,
 
     PREPARE_SECURITY_CONTEXT (self, invocation);
 
-    id = gsignond_identity_remove_reference (self->priv->identity, reference, &self->priv->sec_context, &error);
+    id = gsignond_identity_remove_reference (self->priv->identity, reference, self->priv->sec_context, &error);
 
     if (id) {
         gsignond_dbus_identity_complete_remove_reference (self->priv->dbus_identity, invocation, id);
index 2f8d833..3c77983 100644 (file)
@@ -738,17 +738,19 @@ gsignond_identity_store (GSignondIdentity *identity,
     if (!contexts) {
         contexts = gsignond_identity_info_get_access_control_list (identity->priv->info);
         gsignond_identity_info_set_access_control_list (identity_info, contexts);
-        gsignond_security_context_list_free (contexts);
     }
     else {
         VALIDATE_IDENTITY_WRITE_ACL (identity, ctx, 0);
     }
+    gsignond_security_context_list_free (contexts);
    
     owner = gsignond_identity_info_get_owner (identity_info);
     if (!owner) {
         owner = gsignond_identity_info_get_owner (identity->priv->info);
         gsignond_identity_info_set_owner (identity_info, owner);
     }
+    gsignond_security_context_free (owner);
+
 
     /* update object cache */
     if (identity->priv->info)
index a530966..416aa0a 100644 (file)
@@ -124,8 +124,8 @@ int main (int argc, char **argv)
     main_loop = g_main_loop_new (NULL, FALSE);
 
     _server = gsignond_dbus_server_new ();
+    g_option_context_free (opt_context);
     if (!_server) {
-        g_option_context_free (opt_context);
         return -1;
     }
     g_object_weak_ref (G_OBJECT (_server), _on_server_closed, main_loop);
index 222ae70..14102f2 100644 (file)
@@ -37,7 +37,6 @@
 #include "daemon/gsignond-daemon.h"
 #include "daemon/db/gsignond-db-metadata-database.h"
 #include "daemon/db/gsignond-db-credentials-database.h"
-#include "daemon/db/gsignond-db-secret-cache.h"
 
 static GSequence*
 _sequence_new (gchar *data)
@@ -335,7 +334,9 @@ START_TEST (test_identity_info)
 
     fail_unless (gsignond_identity_info_check_method_mechanism (
             identity, "method1", "mech21", &allowmech) == FALSE);
-
+    if (allowmech) {
+        g_free (allowmech);allowmech = NULL;
+    }
     /*acl*/
     ctx1 = gsignond_security_context_new_from_values ("sysctx1", "appctx1");
     ctx2 = gsignond_security_context_new_from_values ("sysctx2", "appctx2");
@@ -345,6 +346,7 @@ START_TEST (test_identity_info)
     ctx_list = g_list_append (ctx_list,ctx3);
     fail_unless (gsignond_identity_info_set_access_control_list (
             identity, ctx_list) == TRUE);
+
     list = gsignond_identity_info_get_access_control_list (identity);
     fail_if (list == NULL);
     list2 = g_list_nth (list, 0);
@@ -383,66 +385,9 @@ START_TEST (test_identity_info)
     gsignond_identity_info_unref (identity2);
     fail_unless (gsignond_identity_info_compare (identity, identity) == TRUE);
 
-    gsignond_identity_info_unref (identity);
-}
-END_TEST
+    gsignond_security_context_list_free (ctx_list); ctx_list = NULL;
 
-START_TEST (test_secret_cache)
-{
-    GSignondConfig *config = NULL;
-    GSignondSecretStorage *storage =NULL;
-    GHashTable *data = NULL;
-    GHashTable *data2 = NULL;
-    GSignondDbSecretCache *cache = NULL;
-    GSignondCredentials *creds = NULL, *creds2;
-
-    cache = gsignond_db_secret_cache_new();
-    fail_if (cache == NULL);
-
-    creds = gsignond_credentials_new ();
-    gsignond_credentials_set_data (creds, 0, "username2", "password2");
-
-    fail_unless (gsignond_db_secret_cache_get_credentials (cache, 1) == NULL);
-    fail_unless (gsignond_db_secret_cache_get_data (cache, 1, 5) == NULL);
-
-    fail_unless (gsignond_db_secret_cache_update_credentials (
-            cache, creds, TRUE) == TRUE);
-
-    gsignond_credentials_set_id (creds, 1);
-    fail_unless (gsignond_db_secret_cache_update_credentials (
-            cache, creds, TRUE) == TRUE);
-
-    creds2 = gsignond_db_secret_cache_get_credentials (cache, 1);
-    fail_if (creds2 == NULL);
-    fail_unless (gsignond_credentials_equal (creds, creds2) == TRUE);
-    g_object_unref (creds);
-
-    data = g_hash_table_new_full ((GHashFunc)g_str_hash,
-            (GEqualFunc)g_str_equal,
-            (GDestroyNotify)NULL,
-            (GDestroyNotify)g_bytes_unref);
-    g_hash_table_insert (data,"key1",g_bytes_new("value1", strlen ("value1")));
-    g_hash_table_insert (data,"key2",g_bytes_new("value2", strlen ("value2")));
-    g_hash_table_insert (data,"key3",g_bytes_new("value3", strlen ("value3")));
-    g_hash_table_insert (data,"key4",g_bytes_new("value4", strlen ("value4")));
-    g_hash_table_insert (data,"key5",g_bytes_new("value5", strlen ("value5")));
-    fail_unless (gsignond_db_secret_cache_update_data (
-            cache, 1, 5, data) == TRUE);
-    g_hash_table_unref (data);
-
-    data2 = gsignond_db_secret_cache_get_data (cache, 1, 5);
-    fail_if (data2 == NULL);
-    g_hash_table_unref (data2);
-
-    config = gsignond_config_new ();
-    storage = g_object_new (GSIGNOND_TYPE_SECRET_STORAGE,
-            "config", config, NULL);
-    g_object_unref (config);
-    gsignond_secret_storage_open_db (storage);
-    fail_unless (gsignond_db_secret_cache_write_to_storage (
-            cache, storage) == TRUE);
-    g_object_unref (storage);
-    g_object_unref (cache);
+    gsignond_identity_info_unref (identity);
 }
 END_TEST
 
@@ -1097,7 +1042,6 @@ Suite* db_suite (void)
 
     TCase *tc_core = tcase_create ("Tests");
     tcase_add_test (tc_core, test_identity_info);
-    tcase_add_test (tc_core, test_secret_cache);
     tcase_add_test (tc_core, test_secret_database);
     tcase_add_test (tc_core, test_secret_storage);
     tcase_add_test (tc_core, test_metadata_database);