* If USE_SSL is set when compiling the MDR add-ons, SSL will be used.

* By default, it will use a directory generated/cross-ssl where you need to
  unzip the optional openssl package into before. If you're on Haiku, you can
  use the SSL_DIR environment variable to point it to /boot/home/config
  instead.
* Fixed build with USE_SSL defined.
* Renamed USESSL to USE_SSL.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26971 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2008-08-14 12:28:44 +00:00
parent 6a5919034d
commit ad12e71861
9 changed files with 377 additions and 332 deletions
@@ -11,9 +11,14 @@ UsePrivateHeaders mail ;
SubDirHdrs [ FDirName $(HAIKU_TOP) headers os add-ons mail_daemon ] ;
if $(USESSL) {
SubDirC++Flags -DUSESSL ;
SubDirHdrs [ FDirName / boot home config include ] ;
if $(USE_SSL) {
SubDirC++Flags -DUSE_SSL ;
if ! $(SSL_DIR) {
sslDir = [ FDirName $(HAIKU_OUTPUT_DIR) cross-ssl config ] ;
} else {
sslDir = $(SSL_DIR) ;
}
SubDirSysHdrs [ FDirName $(sslDir) include ] ;
}
Addon IMAP :
@@ -23,8 +28,8 @@ Addon IMAP :
LinkAgainst IMAP : be libmail.so $(TARGET_NETWORK_LIBS) ;
if $(USESSL) {
LinkAgainst IMAP : ssl crypto ;
if $(USE_SSL) {
LinkAgainst IMAP : $(sslDir)/lib/libssl.so $(sslDir)/lib/libcrypto.so ;
}
Package haiku-maildaemon-cvs :
@@ -1,3 +1,10 @@
/*
* Copyright 2007-2008, Haiku Inc. All Rights Reserved.
* Copyright 2001-2002 Dr. Zoidberg Enterprises. All rights reserved.
*
* Distributed under the terms of the MIT License.
*/
#include <RemoteStorageProtocol.h>
#include <E-mail.h>
#include <netdb.h>
@@ -22,13 +29,13 @@
#include <sys/socket.h>
#include <sys/time.h>
#ifndef HAIKU_TARGET_PLATFORM_BEOS // These headers don't exist in BeOS R5.
#include <arpa/inet.h>
#include <sys/select.h>
# include <arpa/inet.h>
# include <sys/select.h>
#endif
#ifdef USESSL
#include <openssl/ssl.h>
#include <openssl/rand.h>
#ifdef USE_SSL
# include <openssl/ssl.h>
# include <openssl/rand.h>
#endif
#include "NestedString.h"
@@ -96,7 +103,7 @@ class IMAP4Client : public BRemoteMailStorageProtocol {
BList box_info;
status_t err;
#ifdef USESSL
#ifdef USE_SSL
SSL_CTX *ctx;
SSL *ssl;
BIO *sbio;
@@ -129,7 +136,7 @@ IMAP4Client::IMAP4Client(BMessage *settings, BMailChainRunner *run) : BRemoteMai
err = B_OK;
mb_root = settings->FindString("root");
#ifdef USESSL
#ifdef USE_SSL
use_ssl = (settings->FindInt32("flavor") == 1);
ssl = NULL;
ctx = NULL;
@@ -138,7 +145,7 @@ IMAP4Client::IMAP4Client(BMessage *settings, BMailChainRunner *run) : BRemoteMai
int port = settings->FindInt32("port");
if (port <= 0)
#ifdef USESSL
#ifdef USE_SSL
port = use_ssl ? 993 : 143;
#else
port = 143;
@@ -204,7 +211,7 @@ IMAP4Client::IMAP4Client(BMessage *settings, BMailChainRunner *run) : BRemoteMai
return;
}
#ifdef USESSL
#ifdef USE_SSL
if (use_ssl) {
SSL_library_init();
SSL_load_error_strings();
@@ -288,7 +295,7 @@ IMAP4Client::~IMAP4Client() {
SendCommand("CLOSE");
SendCommand("LOGOUT");
#ifdef USESSL
#ifdef USE_SSL
if (use_ssl) {
if (ssl)
SSL_shutdown(ssl);
@@ -439,7 +446,7 @@ status_t IMAP4Client::AddMessage(const char *mailbox, BPositionIO *data, BString
char *buffer = new char[size];
data->ReadAt(0,buffer,size);
#ifdef USESSL
#ifdef USE_SSL
if (use_ssl) {
SSL_write(ssl,buffer,size);
SSL_write(ssl,"\r\n",2);
@@ -905,7 +912,7 @@ IMAP4Client::SendCommand(const char* command)
static char cmd[255];
::sprintf(cmd,"a%.7ld %s"CRLF,++commandCount,command);
#ifdef USESSL
#ifdef USE_SSL
if (use_ssl)
SSL_write(ssl,cmd,strlen(cmd));
else
@@ -939,7 +946,7 @@ IMAP4Client::ReceiveLine(BString &out)
/* Set the socket in the mask. */
FD_SET(net, &fds);
int result;
#ifdef USESSL
#ifdef USE_SSL
if ((use_ssl) && (SSL_pending(ssl)))
result = 1;
else
@@ -953,7 +960,7 @@ IMAP4Client::ReceiveLine(BString &out)
{
while(c != '\n' && c != xEOF)
{
#ifdef USESSL
#ifdef USE_SSL
if (use_ssl)
r = SSL_read(ssl,&c,1);
else
@@ -962,7 +969,7 @@ IMAP4Client::ReceiveLine(BString &out)
if(r <= 0) {
BString error;
error << "Connection to " << settings->FindString("server") << " lost.";
#ifdef USESSL
#ifdef USE_SSL
if (use_ssl) {
if (ssl)
SSL_shutdown(ssl);
@@ -1019,7 +1026,7 @@ int IMAP4Client::GetResponse(BString &tag, NestedString *parsed_response, bool r
/* Set the socket in the mask. */
FD_SET(net, &fds);
#ifdef USESSL
#ifdef USE_SSL
if ((use_ssl) && (SSL_pending(ssl)))
result = 1;
else
@@ -1037,7 +1044,7 @@ int IMAP4Client::GetResponse(BString &tag, NestedString *parsed_response, bool r
{
while(c != '\n' && c != xEOF)
{
#ifdef USESSL
#ifdef USE_SSL
if (use_ssl)
r = SSL_read(ssl,&c,1);
else
@@ -1046,7 +1053,7 @@ int IMAP4Client::GetResponse(BString &tag, NestedString *parsed_response, bool r
if(r <= 0) {
BString error;
error << "Connection to " << settings->FindString("server") << " lost.";
#ifdef USESSL
#ifdef USE_SSL
if (use_ssl) {
if (ssl)
SSL_shutdown(ssl);
@@ -1110,7 +1117,7 @@ int IMAP4Client::GetResponse(BString &tag, NestedString *parsed_response, bool r
int read_octets = 0;
int nibble_size;
while (read_octets < octets_to_read) {
#ifdef USESSL
#ifdef USE_SSL
if (use_ssl)
nibble_size = SSL_read(ssl,buffer + read_octets,octets_to_read - read_octets);
else
@@ -1,8 +1,11 @@
/* IMAPConfig - config view for the IMAP protocol add-on
**
** Copyright 2001 Dr. Zoidberg Enterprises. All rights reserved.
*/
/*
* Copyright 2007-2008, Haiku Inc. All Rights Reserved.
* Copyright 2001-2002 Dr. Zoidberg Enterprises. All rights reserved.
*
* Distributed under the terms of the MIT License.
*/
//! config view for the IMAP protocol add-on
#include <TextControl.h>
@@ -11,24 +14,29 @@
#include <MDRLanguage.h>
class IMAPConfig : public BMailProtocolConfigView {
public:
IMAPConfig(BMessage *archive);
virtual ~IMAPConfig();
virtual status_t Archive(BMessage *into, bool deep = true) const;
virtual void GetPreferredSize(float *width, float *height);
public:
IMAPConfig(BMessage *archive);
virtual ~IMAPConfig();
virtual status_t Archive(BMessage *into, bool deep = true) const;
virtual void GetPreferredSize(float *width, float *height);
};
IMAPConfig::IMAPConfig(BMessage *archive)
: BMailProtocolConfigView(B_MAIL_PROTOCOL_HAS_USERNAME | B_MAIL_PROTOCOL_HAS_PASSWORD | B_MAIL_PROTOCOL_HAS_HOSTNAME | B_MAIL_PROTOCOL_CAN_LEAVE_MAIL_ON_SERVER
#ifdef USESSL
| B_MAIL_PROTOCOL_HAS_FLAVORS)
: BMailProtocolConfigView(B_MAIL_PROTOCOL_HAS_USERNAME
| B_MAIL_PROTOCOL_HAS_PASSWORD | B_MAIL_PROTOCOL_HAS_HOSTNAME
| B_MAIL_PROTOCOL_CAN_LEAVE_MAIL_ON_SERVER
#ifdef USE_SSL
| B_MAIL_PROTOCOL_HAS_FLAVORS
#endif
)
{
#ifdef USE_SSL
AddFlavor("No Encryption");
AddFlavor("SSL");
#else
) {
#endif
#endif
SetTo(archive);
@@ -11,9 +11,16 @@ UsePrivateHeaders mail ;
SubDirHdrs [ FDirName $(HAIKU_TOP) headers os add-ons mail_daemon ] ;
if $(USESSL) {
SubDirC++Flags -DUSESSL ;
SubDirHdrs [ FDirName / boot home config include ] ;
local sslDir ;
if $(USE_SSL) {
SubDirC++Flags -DUSE_SSL ;
if ! $(SSL_DIR) {
sslDir = [ FDirName $(HAIKU_OUTPUT_DIR) cross-ssl config ] ;
} else {
sslDir = $(SSL_DIR) ;
}
SubDirSysHdrs [ FDirName $(sslDir) include ] ;
}
Addon POP3 :
@@ -24,8 +31,8 @@ Addon POP3 :
LinkAgainst POP3 : be libmail.so $(TARGET_NETWORK_LIBS) ;
if $(USESSL) {
LinkAgainst POP3 : ssl crypto ;
if $(USE_SSL) {
LinkAgainst POP3 : $(sslDir)/lib/libssl.so $(sslDir)/lib/libcrypto.so ;
}
Package haiku-maildaemon-cvs :
@@ -1,6 +1,6 @@
/*
* Copyright 2007-2008, Haiku Inc. All Rights Reserved.
* Copyright 2001-2002 Dr. Zoidberg Enterprises. All rights reserved.
* Copyright 2007, Haiku Inc. All Rights Reserved.
*
* Distributed under the terms of the MIT License.
*/
@@ -19,16 +19,16 @@
#ifndef HAIKU_TARGET_PLATFORM_BEOS
// These headers don't exist in BeOS R5.
#include <arpa/inet.h>
#include <sys/select.h>
# include <arpa/inet.h>
# include <sys/select.h>
#endif
#if USESSL
#include <openssl/ssl.h>
#include <openssl/rand.h>
#include <openssl/md5.h>
#if USE_SSL
# include <openssl/ssl.h>
# include <openssl/rand.h>
# include <openssl/md5.h>
#else
#include "md5.h"
# include "md5.h"
#endif
#include <DataIO.h>
@@ -51,7 +51,7 @@ POP3Protocol::POP3Protocol(BMessage *settings, BMailChainRunner *status)
fNumMessages(-1),
fMailDropSize(0)
{
#ifdef USESSL
#ifdef USE_SSL
fUseSSL = (settings->FindInt32("flavor") == 1);
#endif
Init();
@@ -60,12 +60,12 @@ POP3Protocol::POP3Protocol(BMessage *settings, BMailChainRunner *status)
POP3Protocol::~POP3Protocol()
{
#ifdef USESSL
#ifdef USE_SSL
if (!fUseSSL || fSSL)
#endif
SendCommand("QUIT" CRLF);
#ifdef USESSL
#ifdef USE_SSL
if (fUseSSL) {
if (fSSL)
SSL_shutdown(fSSL);
@@ -89,7 +89,7 @@ POP3Protocol::Open(const char *server, int port, int)
"POP3サーバに接続しています..."));
if (port <= 0) {
#ifdef USESSL
#ifdef USE_SSL
port = fUseSSL ? 995 : 110;
#else
port = 110;
@@ -149,7 +149,7 @@ POP3Protocol::Open(const char *server, int port, int)
return B_ERROR;
}
#ifdef USESSL
#ifdef USE_SSL
if (fUseSSL) {
SSL_library_init();
SSL_load_error_strings();
@@ -412,7 +412,7 @@ POP3Protocol::RetrieveInternal(const char *command, int32 message,
while (cont) {
int result = 0;
#ifdef USESSL
#ifdef USE_SSL
if (fUseSSL && SSL_pending(fSSL))
result = 1;
else
@@ -426,7 +426,7 @@ POP3Protocol::RetrieveInternal(const char *command, int32 message,
}
if (amountToReceive > bufSize - 1 - amountInBuffer)
amountToReceive = bufSize - 1 - amountInBuffer;
#ifdef USESSL
#ifdef USE_SSL
if (fUseSSL) {
amountReceived = SSL_read(fSSL, buf + amountInBuffer,
amountToReceive);
@@ -594,7 +594,7 @@ POP3Protocol::ReceiveLine(BString &line)
FD_SET(fSocket, &readSet);
int result;
#ifdef USESSL
#ifdef USE_SSL
if (fUseSSL && SSL_pending(fSSL))
result = 1;
else
@@ -606,7 +606,7 @@ POP3Protocol::ReceiveLine(BString &line)
// Hope there's an end of line out there else this gets stuck.
int32 bytesReceived;
uint8 c = 0;
#ifdef USESSL
#ifdef USE_SSL
if (fUseSSL)
bytesReceived = SSL_read(fSSL, (char*)&c, 1);
else
@@ -657,7 +657,7 @@ POP3Protocol::SendCommand(const char *cmd)
FD_ZERO(&readSet);
FD_SET(fSocket, &readSet);
int result;
#ifdef USESSL
#ifdef USE_SSL
if (fUseSSL && SSL_pending(fSSL))
result = 1;
else
@@ -667,7 +667,7 @@ POP3Protocol::SendCommand(const char *cmd)
if (result > 0) {
int amountReceived;
char tempString [1025];
#ifdef USESSL
#ifdef USE_SSL
if (fUseSSL)
amountReceived = SSL_read(fSSL, tempString, sizeof(tempString) - 1);
else
@@ -683,7 +683,7 @@ POP3Protocol::SendCommand(const char *cmd)
// break;
}
#ifdef USESSL
#ifdef USE_SSL
if (fUseSSL) {
SSL_write(fSSL, cmd,::strlen(cmd));
} else
@@ -726,7 +726,7 @@ POP3Protocol::MD5Digest(unsigned char *in, char *asciiDigest)
{
unsigned char digest[16];
#ifdef USESSL
#ifdef USE_SSL
MD5(in, ::strlen((char*)in), digest);
#else
MD5_CTX context;
@@ -761,14 +761,14 @@ instantiate_config_panel(BMessage *settings, BMessage *)
B_MAIL_PROTOCOL_HAS_USERNAME | B_MAIL_PROTOCOL_HAS_AUTH_METHODS
| B_MAIL_PROTOCOL_HAS_PASSWORD | B_MAIL_PROTOCOL_HAS_HOSTNAME
| B_MAIL_PROTOCOL_CAN_LEAVE_MAIL_ON_SERVER
#if USESSL
#if USE_SSL
| B_MAIL_PROTOCOL_HAS_FLAVORS
#endif
);
view->AddAuthMethod("Plain Text");
view->AddAuthMethod("APOP");
#if USESSL
#if USE_SSL
view->AddFlavor("No Encryption");
view->AddFlavor("SSL");
#endif
@@ -1,6 +1,6 @@
/*
* Copyright 2007-2008, Haiku Inc. All Rights Reserved.
* Copyright 2001-2002 Dr. Zoidberg Enterprises. All rights reserved.
* Copyright 2007, Haiku Inc. All Rights Reserved.
*
* Distributed under the terms of the MIT License.
*/
@@ -10,6 +10,10 @@
#include <map>
#ifdef USE_SSL
# include <openssl/ssl.h>
#endif
#include <List.h>
#include <String.h>
@@ -47,7 +51,7 @@ private:
size_t fMailDropSize;
BList fSizes;
#ifdef USESSL
#ifdef USE_SSL
SSL_CTX* fSSLContext;
SSL* fSSL;
BIO* fSSLBio;
@@ -11,9 +11,14 @@ UsePrivateHeaders mail ;
SubDirHdrs [ FDirName $(HAIKU_TOP) headers os add-ons mail_daemon ] ;
if $(USESSL) {
SubDirC++Flags -DUSESSL ;
SubDirHdrs [ FDirName / boot home config include ] ;
if $(USE_SSL) {
SubDirC++Flags -DUSE_SSL ;
if ! $(SSL_DIR) {
sslDir = [ FDirName $(HAIKU_OUTPUT_DIR) cross-ssl config ] ;
} else {
sslDir = $(SSL_DIR) ;
}
SubDirSysHdrs [ FDirName $(sslDir) include ] ;
}
Addon SMTP :
@@ -22,8 +27,8 @@ Addon SMTP :
LinkAgainst SMTP : be libmail.so $(TARGET_NETWORK_LIBS) ;
if $(USESSL) {
LinkAgainst SMTP : ssl crypto ;
if $(USE_SSL) {
LinkAgainst SMTP : $(sslDir)/lib/libssl.so $(sslDir)/lib/libcrypto.so ;
}
Package haiku-maildaemon-cvs :
@@ -1,7 +1,11 @@
/* SMTPProtocol - implementation of the SMTP protocol
**
** Copyright 2001 Dr. Zoidberg Enterprises. All rights reserved.
*/
/*
* Copyright 2007-2008, Haiku Inc. All Rights Reserved.
* Copyright 2001-2002 Dr. Zoidberg Enterprises. All rights reserved.
*
* Distributed under the terms of the MIT License.
*/
//! implementation of the SMTP protocol
#include <DataIO.h>
#include <Message.h>
@@ -19,8 +23,8 @@
#include <sys/time.h>
#include <sys/socket.h>
#ifndef HAIKU_TARGET_PLATFORM_BEOS // These headers don't exist in BeOS R5.
#include <arpa/inet.h>
#include <sys/select.h>
# include <arpa/inet.h>
# include <sys/select.h>
#endif
#include <status.h>
@@ -34,8 +38,10 @@
#include <map>
#include "smtp.h"
#ifndef USESSL
#include "md5.h"
#ifdef USE_SSL
# include <openssl/md5.h>
#else
# include "md5.h"
#endif
#include <MDRLanguage.h>
@@ -350,14 +356,14 @@ SMTPProtocol::Open(const char *address, int port, bool esmtp)
{
runner->ReportProgress(0, 0, MDR_DIALECT_CHOICE ("Connecting to server...","接続中..."));
#ifdef USESSL
#ifdef USE_SSL
use_ssl = (fSettings->FindInt32("flavor") == 1);
ssl = NULL;
ctx = NULL;
#endif
if (port <= 0)
#ifdef USESSL
#ifdef USE_SSL
port = use_ssl ? 465 : 25;
#else
port = 25;
@@ -397,7 +403,7 @@ SMTPProtocol::Open(const char *address, int port, bool esmtp)
return errno;
}
#ifdef USESSL
#ifdef USE_SSL
if (use_ssl) {
SSL_library_init();
SSL_load_error_strings();
@@ -749,7 +755,7 @@ SMTPProtocol::Close()
// Error
}
#ifdef USESSL
#ifdef USE_SSL
if (use_ssl) {
if (ssl)
SSL_shutdown(ssl);
@@ -844,7 +850,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 USESSL
#ifdef USE_SSL
if (use_ssl) {
if (SSL_write(ssl,data,i + 3) < 0) {
amountUnread = 0; // Stop when an error happens.
@@ -870,7 +876,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 USESSL
#ifdef USE_SSL
if (use_ssl)
SSL_write(ssl,data,bufferLen);
else
@@ -887,7 +893,7 @@ 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 USESSL
#ifdef USE_SSL
if (use_ssl) {
if (SSL_write(ssl,data,bufferLen - 3) < 0)
break;
@@ -940,7 +946,7 @@ SMTPProtocol::ReceiveResponse(BString &out)
/* Set the socket in the mask. */
FD_SET(_fd, &fds);
int result = -1;
#ifdef USESSL
#ifdef USE_SSL
if ((use_ssl) && (SSL_pending(ssl)))
result = 1;
else
@@ -951,7 +957,7 @@ SMTPProtocol::ReceiveResponse(BString &out)
if (result > 0) {
while (1) {
#ifdef USESSL
#ifdef USE_SSL
if (use_ssl)
r = SSL_read(ssl,buf,SMTP_RESPONSE_SIZE - 1);
else
@@ -991,7 +997,7 @@ SMTPProtocol::SendCommand(const char *cmd)
{
D(bug("C:%s\n", cmd));
#ifdef USESSL
#ifdef USE_SSL
if (use_ssl && ssl) {
if (SSL_write(ssl,cmd,::strlen(cmd)) < 0)
return B_ERROR;
@@ -1039,7 +1045,7 @@ instantiate_mailfilter(BMessage *settings, BMailChainRunner *status)
BView *
instantiate_config_panel(BMessage *settings, BMessage *)
{
#ifdef USESSL
#ifdef USE_SSL
BMailProtocolConfigView *view = new BMailProtocolConfigView(B_MAIL_PROTOCOL_HAS_AUTH_METHODS |
B_MAIL_PROTOCOL_HAS_USERNAME |
B_MAIL_PROTOCOL_HAS_PASSWORD |
@@ -1,20 +1,23 @@
/*
* Copyright 2007-2008, Haiku Inc. All Rights Reserved.
* Copyright 2001-2002 Dr. Zoidberg Enterprises. All rights reserved.
*
* Distributed under the terms of the MIT License.
*/
#ifndef ZOIDBERG_SMTP_H
#define ZOIDBERG_SMTP_H
/* SMTPProtocol - implementation of the SMTP protocol
**
** Copyright 2001 Dr. Zoidberg Enterprises. All rights reserved.
*/
#include <String.h>
#include <MailAddon.h>
#ifdef USESSL
#include <openssl/ssl.h>
#include <openssl/rand.h>
#ifdef USE_SSL
# include <openssl/ssl.h>
# include <openssl/rand.h>
#endif
class SMTPProtocol : public BMailFilter {
public:
SMTPProtocol(BMessage *message, BMailChainRunner *runner);
@@ -42,13 +45,13 @@ class SMTPProtocol : public BMailFilter {
BMailChainRunner *runner;
int32 fAuthType;
#ifdef USESSL
SSL_CTX *ctx;
SSL *ssl;
BIO *sbio;
#ifdef USE_SSL
SSL_CTX *ctx;
SSL *ssl;
BIO *sbio;
bool use_ssl;
#endif
bool use_ssl;
#endif
status_t fStatus;
BString fServerName; // required for DIGEST-MD5