diff -ruN cucipop-1.31.orig/config.h cucipop-1.31/config.h --- cucipop-1.31.orig/config.h Thu Dec 9 18:32:31 1999 +++ cucipop-1.31/config.h Thu Dec 9 15:36:11 1999 @@ -50,9 +50,11 @@ #define UIDLF 'U' #define APOPF 'A' #define TOPF 'T' +#define CONLIMIT 'L' #define HELP1 'h' #define HELP2 '?' -#define USAGE "Usage: %s [-vqaYdPUSDAT] [-E age] [-p port]\n" +#define USAGE \ +"Usage: %s [-vqaYdPUSDAT] [-E age] [-p port] [-L limit ]\n" #define XUSAGE \ "\t-v\tdisplay the version number and exit\ \n\t-q\tquiet\ @@ -65,6 +67,9 @@ \n\t-E age\texpire messages through -S or -D older than age only\ \n\t-A\tdisable optional APOP command\ \n\t-T\tdisable optional TOP command\ +\n\t-L limit\t\ +\n\t\tMaximum number of simultaneous connections. 0 for unlimited\ +\n\t\tDefaults to 0\ \n\t-p port\tspecify port other than %d\n" /*#define LOG_FAILED_PASSWORD /* log failed passwords */ diff -ruN cucipop-1.31.orig/cucipop.8 cucipop-1.31/cucipop.8 --- cucipop-1.31.orig/cucipop.8 Tue May 12 02:35:19 1998 +++ cucipop-1.31/cucipop.8 Thu Dec 9 18:27:34 1999 @@ -51,6 +51,7 @@ .B /usr/sbin/cucipop .RB [ \-qaYdPUSDAT ] .RB [ "\-E \fIage\fP" ] +.RB [ "\-L \fIlimit\fP" ] .RB [ "\-p \fIport\fP" ] .br .B /usr/sbin/cucipop @@ -126,6 +127,11 @@ .TP .B \-T Disable the optional TOP command. +.TP +.I "\fB\-L\fP limit" +Set the maximum number of simultaneous connections to accept. +A value of 0 sets an unlimited number of simultaneous connections. +Default is 0. .TP .I "\fB\-p\fP port" Bind to a different diff -ruN cucipop-1.31.orig/cucipop.c cucipop-1.31/cucipop.c --- cucipop-1.31.orig/cucipop.c Thu Dec 9 18:36:33 1999 +++ cucipop-1.31/cucipop.c Thu Dec 9 18:35:22 1999 @@ -101,8 +101,11 @@ static void bailout(void); -static void zombiecollect(void) -{ while(waitpid((pid_t)-1,(int*)0,WNOHANG)>0); /* collect any zombies */ +static int zombiecollect(void) +{ int nochld=0; + while(waitpid((pid_t)-1,(int*)0,WNOHANG)>0) /* collect any zombies */ + nochld++; + return(nochld); } void blocksignals(void) @@ -627,6 +630,7 @@ { unsigned loginattempts=0,quiet=0,debug=0;short port=POP3_PORT; unsigned douser=1,douidl=1,doapop=1,dotop=1,autodel=0,sabotage=0; static const char tdotnl[]=".\r\n";time_t agecutoff=-AGETOLERANCE; + int connection=0, maxcon=0; #ifdef PAM pam_handle_t *pamh=NULL; #endif @@ -738,6 +742,8 @@ continue; case PORT:Qnext_arg();port=strtol(chp,(char**)&chp,10); continue; + case CONLIMIT:Qnext_arg();maxcon=strtol(chp,(char**)&chp,10); + continue; case '\0':; } break; @@ -754,8 +760,8 @@ peername.sin_port=htons(port);curfd=-1; setsockopt(serverfd,SOL_SOCKET,SO_REUSEADDR,&curfd,sizeof curfd); if(bind(serverfd,(struct sockaddr*)&peername,sizeof peername)) - { syslog(LOG_CRIT,"unable to bind socket %d",POP3_PORT); - fprintf(stderr,"%s: Can't bind socket %d\n",cucipopn,POP3_PORT); + { syslog(LOG_CRIT,"unable to bind socket %d",port); + fprintf(stderr,"%s: Can't bind socket %d\n",cucipopn,port); #ifdef PAM return do_pam_end(pamh, EX_OSFILE); #else @@ -782,10 +788,15 @@ { close(curfd); if(namelen<0) sleep(LOCKSLEEP); - namelen=sizeof peername;checkbulletins();zombiecollect(); + namelen=sizeof peername;checkbulletins();connection-=zombiecollect(); if((curfd=accept(serverfd,(struct sockaddr*)&peername,&namelen))<0) - continue; - zombiecollect(); + continue; + if(maxcon>0 && connection>=maxcon) { + close(curfd); + continue; + } + connection++; + connection-=zombiecollect(); } while(namelen=fork()); close(serverfd);