$NetBSD: patch-bg,v 1.5 2000/02/22 00:49:01 itohy Exp $ --- wwwoffled.c.orig Wed Dec 29 05:05:15 1999 +++ wwwoffled.c Tue Feb 22 08:34:12 2000 @@ -50,8 +50,8 @@ /*+ The server sockets that we listen on +*/ -int http_fd=-1, /*+ for the HTTP connections. +*/ - wwwoffle_fd=-1; /*+ for the WWWOFFLE connections. +*/ +int *http_fd_list, http_fd, /*+ for the HTTP connections. +*/ + *wwwoffle_fd_list, wwwoffle_fd; /*+ for the WWWOFFLE connections. +*/ /*+ The online / offline /autodial status. +*/ int online=0; @@ -173,12 +173,12 @@ if(WWWOFFLE_Gid != -1 || WWWOFFLE_Uid != -1) PrintMessage(Inform,"Running with uid=%d, gid=%d.",getuid(),getgid()); - http_fd=OpenServerSocket(HTTP_Port); - if(http_fd==-1) + http_fd_list=OpenServerSockets(HTTP_Port); + if(!http_fd_list) PrintMessage(Fatal,"Cannot create HTTP server socket."); - wwwoffle_fd=OpenServerSocket(WWWOFFLE_Port); - if(wwwoffle_fd==-1) + wwwoffle_fd_list=OpenServerSockets(WWWOFFLE_Port); + if(!wwwoffle_fd_list) PrintMessage(Fatal,"Cannot create WWWOFFLE server socket."); umask(0); @@ -213,20 +213,29 @@ { struct timeval tv; fd_set readfd; + int fd, i; int nfds; int retval; - if(http_fd>wwwoffle_fd) - nfds=http_fd+1; - else - nfds=wwwoffle_fd+1; + fd = http_fd_list[1]; + for (i = 1; i <= http_fd_list[0]; i++) { + if (!fd || fd < http_fd_list[i]) + fd = http_fd_list[i]; + } + for (i = 1; i <= wwwoffle_fd_list[0]; i++) { + if (!fd || fd < wwwoffle_fd_list[i]) + fd = wwwoffle_fd_list[i]; + } + nfds=fd+1; FD_ZERO(&readfd); - FD_SET(wwwoffle_fd,&readfd); + for (i = 1; i <= wwwoffle_fd_list[0]; i++) + FD_SET(wwwoffle_fd_list[i],&readfd); if(n_servers=0 && !SocketRemoteName(client,&host,&ip,&port)) - { - if(IsAllowedConnectHost(host) || IsAllowedConnectHost(ip)) - { - PrintMessage(Important,"WWWOFFLE Connection from host %s (%s).",host,ip); /* Used in audit-usage.pl */ - - CommandConnect(client); - - if(fetch_fd!=client) - CloseSocket(client); - } - else - { - PrintMessage(Warning,"WWWOFFLE Connection rejected from host %s (%s).",host,ip); /* Used in audit-usage.pl */ - CloseSocket(client); - } - } - } - - if(FD_ISSET(http_fd,&readfd)) - { - char *host,*ip; - int port,client; - - client=AcceptConnect(http_fd); - init_buffer(client); - - if(client>=0 && !SocketRemoteName(client,&host,&ip,&port)) - { - if(IsAllowedConnectHost(host) || IsAllowedConnectHost(ip)) - { - PrintMessage(Inform,"HTTP Proxy connection from host %s (%s).",host,ip); /* Used in audit-usage.pl */ - ForkServer(client,1); - } - else - PrintMessage(Warning,"HTTP Proxy connection rejected from host %s (%s).",host,ip); /* Used in audit-usage.pl */ - - CloseSocket(client); - } - } + for (i = 1; i <= wwwoffle_fd_list[0]; i++) { + wwwoffle_fd = wwwoffle_fd_list[i]; + if(FD_ISSET(wwwoffle_fd,&readfd)) + { + char *host,*ip; + int port,client; + + client=AcceptConnect(wwwoffle_fd); + init_buffer(client); + + if(client>=0 && !SocketRemoteName(client,&host,&ip,&port)) + { + if(IsAllowedConnectHost(host) || IsAllowedConnectHost(ip)) + { + PrintMessage(Important,"WWWOFFLE Connection from host %s (%s).",host,ip); /* Used in audit-usage.pl */ + + CommandConnect(client); + + if(fetch_fd!=client) + CloseSocket(client); + } + else + { + PrintMessage(Warning,"WWWOFFLE Connection rejected from host %s (%s).",host,ip); /* Used in audit-usage.pl */ + CloseSocket(client); + } + } + } + } + for (i = 1; i <= http_fd_list[0]; i++) { + http_fd = http_fd_list[i]; + + if(FD_ISSET(http_fd,&readfd)) + { + char *host,*ip; + int port,client; + + client=AcceptConnect(http_fd); + init_buffer(client); + + if(client>=0 && !SocketRemoteName(client,&host,&ip,&port)) + { + if(IsAllowedConnectHost(host) || IsAllowedConnectHost(ip)) + { + PrintMessage(Inform,"HTTP Proxy connection from host %s (%s).",host,ip); /* Used in audit-usage.pl */ + ForkServer(client,1); + } + else + PrintMessage(Warning,"HTTP Proxy connection rejected from host %s (%s).",host,ip); /* Used in audit-usage.pl */ + + CloseSocket(client); + } + } + } } - + if(readconfig) { readconfig=0; @@ -373,9 +388,11 @@ while(!closedown); /* Close down and exit. */ + for (i = 1; i <= wwwoffle_fd_list[0]; i++) + CloseSocket(wwwoffle_fd_list[i]); - CloseSocket(http_fd); - CloseSocket(wwwoffle_fd); + for (i = 1; i <= http_fd_list[0]; i++) + CloseSocket(http_fd_list[i]); if(n_servers) PrintMessage(Important,"Exit signalled - waiting for %d child wwwoffles servers.",n_servers);