/cpw/tomkiewicz/masterpassword: 99bad5c80d1e: More password wipi...

Tomasz Wasilczyk tomkiewicz at cpw.pidgin.im
Thu Mar 28 06:15:16 EDT 2013


Changeset: 99bad5c80d1eb53b18e6aa04831b0bb8e362a5e0
Author:	 Tomasz Wasilczyk <tomkiewicz at cpw.pidgin.im>
Date:	 2013-03-28 11:15 +0100
Branch:	 soc.2008.masterpassword
URL: https://hg.pidgin.im/cpw/tomkiewicz/masterpassword/rev/99bad5c80d1e

Description:

More password wiping, better password management withing account.c, using actual UI name with KWallet

diffstat:

 libpurple/account.c                          |  15 ++++++++++-----
 libpurple/keyring.c                          |   6 ++++--
 libpurple/plugins/keyrings/internalkeyring.c |   4 ++--
 libpurple/plugins/keyrings/kwallet.cpp       |  22 ++++++++++++++++++++++
 libpurple/prpl.c                             |  11 +++--------
 5 files changed, 41 insertions(+), 17 deletions(-)

diffs (178 lines):

diff --git a/libpurple/account.c b/libpurple/account.c
--- a/libpurple/account.c
+++ b/libpurple/account.c
@@ -976,7 +976,7 @@ parse_account(xmlnode *node)
 		} else {
 			purple_debug_error("account", "Failed to import password.\n");
 		} 
-		g_free(data); 
+		purple_str_wipe(data);
 	}
 
 	return ret;
@@ -1098,7 +1098,7 @@ purple_account_destroy(PurpleAccount *ac
 
 	g_free(account->username);
 	g_free(account->alias);
-	g_free(account->password);
+	purple_str_wipe(account->password);
 	g_free(account->user_info);
 	g_free(account->buddy_icon_path);
 	g_free(account->protocol_id);
@@ -1327,7 +1327,13 @@ purple_account_connect(PurpleAccount *ac
 	purple_debug_info("account", "Connecting to account %s.\n", username);
 
 	prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl);
-	purple_keyring_get_password(account, purple_account_connect_got_password_cb, prpl_info);
+	if (account->password != NULL) {
+		purple_account_connect_got_password_cb(account,
+			account->password, NULL, prpl_info);
+	} else {
+		purple_keyring_get_password(account,
+			purple_account_connect_got_password_cb, prpl_info);
+	}
 }
 
 void
@@ -1710,13 +1716,12 @@ purple_account_set_password(PurpleAccoun
 {
 	g_return_if_fail(account != NULL);
 
-	g_free(account->password);
+	purple_str_wipe(account->password);
 	account->password = g_strdup(password);
 
 	schedule_accounts_save();
 
 	if (!purple_account_get_remember_password(account)) {
-		account->password = g_strdup(password);
 		purple_debug_info("account",
 			"Password for %s set, not sent to keyring.\n",
 			purple_account_get_username(account));
diff --git a/libpurple/keyring.c b/libpurple/keyring.c
--- a/libpurple/keyring.c
+++ b/libpurple/keyring.c
@@ -294,7 +294,7 @@ purple_keyring_pref_cb(const char *pref,
 	purple_keyring_set_inuse(new, FALSE, NULL, data);
 }
 
-static void purple_keyring_core_initialized_cb()
+static void purple_keyring_core_initialized_cb(void)
 {
 	if (purple_keyring_inuse == NULL) {
 		purple_notify_error(NULL, _("Keyrings"),
@@ -422,6 +422,7 @@ purple_keyring_uninit(void)
 	purple_keyring_loaded_plugins = NULL;
 
 	purple_signals_unregister_by_instance(purple_keyring_get_handle());
+	purple_signals_disconnect_by_handle(purple_keyring_get_handle());
 	purple_prefs_disconnect_callback(purple_keyring_pref_cb_id);
 	purple_keyring_pref_cb_id = 0;
 }
@@ -1129,7 +1130,8 @@ purple_keyring_set_password(PurpleAccoun
 		cbinfo = g_new(PurpleKeyringCbInfo, 1);
 		cbinfo->cb = cb;
 		cbinfo->data = data;
-		purple_debug_info("keyring", "Saving password for account %s (%s)...\n",
+		purple_debug_info("keyring", "%s password for account %s (%s)...\n",
+			(password ? "Saving" : "Removing"),
 			purple_account_get_username(account),
 			purple_account_get_protocol_id(account));
 		save(account, password, purple_keyring_set_password_async_cb, cbinfo);
diff --git a/libpurple/plugins/keyrings/internalkeyring.c b/libpurple/plugins/keyrings/internalkeyring.c
--- a/libpurple/plugins/keyrings/internalkeyring.c
+++ b/libpurple/plugins/keyrings/internalkeyring.c
@@ -54,7 +54,7 @@ internal_keyring_open(void)
 	internal_keyring_opened = TRUE;
 
 	internal_keyring_passwords = g_hash_table_new_full(g_direct_hash,
-		g_direct_equal, NULL, g_free);
+		g_direct_equal, NULL, (GDestroyNotify)purple_str_wipe);
 }
 
 static void
@@ -175,7 +175,7 @@ internal_keyring_export_password(PurpleA
 	} else {
 		*mode = "cleartext";
 		*data = g_strdup(password);
-		*destroy = g_free;
+		*destroy = (GDestroyNotify)purple_str_wipe;
 		return TRUE;
 	}
 }
diff --git a/libpurple/plugins/keyrings/kwallet.cpp b/libpurple/plugins/keyrings/kwallet.cpp
--- a/libpurple/plugins/keyrings/kwallet.cpp
+++ b/libpurple/plugins/keyrings/kwallet.cpp
@@ -26,6 +26,7 @@
 
 #include "internal.h"
 #include "account.h"
+#include "core.h"
 #include "debug.h"
 #include "keyring.h"
 #include "plugin.h"
@@ -470,6 +471,21 @@ kwallet_close(GError **error)
 	KWalletPlugin::engine::closeInstance();
 }
 
+static void *
+kwallet_get_handle(void)
+{
+	static int handle;
+
+	return &handle;
+}
+
+static void kwallet_core_initialized_cb(void)
+{
+	const gchar *appName = g_get_application_name();
+	if (qCoreApp && appName)
+		qCoreApp->setApplicationName(appName);
+}
+
 static gboolean
 kwallet_load(PurplePlugin *plugin)
 {
@@ -496,6 +512,10 @@ kwallet_load(PurplePlugin *plugin)
 
 	purple_keyring_register(keyring_handler);
 
+	purple_signal_connect(purple_get_core(), "core-initialized",
+		kwallet_get_handle(),
+		PURPLE_CALLBACK(kwallet_core_initialized_cb), NULL);
+
 	return TRUE;
 }
 
@@ -508,6 +528,8 @@ kwallet_unload(PurplePlugin *plugin)
 		return FALSE;
 	}
 
+	purple_signals_disconnect_by_handle(kwallet_get_handle());
+
 	kwallet_close(NULL);
 
 	purple_keyring_unregister(keyring_handler);
diff --git a/libpurple/prpl.c b/libpurple/prpl.c
--- a/libpurple/prpl.c
+++ b/libpurple/prpl.c
@@ -356,16 +356,11 @@ do_prpl_change_account_status(PurpleAcco
 
 	if (!purple_status_is_online(new_status))
 	{
-		/* Clear out the unsaved password if the disconnect was initiated
-		   by the user */
-		if (!purple_account_get_remember_password(account)) {
-			PurpleConnection *gc = purple_account_get_connection(account);
-			if (gc && purple_connection_had_error(gc))
-				purple_account_set_password(account, NULL, NULL, NULL);
-		}
-
 		if (!purple_account_is_disconnected(account))
 			purple_account_disconnect(account);
+		/* Clear out the unsaved password if we switch to offline status */
+		if (!purple_account_get_remember_password(account))
+			purple_account_set_password(account, NULL, NULL, NULL);
 
 		return;
 	}



More information about the Commits mailing list