diff -urN popa3d-0.6.2/Makefile popa3d-0.6.2-whoson/Makefile --- popa3d-0.6.2/Makefile Sun Mar 2 08:16:40 2003 +++ popa3d-0.6.2-whoson/Makefile Wed Apr 2 14:30:50 2003 @@ -2,7 +2,7 @@ LD = gcc RM = rm -f MKDIR = mkdir -p -INSTALL = install +INSTALL = install -c CFLAGS = -c -Wall -O2 -fomit-frame-pointer # You may use OpenSSL's MD5 routines instead of the ones supplied here #CFLAGS += -DHAVE_OPENSSL @@ -22,6 +22,10 @@ #LIBS += -lnsl # OpenSSL (-DHAVE_OPENSSL) #LIBS += -lcrypto +# Whoson +#LIBS += -lwhoson +#CFLAGS += -I/usr/local/include +#LDFLAGS += -L/usr/local/lib DESTDIR = PREFIX = /usr/local diff -urN popa3d-0.6.2/WHOSON_README popa3d-0.6.2-whoson/WHOSON_README --- popa3d-0.6.2/WHOSON_README Thu Jan 1 05:00:00 1970 +++ popa3d-0.6.2-whoson/WHOSON_README Wed Apr 2 14:30:50 2003 @@ -0,0 +1,24 @@ + Enabling Whoson support + +1. Get whoson library from http://www.average.org/whoson. + Compile and install it. + +2. Edit "params.h", enable whoson support by setting "WHOSON_SUPPORT" to "1". + If you are planning to use popa3d via stunnel, set "STUNNEL_HACK" to "1". + Make sure you use "exec" method for pop3s service, otherwise there is + no way for stunnel to set environment variable "REMOTE_HOST" which is + used by this hack to get remote peer address. + +3. Edit Makefile, uncomment three lines right after "# Whoson": + + LIBS += -lwhoson + CFLAGS += -I/usr/local/include + LDFLAGS += -L/usr/local/lib + + Edit these lines appropriately if you've installed whoson to different + location (by default it is installed in "/usr/local"). + +4. Read INSTALL, compile and install popa3d. + +(C) 2003 Damir Bikmuhametov, dfb@bashnet.ru + diff -urN popa3d-0.6.2/params.h popa3d-0.6.2-whoson/params.h --- popa3d-0.6.2/params.h Sun Sep 8 15:49:24 2002 +++ popa3d-0.6.2-whoson/params.h Wed Apr 2 14:30:50 2003 @@ -210,6 +210,21 @@ #define SYSLOG_PRI_ERROR LOG_CRIT /* + * Do we need Whoson (http://www.average.org/whoson) support? + */ +#define WHOSON_SUPPORT 0 + +#if WHOSON_SUPPORT +/* + * When popa3d is invoked by stunnel (http://www.stunnel.org), getpeername(2) + * returns "127.0.0.1" that may break things (f.e., whoson support). Define + * STUNNEL_HACK to enable getting remote peer address from "REMOTE_HOST" + * environment variable that is set by stunnel. + */ +#define STUNNEL_HACK 1 +#endif + +/* * There's probably no reason to touch anything below this comment. */ diff -urN popa3d-0.6.2/pop_root.c popa3d-0.6.2-whoson/pop_root.c --- popa3d-0.6.2/pop_root.c Fri Mar 22 01:15:19 2002 +++ popa3d-0.6.2-whoson/pop_root.c Wed Apr 2 14:30:50 2003 @@ -33,6 +33,16 @@ #include "virtual.h" #endif +#if WHOSON_SUPPORT +#include +#include +#include +#include +#ifndef socklen_t +#define socklen_t int +#endif +#endif + #if !VIRTUAL_ONLY extern struct passwd *auth_userpass(char *user, char *pass, int *known); #endif @@ -214,6 +224,14 @@ { int channel[2]; int result, status; +#if WHOSON_SUPPORT + struct sockaddr_in peer_addr; + socklen_t peer_addr_len = sizeof(struct sockaddr_in); + char * peer_addr_str = NULL; +#if STUNNEL_HACK + char * tmp_str = NULL; +#endif /* STUNNEL_HACK */ +#endif /* WHOSON_SUPPORT */ /* For SIGCHLD, default action is to ignore the signal. {SIGCHLD, SIG_IGN} * may be invalid (POSIX) or may enable a different behavior (SUSv2), none @@ -248,6 +266,21 @@ if (result == AUTH_OK) { if (close(channel[0])) return log_error("close"); log_pop_auth(result, user); +#if WHOSON_SUPPORT + if (getpeername(0, (struct sockaddr *)&peer_addr, &peer_addr_len)) + return log_error("getpeername"); + + peer_addr_str = inet_ntoa(peer_addr.sin_addr); +#if STUNNEL_HACK + if (peer_addr_str && + !strcmp(peer_addr_str, "127.0.0.1") && + (tmp_str = getenv("REMOTE_HOST"))) + peer_addr_str = tmp_str; +#endif /* STUNNEL_HACK */ + syslog(SYSLOG_PRI_LO, "Session with %s at %s started", user, peer_addr_str); + + wso_login(peer_addr_str, user, NULL, 0); +#endif /* WHOSON_SUPPORT */ return do_pop_trans(spool, mailbox); }