diff options
Diffstat (limited to 'imap/auth_sasl.c')
-rw-r--r-- | imap/auth_sasl.c | 38 |
1 files changed, 24 insertions, 14 deletions
diff --git a/imap/auth_sasl.c b/imap/auth_sasl.c index 640e434f..818d37db 100644 --- a/imap/auth_sasl.c +++ b/imap/auth_sasl.c @@ -27,7 +27,7 @@ #include <saslutil.h> /* imap_auth_sasl: Default authenticator if available. */ -imap_auth_res_t imap_auth_sasl (IMAP_DATA* idata) +imap_auth_res_t imap_auth_sasl (IMAP_DATA* idata, const char* method) { sasl_conn_t* saslconn; sasl_interact_t* interaction = NULL; @@ -48,25 +48,32 @@ imap_auth_res_t imap_auth_sasl (IMAP_DATA* idata) return IMAP_AUTH_FAILURE; } - /* hack for SASL ANONYMOUS support: - * 1. Fetch username. If it's "" or "anonymous" then - * 2. attempt sasl_client_start with only "AUTH=ANONYMOUS" capability - * 3. if sasl_client_start fails, fall through... */ rc = SASL_FAIL; - if (mutt_account_getuser (&idata->conn->account)) - return IMAP_AUTH_FAILURE; + /* If the user hasn't specified a method, use any available */ + if (!method) + { + method = idata->capstr; + + /* hack for SASL ANONYMOUS support: + * 1. Fetch username. If it's "" or "anonymous" then + * 2. attempt sasl_client_start with only "AUTH=ANONYMOUS" capability + * 3. if sasl_client_start fails, fall through... */ - if (mutt_bit_isset (idata->capabilities, AUTH_ANON) && - (!idata->conn->account.user[0] || - !mutt_strncmp (idata->conn->account.user, "anonymous", 9))) - rc = sasl_client_start (saslconn, "AUTH=ANONYMOUS", NULL, NULL, &pc, &olen, - &mech); + if (mutt_account_getuser (&idata->conn->account)) + return IMAP_AUTH_FAILURE; + if (mutt_bit_isset (idata->capabilities, AUTH_ANON) && + (!idata->conn->account.user[0] || + !mutt_strncmp (idata->conn->account.user, "anonymous", 9))) + rc = sasl_client_start (saslconn, "AUTH=ANONYMOUS", NULL, NULL, &pc, &olen, + &mech); + } + if (rc != SASL_OK && rc != SASL_CONTINUE) do { - rc = sasl_client_start (saslconn, idata->capstr, NULL, &interaction, + rc = sasl_client_start (saslconn, method, NULL, &interaction, &pc, &olen, &mech); if (rc == SASL_INTERACT) mutt_sasl_interact (interaction); @@ -77,7 +84,10 @@ imap_auth_res_t imap_auth_sasl (IMAP_DATA* idata) if (rc != SASL_OK && rc != SASL_CONTINUE) { - dprint (1, (debugfile, "imap_auth_sasl: Failure starting authentication exchange. No shared mechanisms?\n")); + if (method) + dprint (2, (debugfile, "imap_auth_sasl: %s unavailable\n", method)); + else + dprint (1, (debugfile, "imap_auth_sasl: Failure starting authentication exchange. No shared mechanisms?\n")); /* SASL doesn't support LOGIN, so fall back */ return IMAP_AUTH_UNAVAIL; |