summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorBerke Viktor <bviktor@hexchat.org>2012-10-25 21:08:26 +0200
committerBerke Viktor <bviktor@hexchat.org>2012-10-25 21:08:26 +0200
commit215325c0589927882389c22761af2db8beb985cd (patch)
tree66d43eda651ea6dd3d1685f49aae7a87eedd7377 /src
parentf50a1bf1dd622e81b12b985a5388df386bf2bcfc (diff)
Move SASL passphrase generation code to utils
Diffstat (limited to 'src')
-rw-r--r--src/common/proto-irc.c21
-rw-r--r--src/common/util.c20
-rw-r--r--src/common/util.h1
3 files changed, 25 insertions, 17 deletions
diff --git a/src/common/proto-irc.c b/src/common/proto-irc.c
index 1b20d17c..b8899855 100644
--- a/src/common/proto-irc.c
+++ b/src/common/proto-irc.c
@@ -28,8 +28,6 @@
 #include <unistd.h>
 #endif
 
-#include <glib.h>
-
 #include "hexchat.h"
 #include "ctcp.h"
 #include "fe.h"
@@ -1132,9 +1130,7 @@ process_named_msg (session *sess, char *type, char *word[], char *word_eol[])
 	else if (len == 3)
 	{
 		guint32 t;
-		int passlen;
-		char *encoded;
-		char *buffer;
+		char *pass;
 
 		t = WORDL((guint8)type[0], (guint8)type[1], (guint8)type[2], (guint8)type[3]);
 		switch (t)
@@ -1152,18 +1148,9 @@ process_named_msg (session *sess, char *type, char *word[], char *word_eol[])
 						PrintTextf (sess, "Authenticating via SASL as %s\n", sess->server->sasluser);
 						tcp_send_len (serv, "AUTHENTICATE PLAIN\r\n", 20);
 
-						/* passphrase generation, nicely copy-pasted from the SASL plugin */
-						passlen = strlen (sess->server->sasluser) * 2 + 2 + strlen (sess->server->saslpassword);
-						buffer = (char*) malloc (passlen + 1);
-						strcpy (buffer, sess->server->sasluser);
-						strcpy (buffer + strlen (sess->server->sasluser) + 1, sess->server->sasluser);
-						strcpy (buffer + strlen (sess->server->sasluser) * 2 + 2, sess->server->saslpassword);
-						encoded = g_base64_encode ((unsigned char*) buffer, passlen);
-
-						tcp_sendf (sess->server, "AUTHENTICATE %s\r\n", encoded);
-
-						free (encoded);
-						free (buffer);
+						pass = encode_sasl_pass (sess->server->sasluser, sess->server->saslpassword);
+						tcp_sendf (sess->server, "AUTHENTICATE %s\r\n", pass);
+						free (pass);
 					}
 				}
 				else if (strncasecmp (word[4], "LS", 2) == 0)
diff --git a/src/common/util.c b/src/common/util.c
index 5120c25a..f05a2c9e 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -1966,3 +1966,23 @@ get_subdirs (const char *path)
 
 	return dirlist;
 }
+
+char *
+encode_sasl_pass (char *user, char *pass)
+{
+	int passlen;
+	char *buffer;
+	char *encoded;
+
+	/* passphrase generation, nicely copy-pasted from the CAP-SASL plugin */
+	passlen = strlen (user) * 2 + 2 + strlen (pass);
+	buffer = (char*) malloc (passlen + 1);
+	strcpy (buffer, user);
+	strcpy (buffer + strlen (user) + 1, user);
+	strcpy (buffer + strlen (user) * 2 + 2, pass);
+	encoded = g_base64_encode ((unsigned char*) buffer, passlen);
+
+	free (buffer);
+
+	return encoded;
+}
diff --git a/src/common/util.h b/src/common/util.h
index 484cd617..d2e8e84e 100644
--- a/src/common/util.h
+++ b/src/common/util.h
@@ -61,5 +61,6 @@ void canonalize_key (char *key);
 int portable_mode ();
 int hextray_mode ();
 GSList *get_subdirs (const char *path);
+char *encode_sasl_pass (char *user, char *pass);
 
 #endif