mirror of
https://github.com/moparisthebest/curl
synced 2024-12-22 16:18:48 -05:00
email: Moved authentication message parsing into a separate function
...in preparation for upcoming modifications.
This commit is contained in:
parent
9f503a254b
commit
aa0eaef483
71
lib/imap.c
71
lib/imap.c
@ -371,6 +371,35 @@ static bool imap_endofresp(struct connectdata *conn, char *line, size_t len,
|
|||||||
return FALSE; /* Nothing for us */
|
return FALSE; /* Nothing for us */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/***********************************************************************
|
||||||
|
*
|
||||||
|
* 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()
|
* state()
|
||||||
@ -1076,9 +1105,9 @@ static CURLcode imap_state_auth_cram_resp(struct connectdata *conn,
|
|||||||
{
|
{
|
||||||
CURLcode result = CURLE_OK;
|
CURLcode result = CURLE_OK;
|
||||||
struct SessionHandle *data = conn->data;
|
struct SessionHandle *data = conn->data;
|
||||||
char *chlg64 = data->state.buffer;
|
char *chlg64 = NULL;
|
||||||
size_t len = 0;
|
|
||||||
char *rplyb64 = NULL;
|
char *rplyb64 = NULL;
|
||||||
|
size_t len = 0;
|
||||||
|
|
||||||
(void)instate; /* no use for this yet */
|
(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;
|
return CURLE_LOGIN_DENIED;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get the challenge */
|
/* Get the challenge message */
|
||||||
for(chlg64 += 2; *chlg64 == ' ' || *chlg64 == '\t'; chlg64++)
|
imap_get_message(data->state.buffer, &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';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Create the response message */
|
/* Create the response message */
|
||||||
result = Curl_sasl_create_cram_md5_message(data, chlg64, conn->user,
|
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;
|
CURLcode result = CURLE_OK;
|
||||||
struct SessionHandle *data = conn->data;
|
struct SessionHandle *data = conn->data;
|
||||||
char *chlg64 = data->state.buffer;
|
char *chlg64 = NULL;
|
||||||
size_t len = 0;
|
|
||||||
char *rplyb64 = NULL;
|
char *rplyb64 = NULL;
|
||||||
|
size_t len = 0;
|
||||||
|
|
||||||
(void)instate; /* no use for this yet */
|
(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;
|
return CURLE_LOGIN_DENIED;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get the challenge */
|
/* Get the challenge message */
|
||||||
for(chlg64 += 2; *chlg64 == ' ' || *chlg64 == '\t'; chlg64++)
|
imap_get_message(data->state.buffer, &chlg64);
|
||||||
;
|
|
||||||
|
|
||||||
/* Create the response message */
|
/* Create the response message */
|
||||||
result = Curl_sasl_create_digest_md5_message(data, chlg64, conn->user,
|
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;
|
CURLcode result = CURLE_OK;
|
||||||
struct SessionHandle *data = conn->data;
|
struct SessionHandle *data = conn->data;
|
||||||
size_t len = 0;
|
char *type2msg = NULL;
|
||||||
char *type3msg = NULL;
|
char *type3msg = NULL;
|
||||||
|
size_t len = 0;
|
||||||
|
|
||||||
(void)instate; /* no use for this yet */
|
(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;
|
result = CURLE_LOGIN_DENIED;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
/* Get the challenge message */
|
||||||
|
imap_get_message(data->state.buffer, &type2msg);
|
||||||
|
|
||||||
/* Create the type-3 message */
|
/* Create the type-3 message */
|
||||||
result = Curl_sasl_create_ntlm_type3_message(data,
|
result = Curl_sasl_create_ntlm_type3_message(data, type2msg, conn->user,
|
||||||
data->state.buffer + 2,
|
conn->passwd, &conn->ntlm,
|
||||||
conn->user, conn->passwd,
|
|
||||||
&conn->ntlm,
|
|
||||||
&type3msg, &len);
|
&type3msg, &len);
|
||||||
|
|
||||||
/* Send the message */
|
/* Send the message */
|
||||||
|
71
lib/pop3.c
71
lib/pop3.c
@ -350,6 +350,35 @@ static bool pop3_endofresp(struct connectdata *conn, char *line, size_t len,
|
|||||||
return FALSE; /* Nothing for us */
|
return FALSE; /* Nothing for us */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/***********************************************************************
|
||||||
|
*
|
||||||
|
* pop3_get_message()
|
||||||
|
*
|
||||||
|
* Gets the authentication message from the response buffer.
|
||||||
|
*/
|
||||||
|
static void pop3_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 challenge */
|
||||||
|
if(++len) {
|
||||||
|
message[len] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
*outptr = message;
|
||||||
|
}
|
||||||
|
|
||||||
/***********************************************************************
|
/***********************************************************************
|
||||||
*
|
*
|
||||||
* state()
|
* state()
|
||||||
@ -934,9 +963,9 @@ static CURLcode pop3_state_auth_cram_resp(struct connectdata *conn,
|
|||||||
{
|
{
|
||||||
CURLcode result = CURLE_OK;
|
CURLcode result = CURLE_OK;
|
||||||
struct SessionHandle *data = conn->data;
|
struct SessionHandle *data = conn->data;
|
||||||
char *chlg64 = data->state.buffer;
|
char *chlg64 = NULL;
|
||||||
size_t len = 0;
|
|
||||||
char *rplyb64 = NULL;
|
char *rplyb64 = NULL;
|
||||||
|
size_t len = 0;
|
||||||
|
|
||||||
(void)instate; /* no use for this yet */
|
(void)instate; /* no use for this yet */
|
||||||
|
|
||||||
@ -945,21 +974,8 @@ static CURLcode pop3_state_auth_cram_resp(struct connectdata *conn,
|
|||||||
return CURLE_LOGIN_DENIED;
|
return CURLE_LOGIN_DENIED;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get the challenge */
|
/* Get the challenge message */
|
||||||
for(chlg64 += 2; *chlg64 == ' ' || *chlg64 == '\t'; chlg64++)
|
pop3_get_message(data->state.buffer, &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';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Create the response message */
|
/* Create the response message */
|
||||||
result = Curl_sasl_create_cram_md5_message(data, chlg64, conn->user,
|
result = Curl_sasl_create_cram_md5_message(data, chlg64, conn->user,
|
||||||
@ -987,9 +1003,9 @@ static CURLcode pop3_state_auth_digest_resp(struct connectdata *conn,
|
|||||||
{
|
{
|
||||||
CURLcode result = CURLE_OK;
|
CURLcode result = CURLE_OK;
|
||||||
struct SessionHandle *data = conn->data;
|
struct SessionHandle *data = conn->data;
|
||||||
char *chlg64 = data->state.buffer;
|
char *chlg64 = NULL;
|
||||||
size_t len = 0;
|
|
||||||
char *rplyb64 = NULL;
|
char *rplyb64 = NULL;
|
||||||
|
size_t len = 0;
|
||||||
|
|
||||||
(void)instate; /* no use for this yet */
|
(void)instate; /* no use for this yet */
|
||||||
|
|
||||||
@ -998,9 +1014,8 @@ static CURLcode pop3_state_auth_digest_resp(struct connectdata *conn,
|
|||||||
return CURLE_LOGIN_DENIED;
|
return CURLE_LOGIN_DENIED;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get the challenge */
|
/* Get the challenge message */
|
||||||
for(chlg64 += 2; *chlg64 == ' ' || *chlg64 == '\t'; chlg64++)
|
pop3_get_message(data->state.buffer, &chlg64);
|
||||||
;
|
|
||||||
|
|
||||||
/* Create the response message */
|
/* Create the response message */
|
||||||
result = Curl_sasl_create_digest_md5_message(data, chlg64, conn->user,
|
result = Curl_sasl_create_digest_md5_message(data, chlg64, conn->user,
|
||||||
@ -1094,8 +1109,9 @@ static CURLcode pop3_state_auth_ntlm_type2msg_resp(struct connectdata *conn,
|
|||||||
{
|
{
|
||||||
CURLcode result = CURLE_OK;
|
CURLcode result = CURLE_OK;
|
||||||
struct SessionHandle *data = conn->data;
|
struct SessionHandle *data = conn->data;
|
||||||
size_t len = 0;
|
char *type2msg = NULL;
|
||||||
char *type3msg = NULL;
|
char *type3msg = NULL;
|
||||||
|
size_t len = 0;
|
||||||
|
|
||||||
(void)instate; /* no use for this yet */
|
(void)instate; /* no use for this yet */
|
||||||
|
|
||||||
@ -1104,11 +1120,12 @@ static CURLcode pop3_state_auth_ntlm_type2msg_resp(struct connectdata *conn,
|
|||||||
result = CURLE_LOGIN_DENIED;
|
result = CURLE_LOGIN_DENIED;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
/* Get the type-2 message */
|
||||||
|
pop3_get_message(data->state.buffer, &type2msg);
|
||||||
|
|
||||||
/* Create the type-3 message */
|
/* Create the type-3 message */
|
||||||
result = Curl_sasl_create_ntlm_type3_message(data,
|
result = Curl_sasl_create_ntlm_type3_message(data, type2msg, conn->user,
|
||||||
data->state.buffer + 2,
|
conn->passwd, &conn->ntlm,
|
||||||
conn->user, conn->passwd,
|
|
||||||
&conn->ntlm,
|
|
||||||
&type3msg, &len);
|
&type3msg, &len);
|
||||||
|
|
||||||
/* Send the message */
|
/* Send the message */
|
||||||
|
71
lib/smtp.c
71
lib/smtp.c
@ -219,7 +219,7 @@ static void smtp_to_smtps(struct connectdata *conn)
|
|||||||
|
|
||||||
/***********************************************************************
|
/***********************************************************************
|
||||||
*
|
*
|
||||||
* pop3_endofresp()
|
* smtp_endofresp()
|
||||||
*
|
*
|
||||||
* Checks for an ending SMTP status code at the start of the given string, but
|
* Checks for an ending SMTP status code at the start of the given string, but
|
||||||
* also detects various capabilities from the EHLO response including the
|
* also detects various capabilities from the EHLO response including the
|
||||||
@ -307,6 +307,35 @@ static bool smtp_endofresp(struct connectdata *conn, char *line, size_t len,
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/***********************************************************************
|
||||||
|
*
|
||||||
|
* smtp_get_message()
|
||||||
|
*
|
||||||
|
* Gets the authentication message from the response buffer.
|
||||||
|
*/
|
||||||
|
static void smtp_get_message(char *buffer, char** outptr)
|
||||||
|
{
|
||||||
|
size_t len = 0;
|
||||||
|
char* message = NULL;
|
||||||
|
|
||||||
|
/* Find the start of the message */
|
||||||
|
for(message = buffer + 4; *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 challenge */
|
||||||
|
if(++len) {
|
||||||
|
message[len] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
*outptr = message;
|
||||||
|
}
|
||||||
|
|
||||||
/***********************************************************************
|
/***********************************************************************
|
||||||
*
|
*
|
||||||
* state()
|
* state()
|
||||||
@ -914,9 +943,9 @@ static CURLcode smtp_state_auth_cram_resp(struct connectdata *conn,
|
|||||||
{
|
{
|
||||||
CURLcode result = CURLE_OK;
|
CURLcode result = CURLE_OK;
|
||||||
struct SessionHandle *data = conn->data;
|
struct SessionHandle *data = conn->data;
|
||||||
char *chlg64 = data->state.buffer;
|
char *chlg64 = NULL;
|
||||||
size_t len = 0;
|
|
||||||
char *rplyb64 = NULL;
|
char *rplyb64 = NULL;
|
||||||
|
size_t len = 0;
|
||||||
|
|
||||||
(void)instate; /* no use for this yet */
|
(void)instate; /* no use for this yet */
|
||||||
|
|
||||||
@ -925,21 +954,8 @@ static CURLcode smtp_state_auth_cram_resp(struct connectdata *conn,
|
|||||||
return CURLE_LOGIN_DENIED;
|
return CURLE_LOGIN_DENIED;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get the challenge */
|
/* Get the challenge message */
|
||||||
for(chlg64 += 4; *chlg64 == ' ' || *chlg64 == '\t'; chlg64++)
|
smtp_get_message(data->state.buffer, &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';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Create the response message */
|
/* Create the response message */
|
||||||
result = Curl_sasl_create_cram_md5_message(data, chlg64, conn->user,
|
result = Curl_sasl_create_cram_md5_message(data, chlg64, conn->user,
|
||||||
@ -967,9 +983,9 @@ static CURLcode smtp_state_auth_digest_resp(struct connectdata *conn,
|
|||||||
{
|
{
|
||||||
CURLcode result = CURLE_OK;
|
CURLcode result = CURLE_OK;
|
||||||
struct SessionHandle *data = conn->data;
|
struct SessionHandle *data = conn->data;
|
||||||
char *chlg64 = data->state.buffer;
|
char *chlg64 = NULL;
|
||||||
size_t len = 0;
|
|
||||||
char *rplyb64 = NULL;
|
char *rplyb64 = NULL;
|
||||||
|
size_t len = 0;
|
||||||
|
|
||||||
(void)instate; /* no use for this yet */
|
(void)instate; /* no use for this yet */
|
||||||
|
|
||||||
@ -978,9 +994,8 @@ static CURLcode smtp_state_auth_digest_resp(struct connectdata *conn,
|
|||||||
return CURLE_LOGIN_DENIED;
|
return CURLE_LOGIN_DENIED;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get the challenge */
|
/* Get the challenge message */
|
||||||
for(chlg64 += 4; *chlg64 == ' ' || *chlg64 == '\t'; chlg64++)
|
smtp_get_message(data->state.buffer, &chlg64);
|
||||||
;
|
|
||||||
|
|
||||||
/* Create the response message */
|
/* Create the response message */
|
||||||
result = Curl_sasl_create_digest_md5_message(data, chlg64, conn->user,
|
result = Curl_sasl_create_digest_md5_message(data, chlg64, conn->user,
|
||||||
@ -1075,6 +1090,7 @@ static CURLcode smtp_state_auth_ntlm_type2msg_resp(struct connectdata *conn,
|
|||||||
{
|
{
|
||||||
CURLcode result = CURLE_OK;
|
CURLcode result = CURLE_OK;
|
||||||
struct SessionHandle *data = conn->data;
|
struct SessionHandle *data = conn->data;
|
||||||
|
char *type2msg = NULL;
|
||||||
char *type3msg = NULL;
|
char *type3msg = NULL;
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
|
|
||||||
@ -1085,11 +1101,12 @@ static CURLcode smtp_state_auth_ntlm_type2msg_resp(struct connectdata *conn,
|
|||||||
result = CURLE_LOGIN_DENIED;
|
result = CURLE_LOGIN_DENIED;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
/* Get the type-2 message */
|
||||||
|
smtp_get_message(data->state.buffer, &type2msg);
|
||||||
|
|
||||||
/* Create the type-3 message */
|
/* Create the type-3 message */
|
||||||
result = Curl_sasl_create_ntlm_type3_message(data,
|
result = Curl_sasl_create_ntlm_type3_message(data, type2msg, conn->user,
|
||||||
data->state.buffer + 4,
|
conn->passwd, &conn->ntlm,
|
||||||
conn->user, conn->passwd,
|
|
||||||
&conn->ntlm,
|
|
||||||
&type3msg, &len);
|
&type3msg, &len);
|
||||||
|
|
||||||
/* Send the message */
|
/* Send the message */
|
||||||
|
Loading…
Reference in New Issue
Block a user