From 1e39b95682781fd9117eef094f6fd8c58b443610 Mon Sep 17 00:00:00 2001 From: Steve Holme Date: Sun, 27 Oct 2013 12:34:56 +0000 Subject: email: Added support for canceling CRAM-MD5 authentication --- lib/imap.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'lib/imap.c') diff --git a/lib/imap.c b/lib/imap.c index b17b7e533..a4e61622f 100644 --- a/lib/imap.c +++ b/lib/imap.c @@ -1106,6 +1106,7 @@ static CURLcode imap_state_auth_cram_resp(struct connectdata *conn, { CURLcode result = CURLE_OK; struct SessionHandle *data = conn->data; + char *chlg = NULL; char *chlg64 = NULL; char *rplyb64 = NULL; size_t len = 0; @@ -1120,22 +1121,31 @@ static CURLcode imap_state_auth_cram_resp(struct connectdata *conn, /* Get the challenge message */ imap_get_message(data->state.buffer, &chlg64); - /* Create the response message */ - result = Curl_sasl_create_cram_md5_message(data, chlg64, conn->user, - conn->passwd, &rplyb64, &len); + /* Decode the challenge message */ + result = Curl_sasl_decode_cram_md5_message(chlg64, &chlg, &len); + if(result) { + /* Send the cancellation */ + result = Curl_pp_sendf(&conn->proto.imapc.pp, "%s", "*"); - /* Send the response */ - if(!result) { - if(rplyb64) { + if(!result) + state(conn, IMAP_AUTHENTICATE_CANCEL); + } + else { + /* Create the response message */ + result = Curl_sasl_create_cram_md5_message(data, chlg, conn->user, + conn->passwd, &rplyb64, &len); + if(!result && rplyb64) { + /* Send the response */ result = Curl_pp_sendf(&conn->proto.imapc.pp, "%s", rplyb64); if(!result) state(conn, IMAP_AUTHENTICATE_FINAL); } - - Curl_safefree(rplyb64); } + Curl_safefree(chlg); + Curl_safefree(rplyb64); + return result; } -- cgit v1.2.3