diff -r -u popa3d-0.5.1/Makefile popa3d-0.5.1-smtp_after_pop-2/Makefile --- popa3d-0.5.1/Makefile 2001-10-28 02:10:49.000000000 +0100 +++ popa3d-0.5.1-smtp_after_pop-2/Makefile 2003-04-03 22:35:20.000000000 +0200 @@ -9,7 +9,7 @@ LDFLAGS = -s LIBS = # Linux with glibc, FreeBSD, NetBSD -#LIBS += -lcrypt +LIBS += -lcrypt -ldb # 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-2/params.h --- popa3d-0.5.1/params.h 2001-10-16 06:10:34.000000000 +0200 +++ popa3d-0.5.1-smtp_after_pop-2/params.h 2003-02-19 19:36:29.000000000 +0100 @@ -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 @@ -178,7 +180,7 @@ * * #undef this for qmail-style $HOME/Mailbox mailboxes. */ -#define MAIL_SPOOL_PATH "/var/mail" +#define MAIL_SPOOL_PATH "/var/spool/mail" #ifndef MAIL_SPOOL_PATH /* @@ -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-2/pop_root.c --- popa3d-0.5.1/pop_root.c 2002-03-21 21:15:19.000000000 +0100 +++ popa3d-0.5.1-smtp_after_pop-2/pop_root.c 2003-04-03 22:34:55.000000000 +0200 @@ -44,6 +44,64 @@ 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 *dbp; + DBT key, data; + int fd, ret; + + if (!ip || !*ip) return; + + if ((ret = db_create(&dbp, NULL, 0)) != 0) { + syslog(LOG_WARNING, "error calling db_create\n"); + return; + } + if ((ret = dbp->open(dbp, dbname, NULL, DB_HASH, 0, 0)) != 0) { + syslog(LOG_WARNING, "error opening %s: %s\n", dbname, strerror(errno)); + return; + } + dbp->fd(dbp, &fd); + if (flock(fd, LOCK_EX) == -1) { + syslog(LOG_WARNING, "can't get lock on %s\n", dbname); + dbp->close(dbp, 0); + return; + } + + memset(&key, 0, sizeof(key)); + memset(&data, 0, sizeof(data)); + key.data = ip; + key.size = strlen(ip); + data.data = "RELAY"; + data.size = strlen(data.data); + if ((ret = dbp->put(dbp, NULL, &key, &data, 0)) == 0) { + /* printf("db: %s: key stored.\n", (char *) key.data); */ + strcat(stamp, ip); + ret = open(stamp, O_CREAT, 0600); + if (ret == -1) { + syslog(LOG_WARNING, "error creating %s\n", stamp); + } else { + close(ret); + } + syslog(LOG_INFO, "inserted %s into %s for user %s\n", + ip, dbname, user); + } else { + /* dbp->err(dbp, ret, "DB->put"); */ + syslog(LOG_WARNING, "error inserting %s into %s for user %s\n", + ip, dbname, user); + } + flock(fd, LOCK_UN); + dbp->close(dbp, 0); +} +#endif + int log_error(char *s) { syslog(SYSLOG_PRI_ERROR, "%s: %m", s); @@ -103,7 +161,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 +218,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 +276,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 +307,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 +343,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-2/standalone.c --- popa3d-0.5.1/standalone.c 2001-09-08 15:44:20.000000000 +0200 +++ popa3d-0.5.1-smtp_after_pop-2/standalone.c 2003-02-06 18:29:12.000000000 +0100 @@ -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-2/startup.c --- popa3d-0.5.1/startup.c 2001-09-08 15:49:22.000000000 +0200 +++ popa3d-0.5.1-smtp_after_pop-2/startup.c 2003-02-06 19:01:47.000000000 +0100 @@ -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