hrev51241 adds 6 changesets to branch 'master'
old head: af45ca81ffa5987582a9d263c41b8b14cf0ffce6
new head: 6a075fc1af9ff6536a76272781ccd7ae62b6d18d
overview:
http://cgit.haiku-os.org/haiku/log/?qt=range&q=6a075fc1af9f+%5Eaf45ca81ffa5
----------------------------------------------------------------------------
954b54ba8d4c: kits/mail: Remove OpenSSL logic from Jamfile.
Nothing in the Mail Kit proper uses OpenSSL directly anymore
(confirmed with a grep for USE_SSL as well as "openssl"),
so we don't need this logic anymore.
92bfd0e09e94: POP3: Remove direct usage of OpenSSL.
It already uses BSecureSocket without checking for USE_SSL,
so just assume we have SSL no matter what.
9980b6b47c8f: IMAP: Remove direct usage of OpenSSL.
It already uses BSecureSocket without checking for USE_SSL,
so just assume we have SSL no matter what.
c86d49716413: SMTP: Remove STARTTLS support.
* It's vulnerable to man-in-the-middle attacks (which can't really be fixed)
* It's rather nasty to implement (and prevents us from using BSecureSocket)
* Nearly all servers I know of which support STARTTLS also support plain
TLS also.
d1136c5a977d: SMTP: Use B{Secure}Socket for communication.
6a075fc1af9f: POP3: Actually return B_TIMED_OUT not just B_ERROR on timeouts.
[ Augustin Cavalier <waddlesplash@xxxxxxxxx> ]
----------------------------------------------------------------------------
12 files changed, 62 insertions(+), 310 deletions(-)
.../inbound_protocols/imap/ConfigView.cpp | 4 -
.../mail_daemon/inbound_protocols/imap/Jamfile | 18 +-
.../inbound_protocols/pop3/ConfigView.cpp | 4 -
.../mail_daemon/inbound_protocols/pop3/Jamfile | 24 +-
.../mail_daemon/inbound_protocols/pop3/POP3.cpp | 10 +-
.../outbound_protocols/smtp/ConfigView.cpp | 11 +-
.../mail_daemon/outbound_protocols/smtp/Jamfile | 28 +--
.../mail_daemon/outbound_protocols/smtp/SMTP.cpp | 241 ++++---------------
.../mail_daemon/outbound_protocols/smtp/SMTP.h | 15 +-
src/kits/mail/Jamfile | 14 --
src/preferences/mail/ProviderInfo/ReadMe | 1 -
src/preferences/mail/ProviderInfo/shaw.ca.rdef | 2 +-
############################################################################
Commit: 954b54ba8d4c19849385929cb39db5244a75e291
URL: http://cgit.haiku-os.org/haiku/commit/?id=954b54ba8d4c
Author: Augustin Cavalier <waddlesplash@xxxxxxxxx>
Date: Sat Jul 1 00:21:09 2017 UTC
kits/mail: Remove OpenSSL logic from Jamfile.
Nothing in the Mail Kit proper uses OpenSSL directly anymore
(confirmed with a grep for USE_SSL as well as "openssl"),
so we don't need this logic anymore.
----------------------------------------------------------------------------
diff --git a/src/kits/mail/Jamfile b/src/kits/mail/Jamfile
index a1c7e2f..b9d0910 100644
--- a/src/kits/mail/Jamfile
+++ b/src/kits/mail/Jamfile
@@ -39,19 +39,6 @@ local sources =
local architectureObject ;
for architectureObject in [ MultiArchSubDirSetup ] {
on $(architectureObject) {
- # use OpenSSL, if enabled
- if [ FIsBuildFeatureEnabled openssl ] {
- SubDirC++Flags -DUSE_SSL ;
- UseBuildFeatureHeaders openssl ;
- Includes [ FGristFiles $(sources) ]
- : [ BuildFeatureAttribute openssl : headers ] ;
- # Dependency needed to trigger
downloading/unzipping the package before
- # compiling the files.
- SetupFeatureObjectsDir ssl ;
- } else {
- SetupFeatureObjectsDir no-ssl ;
- }
-
local libmail = [ MultiArchDefaultGristFiles libmail.so ] ;
AddResources $(libmail) : libmail.rdef ;
@@ -62,7 +49,6 @@ for architectureObject in [ MultiArchSubDirSetup ] {
[ TargetLibstdc++ ]
$(TARGET_NETWORK_LIBS)
$(TARGET_SELECT_UNAME_ETC_LIB)
- [ BuildFeatureAttribute openssl : libraries ]
localestub
;
}
############################################################################
Commit: 92bfd0e09e94e1254b704eae2b57e6b30131c6e0
URL: http://cgit.haiku-os.org/haiku/commit/?id=92bfd0e09e94
Author: Augustin Cavalier <waddlesplash@xxxxxxxxx>
Date: Sat Jul 1 00:26:41 2017 UTC
POP3: Remove direct usage of OpenSSL.
It already uses BSecureSocket without checking for USE_SSL,
so just assume we have SSL no matter what.
----------------------------------------------------------------------------
diff --git a/src/add-ons/mail_daemon/inbound_protocols/pop3/ConfigView.cpp
b/src/add-ons/mail_daemon/inbound_protocols/pop3/ConfigView.cpp
index 05e45ef..155a9d2 100644
--- a/src/add-ons/mail_daemon/inbound_protocols/pop3/ConfigView.cpp
+++ b/src/add-ons/mail_daemon/inbound_protocols/pop3/ConfigView.cpp
@@ -42,18 +42,14 @@ POP3ConfigView::POP3ConfigView(const BMailProtocolSettings&
settings)
| B_MAIL_PROTOCOL_HAS_HOSTNAME
| B_MAIL_PROTOCOL_CAN_LEAVE_MAIL_ON_SERVER
| B_MAIL_PROTOCOL_PARTIAL_DOWNLOAD
-#if USE_SSL
| B_MAIL_PROTOCOL_HAS_FLAVORS
-#endif
)
{
AddAuthMethod(B_TRANSLATE("Plain text"));
AddAuthMethod(B_TRANSLATE("APOP"));
-#if USE_SSL
AddFlavor(B_TRANSLATE("No encryption"));
AddFlavor(B_TRANSLATE("SSL"));
-#endif
SetTo(settings);
diff --git a/src/add-ons/mail_daemon/inbound_protocols/pop3/Jamfile
b/src/add-ons/mail_daemon/inbound_protocols/pop3/Jamfile
index eef083f..1b2299b 100644
--- a/src/add-ons/mail_daemon/inbound_protocols/pop3/Jamfile
+++ b/src/add-ons/mail_daemon/inbound_protocols/pop3/Jamfile
@@ -9,32 +9,14 @@ UsePrivateHeaders mail shared ;
SubDirHdrs [ FDirName $(HAIKU_TOP) headers os add-ons mail_daemon ] ;
-local sources =
+AddResources POP3 : POP3.rdef ;
+
+Addon POP3 :
ConfigView.cpp
MessageIO.cpp
POP3.cpp
md5c.c
-;
-
-# use OpenSSL, if enabled
-if [ FIsBuildFeatureEnabled openssl ] {
- SubDirC++Flags -DUSE_SSL ;
- UseBuildFeatureHeaders openssl ;
- Includes [ FGristFiles $(sources) ]
- : [ BuildFeatureAttribute openssl : headers ] ;
- # Dependency needed to trigger downloading/unzipping the
package before
- # compiling the files.
- SetupFeatureObjectsDir ssl ;
-} else {
- SetupFeatureObjectsDir no-ssl ;
-}
-
-AddResources POP3 : POP3.rdef ;
-
-Addon POP3
- : $(sources)
: be libbnetapi.so libmail.so localestub
- [ BuildFeatureAttribute openssl : libraries ]
[ TargetLibstdc++ ] [ TargetLibsupc++ ]
$(TARGET_NETWORK_LIBS)
;
diff --git a/src/add-ons/mail_daemon/inbound_protocols/pop3/POP3.cpp
b/src/add-ons/mail_daemon/inbound_protocols/pop3/POP3.cpp
index 313aa74..8c796c6 100644
--- a/src/add-ons/mail_daemon/inbound_protocols/pop3/POP3.cpp
+++ b/src/add-ons/mail_daemon/inbound_protocols/pop3/POP3.cpp
@@ -22,11 +22,7 @@
#include <arpa/inet.h>
-#if USE_SSL
-#include <openssl/md5.h>
-#else
#include "md5.h"
-#endif
#include <Alert.h>
#include <Catalog.h>
@@ -814,15 +810,11 @@ POP3Protocol::MD5Digest(unsigned char* in, char*
asciiDigest)
{
unsigned char digest[16];
-#ifdef USE_SSL
- MD5(in, ::strlen((char*)in), digest);
-#else
MD5_CTX context;
MD5Init(&context);
MD5Update(&context, in, ::strlen((char*)in));
MD5Final(digest, &context);
-#endif
for (int i = 0; i < 16; i++) {
sprintf(asciiDigest + 2 * i, "%02x", digest[i]);
############################################################################
Commit: 9980b6b47c8f81fb6324ee25e707448180c9151a
URL: http://cgit.haiku-os.org/haiku/commit/?id=9980b6b47c8f
Author: Augustin Cavalier <waddlesplash@xxxxxxxxx>
Date: Sat Jul 1 00:32:35 2017 UTC
IMAP: Remove direct usage of OpenSSL.
It already uses BSecureSocket without checking for USE_SSL,
so just assume we have SSL no matter what.
----------------------------------------------------------------------------
diff --git a/src/add-ons/mail_daemon/inbound_protocols/imap/ConfigView.cpp
b/src/add-ons/mail_daemon/inbound_protocols/imap/ConfigView.cpp
index 745642d..bc8a1c2 100644
--- a/src/add-ons/mail_daemon/inbound_protocols/imap/ConfigView.cpp
+++ b/src/add-ons/mail_daemon/inbound_protocols/imap/ConfigView.cpp
@@ -57,15 +57,11 @@ ConfigView::ConfigView(const BMailAccountSettings&
accountSettings,
| B_MAIL_PROTOCOL_HAS_PASSWORD | B_MAIL_PROTOCOL_HAS_HOSTNAME
| B_MAIL_PROTOCOL_CAN_LEAVE_MAIL_ON_SERVER
| B_MAIL_PROTOCOL_PARTIAL_DOWNLOAD
-#ifdef USE_SSL
| B_MAIL_PROTOCOL_HAS_FLAVORS
-#endif
)
{
-#ifdef USE_SSL
AddFlavor(B_TRANSLATE("No encryption"));
AddFlavor(B_TRANSLATE("SSL"));
-#endif
SetTo(settings);
diff --git a/src/add-ons/mail_daemon/inbound_protocols/imap/Jamfile
b/src/add-ons/mail_daemon/inbound_protocols/imap/Jamfile
index e5ab6ff..5a3379b 100644
--- a/src/add-ons/mail_daemon/inbound_protocols/imap/Jamfile
+++ b/src/add-ons/mail_daemon/inbound_protocols/imap/Jamfile
@@ -12,7 +12,9 @@ SubDirHdrs [ FDirName $(SUBDIR) imap_lib ] ;
SubDirHdrs [ FDirName $(HAIKU_TOP) headers os add-ons mail_daemon ] ;
-local sources =
+AddResources IMAP : IMAP.rdef ;
+
+Addon IMAP :
IMAPProtocol.cpp
ConfigView.cpp
FolderConfigWindow.cpp
@@ -26,20 +28,6 @@ local sources =
Commands.cpp
Protocol.cpp
Response.cpp
-;
-
-AddResources IMAP : IMAP.rdef ;
-
-if [ FIsBuildFeatureEnabled openssl ] {
- SubDirC++Flags -DUSE_SSL ;
- SetupFeatureObjectsDir ssl ;
-} else {
- SetupFeatureObjectsDir no-ssl ;
-}
-
-Addon IMAP
- :
- $(sources)
:
be libmail.so localestub $(TARGET_NETWORK_LIBS) libbnetapi.so
shared [ TargetLibsupc++ ] [ TargetLibstdc++ ]
############################################################################
Commit: c86d4971641329640a792246c3c61dff25b59400
URL: http://cgit.haiku-os.org/haiku/commit/?id=c86d49716413
Author: Augustin Cavalier <waddlesplash@xxxxxxxxx>
Date: Sat Jul 1 01:42:38 2017 UTC
SMTP: Remove STARTTLS support.
* It's vulnerable to man-in-the-middle attacks (which can't really be fixed)
* It's rather nasty to implement (and prevents us from using BSecureSocket)
* Nearly all servers I know of which support STARTTLS also support plain
TLS also.
----------------------------------------------------------------------------
diff --git a/src/add-ons/mail_daemon/outbound_protocols/smtp/ConfigView.cpp
b/src/add-ons/mail_daemon/outbound_protocols/smtp/ConfigView.cpp
index c66ccd9..620e4a5 100644
--- a/src/add-ons/mail_daemon/outbound_protocols/smtp/ConfigView.cpp
+++ b/src/add-ons/mail_daemon/outbound_protocols/smtp/ConfigView.cpp
@@ -49,12 +49,10 @@ SMTPConfigView::SMTPConfigView(const BMailAccountSettings&
settings)
{
B_TRANSLATE_MARK_VOID("Unencrypted");
B_TRANSLATE_MARK_VOID("SSL");
- B_TRANSLATE_MARK_VOID("STARTTLS");
#ifdef USE_SSL
AddFlavor(B_TRANSLATE_NOCOLLECT("Unencrypted"));
AddFlavor(B_TRANSLATE("SSL"));
- AddFlavor(B_TRANSLATE("STARTTLS"));
#endif
AddAuthMethod(B_TRANSLATE("None"), false);
diff --git a/src/add-ons/mail_daemon/outbound_protocols/smtp/SMTP.cpp
b/src/add-ons/mail_daemon/outbound_protocols/smtp/SMTP.cpp
index 4c0faee..25fdecd 100644
--- a/src/add-ons/mail_daemon/outbound_protocols/smtp/SMTP.cpp
+++ b/src/add-ons/mail_daemon/outbound_protocols/smtp/SMTP.cpp
@@ -374,7 +374,6 @@ SMTPProtocol::Open(const char *address, int port, bool
esmtp)
#ifdef USE_SSL
use_ssl = (fSettingsMessage.FindInt32("flavor") == 1);
- use_STARTTLS = (fSettingsMessage.FindInt32("flavor") == 2);
ssl = NULL;
ctx = NULL;
#endif
@@ -462,48 +461,6 @@ SMTPProtocol::Open(const char *address, int port, bool
esmtp)
return B_ERROR;
}
-#ifdef USE_SSL
- // Check for STARTTLS
- if (use_STARTTLS) {
- const char *res = fLog.String();
- char *p;
-
- SSL_library_init();
- RAND_seed(this,sizeof(SMTPProtocol));
- ::sprintf(cmd, "STARTTLS" CRLF);
-
- if ((p = ::strstr(res, "STARTTLS")) != NULL) {
- // Server advertises STARTTLS support
- if (SendCommand(cmd) != B_OK) {
- delete[] cmd;
- return B_ERROR;
- }
-
- // We should start TLS negotiation
- use_ssl = true;
- ctx = SSL_CTX_new(TLSv1_method());
- ssl = SSL_new(ctx);
- sbio = BIO_new_socket(fSocket,BIO_NOCLOSE);
- BIO_set_nbio(sbio, 0);
- SSL_set_bio(ssl, sbio, sbio);
- SSL_set_connect_state(ssl);
- if(SSL_do_handshake(ssl) != 1)
- return B_ERROR;
-
- // Should send EHLO command again
- if(!esmtp)
- ::sprintf(cmd, "HELO %s" CRLF, localhost);
- else
- ::sprintf(cmd, "EHLO %s" CRLF, localhost);
-
- if (SendCommand(cmd) != B_OK) {
- delete[] cmd;
- return B_ERROR;
- }
- }
- }
-#endif // USE_SSL
-
delete[] cmd;
// Check auth type
diff --git a/src/add-ons/mail_daemon/outbound_protocols/smtp/SMTP.h
b/src/add-ons/mail_daemon/outbound_protocols/smtp/SMTP.h
index 331043e..1ea0732 100644
--- a/src/add-ons/mail_daemon/outbound_protocols/smtp/SMTP.h
+++ b/src/add-ons/mail_daemon/outbound_protocols/smtp/SMTP.h
@@ -58,7 +58,6 @@ private:
BIO* sbio;
bool use_ssl;
- bool use_STARTTLS;
#endif
status_t fStatus;
diff --git a/src/preferences/mail/ProviderInfo/ReadMe
b/src/preferences/mail/ProviderInfo/ReadMe
index 0796821..690cf19 100644
--- a/src/preferences/mail/ProviderInfo/ReadMe
+++ b/src/preferences/mail/ProviderInfo/ReadMe
@@ -35,7 +35,6 @@ you can pass the following options to the last six items:
"SMTP SSL":
0 Unencrypted
1 SSL
- 2 STARTTLS
"Username Pattern":
0 username is the email address (default)
diff --git a/src/preferences/mail/ProviderInfo/shaw.ca.rdef
b/src/preferences/mail/ProviderInfo/shaw.ca.rdef
index 789ed18..d074089 100644
--- a/src/preferences/mail/ProviderInfo/shaw.ca.rdef
+++ b/src/preferences/mail/ProviderInfo/shaw.ca.rdef
@@ -5,5 +5,5 @@ resource(4, "POP Authentication") 0;
resource(5, "SMTP Authentication") 1;
resource(6, "POP SSL") 0;
resource(7, "IMAP SSL") 0;
-resource(8, "SMTP SSL") 2;
+resource(8, "SMTP SSL") 0;
resource(9, "Username Pattern") 1;
############################################################################
Commit: d1136c5a977d9a8357ea395060bbf4d028b09aa1
URL: http://cgit.haiku-os.org/haiku/commit/?id=d1136c5a977d
Author: Augustin Cavalier <waddlesplash@xxxxxxxxx>
Date: Sat Jul 1 03:32:24 2017 UTC
SMTP: Use B{Secure}Socket for communication.
----------------------------------------------------------------------------
diff --git a/src/add-ons/mail_daemon/outbound_protocols/smtp/ConfigView.cpp
b/src/add-ons/mail_daemon/outbound_protocols/smtp/ConfigView.cpp
index 620e4a5..fee7454 100644
--- a/src/add-ons/mail_daemon/outbound_protocols/smtp/ConfigView.cpp
+++ b/src/add-ons/mail_daemon/outbound_protocols/smtp/ConfigView.cpp
@@ -42,18 +42,11 @@ SMTPConfigView::SMTPConfigView(const BMailAccountSettings&
settings)
MailProtocolConfigView(B_MAIL_PROTOCOL_HAS_AUTH_METHODS
| B_MAIL_PROTOCOL_HAS_USERNAME | B_MAIL_PROTOCOL_HAS_PASSWORD
| B_MAIL_PROTOCOL_HAS_HOSTNAME
-#ifdef USE_SSL
| B_MAIL_PROTOCOL_HAS_FLAVORS
-#endif
)
{
- B_TRANSLATE_MARK_VOID("Unencrypted");
- B_TRANSLATE_MARK_VOID("SSL");
-
-#ifdef USE_SSL
- AddFlavor(B_TRANSLATE_NOCOLLECT("Unencrypted"));
+ AddFlavor(B_TRANSLATE("Unencrypted"));
AddFlavor(B_TRANSLATE("SSL"));
-#endif
AddAuthMethod(B_TRANSLATE("None"), false);
AddAuthMethod(B_TRANSLATE("ESMTP"));
diff --git a/src/add-ons/mail_daemon/outbound_protocols/smtp/Jamfile
b/src/add-ons/mail_daemon/outbound_protocols/smtp/Jamfile
index 59e2aa6..929ffc5 100644
--- a/src/add-ons/mail_daemon/outbound_protocols/smtp/Jamfile
+++ b/src/add-ons/mail_daemon/outbound_protocols/smtp/Jamfile
@@ -6,31 +6,15 @@ UsePrivateHeaders mail shared ;
SubDirHdrs [ FDirName $(HAIKU_TOP) headers os add-ons mail_daemon ] ;
-local sources =
+AddResources SMTP : SMTP.rdef ;
+
+Addon SMTP :
ConfigView.cpp
SMTP.cpp
md5c.c
-;
-
-# use OpenSSL, if enabled
-if [ FIsBuildFeatureEnabled openssl ] {
- SubDirC++Flags -DUSE_SSL ;
- UseBuildFeatureHeaders openssl ;
- Includes [ FGristFiles $(sources) ]
- : [ BuildFeatureAttribute openssl : headers ] ;
- # Dependency needed to trigger downloading/unzipping the
package before
- # compiling the files.
- SetupFeatureObjectsDir ssl ;
-} else {
- SetupFeatureObjectsDir no-ssl ;
-}
-
-AddResources SMTP : SMTP.rdef ;
-
-Addon SMTP
- : $(sources)
- : be libmail.so $(TARGET_NETWORK_LIBS) [ TargetLibstdc++ ]
- localestub [ BuildFeatureAttribute openssl : libraries ]
+ : be libbnetapi.so libmail.so localestub
+ [ TargetLibstdc++ ] [ TargetLibsupc++ ]
+ $(TARGET_NETWORK_LIBS)
;
DoCatalogs SMTP :
diff --git a/src/add-ons/mail_daemon/outbound_protocols/smtp/SMTP.cpp
b/src/add-ons/mail_daemon/outbound_protocols/smtp/SMTP.cpp
index 25fdecd..8143631 100644
--- a/src/add-ons/mail_daemon/outbound_protocols/smtp/SMTP.cpp
+++ b/src/add-ons/mail_daemon/outbound_protocols/smtp/SMTP.cpp
@@ -14,14 +14,10 @@
#include <map>
-#include <arpa/inet.h>
#include <ctype.h>
#include <errno.h>
-#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
-#include <sys/select.h>
-#include <sys/socket.h>
#include <sys/time.h>
#include <unistd.h>
@@ -33,6 +29,8 @@
#include <MenuField.h>
#include <Message.h>
#include <Path.h>
+#include <Socket.h>
+#include <SecureSocket.h>
#include <TextControl.h>
#include <crypt.h>
@@ -41,11 +39,7 @@
#include <NodeMessage.h>
#include <ProtocolConfigView.h>
-#ifdef USE_SSL
-# include <openssl/md5.h>
-#else
-# include "md5.h"
-#endif
+#include "md5.h"
#undef B_TRANSLATION_CONTEXT
@@ -291,12 +285,10 @@ SMTPProtocol::Connect()
if (fSettingsMessage.FindInt32("port") > 0)
errorMessage << ":" <<
fSettingsMessage.FindInt32("port");
- // << strerror(err) - BNetEndpoint sucks, we can't use this;
if (fLog.Length() > 0)
errorMessage << B_TRANSLATE(". The server says:\n") <<
fLog;
else {
- errorMessage
- << B_TRANSLATE(": Connection refused or host
not found.");
+ errorMessage << ". " << strerror(status);
}
ShowError(errorMessage.String());
@@ -353,7 +345,7 @@ SMTPProtocol::HandleSendMessages(const BMessage& message,
off_t totalBytes)
if (status != B_OK) {
BString error;
error << "An error occurred while sending the message "
- << ref.name << ":\n" << fLog;
+ << ref.name << " (" << strerror(status) <<
"):\n" << fLog;
ShowError(error.String());
ResetProgress();
@@ -372,83 +364,49 @@ SMTPProtocol::Open(const char *address, int port, bool
esmtp)
{
ReportProgress(0, 0, B_TRANSLATE("Connecting to server"
B_UTF8_ELLIPSIS));
- #ifdef USE_SSL
- use_ssl = (fSettingsMessage.FindInt32("flavor") == 1);
- ssl = NULL;
- ctx = NULL;
- #endif
+ use_ssl = (fSettingsMessage.FindInt32("flavor") == 1);
if (port <= 0)
- #ifdef USE_SSL
port = use_ssl ? 465 : 25;
- #else
- port = 25;
- #endif
-
- uint32 hostIP = inet_addr(address); // first see if we can parse it as
a numeric address
- if ((hostIP == 0)||(hostIP == (uint32)-1)) {
- struct hostent * he = gethostbyname(address);
- hostIP = he ? *((uint32*)he->h_addr) : 0;
- }
- if (hostIP == 0)
- return EHOSTUNREACH;
-
- fSocket = socket(AF_INET, SOCK_STREAM, 0);
- if (fSocket < 0)
- return errno;
-
- struct sockaddr_in saAddr;
- memset(&saAddr, 0, sizeof(saAddr));
- saAddr.sin_family = AF_INET;
- saAddr.sin_port = htons(port);
- saAddr.sin_addr.s_addr = hostIP;
- int result = connect(fSocket, (struct sockaddr *)&saAddr,
- sizeof(saAddr));
- if (result < 0) {
- close(fSocket);
- fSocket = -1;
- return errno;
+ BNetworkAddress addr(address);
+ if (addr.InitCheck() != B_OK) {
+ BString str;
+ str.SetToFormat("Invalid network address for SMTP server: %s",
+ strerror(addr.InitCheck()));
+ ShowError(str.String());
+ return addr.InitCheck();
}
+
+ if (addr.Port() == 0)
+ addr.SetPort(port);
-#ifdef USE_SSL
- if (use_ssl) {
- SSL_library_init();
- SSL_load_error_strings();
- RAND_seed(this,sizeof(SMTPProtocol));
- /*--- Because we're an add-on loaded at an unpredictable time, all
- the memory addresses and things contained in ourself are
- esssentially random. */
-
- ctx = SSL_CTX_new(SSLv23_method());
- ssl = SSL_new(ctx);
- sbio=BIO_new_socket(fSocket,BIO_NOCLOSE);
- SSL_set_bio(ssl,sbio,sbio);
-
- if (SSL_connect(ssl) <= 0) {
- BString error;
- error << "Could not connect to SMTP server "
- << fSettingsMessage.FindString("server");
- if (port != 465)
- error << ":" << port;
- error << ". (SSL connection error)";
- ShowError(error.String());
- SSL_CTX_free(ctx);
- close(fSocket);
- fSocket = -1;
- return B_ERROR;
- }
+ if (use_ssl)
+ fSocket = new(std::nothrow) BSecureSocket;
+ else
+ fSocket = new(std::nothrow) BSocket;
+
+ if (!fSocket)
+ return B_NO_MEMORY;
+
+ if (fSocket->Connect(addr) != B_OK) {
+ BString error;
+ error << "Could not connect to SMTP server "
+ << fSettingsMessage.FindString("server");
+ error << ":" << addr.Port();
+ ShowError(error.String());
+ delete fSocket;
+ return B_ERROR;
}
-#endif // USE_SSL
BString line;
ReceiveResponse(line);
char localhost[255];
- gethostname(localhost,255);
+ gethostname(localhost, 255);
if (localhost[0] == 0)
- strcpy(localhost,"namethisbebox");
+ strcpy(localhost, "namethisbebox");
char *cmd = new char[::strlen(localhost)+8];
if (!esmtp)
@@ -749,16 +707,7 @@ SMTPProtocol::Close()
// Error
}
-#ifdef USE_SSL
- if (use_ssl) {
- if (ssl)
- SSL_shutdown(ssl);
- if (ctx)
- SSL_CTX_free(ctx);
- }
-#endif
-
- close(fSocket);
+ delete fSocket;
}
@@ -838,16 +787,7 @@ SMTPProtocol::Send(const char* to, const char* from,
BPositionIO *message)
if (data[i] == '\r' && data[i+1] == '\n' && data[i+2]
== '.') {
foundCRLFPeriod = true;
// Send data up to the CRLF, and include the
period too.
-#ifdef USE_SSL
- if (use_ssl) {
- if (SSL_write(ssl,data,i + 3) < 0) {
- amountUnread = 0; // Stop when
an error happens.
- bufferLen = 0;
- break;
- }
- } else
-#endif
- if (send (fSocket,data, i + 3,0) < 0) {
+ if (fSocket->Write(data, i + 3) < 0) {
amountUnread = 0; // Stop when an error
happens.
bufferLen = 0;
break;
@@ -864,14 +804,7 @@ SMTPProtocol::Send(const char* to, const char* from,
BPositionIO *message)
if (!foundCRLFPeriod) {
if (amountUnread <= 0) { // No more data, all we have
is in the buffer.
if (bufferLen > 0) {
-#ifdef USE_SSL
- if (use_ssl)
- SSL_write(ssl, data, bufferLen);
- else
- send(fSocket, data, bufferLen,
0);
-#else
- send(fSocket, data, bufferLen, 0);
-#endif
+ fSocket->Write(data, bufferLen);
ReportProgress(bufferLen, 0);
if (bufferLen >= 2)
messageEndedWithCRLF =
(data[bufferLen-2] == '\r' &&
@@ -883,18 +816,9 @@ SMTPProtocol::Send(const char* to, const char* from,
BPositionIO *message)
// Send most of the buffer, except a few characters to
overlap with
// the next read, in case the CRLFPeriod is split
between reads.
if (bufferLen > 3) {
-#ifdef USE_SSL
- if (use_ssl) {
- if (SSL_write(ssl, data, bufferLen - 3)
< 0)
- break;
- } else {
- if (send(fSocket, data, bufferLen - 3,
0) < 0)
- break; // Stop when an error
happens.
- }
-#else
- if (send(fSocket, data, bufferLen - 3, 0) < 0)
+ if (fSocket->Write(data, bufferLen - 3) < 0)
break; // Stop when an error happens.
-#endif
+
ReportProgress(bufferLen - 3, 0);
memmove (data, data + bufferLen - 3, 3);
bufferLen = 3;
@@ -927,42 +851,14 @@ SMTPProtocol::ReceiveResponse(BString &out)
int32 errCode;
BString searchStr = "";
- struct timeval tv;
- struct fd_set fds;
-
- tv.tv_sec = long(timeout / 1e6);
- tv.tv_usec = long(timeout-(tv.tv_sec * 1e6));
-
- /* Initialize (clear) the socket mask. */
- FD_ZERO(&fds);
-
- /* Set the socket in the mask. */
- FD_SET(fSocket, &fds);
- int result = -1;
-#ifdef USE_SSL
- if ((use_ssl) && (SSL_pending(ssl)))
- result = 1;
- else
-#endif
- result = select(1 + fSocket, &fds, NULL, NULL, &tv);
- if (result < 0)
- return errno;
-
- if (result > 0) {
+ if (fSocket->WaitForReadable(timeout) == B_OK) {
while (1) {
- #ifdef USE_SSL
- if (use_ssl)
- r = SSL_read(ssl,buf,SMTP_RESPONSE_SIZE - 1);
- else
- #endif
- r = recv(fSocket,buf, SMTP_RESPONSE_SIZE - 1,0);
+ r = fSocket->Read(buf, SMTP_RESPONSE_SIZE - 1);
if (r <= 0)
break;
- if (!gotCode)
- {
- if (buf[3] == ' ' || buf[3] == '-')
- {
+ if (!gotCode) {
+ if (buf[3] == ' ' || buf[3] == '-') {
errCode = atol(buf);
gotCode = true;
searchStr << errCode << ' ';
@@ -990,13 +886,7 @@ SMTPProtocol::SendCommand(const char *cmd)
{
D(bug("C:%s\n", cmd));
-#ifdef USE_SSL
- if (use_ssl && ssl) {
- if (SSL_write(ssl,cmd,::strlen(cmd)) < 0)
- return B_ERROR;
- } else
-#endif
- if (send(fSocket,cmd, ::strlen(cmd),0) < 0)
+ if (fSocket->Write(cmd, ::strlen(cmd)) < 0)
return B_ERROR;
fLog = "";
diff --git a/src/add-ons/mail_daemon/outbound_protocols/smtp/SMTP.h
b/src/add-ons/mail_daemon/outbound_protocols/smtp/SMTP.h
index 1ea0732..7af6d8a 100644
--- a/src/add-ons/mail_daemon/outbound_protocols/smtp/SMTP.h
+++ b/src/add-ons/mail_daemon/outbound_protocols/smtp/SMTP.h
@@ -15,10 +15,8 @@
#include <MailProtocol.h>
#include <MailSettings.h>
-#ifdef USE_SSL
-# include <openssl/ssl.h>
-# include <openssl/rand.h>
-#endif
+
+class BSocket;
class SMTPProtocol : public BOutboundMailProtocol {
@@ -47,18 +45,12 @@ private:
status_t _SendMessage(const
entry_ref& ref);
status_t _POP3Authentication();
- int fSocket;
+ BSocket* fSocket;
BString fLog;
BMessage fSettingsMessage;
int32 fAuthType;
-#ifdef USE_SSL
- SSL_CTX* ctx;
- SSL* ssl;
- BIO* sbio;
-
bool use_ssl;
-#endif
status_t fStatus;
BString fServerName; //
required for DIGEST-MD5
############################################################################
Revision: hrev51241
Commit: 6a075fc1af9ff6536a76272781ccd7ae62b6d18d
URL: http://cgit.haiku-os.org/haiku/commit/?id=6a075fc1af9f
Author: Augustin Cavalier <waddlesplash@xxxxxxxxx>
Date: Sat Jul 1 08:58:05 2017 UTC
POP3: Actually return B_TIMED_OUT not just B_ERROR on timeouts.
----------------------------------------------------------------------------
diff --git a/src/add-ons/mail_daemon/inbound_protocols/pop3/POP3.cpp
b/src/add-ons/mail_daemon/inbound_protocols/pop3/POP3.cpp
index 8c796c6..75b95dd 100644
--- a/src/add-ons/mail_daemon/inbound_protocols/pop3/POP3.cpp
+++ b/src/add-ons/mail_daemon/inbound_protocols/pop3/POP3.cpp
@@ -603,7 +603,7 @@ POP3Protocol::RetrieveInternal(const char* command, int32
message,
if (result == B_TIMED_OUT) {
// No data available, even after waiting a minute.
fLog = "POP3 timeout - no data received after a long
wait.";
- return B_ERROR;
+ return B_TIMED_OUT;
}
if (amountToReceive > bufSize - 1 - amountInBuffer)
amountToReceive = bufSize - 1 - amountInBuffer;