#include "portab.h"
-static char UNUSED id[] = "$Id: conf.c,v 1.76 2005/04/16 09:23:01 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 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
Conf_Init( void )
{
struct passwd *pwd;
struct group *grp;
- int i;
+ unsigned int i;
+ char *topic;
Use_Log = false;
Set_Defaults( true );
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 );
- printf( " Topic = %s\n", Conf_Channel[i].topic );
+
+ topic = (char*)array_start(&Conf_Channel[i].topic);
+ printf( " Topic = %s\n", topic ? topic : "");
puts( "" );
}
int i;
strcpy( Conf_ServerName, "" );
- sprintf( Conf_ServerInfo, "%s %s", PACKAGE_NAME, PACKAGE_VERSION );
+ snprintf( Conf_ServerInfo, sizeof Conf_ServerInfo, "%s %s", PACKAGE_NAME, PACKAGE_VERSION );
strcpy( Conf_ServerPwd, "" );
strcpy( Conf_ServerAdmin1, "" );
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;
else New_Server_Idx = i;
continue;
}
- if( strcasecmp( section, "[CHANNEL]" ) == 0 )
- {
- if( Conf_Channel_Count + 1 > MAX_DEFCHANNELS ) Config_Error( LOG_ERR, "Too many pre-defined channels configured." );
- else
- {
+ if( strcasecmp( section, "[CHANNEL]" ) == 0 ) {
+ if( Conf_Channel_Count + 1 > MAX_DEFCHANNELS ) {
+ Config_Error( LOG_ERR, "Too many pre-defined channels configured." );
+ } else {
/* Initialize new channel structure */
strcpy( Conf_Channel[Conf_Channel_Count].name, "" );
strcpy( Conf_Channel[Conf_Channel_Count].modes, "" );
- strcpy( Conf_Channel[Conf_Channel_Count].topic, "" );
+ array_free(&Conf_Channel[Conf_Channel_Count].topic);
Conf_Channel_Count++;
}
continue;
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 )
LOCAL void
Handle_OPERATOR( int Line, char *Var, char *Arg )
{
+ unsigned int opercount;
+ size_t len;
assert( Line > 0 );
assert( Var != NULL );
assert( Arg != NULL );
assert( Conf_Oper_Count > 0 );
- if( strcasecmp( Var, "Name" ) == 0 )
- {
+ if ( Conf_Oper_Count == 0 )
+ return;
+
+ opercount = Conf_Oper_Count - 1;
+
+ if( strcasecmp( Var, "Name" ) == 0 ) {
/* Name of IRC operator */
- if( strlcpy( Conf_Oper[Conf_Oper_Count - 1].name, Arg, sizeof( Conf_Oper[Conf_Oper_Count - 1].name )) >= sizeof( Conf_Oper[Conf_Oper_Count - 1].name )) Config_Error_TooLong( Line, Var );
+ len = strlcpy( Conf_Oper[opercount].name, Arg, sizeof( Conf_Oper[opercount].name ));
+ if (len >= sizeof( Conf_Oper[opercount].name ))
+ Config_Error_TooLong( Line, Var );
+
return;
}
- if( strcasecmp( Var, "Password" ) == 0 )
- {
+ if( strcasecmp( Var, "Password" ) == 0 ) {
/* Password of IRC operator */
- if( strlcpy( Conf_Oper[Conf_Oper_Count - 1].pwd, Arg, sizeof( Conf_Oper[Conf_Oper_Count - 1].pwd )) >= sizeof( Conf_Oper[Conf_Oper_Count - 1].pwd )) Config_Error_TooLong( Line, Var );
+ len = strlcpy( Conf_Oper[opercount].pwd, Arg, sizeof( Conf_Oper[opercount].pwd ));
+ if (len >= sizeof( Conf_Oper[opercount].pwd ))
+ Config_Error_TooLong( Line, Var );
return;
}
- if( strcasecmp( Var, "Mask" ) == 0 )
- {
- if (Conf_Oper[Conf_Oper_Count - 1].mask) return; /* Hostname already configured */
- Conf_Oper[Conf_Oper_Count - 1].mask = strdup( Arg );
- if (! Conf_Oper[Conf_Oper_Count - 1].mask) {
- Config_Error( LOG_ERR, "%s, line %d: Cannot allocate memory for operator mask: %s", NGIRCd_ConfFile, Line, strerror(errno) );
+ if( strcasecmp( Var, "Mask" ) == 0 ) {
+ if (Conf_Oper[opercount].mask) return; /* Hostname already configured */
+
+ Conf_Oper[opercount].mask = strdup( Arg );
+ if (! Conf_Oper[opercount].mask) {
+ Config_Error( LOG_ERR, "%s, line %d: Cannot allocate memory for operator mask: %s",
+ NGIRCd_ConfFile, Line, strerror(errno) );
return;
}
return;
}
- Config_Error( LOG_ERR, "%s, line %d (section \"Operator\"): Unknown variable \"%s\"!", NGIRCd_ConfFile, Line, Var );
+ Config_Error( LOG_ERR, "%s, line %d (section \"Operator\"): Unknown variable \"%s\"!",
+ NGIRCd_ConfFile, Line, Var );
} /* Handle_OPERATOR */
if( strcasecmp( Var, "Topic" ) == 0 )
{
/* Initial topic */
- if( strlcpy( Conf_Channel[Conf_Channel_Count - 1].topic, Arg, sizeof( Conf_Channel[Conf_Channel_Count - 1].topic )) >= sizeof( Conf_Channel[Conf_Channel_Count - 1].topic ))
+ if (!array_copys( &Conf_Channel[Conf_Channel_Count - 1].topic, Arg))
Config_Error_TooLong( Line, Var );
return;
/* No administrative information configured! */
Config_Error( LOG_WARNING, "No administrative information configured but required by RFC!" );
}
-#ifdef FD_SETSIZE
- if(( Conf_MaxConnections > (long)FD_SETSIZE ) || ( Conf_MaxConnections < 1 ))
- {
- Conf_MaxConnections = (long)FD_SETSIZE;
- Config_Error( LOG_ERR, "Setting MaxConnections to %ld, select() can't handle more file descriptors!", Conf_MaxConnections );
- }
-#else
- Config_Error( LOG_WARN, "Don't know how many file descriptors select() can handle on this system, don't set MaxConnections too high!" );
-#endif
-
#ifdef DEBUG
servers = servers_once = 0;
for( i = 0; i < MAX_SERVERS; i++ )