Skip to content

Commit

Permalink
Make OpenSSL a mandatory requirement
Browse files Browse the repository at this point in the history
There is no point in having SSL/TLS IMAP support as optional, it's as
useful if not more than the the non-encrypted connections.

The Makefile was better organized to make it easier to change some
options during compile.

The SHAREDIR variable passed as configuration option has changed name.
  • Loading branch information
lefcha committed Feb 19, 2012
1 parent 820e9db commit e907fe5
Show file tree
Hide file tree
Showing 14 changed files with 41 additions and 94 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
all nossl install uninstall clean:
all install uninstall clean:
cd src && $(MAKE) $@
2 changes: 1 addition & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Changes
Installation

Compile time requirements are Lua (version 5.2 or 5.1), the PCRE library, and
optionally the OpenSSL library (for SSL/TLS and CRAM-MD5 support).
the OpenSSL library.

Compile and install the program:

Expand Down
22 changes: 15 additions & 7 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,21 @@ BINDIR = $(PREFIX)/bin
SHAREDIR = $(PREFIX)/share/imapfilter
MANDIR = $(PREFIX)/man

CFLAGS = -Wall -O -DMAKEFILE_SHAREDIR='"$(SHAREDIR)"'
LDFLAGS =
LIBS = -lm -llua -lpcre -lssl -lcrypto
MYCFLAGS =
MYLDFLAGS =
MYLIBS =

INCDIRS =
LIBDIRS =

LIBLUA = -llua
LIBPCRE = -lpcre
LIBSSL = -lssl
LIBCRYPTO = -lcrypto

CFLAGS = -Wall -O -DCONFIG_SHAREDIR='"$(SHAREDIR)"' $(INCDIRS) $(MYCFLAGS)
LDFLAGS = $(LIBDIRS) $(MYLDFLAGS)
LIBS = -lm $(LIBLUA) $(LIBPCRE) $(LIBSSL) $(LIBCRYPTO) $(MYLIBS)

MAN1 = imapfilter.1
MAN5 = imapfilter_config.5
Expand All @@ -21,10 +33,6 @@ OBJ = auth.o buffer.o cert.o core.o file.o imapfilter.o list.o log.o lua.o \

all: $(BIN)

nossl:
$(MAKE) $(BIN) CFLAGS="-Wall -O -DMAKEFILE_SHAREDIR='\"$(SHAREDIR)\"' \
-DNO_SSLTLS -DNO_CRAMMD5" LIBS="-lm -llua -lpcre"

$(BIN): $(OBJ)
$(CC) -o $(BIN) $(LDFLAGS) $(OBJ) $(LIBS)

Expand Down
6 changes: 2 additions & 4 deletions src/auth.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#include <stdio.h>
#include <string.h>

#include "imapfilter.h"

#ifndef NO_CRAMMD5
#include <openssl/hmac.h>
#include <openssl/evp.h>

#include "imapfilter.h"


/*
* Authenticate to the server with the Challenge-Response Authentication
Expand Down Expand Up @@ -57,4 +56,3 @@ auth_cram_md5(const char *user, const char *pass, unsigned char *chal)

return out;
}
#endif /* NO_CRAMMD5 */
9 changes: 3 additions & 6 deletions src/cert.c
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
#ifndef NO_SSLTLS

#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <limits.h>
#include <sys/stat.h>
#include <unistd.h>

#include "imapfilter.h"
#include "session.h"

#include <openssl/x509.h>
#include <openssl/ssl.h>
#include <openssl/pem.h>
#include <openssl/evp.h>

#include "imapfilter.h"
#include "session.h"


extern environment env;

Expand Down Expand Up @@ -207,4 +205,3 @@ mismatch_cert(void)
else
return -1;
}
#endif /* NO_SSLTLS */
1 change: 1 addition & 0 deletions src/file.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
Expand Down
12 changes: 3 additions & 9 deletions src/imapfilter.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
#include <sys/stat.h>
#include <locale.h>

#include <openssl/ssl.h>
#include <openssl/err.h>

#include "imapfilter.h"
#include "session.h"
#include "list.h"
Expand All @@ -15,11 +18,6 @@
#include "pathnames.h"
#include "regexp.h"

#ifndef NO_SSLTLS
#include <openssl/ssl.h>
#include <openssl/err.h>
#endif


extern buffer ibuf, obuf, nbuf, cbuf;
extern regexp responses[];
Expand Down Expand Up @@ -100,10 +98,8 @@ main(int argc, char *argv[])

regexp_compile(responses);

#ifndef NO_SSLTLS
SSL_library_init();
SSL_load_error_strings();
#endif

start_lua();
#if LUA_VERSION_NUM < 502
Expand All @@ -122,9 +118,7 @@ main(int argc, char *argv[])
#endif
stop_lua();

#ifndef NO_SSLTLS
ERR_free_strings();
#endif

regexp_free(responses);

Expand Down
12 changes: 2 additions & 10 deletions src/imapfilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@
#include <lua.h>
#include <lualib.h>

#include "session.h"

#ifndef NO_SSLTLS
#include <openssl/ssl.h>
#endif

#include "session.h"


/* Fatal error exit codes. */
Expand Down Expand Up @@ -79,15 +77,11 @@ typedef struct environment {


/* auth.c */
#ifndef NO_CRAMMD5
unsigned char *auth_cram_md5(const char *user, const char *pass,
unsigned char *chal);
#endif

/* cert.c */
#ifndef NO_SSLTLS
int get_cert(session *ssn);
#endif

/* core.c */
LUALIB_API int luaopen_ifcore(lua_State *lua);
Expand Down Expand Up @@ -218,12 +212,10 @@ int close_connection(session *ssn);
ssize_t socket_read(session *ssn, char *buf, size_t len, long timeout,
int timeoutfail);
ssize_t socket_write(session *ssn, const char *buf, size_t len);
#ifndef NO_SSLTLS
int open_secure_connection(session *ssn);
int close_secure_connection(session *ssn);
ssize_t socket_secure_read(session *ssn, char *buf, size_t len);
ssize_t socket_secure_write(session *ssn, const char *buf, size_t len);
#endif

/* system.c */
LUALIB_API int luaopen_ifsys(lua_State *lua);
Expand Down
16 changes: 8 additions & 8 deletions src/pathnames.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,28 @@


/* Lua imapfilter set functions file. */
#define PATHNAME_COMMON MAKEFILE_SHAREDIR "/common.lua"
#define PATHNAME_COMMON CONFIG_SHAREDIR "/common.lua"

/* Lua imapfilter set functions file. */
#define PATHNAME_SET MAKEFILE_SHAREDIR "/set.lua"
#define PATHNAME_SET CONFIG_SHAREDIR "/set.lua"

/* Lua imapfilter account functions file. */
#define PATHNAME_ACCOUNT MAKEFILE_SHAREDIR "/account.lua"
#define PATHNAME_ACCOUNT CONFIG_SHAREDIR "/account.lua"

/* Lua imapfilter mailbox functions file. */
#define PATHNAME_MAILBOX MAKEFILE_SHAREDIR "/mailbox.lua"
#define PATHNAME_MAILBOX CONFIG_SHAREDIR "/mailbox.lua"

/* Lua imapfilter message functions file. */
#define PATHNAME_MESSAGE MAKEFILE_SHAREDIR "/message.lua"
#define PATHNAME_MESSAGE CONFIG_SHAREDIR "/message.lua"

/* Lua imapfilter message functions file. */
#define PATHNAME_OPTIONS MAKEFILE_SHAREDIR "/options.lua"
#define PATHNAME_OPTIONS CONFIG_SHAREDIR "/options.lua"

/* Lua imapfilter regex functions file. */
#define PATHNAME_REGEX MAKEFILE_SHAREDIR "/regex.lua"
#define PATHNAME_REGEX CONFIG_SHAREDIR "/regex.lua"

/* Lua imapfilter auxiliary functions file. */
#define PATHNAME_AUXILIARY MAKEFILE_SHAREDIR "/auxiliary.lua"
#define PATHNAME_AUXILIARY CONFIG_SHAREDIR "/auxiliary.lua"


#endif /* PATHNAMES_H */
4 changes: 0 additions & 4 deletions src/request.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ request_login(session **ssnptr, const char *server, const char *port, const
if (response_capability(ssn, t) == -1)
goto fail;

#ifndef NO_SSLTLS
if (!ssn->ssl && ssn->capabilities & CAPABILITY_STARTTLS &&
get_option_boolean("starttls")) {
t = send_request(ssn, "STARTTLS");
Expand All @@ -198,10 +197,8 @@ request_login(session **ssnptr, const char *server, const char *port, const
break;
}
}
#endif

if (rg != STATUS_PREAUTH) {
#ifndef NO_CRAMMD5
if (ssn->capabilities & CAPABILITY_CRAMMD5 &&
get_option_boolean("crammd5")) {
unsigned char *in, *out;
Expand All @@ -221,7 +218,6 @@ request_login(session **ssnptr, const char *server, const char *port, const
} else
goto fail;
}
#endif
if (r != STATUS_OK) {
t = send_request(ssn, "LOGIN \"%s\" \"%s\"",
ssn->username, ssn->password);
Expand Down
6 changes: 0 additions & 6 deletions src/response.c
Original file line number Diff line number Diff line change
Expand Up @@ -320,14 +320,10 @@ response_capability(session *ssn, int tag)

if (xstrcasestr(s, "NAMESPACE"))
ssn->capabilities |= CAPABILITY_NAMESPACE;
#ifndef NO_CRAMMD5
if (xstrcasestr(s, "AUTH=CRAM-MD5"))
ssn->capabilities |= CAPABILITY_CRAMMD5;
#endif
#ifndef NO_SSLTLS
if (xstrcasestr(s, "STARTTLS"))
ssn->capabilities |= CAPABILITY_STARTTLS;
#endif
if (xstrcasestr(s, "CHILDREN"))
ssn->capabilities |= CAPABILITY_CHILDREN;

Expand All @@ -341,7 +337,6 @@ response_capability(session *ssn, int tag)
}


#ifndef NO_CRAMMD5
/*
* Process the data that server sent due to IMAP AUTHENTICATE client request.
*/
Expand All @@ -361,7 +356,6 @@ response_authenticate(session *ssn, int tag, unsigned char **cont)

return r;
}
#endif


/*
Expand Down
2 changes: 0 additions & 2 deletions src/session.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ session_init(session *ssn)
ssn->username = NULL;
ssn->password = NULL;
ssn->socket = -1;
#ifndef NO_SSLTLS
ssn->sslsocket = NULL;
#endif
ssn->protocol = PROTOCOL_NONE;
ssn->capabilities = CAPABILITY_NONE;
ssn->ns.prefix = NULL;
Expand Down
4 changes: 0 additions & 4 deletions src/session.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
#define SESSION_H


#ifndef NO_SSLTLS
#include <openssl/ssl.h>
#endif


/* IMAP session. */
Expand All @@ -15,9 +13,7 @@ typedef struct session {
const char *username; /* User name. */
const char *password; /* User password. */
int socket; /* Socket. */
#ifndef NO_SSLTLS
SSL *sslsocket; /* SSL socket. */
#endif
unsigned int protocol; /* IMAP protocol. Currently IMAP4rev1 and
* IMAP4 are supported. */
unsigned int capabilities; /* Capabilities of the mail server. */
Expand Down
Loading

0 comments on commit e907fe5

Please sign in to comment.