X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=imap%2Fauth_sasl.c;h=71b8f49ad66a7376b94f9bd309d1ae9c118d2109;hp=23949eadb7c4e680ec1e7bb65052ce77b3f0bf6a;hb=9afa66139f6099fc06d9866d4283191e43b0e17a;hpb=39d11f5b3feb125654d5c2a4e8f93637a12706c3 diff --git a/imap/auth_sasl.c b/imap/auth_sasl.c index 23949ea..71b8f49 100644 --- a/imap/auth_sasl.c +++ b/imap/auth_sasl.c @@ -14,17 +14,17 @@ #endif #include "mutt.h" +#include "ascii.h" #include "mutt_sasl.h" #include "imap_private.h" #include "auth.h" -#ifdef USE_SASL2 +#include "lib/mem.h" +#include "lib/intl.h" +#include "lib/debug.h" + #include #include -#else -#include -#include -#endif /* imap_auth_sasl: Default authenticator if available. */ imap_auth_res_t imap_auth_sasl (IMAP_DATA * idata, const char *method) @@ -35,17 +35,12 @@ imap_auth_res_t imap_auth_sasl (IMAP_DATA * idata, const char *method) char buf[HUGE_STRING]; const char *mech; -#ifdef USE_SASL2 const char *pc = NULL; -#else - char *pc = NULL; -#endif unsigned int len, olen; unsigned char client_start; if (mutt_sasl_client_new (idata->conn, &saslconn) < 0) { - dprint (1, (debugfile, - "imap_auth_sasl: Error allocating SASL connection.\n")); + debug_print (1, ("Error allocating SASL connection.\n")); return IMAP_AUTH_FAILURE; } @@ -66,25 +61,14 @@ imap_auth_res_t imap_auth_sasl (IMAP_DATA * idata, const char *method) if (mutt_bit_isset (idata->capabilities, AUTH_ANON) && (!idata->conn->account.user[0] || !ascii_strncmp (idata->conn->account.user, "anonymous", 9))) -#ifdef USE_SASL2 rc = sasl_client_start (saslconn, "AUTH=ANONYMOUS", NULL, &pc, &olen, &mech); -#else - rc = - sasl_client_start (saslconn, "AUTH=ANONYMOUS", NULL, NULL, &pc, &olen, - &mech); -#endif } if (rc != SASL_OK && rc != SASL_CONTINUE) do { -#ifdef USE_SASL2 rc = sasl_client_start (saslconn, method, &interaction, &pc, &olen, &mech); -#else - rc = sasl_client_start (saslconn, method, NULL, &interaction, - &pc, &olen, &mech); -#endif if (rc == SASL_INTERACT) mutt_sasl_interact (interaction); } @@ -94,11 +78,9 @@ imap_auth_res_t imap_auth_sasl (IMAP_DATA * idata, const char *method) if (rc != SASL_OK && rc != SASL_CONTINUE) { if (method) - dprint (2, (debugfile, "imap_auth_sasl: %s unavailable\n", method)); + debug_print (2, ("%s unavailable\n", method)); else - dprint (1, - (debugfile, - "imap_auth_sasl: Failure starting authentication exchange. No shared mechanisms?\n")); + debug_print (1, ("Failure starting authentication exchange. No shared mechanisms?\n")); /* SASL doesn't support LOGIN, so fall back */ return IMAP_AUTH_UNAVAIL; @@ -117,7 +99,7 @@ imap_auth_res_t imap_auth_sasl (IMAP_DATA * idata, const char *method) while (irc == IMAP_CMD_CONTINUE); if (method && irc == IMAP_CMD_NO) { - dprint (2, (debugfile, "imap_auth_sasl: %s failed\n", method)); + debug_print (2, ("%s failed\n", method)); sasl_dispose (&saslconn); return IMAP_AUTH_UNAVAIL; } @@ -126,22 +108,19 @@ imap_auth_res_t imap_auth_sasl (IMAP_DATA * idata, const char *method) goto bail; if (irc == IMAP_CMD_RESPOND) { -#ifdef USE_SASL2 if (sasl_decode64 - (idata->cmd.buf + 2, mutt_strlen (idata->cmd.buf + 2), buf, + (idata->cmd.buf + 2, str_len (idata->cmd.buf + 2), buf, LONG_STRING - 1, -#else - if (sasl_decode64 (idata->cmd.buf + 2, mutt_strlen (idata->cmd.buf + 2), buf, -#endif &len) != SASL_OK) { - dprint (1, - (debugfile, - "imap_auth_sasl: error base64-decoding server response.\n")); + debug_print (1, ("error base64-decoding server response.\n")); goto bail; } } - if (!client_start) { + /* client-start is only available with the SASL-IR extension, but + * SASL 2.1 seems to want to use it regardless, at least for DIGEST + * fast reauth. Override if the server sent an initial continuation */ + if (!client_start || buf[0]) { do { rc = sasl_client_step (saslconn, buf, len, &interaction, &pc, &olen); if (rc == SASL_INTERACT) @@ -155,17 +134,13 @@ imap_auth_res_t imap_auth_sasl (IMAP_DATA * idata, const char *method) /* send out response, or line break if none needed */ if (olen) { if (sasl_encode64 (pc, olen, buf, sizeof (buf), &olen) != SASL_OK) { - dprint (1, - (debugfile, - "imap_auth_sasl: error base64-encoding client response.\n")); + debug_print (1, ("error base64-encoding client response.\n")); goto bail; } /* sasl_client_st(art|ep) allocate pc with malloc, expect me to * free it */ -#ifndef USE_SASL2 - FREE (&pc); -#endif + mem_free (&pc); } if (irc == IMAP_CMD_RESPOND) { @@ -176,8 +151,7 @@ imap_auth_res_t imap_auth_sasl (IMAP_DATA * idata, const char *method) /* If SASL has errored out, send an abort string to the server */ if (rc < 0) { mutt_socket_write (idata->conn, "*\r\n"); - dprint (1, - (debugfile, "imap_auth_sasl: sasl_client_step error %d\n", rc)); + debug_print (1, ("sasl_client_step error %d\n", rc)); } olen = 0;