$OpenBSD: patch-main_c,v 1.2 2005/12/14 06:02:09 jolan Exp $ --- main.c.orig Sun Aug 3 00:54:56 2003 +++ main.c Mon Nov 28 11:25:21 2005 @@ -23,26 +23,34 @@ #include "ssl.h" #include "strlcpy.h" +#ifndef DEFAULT_GROUP_NAME +# define DEFAULT_GROUP_NAME "_akpop3d" +#endif + static char * port = NULL; static int become_daemon = 0; const char * pidfile = "/var/run/akpop3d.pid"; -const char * ssl_certfile = "/etc/akpop3d/cert.pem"; -const char * ssl_keyfile = "/etc/akpop3d/key.pem"; +const char * ssl_certfile = SYSCONFDIR "/akpop3d/cert.pem"; +const char * ssl_keyfile = SYSCONFDIR "/akpop3d/key.pem"; +const char * group_name = DEFAULT_GROUP_NAME; const char * authfile = NULL; const char * local_mbox = NULL; const char * tmp_dir = "/tmp"; char * mailspool = "/var/mail/"; int use_pop3_allow_deny = 0; int enable_mysql = 0; -unsigned int timeout = 30; +unsigned int timeout = 600; +extern int *socks, maxs; +extern fd_set deffds; - +#ifdef HAVE_LIBMYSQLCLIENT /* mysql pointers */ extern char *HOSTNAME; extern char *USERNAME; extern char *PASSWORD; extern char *DATABASE; extern char *TABLE; +#endif /* HAVE_LIBMYSQLCLIENT */ int daemonize(void); void pop3_session(int fd); @@ -68,14 +76,15 @@ static void usage(char * argv0) { " -s use SSL for all connections\n" " -c use for SSL certificate [%s]\n" " -k use for SSL RSA key [%s]\n" - " -p listen on [default: 110, or 995 if SSL]\n", - ssl_certfile, ssl_keyfile + " -p listen on [default: 110, or 995 if SSL]\n" + " -g use GID to access spool directory [default: %s]\n", + ssl_certfile, ssl_keyfile, group_name ); printf( " -l
listen on
[default: any]\n" " -a use text file for authentication\n" " -m use directory as mail spool\n" - " -D use /etc/pop3.{allow,deny} files\n" + " -D use " SYSCONFDIR "/pop3.{allow,deny} files\n" " -L use ~/ as mail spool\n" " -t use seconds as r/w timeout\n" #ifdef HAVE_LIBMYSQLCLIENT @@ -107,21 +116,25 @@ static void delete_pid(void) { } int main(int argc, char * argv[]) { - int listenfd, connfd; + int connfd, maxfd; + int *socks; + fd_set fds; pid_t childpid; struct stat sbuf; - socklen_t addrlen; #ifdef HAVE_LIBMYSQLCLIENT - const char * optstring = "df:sp:c:k:l:a:m:hvDL:MH:U:P:I:T:t:x:"; + const char * optstring = "df:sp:c:k:l:a:m:hvDL:MH:U:P:I:T:t:x:g:"; int len = 0; #else - const char * optstring = "df:sp:c:k:l:a:m:hvDL:t:x:"; + const char * optstring = "df:sp:c:k:l:a:m:hvDL:t:x:g:"; #endif char * listenhost = NULL; char * progname; - int c; + int c,i; + struct sockaddr_storage client; socklen_t clen; - struct sockaddr_in client; + uint16_t sin_port_number; + const char *sin_addr_text; + char sin_addr_text_buffer[64]; #ifdef HAVE_LIBMYSQLCLIENT struct rlimit memlim, cpulim; @@ -159,6 +172,7 @@ int main(int argc, char * argv[]) { case 'k': ssl_keyfile = optarg; break; case 'l': listenhost = optarg; break; case 'a': authfile = optarg; break; + case 'g': group_name = optarg; break; case 't': sscanf(optarg,"%u",&timeout); break; case 'x': tmp_dir = optarg; break; case 'm': if (stat(optarg,&sbuf)!=0) { @@ -253,8 +267,13 @@ int main(int argc, char * argv[]) { } openlog(progname, LOG_PID, LOG_MAIL); - listenfd = Tcp_listen(listenhost, port, &addrlen); - + socks = Tcp_listen(listenhost, port); + for (maxfd = -1, i=0; isin6_family,&(((struct sockaddr_in6 *)&client)->sin6_addr),sin_addr_text_buffer,64); + sin_port_number=ntohs(((struct sockaddr_in6 *)&client)->sin6_port); + } + else + { + sin_addr_text=inet_ntoa(((struct sockaddr_in *)&client)->sin_addr); // IPv4 + sin_port_number=ntohs(((struct sockaddr_in *)&client)->sin_port); + } + syslog( LOG_INFO, "Connection from %s:%u",sin_addr_text,sin_port_number); - syslog( LOG_INFO, "Connection from %s:%u", inet_ntoa( client.sin_addr ), ntohs( client.sin_port ) ); - if ((childpid = fork()) == 0) { - close(listenfd); +/* close(listenfd); */ pop3_session(connfd); syslog( LOG_INFO, "Connection closed" ); exit(0);