email: Extended the login options to support multiple auth mechanisms

This commit is contained in:
Steve Holme 2013-12-21 23:34:45 +00:00
Родитель 1deac31eba
Коммит 195b63f99c
3 изменённых файлов: 130 добавлений и 93 удалений

Просмотреть файл

@ -2312,52 +2312,64 @@ static CURLcode imap_parse_url_options(struct connectdata *conn)
struct imap_conn *imapc = &conn->proto.imapc;
const char *options = conn->options;
const char *ptr = options;
bool reset = TRUE;
if(options) {
while(*ptr) {
const char *key = ptr;
while(*ptr && *ptr != '=')
ptr++;
if(strnequal(key, "AUTH", 4)) {
const char *value = ptr + 1;
size_t len = 0;
const char *value = ++ptr;
if(strequal(value, "*")) {
imapc->preftype = IMAP_TYPE_ANY;
imapc->prefmech = SASL_AUTH_ANY;
}
else if(strequal(value, SASL_MECH_STRING_LOGIN)) {
imapc->preftype = IMAP_TYPE_SASL;
imapc->prefmech = SASL_MECH_LOGIN;
}
else if(strequal(value, SASL_MECH_STRING_PLAIN)) {
imapc->preftype = IMAP_TYPE_SASL;
imapc->prefmech = SASL_MECH_PLAIN;
}
else if(strequal(value, SASL_MECH_STRING_CRAM_MD5)) {
imapc->preftype = IMAP_TYPE_SASL;
imapc->prefmech = SASL_MECH_CRAM_MD5;
}
else if(strequal(value, SASL_MECH_STRING_DIGEST_MD5)) {
imapc->preftype = IMAP_TYPE_SASL;
imapc->prefmech = SASL_MECH_DIGEST_MD5;
}
else if(strequal(value, SASL_MECH_STRING_GSSAPI)) {
imapc->preftype = IMAP_TYPE_SASL;
imapc->prefmech = SASL_MECH_GSSAPI;
}
else if(strequal(value, SASL_MECH_STRING_NTLM)) {
imapc->preftype = IMAP_TYPE_SASL;
imapc->prefmech = SASL_MECH_NTLM;
}
else if(strequal(value, SASL_MECH_STRING_XOAUTH2)) {
imapc->preftype = IMAP_TYPE_SASL;
imapc->prefmech = SASL_MECH_XOAUTH2;
}
else {
if(reset) {
reset = FALSE;
imapc->preftype = IMAP_TYPE_NONE;
imapc->prefmech = SASL_AUTH_NONE;
}
while(*ptr && *ptr != ';') {
ptr++;
len++;
}
if(strnequal(value, "*", len)) {
imapc->preftype = IMAP_TYPE_ANY;
imapc->prefmech = SASL_AUTH_ANY;
}
else if(strnequal(value, SASL_MECH_STRING_LOGIN, len)) {
imapc->preftype = IMAP_TYPE_SASL;
imapc->prefmech |= SASL_MECH_LOGIN;
}
else if(strnequal(value, SASL_MECH_STRING_PLAIN, len)) {
imapc->preftype = IMAP_TYPE_SASL;
imapc->prefmech |= SASL_MECH_PLAIN;
}
else if(strnequal(value, SASL_MECH_STRING_CRAM_MD5, len)) {
imapc->preftype = IMAP_TYPE_SASL;
imapc->prefmech |= SASL_MECH_CRAM_MD5;
}
else if(strnequal(value, SASL_MECH_STRING_DIGEST_MD5, len)) {
imapc->preftype = IMAP_TYPE_SASL;
imapc->prefmech |= SASL_MECH_DIGEST_MD5;
}
else if(strnequal(value, SASL_MECH_STRING_GSSAPI, len)) {
imapc->preftype = IMAP_TYPE_SASL;
imapc->prefmech |= SASL_MECH_GSSAPI;
}
else if(strnequal(value, SASL_MECH_STRING_NTLM, len)) {
imapc->preftype = IMAP_TYPE_SASL;
imapc->prefmech |= SASL_MECH_NTLM;
}
else if(strnequal(value, SASL_MECH_STRING_XOAUTH2, len)) {
imapc->preftype = IMAP_TYPE_SASL;
imapc->prefmech |= SASL_MECH_XOAUTH2;
}
if(*ptr == ';')
ptr++;
}
else
result = CURLE_URL_MALFORMAT;

Просмотреть файл

@ -1832,56 +1832,68 @@ static CURLcode pop3_parse_url_options(struct connectdata *conn)
struct pop3_conn *pop3c = &conn->proto.pop3c;
const char *options = conn->options;
const char *ptr = options;
bool reset = TRUE;
if(options) {
while(*ptr) {
const char *key = ptr;
while(*ptr && *ptr != '=')
ptr++;
if(strnequal(key, "AUTH", 4)) {
const char *value = ptr + 1;
size_t len = 0;
const char *value = ++ptr;
if(strequal(value, "*")) {
pop3c->preftype = POP3_TYPE_ANY;
pop3c->prefmech = SASL_AUTH_ANY;
}
else if(strequal(value, "+APOP")) {
pop3c->preftype = POP3_TYPE_APOP;
pop3c->prefmech = SASL_AUTH_NONE;
}
else if(strequal(value, SASL_MECH_STRING_LOGIN)) {
pop3c->preftype = POP3_TYPE_SASL;
pop3c->prefmech = SASL_MECH_LOGIN;
}
else if(strequal(value, SASL_MECH_STRING_PLAIN)) {
pop3c->preftype = POP3_TYPE_SASL;
pop3c->prefmech = SASL_MECH_PLAIN;
}
else if(strequal(value, SASL_MECH_STRING_CRAM_MD5)) {
pop3c->preftype = POP3_TYPE_SASL;
pop3c->prefmech = SASL_MECH_CRAM_MD5;
}
else if(strequal(value, SASL_MECH_STRING_DIGEST_MD5)) {
pop3c->preftype = POP3_TYPE_SASL;
pop3c->prefmech = SASL_MECH_DIGEST_MD5;
}
else if(strequal(value, SASL_MECH_STRING_GSSAPI)) {
pop3c->preftype = POP3_TYPE_SASL;
pop3c->prefmech = SASL_MECH_GSSAPI;
}
else if(strequal(value, SASL_MECH_STRING_NTLM)) {
pop3c->preftype = POP3_TYPE_SASL;
pop3c->prefmech = SASL_MECH_NTLM;
}
else if(strequal(value, SASL_MECH_STRING_XOAUTH2)) {
pop3c->preftype = POP3_TYPE_SASL;
pop3c->prefmech = SASL_MECH_XOAUTH2;
}
else {
if(reset) {
reset = FALSE;
pop3c->preftype = POP3_TYPE_NONE;
pop3c->prefmech = SASL_AUTH_NONE;
}
while(*ptr && *ptr != ';') {
ptr++;
len++;
}
if(strnequal(value, "*", len)) {
pop3c->preftype = POP3_TYPE_ANY;
pop3c->prefmech = SASL_AUTH_ANY;
}
else if(strnequal(value, "+APOP", len)) {
pop3c->preftype = POP3_TYPE_APOP;
pop3c->prefmech = SASL_AUTH_NONE;
}
else if(strnequal(value, SASL_MECH_STRING_LOGIN, len)) {
pop3c->preftype = POP3_TYPE_SASL;
pop3c->prefmech |= SASL_MECH_LOGIN;
}
else if(strnequal(value, SASL_MECH_STRING_PLAIN, len)) {
pop3c->preftype = POP3_TYPE_SASL;
pop3c->prefmech |= SASL_MECH_PLAIN;
}
else if(strnequal(value, SASL_MECH_STRING_CRAM_MD5, len)) {
pop3c->preftype = POP3_TYPE_SASL;
pop3c->prefmech |= SASL_MECH_CRAM_MD5;
}
else if(strnequal(value, SASL_MECH_STRING_DIGEST_MD5, len)) {
pop3c->preftype = POP3_TYPE_SASL;
pop3c->prefmech |= SASL_MECH_DIGEST_MD5;
}
else if(strnequal(value, SASL_MECH_STRING_GSSAPI, len)) {
pop3c->preftype = POP3_TYPE_SASL;
pop3c->prefmech |= SASL_MECH_GSSAPI;
}
else if(strnequal(value, SASL_MECH_STRING_NTLM, len)) {
pop3c->preftype = POP3_TYPE_SASL;
pop3c->prefmech |= SASL_MECH_NTLM;
}
else if(strnequal(value, SASL_MECH_STRING_XOAUTH2, len)) {
pop3c->preftype = POP3_TYPE_SASL;
pop3c->prefmech |= SASL_MECH_XOAUTH2;
}
if(*ptr == ';')
ptr++;
}
else
result = CURLE_URL_MALFORMAT;

Просмотреть файл

@ -1927,34 +1927,47 @@ static CURLcode smtp_parse_url_options(struct connectdata *conn)
struct smtp_conn *smtpc = &conn->proto.smtpc;
const char *options = conn->options;
const char *ptr = options;
bool reset = TRUE;
if(options) {
while(*ptr) {
const char *key = ptr;
while(*ptr && *ptr != '=')
ptr++;
if(strnequal(key, "AUTH", 4)) {
const char *value = ptr + 1;
size_t len = 0;
const char *value = ++ptr;
if(strequal(value, "*"))
smtpc->prefmech = SASL_AUTH_ANY;
else if(strequal(value, SASL_MECH_STRING_LOGIN))
smtpc->prefmech = SASL_MECH_LOGIN;
else if(strequal(value, SASL_MECH_STRING_PLAIN))
smtpc->prefmech = SASL_MECH_PLAIN;
else if(strequal(value, SASL_MECH_STRING_CRAM_MD5))
smtpc->prefmech = SASL_MECH_CRAM_MD5;
else if(strequal(value, SASL_MECH_STRING_DIGEST_MD5))
smtpc->prefmech = SASL_MECH_DIGEST_MD5;
else if(strequal(value, SASL_MECH_STRING_GSSAPI))
smtpc->prefmech = SASL_MECH_GSSAPI;
else if(strequal(value, SASL_MECH_STRING_NTLM))
smtpc->prefmech = SASL_MECH_NTLM;
else if(strequal(value, SASL_MECH_STRING_XOAUTH2))
smtpc->prefmech = SASL_MECH_XOAUTH2;
else
if(reset) {
reset = FALSE;
smtpc->prefmech = SASL_AUTH_NONE;
}
while(*ptr && *ptr != ';') {
ptr++;
len++;
}
if(strnequal(value, "*", len))
smtpc->prefmech = SASL_AUTH_ANY;
else if(strnequal(value, SASL_MECH_STRING_LOGIN, len))
smtpc->prefmech |= SASL_MECH_LOGIN;
else if(strnequal(value, SASL_MECH_STRING_PLAIN, len))
smtpc->prefmech |= SASL_MECH_PLAIN;
else if(strnequal(value, SASL_MECH_STRING_CRAM_MD5, len))
smtpc->prefmech |= SASL_MECH_CRAM_MD5;
else if(strnequal(value, SASL_MECH_STRING_DIGEST_MD5, len))
smtpc->prefmech |= SASL_MECH_DIGEST_MD5;
else if(strnequal(value, SASL_MECH_STRING_GSSAPI, len))
smtpc->prefmech |= SASL_MECH_GSSAPI;
else if(strnequal(value, SASL_MECH_STRING_NTLM, len))
smtpc->prefmech |= SASL_MECH_NTLM;
else if(strnequal(value, SASL_MECH_STRING_XOAUTH2, len))
smtpc->prefmech |= SASL_MECH_XOAUTH2;
if(*ptr == ';')
ptr++;
}
else
result = CURLE_URL_MALFORMAT;