Simplify SASL auth string generation code
This commit is contained in:
parent
5701ba287b
commit
f778245a86
@ -1931,19 +1931,15 @@ get_subdirs (const char *path)
|
|||||||
char *
|
char *
|
||||||
encode_sasl_pass (char *user, char *pass)
|
encode_sasl_pass (char *user, char *pass)
|
||||||
{
|
{
|
||||||
int passlen;
|
int authlen;
|
||||||
char *buffer;
|
char *buffer;
|
||||||
char *encoded;
|
char *encoded;
|
||||||
|
|
||||||
/* passphrase generation, nicely copy-pasted from the CAP-SASL plugin */
|
/* we can't call strlen() directly on buffer thanks to the atrocious \0 characters it requires */
|
||||||
passlen = strlen (user) * 2 + 2 + strlen (pass);
|
authlen = strlen (user) * 2 + 2 + strlen (pass);
|
||||||
buffer = (char*) malloc (passlen + 1);
|
buffer = g_strdup_printf ("%s%c%s%c%s", user, '\0', user, '\0', pass);
|
||||||
strcpy (buffer, user);
|
encoded = g_base64_encode ((unsigned char*) buffer, authlen);
|
||||||
strcpy (buffer + strlen (user) + 1, user);
|
g_free (buffer);
|
||||||
strcpy (buffer + strlen (user) * 2 + 2, pass);
|
|
||||||
encoded = g_base64_encode ((unsigned char*) buffer, passlen);
|
|
||||||
|
|
||||||
free (buffer);
|
|
||||||
|
|
||||||
return encoded;
|
return encoded;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user