aboutsummaryrefslogtreecommitdiff
path: root/lib/imap.c
diff options
context:
space:
mode:
authorSteve Holme <steve_holme@hotmail.com>2013-10-27 09:00:41 +0000
committerSteve Holme <steve_holme@hotmail.com>2013-10-27 09:04:59 +0000
commitaa0eaef4838ccda89606459a1dd9a9cecbd612e7 (patch)
tree99b897b5178048fc6bb4ea9a059dfaa2b2d79d74 /lib/imap.c
parent9f503a254b0c720706124cb75922a0123f0079f0 (diff)
email: Moved authentication message parsing into a separate function
...in preparation for upcoming modifications.
Diffstat (limited to 'lib/imap.c')
-rw-r--r--lib/imap.c71
1 files changed, 44 insertions, 27 deletions
diff --git a/lib/imap.c b/lib/imap.c
index 748d6259a..f856dcd3d 100644
--- a/lib/imap.c
+++ b/lib/imap.c
@@ -373,6 +373,35 @@ static bool imap_endofresp(struct connectdata *conn, char *line, size_t len,
/***********************************************************************
*
+ * imap_get_message()
+ *
+ * Gets the authentication message from the response buffer.
+ */
+static void imap_get_message(char *buffer, char** outptr)
+{
+ size_t len = 0;
+ char* message = NULL;
+
+ /* Find the start of the message */
+ for(message = buffer + 2; *message == ' ' || *message == '\t'; message++)
+ ;
+
+ /* Find the end of the message */
+ for(len = strlen(message); len--;)
+ if(message[len] != '\r' && message[len] != '\n' && message[len] != ' ' &&
+ message[len] != '\t')
+ break;
+
+ /* Terminate the message */
+ if(++len) {
+ message[len] = '\0';
+ }
+
+ *outptr = message;
+}
+
+/***********************************************************************
+ *
* state()
*
* This is the ONLY way to change IMAP state!
@@ -1076,9 +1105,9 @@ static CURLcode imap_state_auth_cram_resp(struct connectdata *conn,
{
CURLcode result = CURLE_OK;
struct SessionHandle *data = conn->data;
- char *chlg64 = data->state.buffer;
- size_t len = 0;
+ char *chlg64 = NULL;
char *rplyb64 = NULL;
+ size_t len = 0;
(void)instate; /* no use for this yet */
@@ -1087,21 +1116,8 @@ static CURLcode imap_state_auth_cram_resp(struct connectdata *conn,
return CURLE_LOGIN_DENIED;
}
- /* Get the challenge */
- for(chlg64 += 2; *chlg64 == ' ' || *chlg64 == '\t'; chlg64++)
- ;
-
- /* Terminate the challenge */
- if(*chlg64 != '=') {
- for(len = strlen(chlg64); len--;)
- if(chlg64[len] != '\r' && chlg64[len] != '\n' && chlg64[len] != ' ' &&
- chlg64[len] != '\t')
- break;
-
- if(++len) {
- chlg64[len] = '\0';
- }
- }
+ /* 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,
@@ -1129,9 +1145,9 @@ static CURLcode imap_state_auth_digest_resp(struct connectdata *conn,
{
CURLcode result = CURLE_OK;
struct SessionHandle *data = conn->data;
- char *chlg64 = data->state.buffer;
- size_t len = 0;
+ char *chlg64 = NULL;
char *rplyb64 = NULL;
+ size_t len = 0;
(void)instate; /* no use for this yet */
@@ -1140,9 +1156,8 @@ static CURLcode imap_state_auth_digest_resp(struct connectdata *conn,
return CURLE_LOGIN_DENIED;
}
- /* Get the challenge */
- for(chlg64 += 2; *chlg64 == ' ' || *chlg64 == '\t'; chlg64++)
- ;
+ /* Get the challenge message */
+ imap_get_message(data->state.buffer, &chlg64);
/* Create the response message */
result = Curl_sasl_create_digest_md5_message(data, chlg64, conn->user,
@@ -1236,8 +1251,9 @@ static CURLcode imap_state_auth_ntlm_type2msg_resp(struct connectdata *conn,
{
CURLcode result = CURLE_OK;
struct SessionHandle *data = conn->data;
- size_t len = 0;
+ char *type2msg = NULL;
char *type3msg = NULL;
+ size_t len = 0;
(void)instate; /* no use for this yet */
@@ -1246,11 +1262,12 @@ static CURLcode imap_state_auth_ntlm_type2msg_resp(struct connectdata *conn,
result = CURLE_LOGIN_DENIED;
}
else {
+ /* Get the challenge message */
+ imap_get_message(data->state.buffer, &type2msg);
+
/* Create the type-3 message */
- result = Curl_sasl_create_ntlm_type3_message(data,
- data->state.buffer + 2,
- conn->user, conn->passwd,
- &conn->ntlm,
+ result = Curl_sasl_create_ntlm_type3_message(data, type2msg, conn->user,
+ conn->passwd, &conn->ntlm,
&type3msg, &len);
/* Send the message */