diff -ru courier-imap-4.0.1/imap/pop3d.dist.in courier-imap-4.0.1-apop/imap/pop3d.dist.in --- courier-imap-4.0.1/imap/pop3d.dist.in 2004-10-31 00:39:57.000000000 +0900 +++ courier-imap-4.0.1-apop/imap/pop3d.dist.in 2005-01-09 19:43:02.000000000 +0900 @@ -119,3 +119,9 @@ # MAILDIRPATH - directory name of the maildir directory. # MAILDIRPATH=Maildir + +##NAME: POP3DHOSTNAME:0 +# +# POP3DHOSTNAME - APOP time-stamp hostname. +# +POP3DHOSTNAME=localhost.localdomain diff -ru courier-imap-4.0.1/imap/pop3login.c courier-imap-4.0.1-apop/imap/pop3login.c --- courier-imap-4.0.1/imap/pop3login.c 2005-01-05 11:31:36.000000000 +0900 +++ courier-imap-4.0.1-apop/imap/pop3login.c 2005-01-09 19:44:50.000000000 +0900 @@ -14,6 +14,7 @@ #include #include #include +#include #if HAVE_UNISTD_H #include #endif @@ -26,6 +27,7 @@ #include #include #include "tcpd/spipe.h" +#include "md5/md5.h" static const char rcsid[]="$Id: courier-imap-4.0.1-apop.patch 2 2005-12-30 14:34:29Z setoppu $"; @@ -242,12 +244,15 @@ int main(int argc, char **argv) { char *user=0; -char *p; +char *p,*r=0; char buf[BUFSIZ]; -int c; +int c,j; const char *ip=getenv("TCPREMOTEIP"); char authservice[40]; char *q ; +time_t now; +char *okmesg=0; +char *hostname=getenv("POP3DHOSTNAME"); if (!ip || !*ip) { @@ -264,10 +269,27 @@ pop3d=argv[1]; defaultmaildir=argv[2]; + if(hostname == NULL || *hostname == '\0') + { + fprintf(stderr, "INFO: Hostname is not setup, A default Hostname is used,\n"); + fflush(stderr); + hostname="localhost.localdomain"; + } + courier_authdebug_login_init(); + time(&now); fprintf(stderr, "DEBUG: Connection, ip=[%s]\n", ip); - printf("+OK Hello there.\r\n"); + j=strlen(hostname)+26; + if ((okmesg=malloc(j)) == 0) + { + printf("-ERR Server out of memory, aborting connection.\r\n"); + fflush(stdout); + perror("malloc"); + exit(1); + } + snprintf(okmesg, j, "<%lu.%lu@%s>", (unsigned long)(getpid() & 0xffffffff), (unsigned long)(now & 0xffffffff), hostname); + printf("+OK Hello there. %s\r\n", okmesg); fflush(stdout); fflush(stderr); @@ -433,12 +455,65 @@ printf("-ERR Login failed.\r\n"); fflush(stdout); continue; + + } else if (strcmp(p, "APOP") == 0) + { + int rc; + + p=strtok(0, " \t\r"); + if (p) + { + if (user) free(user); + if ((user=malloc(strlen(p)+1)) == 0) + { + printf("-ERR Server out of memory, aborting connection.\r\n"); + fflush(stdout); + perror("malloc"); + exit(1); + } + strcpy(user, p); + } + p=strtok(0, "\t\r"); + if (p == 0) + { + printf("-ERR APOP required.\r\n"); + fflush(stdout); + continue; + } + if ((r=malloc(strlen(p)+strlen(okmesg)+3)) == 0) + { + printf("-ERR Server out of memory, aborting connection.\r\n"); + fflush(stdout); + perror("malloc"); + exit(1); + } + strcat(strcat(strcat(strcpy(r, p), " "), okmesg), "\t"); + q="apop"; + rc=auth_login(q, user, r, login_callback, NULL); + free(r); + r=0; + courier_safe_printf("INFO: LOGIN " + "FAILED, user=%s, ip=[%s]", + user, ip); + if (rc > 0) + { + perror("ERR: authentication error"); + printf("-ERR Temporary problem, please try again later\r\n"); + fflush(stdout); + exit(1); + } + sleep(5); + printf("-ERR Login failed.\r\n"); + fflush(stdout); + continue; } } printf("-ERR Invalid command.\r\n"); fflush(stdout); } fprintf(stderr, "DEBUG: Disconnected, ip=[%s]\n", ip); + free(okmesg); + if (r) free(r); exit(0); return (0); }