Move SASL passphrase generation code to utils

This commit is contained in:
Berke Viktor 2012-10-25 21:08:26 +02:00
parent f50a1bf1dd
commit 215325c058
3 changed files with 25 additions and 17 deletions

View File

@ -28,8 +28,6 @@
#include <unistd.h> #include <unistd.h>
#endif #endif
#include <glib.h>
#include "hexchat.h" #include "hexchat.h"
#include "ctcp.h" #include "ctcp.h"
#include "fe.h" #include "fe.h"
@ -1132,9 +1130,7 @@ process_named_msg (session *sess, char *type, char *word[], char *word_eol[])
else if (len == 3) else if (len == 3)
{ {
guint32 t; guint32 t;
int passlen; char *pass;
char *encoded;
char *buffer;
t = WORDL((guint8)type[0], (guint8)type[1], (guint8)type[2], (guint8)type[3]); t = WORDL((guint8)type[0], (guint8)type[1], (guint8)type[2], (guint8)type[3]);
switch (t) 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); PrintTextf (sess, "Authenticating via SASL as %s\n", sess->server->sasluser);
tcp_send_len (serv, "AUTHENTICATE PLAIN\r\n", 20); tcp_send_len (serv, "AUTHENTICATE PLAIN\r\n", 20);
/* passphrase generation, nicely copy-pasted from the SASL plugin */ pass = encode_sasl_pass (sess->server->sasluser, sess->server->saslpassword);
passlen = strlen (sess->server->sasluser) * 2 + 2 + strlen (sess->server->saslpassword); tcp_sendf (sess->server, "AUTHENTICATE %s\r\n", pass);
buffer = (char*) malloc (passlen + 1); free (pass);
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);
} }
} }
else if (strncasecmp (word[4], "LS", 2) == 0) else if (strncasecmp (word[4], "LS", 2) == 0)

View File

@ -1966,3 +1966,23 @@ get_subdirs (const char *path)
return dirlist; 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;
}

View File

@ -61,5 +61,6 @@ void canonalize_key (char *key);
int portable_mode (); int portable_mode ();
int hextray_mode (); int hextray_mode ();
GSList *get_subdirs (const char *path); GSList *get_subdirs (const char *path);
char *encode_sasl_pass (char *user, char *pass);
#endif #endif