/cpw/tomkiewicz/masterpassword: 2fd6b1439c56: Don't allow sensit...

Tomasz Wasilczyk tomkiewicz at cpw.pidgin.im
Tue Mar 26 10:13:46 EDT 2013


Changeset: 2fd6b1439c566a3601a52f6acb635a639890603d
Author:	 Tomasz Wasilczyk <tomkiewicz at cpw.pidgin.im>
Date:	 2013-03-26 15:13 +0100
Branch:	 soc.2008.masterpassword
URL: https://hg.pidgin.im/cpw/tomkiewicz/masterpassword/rev/2fd6b1439c56

Description:

Don't allow sensitive operations while quitting or migrating passwords

diffstat:

 libpurple/keyring.c |  46 ++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 44 insertions(+), 2 deletions(-)

diffs (84 lines):

diff --git a/libpurple/keyring.c b/libpurple/keyring.c
--- a/libpurple/keyring.c
+++ b/libpurple/keyring.c
@@ -261,6 +261,7 @@ static char *purple_keyring_to_use;
 static guint purple_keyring_pref_cb_id;
 static GList *purple_keyring_loaded_plugins = NULL;
 static PurpleKeyringChangeTracker *current_change_tracker = NULL;
+static gboolean purple_keyring_is_quitting = FALSE;
 
 static void
 purple_keyring_pref_cb(const char *pref,
@@ -311,6 +312,7 @@ static void purple_keyring_core_quitting
 				cancel();
 		}
 	}
+	purple_keyring_is_quitting = TRUE;
 	if (purple_keyring_inuse != NULL) {
 		PurpleKeyringCancelRequests cancel;
 		cancel = purple_keyring_get_cancel_requests(
@@ -966,6 +968,16 @@ purple_keyring_get_password(PurpleAccoun
 	const PurpleKeyring *inuse;
 	PurpleKeyringRead read;
 
+	if (purple_keyring_is_quitting) {
+		purple_debug_error("keyring", "Cannot request a password while quitting.\n");
+		error = g_error_new(PURPLE_KEYRING_ERROR, PURPLE_KEYRING_ERROR_NOCHANNEL,
+			"Cannot request a password while quitting.");
+		if (cb != NULL)
+			cb(account, NULL, error, data);
+		g_error_free(error);
+		return;
+	}
+
 	if (account == NULL) {
 		purple_debug_error("keyring", "No account passed to the function.\n");
 		error = g_error_new(PURPLE_KEYRING_ERROR, PURPLE_KEYRING_ERROR_INVALID,
@@ -1062,7 +1074,27 @@ purple_keyring_set_password(PurpleAccoun
 
 	g_return_if_fail(account != NULL);
 
-	inuse = purple_keyring_get_inuse(); /* TODO: if in change, don't save */
+	if (purple_keyring_is_quitting) {
+		purple_debug_error("keyring", "Cannot save a password while quitting.\n");
+		error = g_error_new(PURPLE_KEYRING_ERROR, PURPLE_KEYRING_ERROR_NOCHANNEL,
+			"Cannot save a password while quitting.");
+		if (cb != NULL)
+			cb(account, error, data);
+		g_error_free(error);
+		return;
+	}
+
+	if (current_change_tracker != NULL) {
+		purple_debug_error("keyring", "Cannot save a password during password migration.\n");
+		error = g_error_new(PURPLE_KEYRING_ERROR, PURPLE_KEYRING_ERROR_NOCHANNEL,
+			"Cannot save a password during password migration.");
+		if (cb != NULL)
+			cb(account, error, data);
+		g_error_free(error);
+		return;
+	}
+
+	inuse = purple_keyring_get_inuse();
 	if (inuse == NULL) {
 		error = g_error_new(PURPLE_KEYRING_ERROR, PURPLE_KEYRING_ERROR_NOKEYRING,
 			"No keyring configured.");
@@ -1123,7 +1155,17 @@ purple_keyring_change_master(PurpleKeyri
 	PurpleKeyringChangeMaster change;
 	const PurpleKeyring *inuse;
 
-	inuse = purple_keyring_get_inuse(); /* TODO: if in change, don't mess */
+	inuse = purple_keyring_get_inuse();
+
+	if (purple_keyring_is_quitting || current_change_tracker != NULL) {
+		purple_debug_error("keyring", "Cannot change a master password at the moment.\n");
+		error = g_error_new(PURPLE_KEYRING_ERROR, PURPLE_KEYRING_ERROR_NOCHANNEL,
+			"Cannot change a master password at the moment.");
+		if (cb != NULL)
+			cb(FALSE, error, data);
+		g_error_free(error);
+		return;
+	}
 
 	if (inuse == NULL) {
 		error = g_error_new(PURPLE_KEYRING_ERROR, PURPLE_KEYRING_ERROR_NOKEYRING,



More information about the Commits mailing list