[gnome-keyring/dbus-api] [secret-store] Implement always present 'session' keyring.



commit 70e648061bd8dc2ced9980edae8172b0bf62521a
Author: Stef Walter <stef memberwebs com>
Date:   Sun Dec 13 00:18:22 2009 +0000

    [secret-store] Implement always present 'session' keyring.

 pkcs11/secret-store/gck-secret-collection.c |    4 +++
 pkcs11/secret-store/gck-secret-module.c     |   38 ++++++++++++++++++++++++++-
 2 files changed, 41 insertions(+), 1 deletions(-)
---
diff --git a/pkcs11/secret-store/gck-secret-collection.c b/pkcs11/secret-store/gck-secret-collection.c
index 03d826a..d53df9a 100644
--- a/pkcs11/secret-store/gck-secret-collection.c
+++ b/pkcs11/secret-store/gck-secret-collection.c
@@ -709,6 +709,10 @@ gck_secret_collection_save (GckSecretCollection *self, GckTransaction *transacti
 	if (!self->sdata)
 		return gck_transaction_fail (transaction, CKR_USER_NOT_LOGGED_IN);
 
+	/* Don't save ourselves if no filename */
+	if (!self->filename)
+		return;
+
 	master = gck_secret_data_get_master (self->sdata);
 	if (master == NULL || gck_secret_equals (master, NULL, 0))
 		res = gck_secret_textual_write (self, self->sdata, &data, &n_data);
diff --git a/pkcs11/secret-store/gck-secret-module.c b/pkcs11/secret-store/gck-secret-module.c
index fdf2178..0e20c3c 100644
--- a/pkcs11/secret-store/gck-secret-module.c
+++ b/pkcs11/secret-store/gck-secret-module.c
@@ -27,6 +27,7 @@
 #include "gck-secret-search.h"
 #include "gck-secret-store.h"
 
+#include "gck/gck-credential.h"
 #include "gck/gck-file-tracker.h"
 #include "gck/gck-transaction.h"
 
@@ -41,6 +42,10 @@ struct _GckSecretModule {
 	GckFileTracker *tracker;
 	GHashTable *collections;
 	gchar *directory;
+
+	/* Special 'session' keyring */
+	GckCredential *session_credential;
+	GckSecretCollection *session_collection;
 };
 
 static const CK_SLOT_INFO gck_secret_module_slot_info = {
@@ -364,6 +369,8 @@ static GObject*
 gck_secret_module_constructor (GType type, guint n_props, GObjectConstructParam *props) 
 {
 	GckSecretModule *self = GCK_SECRET_MODULE (G_OBJECT_CLASS (gck_secret_module_parent_class)->constructor(type, n_props, props));
+	GckManager *manager;
+	CK_RV rv;
 
 	g_return_val_if_fail (self, NULL);
 
@@ -378,6 +385,24 @@ gck_secret_module_constructor (GType type, guint n_props, GObjectConstructParam
 	g_signal_connect (self->tracker, "file-changed", G_CALLBACK (on_file_load), self);
 	g_signal_connect (self->tracker, "file-removed", G_CALLBACK (on_file_remove), self);
 
+	manager = gck_module_get_manager (GCK_MODULE (self));
+
+	/* Create the 'session' keyring, which is not stored to disk */
+	self->session_collection = g_object_new (GCK_TYPE_SECRET_COLLECTION,
+	                                         "module", self,
+	                                         "identifier", "session",
+	                                         "manager", manager,
+	                                         NULL);
+	gck_object_expose (GCK_OBJECT (self->session_collection), TRUE);
+
+	/* Unlock the 'session' keyring */
+	rv = gck_credential_create (GCK_MODULE (self), manager, GCK_OBJECT (self->session_collection),
+	                            NULL, 0, &self->session_credential);
+	if (rv == CKR_OK)
+		gck_object_expose (GCK_OBJECT (self->session_credential), TRUE);
+	else
+		g_warning ("couldn't unlock the 'session' keyring");
+
 	return G_OBJECT (self);
 }
 
@@ -394,11 +419,19 @@ static void
 gck_secret_module_dispose (GObject *obj)
 {
 	GckSecretModule *self = GCK_SECRET_MODULE (obj);
-	
+
 	if (self->tracker)
 		g_object_unref (self->tracker);
 	self->tracker = NULL;
 
+	if (self->session_collection)
+		g_object_unref (self->session_collection);
+	self->session_collection = NULL;
+
+	if (self->session_credential)
+		g_object_unref (self->session_credential);
+	self->session_credential = NULL;
+
 	g_hash_table_remove_all (self->collections);
 
 	G_OBJECT_CLASS (gck_secret_module_parent_class)->dispose (obj);
@@ -417,6 +450,9 @@ gck_secret_module_finalize (GObject *obj)
 	g_free (self->directory);
 	self->directory = NULL;
 
+	g_assert (!self->session_credential);
+	g_assert (!self->session_collection);
+
 	G_OBJECT_CLASS (gck_secret_module_parent_class)->finalize (obj);
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]