soc.2008.masterpassword: c679068b: Broke something. Again. Commiting so i g...

scrouaf at soc.pidgin.im scrouaf at soc.pidgin.im
Fri Aug 15 22:25:56 EDT 2008


-----------------------------------------------------------------
Revision: c679068b3d34ff6ccb44f7902636b39dea2336ee
Ancestor: 378b58b6aa7f2f7424cf1e2321866e7c93336884
Author: scrouaf at soc.pidgin.im
Date: 2008-08-16T02:14:04
Branch: im.pidgin.soc.2008.masterpassword
URL: http://d.pidgin.im/viewmtn/revision/info/c679068b3d34ff6ccb44f7902636b39dea2336ee

Modified files:
        libpurple/account.c libpurple/connection.c
        libpurple/keyring.c
        libpurple/plugins/keyrings/gnomekeyring.c
        libpurple/plugins/keyrings/internalkeyring.c
        pidgin/gtkaccount.c

ChangeLog: 

Broke something. Again. Commiting so i get back here if need be.
segfault in malloc() seems to point to a heap overflow...

-------------- next part --------------
============================================================
--- libpurple/account.c	8f8aa52620113831e04edaf8d7da193c78044ec8
+++ libpurple/account.c	f728af63918e67cceb0657cb4dfb63bac4f0e92d
@@ -102,8 +102,10 @@ static void purple_account_unregister_go
 static void purple_account_unregister_got_password_cb(PurpleAccount * account,
 	char * password, GError * error, gpointer data);
 
-static void purple_account_connect_got_password_cb(const PurpleAccount * account,
+static void purple_account_connect_got_password_cb(PurpleAccount * account,
        gchar * password, GError * error, gpointer data);
+static void request_password_ok_cb_continue(const PurpleAccount * account, 
+	GError * error,	gpointer data);
 /*********************************************************************
  * Writing to disk                                                   *
  *********************************************************************/
@@ -1166,11 +1168,27 @@ request_password_ok_cb(PurpleAccount *ac
 
 	if(remember)
 		purple_account_set_remember_password(account, TRUE);
+	else
+		purple_account_set_remember_password(account, FALSE);
 
-	/* XXX this might be a problem if a read occurs before the write is finished */
+#if 0
+	purple_account_set_password_async(account, g_strdup(entry), g_free,
+			request_password_ok_cb_continue, g_strdup(entry));
+#else
 	purple_account_set_password(account, entry);
+	purple_connection_new(account, FALSE, entry);
+#endif
+}
 
-	purple_connection_new(account, FALSE, entry);
+static void
+request_password_ok_cb_continue(const PurpleAccount * account, 
+				GError * error,
+				gpointer data)
+{
+	char * password = data;
+
+	purple_connection_new(account, FALSE, password);
+	g_free(password);
 }
 
 static void
@@ -1255,7 +1273,7 @@ static void
 }
 
 static void
-purple_account_connect_got_password_cb(const PurpleAccount * account,
+purple_account_connect_got_password_cb(PurpleAccount * account,
 				       gchar * password,
 				       GError * error,
 				       gpointer data)
@@ -1286,10 +1304,14 @@ purple_account_disconnect(PurpleAccount 
 
 	gc = purple_account_get_connection(account);
 	purple_connection_destroy(gc);
+
+/* FIXME : if this works, remove the commented code. */
+#if 0
 	if (!purple_account_get_remember_password(account))
 		purple_account_set_password_async(account, NULL, NULL, NULL, NULL);
+	
+#endif
 	purple_account_set_connection(account, NULL);
-
 	account->disconnecting = FALSE;
 }
 
@@ -1721,15 +1743,25 @@ purple_account_set_connection(PurpleAcco
 
 /**
  * FIXME :
- *  This should add/remove the password to/from the keyring
+ *  This should be async
  */
 void
 purple_account_set_remember_password(PurpleAccount *account, gboolean value)
 {
 	g_return_if_fail(account != NULL);
 
-	account->remember_pass = value;
+	if (account->remember_pass != value) {
+		purple_debug_info("accounts",
+			"Setting remember_password for account %s to %s.\n",
+			purple_account_get_username(account),
+			(value)?"TRUE":"FALSE");
 
+		account->remember_pass = value;
+
+		if (value == FALSE)
+			purple_keyring_set_password_sync(account, NULL);
+
+	}
 	schedule_accounts_save();
 }
 
============================================================
--- libpurple/connection.c	a6f921d711d5e480297fb161211ce985e31ac737
+++ libpurple/connection.c	a1835ad0d55af9951fc9aa8b592f46777abf3898
@@ -449,6 +449,7 @@ purple_connection_get_password(const Pur
 		purple_debug_info("connection",
 			"Password was unknown, getting password from account");
 		return purple_account_get_password(gc->account);
+	}
 }
 
 void
@@ -510,12 +511,12 @@ purple_connection_disconnect_cb(gpointer
 purple_connection_disconnect_cb(gpointer data)
 {
 	PurpleAccount *account = data;
-	purple_account_get_password_async(account, 
-		purple_connection_disconnect_got_pw_cb, NULL);
-
+//	purple_account_get_password_async(account, purple_connection_disconnect_got_pw_cb, NULL);
+	purple_account_disconnect(account);
 	return FALSE;
 }
 
+#if 0
 static void
 purple_connection_disconnect_got_pw_cb(PurpleAccount * account,
 				       gchar * password,
@@ -526,6 +527,7 @@ purple_connection_disconnect_got_pw_cb(P
 	purple_account_disconnect(account);
 	purple_account_set_password(account, password);
 }
+#endif
 
 void
 purple_connection_error(PurpleConnection *gc, const char *text)
@@ -542,6 +544,7 @@ purple_connection_error(PurpleConnection
 	purple_connection_error_reason (gc, reason, text);
 }
 
+
 void
 purple_connection_error_reason (PurpleConnection *gc,
                                 PurpleConnectionError reason,
============================================================
--- libpurple/keyring.c	b818e89b24d41e4053eddab75d3c053a325f131d
+++ libpurple/keyring.c	6715ee72ed55de37ee680d83c0406786c60a1eee
@@ -1036,6 +1036,7 @@ purple_keyring_set_password_async_cb(Pur
 		cb(account, error, cbinfo->data);
 	g_free(data);
 }
+
 /**
  * This should be dropped at 3.0 (it's here for compatibility)
  */
============================================================
--- libpurple/plugins/keyrings/gnomekeyring.c	692b04cbd20c9e00ddc89a8625d666b0a12f0b60
+++ libpurple/plugins/keyrings/gnomekeyring.c	86a221688e2f9cd8701d39223940d97031a74d5d
@@ -184,13 +184,14 @@ gkp_save(PurpleAccount * account,
 	 PurpleKeyringSaveCallback cb,
 	 gpointer data)
 {
+	/* FIXME : the name will leak */
 	InfoStorage * storage = g_malloc(sizeof(InfoStorage));
 
 	storage->account = account;
 	storage->cb = cb;
 	storage->user_data = data;
 
-	if(password != NULL) {
+	if(password != NULL || *password != '\O') {
 
 		purple_debug_info("Gnome keyring plugin",
 			"Updating password for account %s (%s).\n",
@@ -327,9 +328,33 @@ gkp_save_sync(PurpleAccount * account,
 gkp_save_sync(PurpleAccount * account,
 	const char * password)
 {
-	char * copy = g_strdup(password);
-	gkp_save(account, copy, NULL, NULL, NULL);
-	g_free(copy);
+	const char * name;
+
+	if(password != NULL || *password != '\O') {
+
+		name =g_strdup_printf("pidgin-%s", purple_account_get_username(account)),
+
+		gnome_keyring_store_password_sync(GNOME_KEYRING_NETWORK_PASSWORD,
+			NULL, name, password, 
+			"user", purple_account_get_username(account),
+			"protocol", purple_account_get_protocol_id(account),
+			NULL);
+		purple_debug_info("GnomeKeyring plugin (sync)", 
+			"Updated password for account %s (%s).\n",
+			purple_account_get_username(account),
+			purple_account_get_protocol_id(account));
+
+	} else {
+		gnome_keyring_delete_password_sync(GNOME_KEYRING_NETWORK_PASSWORD,
+			"user", purple_account_get_username(account),
+			"protocol", purple_account_get_protocol_id(account),
+			NULL);
+		purple_debug_info("GnomeKeyring plugin (sync)", 
+			"Deleted password for account %s (%s).\n",
+			purple_account_get_username(account),
+			purple_account_get_protocol_id(account));
+	
+	}
 }
 
 static void
============================================================
--- libpurple/plugins/keyrings/internalkeyring.c	a60976c9fc96aa38dc229ecfcfa0b97de82cadd3
+++ libpurple/plugins/keyrings/internalkeyring.c	e2de871d9e1a339a0d0fe14ba80b277c5e80bde0
@@ -130,7 +130,7 @@ internal_keyring_save(PurpleAccount * ac
 
 	ACTIVATE();
 
-	if (password == NULL) {
+	if (password == NULL || *password == '\0') {
 		g_hash_table_remove(internal_keyring_passwords, account);
 		purple_debug_info("Internal Keyring",
 			"Deleted password for account %s (%s).\n",
@@ -176,7 +176,7 @@ internal_keyring_save_sync(PurpleAccount
 
 	ACTIVATE();
 
-	if (password == NULL) {
+	if (password == NULL || *password != '\O') {
 		g_hash_table_remove(internal_keyring_passwords, account);
 		purple_debug_info("Internal Keyring (sync)", 
 			"Password for %s (%s) was deleted.\n",
============================================================
--- pidgin/gtkaccount.c	7d0f4a75bcf76de97d89adea0211f186f0e7a245
+++ pidgin/gtkaccount.c	96ae00e327f7edd1349b84e12e948304ce1e36e8
@@ -1331,15 +1331,14 @@ ok_account_prefs_cb(GtkWidget *w, Accoun
 	value = gtk_entry_get_text(GTK_ENTRY(dialog->password_entry));
 
 	/*
-	 * We set the password if this is a new account because new accounts
-	 * will be set to online, and if the user has entered a password into
-	 * the account editor (but has not checked the 'save' box), then we
-	 * don't want to prompt them.
+	 * The function most likely needs to be split in two here.
 	 */
 	if ((purple_account_get_remember_password(account) || new_acct) && (*value != '\0'))
-		purple_account_set_password_async(account, g_strdup(value), g_free, NULL, NULL);
+/* 		purple_account_set_password_async(account, g_strdup(value), g_free, NULL, NULL); */
+		purple_account_set_password(account, value);
 	else
-		purple_account_set_password_async(account, NULL, NULL, NULL,NULL);
+/*		purple_account_set_password_async(account, NULL, NULL, NULL,NULL); */
+		purple_account_set_password(account, NULL);
 
 	purple_account_set_username(account, username);
 	g_free(username);


More information about the Commits mailing list