IRCv3: Set the SASL login name to the current nick if not set during connection

Fri, 10 Mar 2023 01:10:24 -0600

author
Gary Kramlich <grim@reaperworld.com>
date
Fri, 10 Mar 2023 01:10:24 -0600
changeset 42133
e9a794bfe183
parent 42132
358f8573573f
child 42134
1b5ce0f4302d

IRCv3: Set the SASL login name to the current nick if not set during connection

This _should_ help users make sure they authenticate as the correct user. They
are still able to manually specify a SASL Login Name, but if it isn't set when
a connection is attempted, it will be set to the nick defined on the account.

This should also fix the scenario where a user is adding the account to Pidgin
but already has the same account connected because the login name will be the
nick they entered not the one that's chosen if there's a nick collision.

Testing Done:
Connected an IRCv3 account with the `SASL Login Name` unset and verified it was set after connecting. Then set the `SASL Login Name` to something else, attempted connection, verified a SASL failure and verified that the `SASL Login Name` changed persisted.

Reviewed at https://reviews.imfreedom.org/r/2329/

libpurple/protocols/ircv3/purpleircv3connection.c file | annotate | diff | comparison | revisions
--- a/libpurple/protocols/ircv3/purpleircv3connection.c	Thu Mar 09 02:55:35 2023 -0600
+++ b/libpurple/protocols/ircv3/purpleircv3connection.c	Fri Mar 10 01:10:24 2023 -0600
@@ -423,8 +423,9 @@
 	PurpleIRCv3Connection *connection = PURPLE_IRCV3_CONNECTION(obj);
 	PurpleIRCv3ConnectionPrivate *priv = NULL;
 	PurpleAccount *account = NULL;
-	gchar **userparts = NULL;
-	const gchar *username = NULL;
+	char **userparts = NULL;
+	const char *sasl_name = NULL;
+	const char *username = NULL;
 
 	G_OBJECT_CLASS(purple_ircv3_connection_parent_class)->constructed(obj);
 
@@ -437,6 +438,16 @@
 	purple_connection_set_display_name(PURPLE_CONNECTION(connection),
 	                                   userparts[0]);
 	priv->server_name = g_strdup(userparts[1]);
+
+	/* Check if the SASL login name is not set. If it isn't set, set it to the
+	 * current nick.
+	 */
+	sasl_name = purple_account_get_string(account, "sasl-login-name", "");
+	if(purple_strempty(sasl_name)) {
+		purple_account_set_string(account, "sasl-login-name", userparts[0]);
+	}
+
+	/* Free the userparts vector. */
 	g_strfreev(userparts);
 
 	/* Finally create our objects. */

mercurial