fix 223692, don't use the initial-response argument with SMTP AUTH LOGIN, patch by ch.ey@gmx.net, r/sr=me

This commit is contained in:
bienvenu%nventure.com 2003-11-14 16:13:48 +00:00
parent 7c0cff6574
commit 3c5c4da69b
2 changed files with 209 additions and 218 deletions

View File

@ -484,31 +484,6 @@ PRInt32 nsSmtpProtocol::SmtpResponse(nsIInputStream * inputStream, PRUint32 leng
return(0); /* everything ok */
}
PRInt32 nsSmtpProtocol::LoginResponse(nsIInputStream * inputStream, PRUint32 length)
{
PRInt32 status = 0;
nsCAutoString buffer ("HELO ");
if(m_responseCode != 220)
{
m_urlErrorState = NS_ERROR_COULD_NOT_LOGIN_TO_SMTP_SERVER;
return(NS_ERROR_COULD_NOT_LOGIN_TO_SMTP_SERVER);
}
buffer += GetUserDomainName();
buffer += CRLF;
nsCOMPtr<nsIURI> url = do_QueryInterface(m_runningURL);
status = SendData(url, buffer.get());
m_nextState = SMTP_RESPONSE;
m_nextStateAfterResponse = SMTP_SEND_HELO_RESPONSE;
SetFlag(SMTP_PAUSE_FOR_READ);
return(status);
}
PRInt32 nsSmtpProtocol::ExtensionLoginResponse(nsIInputStream * inputStream, PRUint32 length)
{
PRInt32 status = 0;
@ -544,7 +519,8 @@ PRInt32 nsSmtpProtocol::SendHeloResponse(nsIInputStream * inputStream, PRUint32
nsCOMPtr <nsIMsgIdentity> senderIdentity;
rv = m_runningURL->GetSenderIdentity(getter_AddRefs(senderIdentity));
if (NS_FAILED(rv) || !senderIdentity) {
if (NS_FAILED(rv) || !senderIdentity)
{
m_urlErrorState = NS_ERROR_COULD_NOT_GET_USERS_MAIL_ADDRESS;
return(NS_ERROR_COULD_NOT_GET_USERS_MAIL_ADDRESS);
}
@ -574,7 +550,8 @@ PRInt32 nsSmtpProtocol::SendHeloResponse(nsIInputStream * inputStream, PRUint32
/* else send the MAIL FROM: command */
nsCOMPtr<nsIMsgHeaderParser> parser = do_GetService(NS_MAILNEWS_MIME_HEADER_PARSER_CONTRACTID);
char *fullAddress = nsnull;
if (parser) {
if (parser)
{
// pass nsnull for the name, since we just want the email.
//
// seems a little weird that we are passing in the emailAddress
@ -616,7 +593,7 @@ PRInt32 nsSmtpProtocol::SendHeloResponse(nsIInputStream * inputStream, PRUint32
buffer += nsPrintfCString(" SIZE=%d", m_totalMessageSize);;
buffer += CRLF;
}
PR_FREEIF (fullAddress);
PR_Free (fullAddress);
}
nsCOMPtr<nsIURI> url = do_QueryInterface(m_runningURL);
@ -824,22 +801,8 @@ PRInt32 nsSmtpProtocol::ProcessAuth()
m_urlErrorState = NS_ERROR_COULD_NOT_LOGIN_TO_SMTP_SERVER;
return(NS_ERROR_COULD_NOT_LOGIN_TO_SMTP_SERVER);
}
if ((TestFlag(SMTP_AUTH_PLAIN_ENABLED) ||
TestFlag(SMTP_AUTH_CRAM_MD5_ENABLED) ||
TestFlag(SMTP_AUTH_LOGIN_ENABLED)) &&
(m_prefAuthMethod == PREF_AUTH_ANY))
{
m_nextState = SMTP_SEND_AUTH_LOGIN_USERNAME;
m_nextStateAfterResponse = SMTP_AUTH_LOGIN_RESPONSE;
}
else
m_nextState = SMTP_SEND_HELO_RESPONSE;
return NS_OK;
}
else // TLS enabled
{
if (TestFlag(SMTP_AUTH_EXTERNAL_ENABLED))
{
buffer = "AUTH EXTERNAL =";
@ -850,20 +813,22 @@ PRInt32 nsSmtpProtocol::ProcessAuth()
SetFlag(SMTP_PAUSE_FOR_READ);
return NS_OK;
}
else if ((TestFlag(SMTP_AUTH_LOGIN_ENABLED) ||
TestFlag(SMTP_AUTH_PLAIN_ENABLED) ||
TestFlag(SMTP_AUTH_CRAM_MD5_ENABLED)) &&
m_prefAuthMethod == PREF_AUTH_ANY)
else
if (m_prefAuthMethod == PREF_AUTH_ANY)
{
if (TestFlag(SMTP_AUTH_CRAM_MD5_ENABLED) ||
TestFlag(SMTP_AUTH_PLAIN_ENABLED))
m_nextState = SMTP_SEND_AUTH_LOGIN_USERNAME;
m_nextStateAfterResponse = SMTP_AUTH_LOGIN_RESPONSE;
else if (TestFlag(SMTP_AUTH_LOGIN_ENABLED))
m_nextState = SMTP_SEND_AUTH_LOGIN;
else
m_nextState = SMTP_SEND_HELO_RESPONSE;
}
else
m_nextState = SMTP_SEND_HELO_RESPONSE;
return NS_OK;
}
}
void nsSmtpProtocol::BackupAuthFlags()
@ -926,7 +891,7 @@ PRInt32 nsSmtpProtocol::AuthLoginResponse(nsIInputStream * stream, PRUint32 leng
RestoreAuthFlags();
}
m_nextState = SMTP_SEND_AUTH_LOGIN_USERNAME;
m_nextState = SMTP_AUTH_PROCESS_STATE;
}
else
status = NS_ERROR_SMTP_PASSWORD_UNDEFINED;
@ -936,6 +901,29 @@ PRInt32 nsSmtpProtocol::AuthLoginResponse(nsIInputStream * stream, PRUint32 leng
return (status);
}
// LOGIN consists of three steps not two as PLAIN or CRAM-MD5,
// so we've to start here and continue in AuthLoginUsername if the
// server responds with with 200 or 300 code to "AUTH LOGIN"
PRInt32 nsSmtpProtocol::SendAuthLogin()
{
nsCAutoString command("AUTH LOGIN" CRLF);
m_nextState = SMTP_RESPONSE;
m_nextStateAfterResponse = SMTP_LOGIN_RESPONSE;
SetFlag(SMTP_PAUSE_FOR_READ);
return SendData(m_url, command.get());
}
PRInt32 nsSmtpProtocol::LoginResponse()
{
// need the test to be here instead in AuthResponse() to
// differentiate between command AUTH LOGIN failed and
// sending username using LOGIN mechanism failed.
m_nextState = (m_responseCode/100 == 3) ?
SMTP_SEND_AUTH_LOGIN_USERNAME : SMTP_AUTH_LOGIN_RESPONSE;
return 0;
}
PRInt32 nsSmtpProtocol::AuthLoginUsername()
{
@ -965,7 +953,6 @@ PRInt32 nsSmtpProtocol::AuthLoginUsername()
password.Assign(origPassword);
if (password.IsEmpty())
return NS_ERROR_SMTP_PASSWORD_UNDEFINED;
}
else
password.Assign(mLogonCookie);
@ -990,6 +977,7 @@ PRInt32 nsSmtpProtocol::AuthLoginUsername()
PL_Base64Encode((const char *) username,
strlen((const char*)username), nsnull);
}
if (base64Str) {
// if cram md5 available, let's use it.
if (TestFlag(SMTP_AUTH_CRAM_MD5_ENABLED))
@ -997,7 +985,7 @@ PRInt32 nsSmtpProtocol::AuthLoginUsername()
else if (TestFlag(SMTP_AUTH_PLAIN_ENABLED))
PR_snprintf(buffer, sizeof(buffer), "AUTH PLAIN %.256s" CRLF, base64Str);
else if (TestFlag(SMTP_AUTH_LOGIN_ENABLED))
PR_snprintf(buffer, sizeof(buffer), "AUTH LOGIN %.256s" CRLF, base64Str);
PR_snprintf(buffer, sizeof(buffer), "%.256s" CRLF, base64Str);
else
return (NS_ERROR_COMMUNICATIONS_ERROR);
@ -1535,12 +1523,6 @@ nsresult nsSmtpProtocol::ProcessProtocolState(nsIURI * url, nsIInputStream * inp
case SMTP_FINISH_CONNECT:
SetFlag(SMTP_PAUSE_FOR_READ);
break;
case SMTP_LOGIN_RESPONSE:
if (inputStream == nsnull)
SetFlag(SMTP_PAUSE_FOR_READ);
else
status = LoginResponse(inputStream, length);
break;
case SMTP_TLS_RESPONSE:
if (inputStream == nsnull)
SetFlag(SMTP_PAUSE_FOR_READ);
@ -1570,6 +1552,14 @@ nsresult nsSmtpProtocol::ProcessProtocolState(nsIURI * url, nsIInputStream * inp
status = ProcessAuth();
break;
case SMTP_SEND_AUTH_LOGIN:
status = SendAuthLogin();
break;
case SMTP_LOGIN_RESPONSE:
status = LoginResponse();
break;
case SMTP_AUTH_EXTERNAL_RESPONSE:
case SMTP_AUTH_LOGIN_RESPONSE:
if (inputStream == nsnull)
@ -1637,7 +1627,6 @@ nsresult nsSmtpProtocol::ProcessProtocolState(nsIURI * url, nsIInputStream * inp
nsCOMPtr <nsIMsgMailNewsUrl> mailNewsUrl = do_QueryInterface(m_runningURL);
// propagate the right error code
mailNewsUrl->SetUrlState(PR_FALSE, m_urlErrorState);
m_nextState = SMTP_FREE;
}
m_nextState = SMTP_FREE;

View File

@ -68,13 +68,14 @@ SMTP_ERROR_DONE, // 12
SMTP_FREE, // 13
SMTP_EXTN_LOGIN_RESPONSE, // 14
SMTP_SEND_EHLO_RESPONSE, // 15
SMTP_SEND_AUTH_LOGIN_USERNAME, // 16
SMTP_SEND_AUTH_LOGIN_PASSWORD, // 17
SMTP_AUTH_LOGIN_RESPONSE, // 18
SMTP_TLS_RESPONSE, // 19
SMTP_AUTH_EXTERNAL_RESPONSE, // 20
SMTP_AUTH_PROCESS_STATE, // 21
SMTP_AUTH_CRAM_MD5_CHALLENGE_RESPONSE // 22
SMTP_SEND_AUTH_LOGIN, // 16
SMTP_SEND_AUTH_LOGIN_USERNAME, // 17
SMTP_SEND_AUTH_LOGIN_PASSWORD, // 18
SMTP_AUTH_LOGIN_RESPONSE, // 19
SMTP_TLS_RESPONSE, // 20
SMTP_AUTH_EXTERNAL_RESPONSE, // 21
SMTP_AUTH_PROCESS_STATE, // 22
SMTP_AUTH_CRAM_MD5_CHALLENGE_RESPONSE // 23
} SmtpState;
// State Flags (Note, I use the word state in terms of storing
@ -218,11 +219,12 @@ private:
////////////////////////////////////////////////////////////////////////////////////////
PRInt32 SmtpResponse(nsIInputStream * inputStream, PRUint32 length);
PRInt32 LoginResponse(nsIInputStream * inputStream, PRUint32 length);
PRInt32 ExtensionLoginResponse(nsIInputStream * inputStream, PRUint32 length);
PRInt32 SendHeloResponse(nsIInputStream * inputStream, PRUint32 length);
PRInt32 SendEhloResponse(nsIInputStream * inputStream, PRUint32 length);
PRInt32 SendAuthLogin();
PRInt32 LoginResponse();
PRInt32 AuthLoginUsername();
PRInt32 AuthLoginPassword();
PRInt32 AuthLoginResponse(nsIInputStream * stream, PRUint32 length);