diff -r -u popa3d-0.5.1/Makefile popa3d-0.5.1-smtp_after_pop-1/Makefile --- popa3d-0.5.1/Makefile Sun Oct 28 02:10:49 2001 +++ popa3d-0.5.1-smtp_after_pop-1/Makefile Fri Feb 7 12:24:51 2003 @@ -9,7 +9,7 @@ LDFLAGS = -s LIBS = # Linux with glibc, FreeBSD, NetBSD -#LIBS += -lcrypt +LIBS += -lcrypt -ldb1 # HP-UX trusted system #LIBS += -lsec # Solaris (POP_STANDALONE, POP_VIRTUAL) diff -r -u popa3d-0.5.1/params.h popa3d-0.5.1-smtp_after_pop-1/params.h --- popa3d-0.5.1/params.h Tue Oct 16 06:10:34 2001 +++ popa3d-0.5.1-smtp_after_pop-1/params.h Tue Feb 18 20:57:50 2003 @@ -12,8 +12,10 @@ /* * Are we going to be a standalone server or start via an inetd clone? + * Set this to "1" if you want to use SMTP_AFTER_POP (see below). + * SMTP_AFTER_POP isn't (yet?) implemented for non-standalone. */ -#define POP_STANDALONE 0 +#define POP_STANDALONE 1 #if POP_STANDALONE @@ -209,6 +211,11 @@ #define SYSLOG_PRI_ERROR LOG_CRIT /* + * Do SMTP after POP? + */ +#define SMTP_AFTER_POP 1 + +/* * There's probably no reason to touch anything below this comment. */ @@ -250,3 +257,4 @@ #define LINE_BUFFER_SIZE 0x20 #endif + diff -r -u popa3d-0.5.1/pop_root.c popa3d-0.5.1-smtp_after_pop-1/pop_root.c --- popa3d-0.5.1/pop_root.c Thu Mar 21 21:15:19 2002 +++ popa3d-0.5.1-smtp_after_pop-1/pop_root.c Mon Feb 10 16:24:19 2003 @@ -44,6 +44,65 @@ static char *user; static char *spool, *mailbox; +#if SMTP_AFTER_POP + +#include +#include +#include + +static void smtp_after_pop(char *ip) +{ + char stamp[64] = "/etc/mail/popips/"; + char *dbname = "/etc/mail/access.db"; + DB *db; + DBT key, data; + DBT *pk = &key, *pd = &data; + int fd, rc; + + if (!ip || !*ip) return; + + db = dbopen(dbname, O_RDWR, 0, DB_HASH, NULL); + if (db == NULL) { + syslog(LOG_WARNING, "error opening %s: %s\n", dbname, strerror(errno)); + return; + } + fd = (db->fd)(db); + if (flock(fd, LOCK_EX) == -1) { + syslog(LOG_WARNING, "can't get lock on %s\n", dbname); + (db->close)(db); + return; + } + key.data = ip; + key.size = strlen(key.data); + data.data = "RELAY"; + data.size = strlen(data.data); + rc = (db->put)(db, pk, pd, 0); + switch (rc) { + case 0: + strcat(stamp, ip); + rc = open(stamp, O_CREAT, 0600); + if (rc == -1) { + syslog(LOG_WARNING, "error creating %s\n", stamp); + } else { + close(rc); + } + syslog(LOG_INFO, "inserted %s into %s for user %s\n", + ip, dbname, user); + break; + case 1: + syslog(LOG_INFO, "%s alrady in %s for user %s\n", + ip, dbname, user); + break; + default: + syslog(LOG_WARNING, "error inserting %s into %s for user %s\n", + ip, dbname, user); + break; + } + flock(fd, LOCK_UN); + (db->close)(db); +} +#endif + int log_error(char *s) { syslog(SYSLOG_PRI_ERROR, "%s: %m", s); @@ -103,7 +162,11 @@ * attempts authentication, and, if successful, drops privilege to the * authenticated user. Returns one of the AUTH_* result codes. */ -static int do_root_auth(int channel) +static int do_root_auth(int channel +#if SMTP_AFTER_POP + , char *IP +#endif +) { static char auth[AUTH_BUFFER_SIZE + 2]; char *pass; @@ -156,6 +219,10 @@ if (!virtual_domain) return AUTH_FAILED; #endif +#if SMTP_AFTER_POP + smtp_after_pop(IP); +#endif + if (set_user(pw)) return AUTH_FAILED; #if POP_VIRTUAL @@ -210,7 +277,13 @@ return 0; } -int do_pop_session(void) +int do_pop_session( +#if SMTP_AFTER_POP + char *IP +#else + void +#endif +) { int channel[2]; int result, status; @@ -235,7 +308,11 @@ if (close(channel[1])) result = AUTH_NONE; else - result = do_root_auth(channel[0]); + result = do_root_auth(channel[0] +#if SMTP_AFTER_POP + , IP +#endif + ); if (wait(&status) < 0) status = 1; @@ -267,6 +344,10 @@ int main(void) { if (do_pop_startup()) return 1; - return do_pop_session(); + return do_pop_session( +#if SMTP_AFTER_POP + NULL +#endif + ); } #endif diff -r -u popa3d-0.5.1/standalone.c popa3d-0.5.1-smtp_after_pop-1/standalone.c --- popa3d-0.5.1/standalone.c Sat Sep 8 15:44:20 2001 +++ popa3d-0.5.1-smtp_after_pop-1/standalone.c Thu Feb 6 18:29:12 2003 @@ -33,7 +33,13 @@ */ extern int log_error(char *s); extern int do_pop_startup(void); -extern int do_pop_session(void); +extern int do_pop_session( +#if SMTP_AFTER_POP + char *IP +#else + void +#endif +); typedef sig_atomic_t a_int; typedef volatile a_int va_int; @@ -231,7 +237,11 @@ if (dup2(new, 1) < 0) return log_error("dup2"); if (dup2(new, 2) < 0) return log_error("dup2"); if (close(new)) return log_error("close"); - return do_pop_session(); + return do_pop_session( +#if SMTP_AFTER_POP + inet_ntoa(addr.sin_addr) +#endif + ); default: sessions[j].addr = addr.sin_addr; diff -r -u popa3d-0.5.1/startup.c popa3d-0.5.1-smtp_after_pop-1/startup.c --- popa3d-0.5.1/startup.c Sat Sep 8 15:49:22 2001 +++ popa3d-0.5.1-smtp_after_pop-1/startup.c Thu Feb 6 19:01:47 2003 @@ -12,7 +12,13 @@ /* pop_root.c */ extern int do_pop_startup(void); -extern int do_pop_session(void); +extern int do_pop_session( +#if SMTP_AFTER_POP + char *IP +#else + void +#endif +); /* standalone.c */ extern int do_standalone(void); @@ -58,7 +64,11 @@ return do_standalone(); if (do_pop_startup()) return 1; - return do_pop_session(); + return do_pop_session( +#if SMTP_AFTER_POP + NULL +#endif + ); } #endif