diff -Nuard popa3d-0.4_orig/CUSTOM_FILE_README popa3d-0.4/CUSTOM_FILE_README --- popa3d-0.4_orig/CUSTOM_FILE_README Thu Jan 1 01:00:00 1970 +++ popa3d-0.4/CUSTOM_FILE_README Tue May 29 17:21:36 2001 @@ -0,0 +1,22 @@ +Allow to authenticate users from other file than /etc/passwd or /etc/shadow + +The /custom/file authentication routine. +file have to be compatible with /etc/passwd and/or /etc/shadow syntax. + +#define AUTH_PASSWD_FILE_PATH "/path/to/file" +#define AUTH_SHADOW_FILE_PATH "/path/to/file" +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it define paths to you files. +(it don't have to be you regular system files with users, use it to store pop3 users only) + +in params.h set + +for example : + +#define AUTH_PASSWD 0 +#define AUTH_SHADOW 1 +#define AUTH_PASSWD_FILE_PATH "/path/to/passwd/file" +#define AUTH_SHADOW_FILE_PATH "/path/to/shadow/file" + +or any other combination + +2001-05-28 by Marcin Krzyzanowski diff -Nuard popa3d-0.4_orig/Makefile popa3d-0.4/Makefile --- popa3d-0.4_orig/Makefile Tue Feb 1 04:56:46 2000 +++ popa3d-0.4/Makefile Tue May 29 16:17:20 2001 @@ -2,8 +2,8 @@ LD = gcc RM = rm -f CFLAGS = -c -Wall -O2 -fomit-frame-pointer -LDFLAGS = -s -#LDFLAGS = -s -lcrypt +#LDFLAGS = -s +LDFLAGS = -s -lcrypt PROJ = popa3d OBJS = md5/md5.o \ diff -Nuard popa3d-0.4_orig/params.h popa3d-0.4/params.h --- popa3d-0.4_orig/params.h Tue Feb 1 07:16:24 2000 +++ popa3d-0.4/params.h Wed May 30 11:17:31 2001 @@ -8,7 +8,7 @@ /* * Are we going to be a standalone server, or start via an inetd clone? */ -#define POP_STANDALONE 0 +#define POP_STANDALONE 1 #if POP_STANDALONE @@ -63,7 +63,8 @@ * Note: password aging is not supported. */ #define AUTH_SHADOW 1 - +#define AUTH_PASSWD_FILE_PATH "/etc/passwd.pop3" +#define AUTH_SHADOW_FILE_PATH "/etc/shadow.pop3" /* * A salt used to waste some CPU time on dummy crypt(3) calls and make * it harder (but still far from impossible, on most systems) to check @@ -88,7 +89,7 @@ */ #define SYSLOG_IDENT "popa3d" #define SYSLOG_OPTIONS LOG_PID -#define SYSLOG_FACILITY LOG_DAEMON +#define SYSLOG_FACILITY LOG_MAIL #define SYSLOG_PRIORITY LOG_NOTICE /* diff -Nuard popa3d-0.4_orig/pop_root.c popa3d-0.4/pop_root.c --- popa3d-0.4_orig/pop_root.c Tue Feb 1 07:18:12 2000 +++ popa3d-0.4/pop_root.c Wed May 30 11:19:20 2001 @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -21,11 +22,12 @@ #include "pop_auth.h" #include "pop_trans.h" -#if AUTH_SHADOW -#include #ifdef __GLIBC__ #include #endif + +#if AUTH_SHADOW +#include #endif static struct passwd pop_pw; @@ -81,6 +83,7 @@ * arguable whether this was worth the extra code and the performance * penalty or not, but such discussions are outside of the scope of a * comment like this. ;^) + * with add a custom "passwd" and/or "shadow" file by Marcin Krzyzanowski */ static struct passwd *do_shadow_auth(char *user, char *pass) { @@ -89,10 +92,44 @@ struct spwd *spw; char result; +#ifdef AUTH_SHADOW_FILE_PATH + FILE *usersshadowdb = NULL; +#endif +#ifdef AUTH_PASSWD_FILE_PATH + FILE *usersdb = NULL; +#endif + +#ifdef AUTH_PASSWD_FILE_PATH + + usersdb = fopen(AUTH_PASSWD_FILE_PATH,"r"); + if (usersdb == NULL) { + syslog(SYSLOG_PRIORITY, "where is users database ? "); + exit(0); + } + + /* initialize */ + pw = NULL; + result = 0; + + /* user searching */ + do { + pw = fgetpwent(usersdb); + if (!strcmp(pw->pw_name,user)) { + mailbox = pw->pw_name; + break; + } + } while((pw != NULL)); + + endpwent(); + fclose(usersdb); +#else + if ((pw = getpwnam(user))) mailbox = user; endpwent(); result = 0; +#endif + if (pipe(channel)) { log_error("pipe"); return NULL; @@ -104,6 +141,35 @@ return NULL; case 0: +#ifdef AUTH_SHADOW_FILE_PATH + + close(channel[0]); + usersshadowdb = fopen(AUTH_SHADOW_FILE_PATH,"r"); + if (usersshadowdb == NULL) { + syslog(SYSLOG_PRIORITY, "where is users database ? "); + exit(0); + } + + spw = NULL; + + /* user searching */ + do { + spw = fgetspent(usersshadowdb); + if (!strcmp(spw->sp_namp,user)) { + mailbox = spw->sp_namp; + break; + } + } while (spw != NULL); + + if (!pw || !*spw->sp_pwdp || + *spw->sp_pwdp == '*' || *spw->sp_pwdp == '!') + crypt(pass, AUTH_DUMMY_SALT); + else + if (!strcmp(crypt(pass, spw->sp_pwdp), spw->sp_pwdp)) + result = 1; + write(channel[1], &result, 1); + exit(0); +#else close(channel[0]); if (!(spw = getspnam(user)) || !pw || !*spw->sp_pwdp || *spw->sp_pwdp == '*' || *spw->sp_pwdp == '!') @@ -113,6 +179,8 @@ result = 1; write(channel[1], &result, 1); exit(0); +#endif + } if (close(channel[1])) @@ -127,18 +195,47 @@ return result == 1 ? pw : NULL; } + #else + /* * The /etc/passwd authentication routine. + * with add a custom "passwd" file by Marcin Krzyzanowski + * */ static struct passwd *do_passwd_auth(char *user, char *pass) { struct passwd *pw, *result; + +#ifdef AUTH_PASSWD_FILE_PATH + FILE *usersdb; + + usersdb = fopen(AUTH_PASSWD_FILE_PATH,"r"); + if (usersdb == NULL) { + syslog(SYSLOG_PRIORITY, "where is users database ? "); + exit(0); + } + + /* initialize */ + pw = NULL; + result = NULL; + + /* user searching */ + do { + pw = fgetpwent(usersdb); + if (!strcmp(pw->pw_name,user)) { + mailbox = pw->pw_name; + break; + } + } while(pw != NULL); + endpwent(); + fclose(usersdb); +#else if ((pw = getpwnam(user))) mailbox = user; endpwent(); result = NULL; - +#endif if (!pw || !*pw->pw_passwd || *pw->pw_passwd == '*' || *pw->pw_passwd == '!') crypt(pass, AUTH_DUMMY_SALT); @@ -152,6 +249,7 @@ return result; } #endif + /* * The root-privileged part of the AUTHORIZATION state handling: reads