/cpw/tomkiewicz/masterpassword: 50bc553c8c52: Handle the case of...

Tomasz Wasilczyk tomkiewicz at cpw.pidgin.im
Wed Mar 20 11:37:03 EDT 2013


Changeset: 50bc553c8c52b78ba4e3b2bb528b6b097ec2199f
Author:	 Tomasz Wasilczyk <tomkiewicz at cpw.pidgin.im>
Date:	 2013-03-20 16:36 +0100
Branch:	 soc.2008.masterpassword
URL: https://hg.pidgin.im/cpw/tomkiewicz/masterpassword/rev/50bc553c8c52

Description:

Handle the case of disabled KWallet system

diffstat:

 libpurple/core.c                       |   4 +++-
 libpurple/keyring.c                    |  30 +++++++++++++++++++++++++-----
 libpurple/plugins/keyrings/kwallet.cpp |  12 ++++++++++++
 pidgin/gtkprefs.c                      |  12 ++++++++----
 4 files changed, 48 insertions(+), 10 deletions(-)

diffs (148 lines):

diff --git a/libpurple/core.c b/libpurple/core.c
--- a/libpurple/core.c
+++ b/libpurple/core.c
@@ -148,7 +148,6 @@ purple_core_init(const char *ui)
 
 	purple_plugins_probe(G_MODULE_SUFFIX);
 
-	purple_keyring_load_plugins();
 	purple_theme_manager_init();
 
 	/* The buddy icon code uses the imgstore, so init it early. */
@@ -189,6 +188,9 @@ purple_core_init(const char *ui)
 	if (ops != NULL && ops->ui_init != NULL)
 		ops->ui_init();
 
+	/* Selected keyring may have failed to load, so UI should be notified */
+	purple_keyring_load_plugins();
+
 	/* The UI may have registered some theme types, so refresh them */
 	purple_theme_manager_refresh();
 
diff --git a/libpurple/keyring.c b/libpurple/keyring.c
--- a/libpurple/keyring.c
+++ b/libpurple/keyring.c
@@ -274,6 +274,14 @@ void purple_keyring_load_plugins(void)
 				purple_keyring_loaded_plugins, plugin);
 		}
 	}
+
+	if (purple_keyring_inuse == NULL) {
+		purple_debug_error("keyring", "selected keyring failed to load\n");
+		purple_notify_error(NULL, _("Keyrings"),
+			_("Failed to load selected keyring."),
+			_("Check your system configuration or select another "
+			"one in Preferences dialog."));
+	}
 }
 
 void
@@ -620,10 +628,18 @@ purple_keyring_get_options(void)
 	const GList *keyrings;
 	PurpleKeyring *keyring;
 	GList *list = NULL;
+	static char currentDisabledName[40];
 
-	for (keyrings = purple_keyring_get_keyrings();
-	     keyrings != NULL;
-	     keyrings = keyrings->next) {
+	if (purple_keyring_get_inuse() == NULL && purple_keyring_to_use != NULL
+		&& purple_keyring_to_use[0] != '\0') {
+		g_snprintf(currentDisabledName, sizeof(currentDisabledName),
+			_("%s (disabled)"), purple_keyring_to_use);
+		list = g_list_append(list, currentDisabledName);
+		list = g_list_append(list, purple_keyring_to_use);
+	}
+
+	for (keyrings = purple_keyring_get_keyrings(); keyrings != NULL;
+		keyrings = keyrings->next) {
 
 		keyring = keyrings->data;
 		list = g_list_append(list, keyring->name);
@@ -690,6 +706,9 @@ purple_keyring_unregister(PurpleKeyring 
 	inuse = purple_keyring_get_inuse();
 	fallback = purple_keyring_find_keyring_by_id(PURPLE_DEFAULT_KEYRING);
 
+	/* TODO: is there a possibility for (unneeded) password migration at
+	 * Pidgin's exit?
+	 */
 	if (inuse == keyring) {
 		if (inuse != fallback) {
 			purple_keyring_set_inuse(fallback, TRUE, NULL, NULL);
@@ -973,8 +992,9 @@ purple_keyring_change_master(PurpleKeyri
 	inuse = purple_keyring_get_inuse();
 
 	if (inuse == NULL) {
-		error = g_error_new(PURPLE_KEYRING_ERROR, PURPLE_KEYRING_ERROR_NOCAP,
-			"Keyring doesn't support master passwords.");
+		error = g_error_new(PURPLE_KEYRING_ERROR, PURPLE_KEYRING_ERROR_NOKEYRING,
+			"No keyring configured, cannot change master password.");
+		purple_debug_info("keyring", "No keyring configured, cannot change master password.\n");
 		if (cb)
 			cb(FALSE, error, data);
 		g_error_free(error);
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
@@ -129,6 +129,12 @@ kwallet_plugin_error_domain(void)
 
 }
 
+static gboolean
+kwallet_is_enabled(void)
+{
+	return KWallet::Wallet::isEnabled() ? TRUE : FALSE;
+}
+
 KWalletPlugin::engine *KWalletPlugin::engine::pinstance = NULL;
 
 KWalletPlugin::request::~request()
@@ -431,6 +437,12 @@ kwallet_load(PurplePlugin *plugin)
 		qCoreApp->setApplicationName(KWALLET_APP_NAME);
 	}
 
+	if (!kwallet_is_enabled()) {
+		purple_debug_info("keyring-kwallet",
+			"KWallet service is disabled\n");
+		return FALSE;
+	}
+
 	keyring_handler = purple_keyring_new();
 
 	purple_keyring_set_name(keyring_handler, KWALLET_NAME);
diff --git a/pidgin/gtkprefs.c b/pidgin/gtkprefs.c
--- a/pidgin/gtkprefs.c
+++ b/pidgin/gtkprefs.c
@@ -2532,8 +2532,12 @@ keyring_page_pref_changed(const char *na
 	 */
 
 	keyring = purple_keyring_find_keyring_by_id(val);
-
-	if (purple_keyring_get_change_master(keyring))
+	if (keyring == NULL) {
+		purple_notify_error(NULL, _("Keyring"),
+			_("Selected keyring is disabled"), NULL);
+	}
+
+	if (keyring && purple_keyring_get_change_master(keyring))
 		gtk_widget_set_sensitive(button, TRUE);
 	else
 		gtk_widget_set_sensitive(button, FALSE);
@@ -2561,7 +2565,7 @@ keyring_page(void)
 	/*  Keyring selection */
 	vbox = pidgin_make_frame(ret, _("Keyring"));
 	names = purple_keyring_get_options();
-	pidgin_prefs_dropdown_from_list(vbox, _("Keyring :"), PURPLE_PREF_STRING,
+	pidgin_prefs_dropdown_from_list(vbox, _("Keyring:"), PURPLE_PREF_STRING,
 				 "/purple/keyring/active", names);
 	g_list_free(names);
 
@@ -2571,7 +2575,7 @@ keyring_page(void)
 	g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(change_master_password_cb), NULL);
 	purple_prefs_connect_callback (prefs, "/purple/keyring/active", keyring_page_pref_changed, button);
 
-	if (purple_keyring_get_change_master(keyring))
+	if (keyring && purple_keyring_get_change_master(keyring))
 		gtk_widget_set_sensitive(button, TRUE);
 	else
 		gtk_widget_set_sensitive(button, FALSE);



More information about the Commits mailing list