dmc

dynamic mail client
git clone git://git.suckless.org/dmc
Log | Files | Refs | README | LICENSE

commit 2de7aaaac3b68dd6541a143be1a22f82be464055
parent 04588cd4d55df9ab88a95bc6777347db35ab6fdc
Author: pancake@localhost.localdomain <unknown>
Date:   Sun,  8 Nov 2009 19:54:48 +0100

* Fix the OpenSSL support in sock.c
  - Fail sock_connect () if ssl handshake fails
* Rebuild pop3.o and imap4.o if sock.c changes
Diffstat:
Makefile | 8++++++--
dmc | 3++-
sock.c | 20++++++++++++--------
3 files changed, 20 insertions(+), 11 deletions(-)

diff --git a/Makefile b/Makefile @@ -24,10 +24,14 @@ dmc-pack: pack.o dmc-filter: filter.o ${CC} ${LDFLAGS} filter.o -o dmc-filter -dmc-pop3: pop3.o +sock.tmp: sock.o + rm -f pop3.o imap4.o + @:> sock.tmp + +dmc-pop3: sock.tmp pop3.o ${CC} ${LDFLAGS} ${SSL_LIBS} pop3.o -o dmc-pop3 -dmc-imap4: imap4.o +dmc-imap4: sock.tmp imap4.o ${CC} ${LDFLAGS} ${SSL_LIBS} imap4.o -o dmc-imap4 install: diff --git a/dmc b/dmc @@ -101,7 +101,7 @@ add_attachment () { FILE="`basename \"$1\"`" ln -fs "$1" "${OUT}.d/${FILE}" else - echo "Cannot find \⅛$1\"" + echo "Cannot find \"$1\"" fi fi } @@ -114,6 +114,7 @@ send_message () { fi # TODO: find better name for the auto mode if [ "${SEND}" = "!msmtp" ]; then + # TODO: use dmc-filter here TO="`dmc -H To < $FILE`" SJ="`dmc -H Subject < $FILE`" echo "Sending mail to $TO (${SJ})..." diff --git a/sock.c b/sock.c @@ -2,6 +2,7 @@ #include <stdio.h> #include <string.h> +#include <unistd.h> #include <poll.h> #include <stdarg.h> #include <netdb.h> @@ -20,17 +21,19 @@ static int fd = -1; int sock_ssl (int enable) { #if HAVE_SSL - int err; - if (ssl) { - // challenge, check cert, etc.. + int err = 1; + if (enable) { + // TODO Check certificate + SSL_library_init (); + SSL_load_error_strings (); + OpenSSL_add_all_algorithms (); + ctx = SSL_CTX_new (SSLv23_method ()); sfd = SSL_new (ctx); SSL_set_fd (sfd, fd); err = SSL_connect (sfd); - /* TODO: check cert */ - SSL_set_accept_state (sfd); } ssl = enable; - return 1; + return err; #else return 0; #endif @@ -41,7 +44,6 @@ int sock_connect(const char *host, int port, int ssl) { struct sockaddr_in sa; struct hostent *he; int s = socket (AF_INET, SOCK_STREAM, 0); - sock_ssl (ssl); fd = -1; if (s != -1) { fd = s; @@ -53,6 +55,7 @@ int sock_connect(const char *host, int port, int ssl) { sa.sin_port = htons (port); if (connect (fd, (const struct sockaddr*)&sa, sizeof (struct sockaddr))) fd = -1; + else fd = sock_ssl (ssl); } else fd = -1; if (fd == -1) close (s); @@ -60,7 +63,7 @@ int sock_connect(const char *host, int port, int ssl) { return fd; } -static int sock_ready() { +int sock_ready() { struct pollfd fds[1]; fds[0].fd = fd; fds[0].events = POLLIN|POLLPRI; @@ -70,6 +73,7 @@ static int sock_ready() { void sock_close() { #if HAVE_SSL + SSL_CTX_free (ctx); SSL_free (sfd); #endif close (fd);