commit - 890c3d9d72f468ca90e81e63bd27bb1dfa7311c8
commit + 51ccb5928ad1453b0593fedd934298384d09e619
blob - 0764d2c7d96d720f700860221543479f07f86567
blob + b4e56172d0e7237120efb3ace301e7a6080405c1
--- src/ngircd/conf.c
+++ src/ngircd/conf.c
#include "portab.h"
-static char UNUSED id[] = "$Id: conf.c,v 1.81 2005/07/28 16:23:55 fw Exp $";
+static char UNUSED id[] = "$Id: conf.c,v 1.82 2005/07/29 09:29:47 fw Exp $";
#include "imp.h"
#include <assert.h>
# include <ctype.h>
#endif
+#include "array.h"
#include "ngircd.h"
#include "conn.h"
#include "client.h"
LOCAL void Config_Error_TooLong PARAMS(( const int LINE, const char *Value ));
LOCAL void Init_Server_Struct PARAMS(( CONF_SERVER *Server ));
+
+
+static void
+ports_puts(array *a)
+{
+ unsigned int len;
+ UINT16 *ports;
+ len = array_length(a, sizeof(UINT16));
+ if (len--) {
+ ports = (UINT16*) array_start(a);
+ printf("%u", (unsigned int) *ports);
+ while (len--) {
+ ports++;
+ printf(", %u", (unsigned int) *ports);
+ }
+ }
+ putc('\n', stdout);
+}
+
+
+static void
+ports_parse(array *a, int Line, char *Arg)
+{
+ char *ptr;
+ int port;
+ UINT16 port16;
+
+ array_trunc(a);
+
+ /* Ports on that the server should listen. More port numbers
+ * must be separated by "," */
+ ptr = strtok( Arg, "," );
+ while (ptr) {
+ ngt_TrimStr( ptr );
+ port = atol( ptr );
+ if (port > 0 && port < 0xFFFF) {
+ port16 = (UINT16) port;
+ if (!array_catb(a, (char*)&port16, sizeof port16))
+ Config_Error(LOG_ERR, "%s, line %d Could not add port number %ld: %s",
+ NGIRCd_ConfFile, Line, port, strerror(errno));
+ } else {
+ Config_Error( LOG_ERR, "%s, line %d (section \"Global\"): Illegal port number %ld!",
+ NGIRCd_ConfFile, Line, port );
+ }
+
+ ptr = strtok( NULL, "," );
+ }
+}
GLOBAL void
printf( " MotdPhrase = %s\n", Conf_MotdPhrase );
printf( " ChrootDir = %s\n", Conf_Chroot );
printf( " PidFile = %s\n", Conf_PidFile);
- printf( " Ports = " );
- for( i = 0; i < Conf_ListenPorts_Count; i++ )
- {
- if( i != 0 ) printf( ", " );
- printf( "%u", (unsigned int) Conf_ListenPorts[i] );
- }
- puts( "" );
+ fputs(" Ports = ", stdout);
+
+ ports_puts(&Conf_ListenPorts);
+
printf( " Listen = %s\n", Conf_ListenAddress );
pwd = getpwuid( Conf_UID );
if( pwd ) printf( " ServerUID = %s\n", pwd->pw_name );
puts( "[CHANNEL]" );
printf( " Name = %s\n", Conf_Channel[i].name );
printf( " Modes = %s\n", Conf_Channel[i].modes );
+
topic = (char*)array_start(&Conf_Channel[i].topic);
printf( " Topic = %s\n", topic ? topic : "");
puts( "" );
strlcpy( Conf_PidFile, PID_FILE, sizeof( Conf_PidFile ));
- Conf_ListenPorts_Count = 0;
strcpy( Conf_ListenAddress, "" );
Conf_UID = Conf_GID = 0;
/* Read configuration file. */
char section[LINE_LEN], str[LINE_LEN], *var, *arg, *ptr;
+ const UINT16 defaultport = 6667;
int line, i, n;
FILE *fd;
assert( New_Server_Idx > NONE );
Conf_Server[New_Server_Idx] = New_Server;
}
-
- /* If there are no ports configured use the default: 6667 */
- if( Conf_ListenPorts_Count < 1 )
- {
- Conf_ListenPorts_Count = 1;
- Conf_ListenPorts[0] = 6667;
+
+ if (0 == array_length(&Conf_ListenPorts, sizeof(UINT16))) {
+ if (!array_copyb(&Conf_ListenPorts, (char*) &defaultport, sizeof defaultport)) {
+ Config_Error( LOG_ALERT, "Could not add default listening Port %u: %s",
+ (unsigned int) defaultport, strerror(errno));
+ exit( 1 );
+ }
}
} /* Read_Config */
{
struct passwd *pwd;
struct group *grp;
- char *ptr;
- long port;
assert( Line > 0 );
assert( Var != NULL );
if( strlcpy( Conf_ServerAdminMail, Arg, sizeof( Conf_ServerAdminMail )) >= sizeof( Conf_ServerAdminMail )) Config_Error_TooLong( Line, Var );
return;
}
- if( strcasecmp( Var, "Ports" ) == 0 )
- {
- /* Ports on that the server should listen. More port numbers
- * must be separated by "," */
- ptr = strtok( Arg, "," );
- while( ptr )
- {
- ngt_TrimStr( ptr );
- port = atol( ptr );
- if( Conf_ListenPorts_Count + 1 > MAX_LISTEN_PORTS ) Config_Error( LOG_ERR, "Too many listen ports configured. Port %ld ignored.", port );
- else
- {
- if( port > 0 && port < 0xFFFF ) Conf_ListenPorts[Conf_ListenPorts_Count++] = (UINT16)port;
- else Config_Error( LOG_ERR, "%s, line %d (section \"Global\"): Illegal port number %ld!", NGIRCd_ConfFile, Line, port );
- }
- ptr = strtok( NULL, "," );
- }
+
+ if( strcasecmp( Var, "Ports" ) == 0 ) {
+ ports_parse(&Conf_ListenPorts, Line, Arg);
return;
}
if( strcasecmp( Var, "MotdFile" ) == 0 )
blob - e312cccad1b0f5228dbc38db10e3b081eed52f75
blob + f9e30da20b39ef30cad2ad94d88b3c6df4b14845
--- src/ngircd/conf.h
+++ src/ngircd/conf.h
* (at your option) any later version.
* Please read the file COPYING, README and AUTHORS for more information.
*
- * $Id: conf.h,v 1.36 2005/07/28 16:23:55 fw Exp $
+ * $Id: conf.h,v 1.37 2005/07/29 09:29:47 fw Exp $
*
* Configuration management (header)
*/
GLOBAL char Conf_MotdPhrase[LINE_LEN];
/* Ports the server should listen on */
-GLOBAL UINT16 Conf_ListenPorts[MAX_LISTEN_PORTS];
-GLOBAL unsigned int Conf_ListenPorts_Count;
+GLOBAL array Conf_ListenPorts;
/* Address to which the socket should be bound or empty (=all) */
GLOBAL char Conf_ListenAddress[16];
blob - 07c504cc506825275979f490821b1eda50854b02
blob + 146cb8ef4bdcbb2fac1d6ddad19353c04d006137
--- src/ngircd/conn.c
+++ src/ngircd/conn.c
#include "portab.h"
#include "io.h"
-static char UNUSED id[] = "$Id: conn.c,v 1.166 2005/07/28 16:13:09 fw Exp $";
+static char UNUSED id[] = "$Id: conn.c,v 1.167 2005/07/29 09:29:47 fw Exp $";
#include "imp.h"
#include <assert.h>
LOCAL bool Handle_Write PARAMS(( CONN_ID Idx ));
-LOCAL void New_Connection PARAMS(( int Sock ));
+LOCAL int New_Connection PARAMS(( int Sock ));
LOCAL CONN_ID Socket2Index PARAMS(( int Sock ));
LOCAL void Read_Request PARAMS(( CONN_ID Idx ));
LOCAL bool Handle_Buffer PARAMS(( CONN_ID Idx ));
int deny_severity = LOG_ERR;
#endif
+static void server_login PARAMS((CONN_ID idx));
static void cb_clientserver PARAMS((int sock, short what));
}
Conn_OPTION_DEL( &My_Connections[idx], CONN_ISCONNECTING );
+ server_login(idx);
+}
+
+static void
+server_login(CONN_ID idx)
+{
Log( LOG_INFO, "Connection %d with \"%s:%d\" established. Now logging in ...", idx,
My_Connections[idx].host, Conf_Server[Conf_GetServer( idx )].port );
} /* Conn_Exit */
-GLOBAL int
-Conn_InitListeners( void )
+static unsigned int
+ports_initlisteners(array *a, void (*func)(int,short))
{
- /* Initialize ports on which the server should accept connections */
-
- int created, fd;
- unsigned int i;
-
- if (!io_library_init(CONNECTION_POOL)) {
- Log(LOG_EMERG, "Cannot initialize IO routines: %s", strerror(errno));
- return -1;
- }
+ unsigned int created = 0, len;
+ int fd;
+ UINT16 *port;
- created = 0;
- for( i = 0; i < Conf_ListenPorts_Count; i++ ) {
- fd = NewListener( Conf_ListenPorts[i] );
+ len = array_length(a, sizeof (UINT16));
+ port = array_start(a);
+ while(len--) {
+ fd = NewListener( *port );
if (fd < 0) {
- Log( LOG_ERR, "Can't listen on port %u!", (unsigned int) Conf_ListenPorts[i] );
+ port++;
continue;
}
- if (!io_event_create( fd, IO_WANTREAD, cb_listen )) {
+ if (!io_event_create( fd, IO_WANTREAD, func )) {
Log( LOG_ERR, "io_event_create(): Could not add listening fd %d (port %u): %s!",
- fd, (unsigned int) Conf_ListenPorts[i], strerror(errno));
+ fd, (unsigned int) *port, strerror(errno));
close(fd);
+ port++;
continue;
}
created++;
+ port++;
+ }
+
+ return created;
+}
+
+
+GLOBAL int
+Conn_InitListeners( void )
+{
+ /* Initialize ports on which the server should accept connections */
+
+ unsigned int created;
+
+ if (!io_library_init(CONNECTION_POOL)) {
+ Log(LOG_EMERG, "Cannot initialize IO routines: %s", strerror(errno));
+ return -1;
}
+
+ created = ports_initlisteners(&Conf_ListenPorts, cb_listen);
+
return created;
} /* Conn_InitListeners */
}
assert( My_Connections[Idx].sock > NONE );
-
wdatalen = array_bytes(&My_Connections[Idx].wbuf );
#ifdef ZLIB
if(( wdatalen == 0 ) && ( ! array_bytes(&My_Connections[Idx].zip.wbuf))) {
} /* Handle_Write */
-LOCAL void
+LOCAL int
New_Connection( int Sock )
{
/* Neue Client-Verbindung von Listen-Socket annehmen und
if( new_sock < 0 )
{
Log( LOG_CRIT, "Can't accept connection: %s!", strerror( errno ));
- return;
+ return -1;
}
#ifdef TCPWRAP
Log( deny_severity, "Refused connection from %s (by TCP Wrappers)!", inet_ntoa( new_addr.sin_addr ));
Simple_Message( new_sock, "ERROR :Connection refused" );
close( new_sock );
- return;
+ return -1;
}
#endif
Log( LOG_ERR, "Refused connection from %s: too may connections (%ld) from this IP address!", inet_ntoa( new_addr.sin_addr ), cnt);
Simple_Message( new_sock, "ERROR :Connection refused, too many connections from your IP address!" );
close( new_sock );
- return;
+ return -1;
}
/* Freie Connection-Struktur suchen */
Log( LOG_ALERT, "Can't accept connection: limit (%d) reached!", Pool_Size );
Simple_Message( new_sock, "ERROR :Connection limit reached" );
close( new_sock );
- return;
+ return -1;
}
if( new_size > Conf_MaxConnections ) new_size = Conf_MaxConnections;
}
Log( LOG_ALERT, "Can't accept connection: limit (%d) reached -- overflow!", Pool_Size );
Simple_Message( new_sock, "ERROR :Connection limit reached" );
close( new_sock );
- return;
+ return -1;
}
ptr = (POINTER *)realloc( My_Connections, sizeof( CONNECTION ) * new_size );
Log( LOG_EMERG, "Can't allocate memory! [New_Connection]" );
Simple_Message( new_sock, "ERROR: Internal error" );
close( new_sock );
- return;
+ return -1;
}
#ifdef DEBUG
Log( LOG_ALERT, "Can't accept connection: can't create client structure!" );
Simple_Message( new_sock, "ERROR :Internal error" );
close( new_sock );
- return;
+ return -1;
}
/* Verbindung registrieren */
if (!io_event_create( new_sock, IO_WANTREAD, cb_clientserver)) {
Simple_Message( new_sock, "ERROR :Internal error" );
Conn_Close( idx, "io_event_create() failed", NULL, false );
- return;
+ return -1;
}
Log( LOG_INFO, "Accepted connection %d from %s:%d on socket %d.", idx, inet_ntoa( new_addr.sin_addr ), ntohs( new_addr.sin_port), Sock );
/* Penalty-Zeit setzen */
Conn_SetPenalty( idx, 4 );
+ return new_sock;
} /* New_Connection */
/* Read result from pipe */
bytes_read = read( r_fd, readbuf, sizeof readbuf -1 );
- if( bytes_read < 0 )
- {
+ if( bytes_read < 0 ) {
/* Error! */
Log( LOG_CRIT, "Resolver: Can't read result: %s!", strerror( errno ));
FreeRes_stat( &My_Connections[i] );
}
len = (unsigned int) bytes_read;
readbuf[len] = '\0';
- if (!array_catb(&s->buffer, readbuf, len)) {
+ if (!array_catb(&s->buffer, readbuf, len)) {
Log( LOG_CRIT, "Resolver: Can't append result %s to buffer: %s", readbuf, strerror( errno ));
FreeRes_stat(&My_Connections[i]);
return;
/* Search server ... */
n = Conf_GetServer( i );
assert( n > NONE );
-
+
bufptr = (char*) array_start(&s->buffer);
strlcpy( Conf_Server[n].ip, bufptr, sizeof( Conf_Server[n].ip ));
}