[libgnome-keyring] Clear the client's session when the service disconnects.



commit 48b8a75059b05d6f1b8e7e040e811d8429f514f5
Author: Stef Walter <stef memberwebs com>
Date:   Sun Jan 3 02:09:45 2010 +0000

    Clear the client's session when the service disconnects.

 library/gkr-operation.c |   33 ++++++++++++++++++++++++++++++++-
 library/gkr-session.c   |   13 +++++++++++++
 library/gkr-session.h   |    2 ++
 3 files changed, 47 insertions(+), 1 deletions(-)
---
diff --git a/library/gkr-operation.c b/library/gkr-operation.c
index 4f36763..ebc93d6 100644
--- a/library/gkr-operation.c
+++ b/library/gkr-operation.c
@@ -27,6 +27,7 @@
 
 #include "gkr-misc.h"
 #include "gkr-operation.h"
+#include "gkr-session.h"
 #include "gnome-keyring.h"
 #include "gnome-keyring-private.h"
 
@@ -216,6 +217,33 @@ gkr_operation_complete_later (GkrOperation *op, GnomeKeyringResult res)
 		                 gkr_operation_ref (op), gkr_operation_unref);
 }
 
+static DBusHandlerResult
+on_name_changed_filter (DBusConnection *connection, DBusMessage *message, void *user_data)
+{
+	const char *object_name;
+	const char *new_owner;
+	const char *old_owner;
+
+	/* org.freedesktop.DBus.NameOwnerChanged(STRING name, STRING old_owner, STRING new_owner) */
+	if (dbus_message_is_signal (message, DBUS_INTERFACE_DBUS, "NameOwnerChanged") &&
+	    dbus_message_get_args (message, NULL, DBUS_TYPE_STRING, &object_name,
+	                           DBUS_TYPE_STRING, &old_owner, DBUS_TYPE_STRING, &new_owner,
+	                           DBUS_TYPE_INVALID)) {
+
+		/* See if it's the secret service going away */
+		if (object_name && g_str_equal (SECRETS_SERVICE, object_name) &&
+		    new_owner && g_str_equal ("", new_owner)) {
+
+			/* Clear any session, when the service goes away */
+			gkr_session_clear ();
+		}
+
+		return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+	}
+
+	return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+}
+
 static DBusConnection*
 connect_to_service (void)
 {
@@ -245,18 +273,21 @@ connect_to_service (void)
 		rule = "type='signal',interface='org.gnome.secrets.Prompt',member='Completed'";
 		dbus_bus_add_match (conn, rule, NULL);
 
+		/* Listen for name owner changed signals */
 		rule = "type='signal',member='NameOwnerChanged',interface='org.freedesktop.DBus'";
 		dbus_bus_add_match (conn, rule, NULL);
+		dbus_connection_add_filter (conn, on_name_changed_filter, NULL, NULL);
 
 		G_LOCK (dbus_connection);
 		{
 			if (dbus_connection) {
-				dbus_connection_unref (dbus_connection);
+				dbus_connection_unref (conn);
 			} else {
 				egg_dbus_connect_with_mainloop (conn, NULL);
 				dbus_connection = conn;
 			}
 		}
+		G_UNLOCK (dbus_connection);
 	}
 
 	return dbus_connection_ref (dbus_connection);
diff --git a/library/gkr-session.c b/library/gkr-session.c
index ed1480d..f5b4c81 100644
--- a/library/gkr-session.c
+++ b/library/gkr-session.c
@@ -379,6 +379,19 @@ gkr_session_negotiate (GkrOperation *op)
 	session_negotiate_aes (op);
 }
 
+void
+gkr_session_clear (void)
+{
+	G_LOCK (session_globals);
+	{
+		if (the_session) {
+			gkr_session_unref (the_session);
+			the_session = NULL;
+		}
+	}
+	G_UNLOCK (session_globals);
+}
+
 static gboolean
 session_encode_secret (DBusMessageIter *iter, const gchar *path, gconstpointer parameter,
                        gsize n_parameter, gconstpointer secret, gsize n_secret)
diff --git a/library/gkr-session.h b/library/gkr-session.h
index c6f02b3..e3a0632 100644
--- a/library/gkr-session.h
+++ b/library/gkr-session.h
@@ -28,6 +28,8 @@
 
 void                 gkr_session_negotiate            (GkrOperation *op);
 
+void                 gkr_session_clear                (void);
+
 GkrSession*          gkr_session_ref                  (GkrSession *session);
 
 void                 gkr_session_unref                (gpointer data);



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