diff -urN popa3d-0.6.2/params.h popa3d-0.6.2-spool-hashing/params.h --- popa3d-0.6.2/params.h Sun Sep 8 15:49:24 2002 +++ popa3d-0.6.2-spool-hashing/params.h Wed Apr 2 15:38:48 2003 @@ -209,6 +209,13 @@ #define SYSLOG_PRI_HI LOG_NOTICE #define SYSLOG_PRI_ERROR LOG_CRIT + /* + * Do we need mail spool hashing? Define hash depth here, i.e. value + * of 2 means two-level hashing, so user "foo"'s mailbox would be + * "SPOOL_PATH/f/o/foo". Value of 0 stands for "no hashing". + */ +#define MAIL_SPOOL_HASH 0 + /* * There's probably no reason to touch anything below this comment. */ diff -urN popa3d-0.6.2/pop_root.c popa3d-0.6.2-spool-hashing/pop_root.c --- popa3d-0.6.2/pop_root.c Fri Mar 22 01:15:19 2002 +++ popa3d-0.6.2-spool-hashing/pop_root.c Wed Apr 2 15:38:48 2003 @@ -97,6 +97,60 @@ return offset; } +#if MAIL_SPOOL_HASH +/* + * This routine returns string like "/var/mail/u/s" based on value + * of variable 'user' and 'MAIL_SPOOL_HASH' macro, i.e. if MAIL_SPOOL_HASH + * is 3 and user == "user" then returned string will be smth like that: + * "/var/mail/u/s/e" + */ + +char * hashed_spool(char * spool, char * user) +{ + char * hashed_spool_str = NULL; /* Return value */ + char * p = NULL; /* Temporary pointer */ + char * u = NULL; /* Temporary pointer */ + char c = 0; /* Temporary char */ + int i = 0; /* Counter */ + + /* Sanity checks */ + if (!spool || !*spool) return NULL; + if (!user || !*user) return NULL; + + /* + * Memory allocation. Don't bother freeing it, as it will be freed + * at the end of forked process lifetime. + */ + + if (!(hashed_spool_str = + (char *) malloc(strlen(spool) + 2*MAIL_SPOOL_HASH + 1))) + return NULL; + + /* + * We've allocated enough memory, so strcpy() usage is safe + */ + + strcpy(hashed_spool_str, spool); + + /* + * This part was stolen from procmail's source and seems safe enough + */ + + for (p = hashed_spool_str + strlen(spool), + i = MAIL_SPOOL_HASH, + u = user; + i--;) { + *p++ = '/'; + if (*u) c = *u++; + *p++ = c; + } + + *p = 0; /* end of string */ + + return hashed_spool_str; +} +#endif /* MAIL_SPOOL_HASH */ + /* * The root-privileged part of the AUTHORIZATION state handling: reads * the authentication data obtained over POP from its end of the pipe, @@ -160,7 +214,13 @@ #if POP_VIRTUAL if (virtual_domain) { + +#if MAIL_SPOOL_HASH + spool = hashed_spool(virtual_spool, user); +#else spool = virtual_spool; +#endif /* MAIL_SPOOL_HASH */ + mailbox = user; return AUTH_OK; @@ -172,7 +232,13 @@ return AUTH_FAILED; #else #ifdef MAIL_SPOOL_PATH + +#if MAIL_SPOOL_HASH + spool = hashed_spool(MAIL_SPOOL_PATH, user); +#else spool = MAIL_SPOOL_PATH; +#endif /* MAIL_SPOOL_HASH */ + mailbox = user; #else spool = pw->pw_dir;