Patch for popa3d-0.5.9 enabling `user mode' -- when server is started in inetd (i.e. non-standalone) mode with non-zero UID, it will not do anything that requires root priviledges, omit any authentication (accept anything for USER and PASS) and work on current user's own mailbox. It lets user start pop3 sessions from other programs that he can run with his UID without needing to give them his password (e.g. start popa3d via SSH (like with `plugin' option of fetchmail), thus securing his POP3 sessions) Hope it will function well and be useful. --Maciek Pasternacki diff -b -u -r -U 5 popa3d-0.5.9-vanilla/params.h popa3d-0.5.9-jph/params.h --- popa3d-0.5.9-vanilla/params.h 2002-09-08 11:49:24.000000000 +0200 +++ popa3d-0.5.9-jph/params.h 2003-01-04 02:43:16.000000000 +0100 @@ -122,10 +122,18 @@ * work without it. */ #define POP_SUPPORT_LAST 1 /* + * Should the server enable user mode (without chroot, authentication + * etc) when invoked with nonzero UID, thus letting user start pop3 + * session as SSH command without having to specify the password + * twice? + */ +#define ENABLE_USER_MODE 0 + +/* * Introduce some sane limits on the mailbox size in order to prevent * a single huge mailbox from stopping the entire POP service. */ #define MAX_MAILBOX_MESSAGES 200000 #define MAX_MAILBOX_OPEN_BYTES 200000000 diff -b -u -r -U 5 popa3d-0.5.9-vanilla/pop_root.c popa3d-0.5.9-jph/pop_root.c --- popa3d-0.5.9-vanilla/pop_root.c 2002-03-21 21:15:19.000000000 +0100 +++ popa3d-0.5.9-jph/pop_root.c 2003-01-04 02:41:32.000000000 +0100 @@ -42,10 +42,14 @@ static int known; static char *user; static char *spool, *mailbox; +#if ENABLE_USER_MODE +static int user_mode = 0; +#endif + int log_error(char *s) { syslog(SYSLOG_PRI_ERROR, "%s: %m", s); return 1; } @@ -67,10 +71,15 @@ static int drop_root(void) { tzset(); openlog(SYSLOG_IDENT, SYSLOG_OPTIONS | LOG_NDELAY, SYSLOG_FACILITY); +#if ENABLE_USER_MODE + if ( user_mode ) + return 0; +#endif + if (chroot(POP_CHROOT)) return log_error("chroot"); if (chdir("/")) return log_error("chdir"); return set_user(&pop_pw); } @@ -129,10 +138,17 @@ user = auth; pass = &user[strlen(user) + 1]; pw = NULL; + +#if ENABLE_USER_MODE + if ( user_mode ) { + pw = getpwuid(getuid()); + } else { +#endif /* ENABLE_USER_MODE */ + #if POP_VIRTUAL if (!(pw = virtual_userpass(user, pass, &known)) && virtual_domain) { memset(pass, 0, strlen(pass)); return AUTH_FAILED; } @@ -169,10 +185,14 @@ #if VIRTUAL_ONLY /* never reached */ return AUTH_FAILED; #else +#if ENABLE_USER_MODE + } +#endif + #ifdef MAIL_SPOOL_PATH spool = MAIL_SPOOL_PATH; mailbox = user; #else spool = pw->pw_dir; @@ -185,10 +205,16 @@ int do_pop_startup(void) { struct passwd *pw; +#if ENABLE_USER_MODE + user_mode = ( getuid() != 0 ); + if ( user_mode ) + return 0; +#endif /* ENABLE_USER_MODE */ + umask(077); signal(SIGPIPE, SIG_IGN); openlog(SYSLOG_IDENT, SYSLOG_OPTIONS, SYSLOG_FACILITY);