2 * ngIRCd -- The Next Generation IRC Daemon
3 * Copyright (c)2001,2002 Alexander Barton (alex@barton.de)
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 * Please read the file COPYING, README and AUTHORS for more information.
11 * Configuration management (reading, parsing & validation)
17 static char UNUSED id[] = "$Id: conf.c,v 1.52 2002/12/30 00:01:45 alex Exp $";
29 #include <sys/types.h>
48 LOCAL BOOLEAN Use_Log = TRUE;
49 LOCAL CONF_SERVER New_Server;
50 LOCAL INT New_Server_Idx;
53 LOCAL VOID Set_Defaults PARAMS(( BOOLEAN InitServers ));
54 LOCAL VOID Read_Config PARAMS(( VOID ));
55 LOCAL VOID Validate_Config PARAMS(( BOOLEAN TestOnly ));
57 LOCAL VOID Handle_GLOBAL PARAMS(( INT Line, CHAR *Var, CHAR *Arg ));
58 LOCAL VOID Handle_OPERATOR PARAMS(( INT Line, CHAR *Var, CHAR *Arg ));
59 LOCAL VOID Handle_SERVER PARAMS(( INT Line, CHAR *Var, CHAR *Arg ));
60 LOCAL VOID Handle_CHANNEL PARAMS(( INT Line, CHAR *Var, CHAR *Arg ));
62 LOCAL VOID Config_Error PARAMS(( CONST INT Level, CONST CHAR *Format, ... ));
64 LOCAL VOID Init_Server_Struct PARAMS(( CONF_SERVER *Server ));
72 Validate_Config( FALSE );
79 Set_Defaults( FALSE );
81 Validate_Config( FALSE );
88 /* Read configuration, validate and output it. */
98 Validate_Config( TRUE );
100 /* If stdin is a valid tty wait for a key: */
101 if( isatty( fileno( stdout )))
103 puts( "OK, press enter to see a dump of your service configuration ..." );
106 else puts( "Ok, dump of your server configuration follows:\n" );
109 printf( " ServerName = %s\n", Conf_ServerName );
110 printf( " ServerInfo = %s\n", Conf_ServerInfo );
111 printf( " ServerPwd = %s\n", Conf_ServerPwd );
112 printf( " AdminInfo1 = %s\n", Conf_ServerAdmin1 );
113 printf( " AdminInfo2 = %s\n", Conf_ServerAdmin2 );
114 printf( " AdminEMail = %s\n", Conf_ServerAdminMail );
115 printf( " MotdFile = %s\n", Conf_MotdFile );
116 printf( " Ports = " );
117 for( i = 0; i < Conf_ListenPorts_Count; i++ )
119 if( i != 0 ) printf( ", " );
120 printf( "%u", Conf_ListenPorts[i] );
123 pwd = getpwuid( Conf_UID );
124 if( pwd ) printf( " ServerUID = %s\n", pwd->pw_name );
125 else printf( " ServerUID = %ld\n", (LONG)Conf_UID );
126 grp = getgrgid( Conf_GID );
127 if( grp ) printf( " ServerGID = %s\n", grp->gr_name );
128 else printf( " ServerGID = %ld\n", (LONG)Conf_GID );
129 printf( " PingTimeout = %d\n", Conf_PingTimeout );
130 printf( " PongTimeout = %d\n", Conf_PongTimeout );
131 printf( " ConnectRetry = %d\n", Conf_ConnectRetry );
132 printf( " OperCanUseMode = %s\n", Conf_OperCanMode == TRUE ? "yes" : "no" );
133 if( Conf_MaxConnections > 0 ) printf( " MaxConnections = %ld\n", Conf_MaxConnections );
134 else printf( " MaxConnections = -1\n" );
135 if( Conf_MaxJoins > 0 ) printf( " MaxJoins = %d\n", Conf_MaxJoins );
136 else printf( " MaxJoins = -1\n" );
139 for( i = 0; i < Conf_Oper_Count; i++ )
141 if( ! Conf_Oper[i].name[0] ) continue;
143 /* Valid "Operator" section */
144 puts( "[OPERATOR]" );
145 printf( " Name = %s\n", Conf_Oper[i].name );
146 printf( " Password = %s\n", Conf_Oper[i].pwd );
150 for( i = 0; i < MAX_SERVERS; i++ )
152 if( ! Conf_Server[i].name[0] ) continue;
154 /* Valid "Server" section */
156 printf( " Name = %s\n", Conf_Server[i].name );
157 printf( " Host = %s\n", Conf_Server[i].host );
158 printf( " Port = %d\n", Conf_Server[i].port );
159 printf( " MyPassword = %s\n", Conf_Server[i].pwd_in );
160 printf( " PeerPassword = %s\n", Conf_Server[i].pwd_out );
161 printf( " Group = %d\n", Conf_Server[i].group );
165 for( i = 0; i < Conf_Channel_Count; i++ )
167 if( ! Conf_Channel[i].name[0] ) continue;
169 /* Valid "Channel" section */
171 printf( " Name = %s\n", Conf_Channel[i].name );
172 printf( " Modes = %s\n", Conf_Channel[i].modes );
173 printf( " Topic = %s\n", Conf_Channel[i].topic );
182 Conf_UnsetServer( CONN_ID Idx )
184 /* Set next time for next connection attempt, if this is a server
185 * link that is (still) configured here. If the server is set as
186 * "once", delete it from our configuration.
187 * Non-Server-Connections will be silently ignored. */
191 /* Check all our configured servers */
192 for( i = 0; i < MAX_SERVERS; i++ )
194 if( Conf_Server[i].conn_id != Idx ) continue;
196 /* Gotcha! Mark server configuration as "unused": */
197 Conf_Server[i].conn_id = NONE;
199 if( Conf_Server[i].once )
201 /* Delete configuration here */
202 Init_Server_Struct( &Conf_Server[i] );
206 /* Set time for next connect attempt */
207 if( Conf_Server[i].lasttry < time( NULL ) - Conf_ConnectRetry )
209 /* Okay, the connection was established "long enough": */
210 Conf_Server[i].lasttry = time( NULL ) - Conf_ConnectRetry + RECONNECT_DELAY;
215 } /* Conf_UnsetServer */
219 Conf_SetServer( INT ConfServer, CONN_ID Idx )
221 /* Set connection for specified configured server */
223 assert( ConfServer > NONE );
224 assert( Idx > NONE );
226 Conf_Server[ConfServer].conn_id = Idx;
227 } /* Conf_SetServer */
231 Conf_GetServer( CONN_ID Idx )
233 /* Get index of server in configuration structure */
237 assert( Idx > NONE );
239 for( i = 0; i < MAX_SERVERS; i++ )
241 if( Conf_Server[i].conn_id == Idx ) return i;
244 } /* Conf_GetServer */
248 Set_Defaults( BOOLEAN InitServers )
250 /* Initialize configuration variables with default values. */
254 strcpy( Conf_ServerName, "" );
255 sprintf( Conf_ServerInfo, "%s %s", PACKAGE, VERSION );
256 strcpy( Conf_ServerPwd, "" );
258 strcpy( Conf_ServerAdmin1, "" );
259 strcpy( Conf_ServerAdmin2, "" );
260 strcpy( Conf_ServerAdminMail, "" );
262 strlcpy( Conf_MotdFile, SYSCONFDIR, sizeof( Conf_MotdFile ));
263 strlcat( Conf_MotdFile, MOTD_FILE, sizeof( Conf_MotdFile ));
265 Conf_ListenPorts_Count = 0;
267 Conf_UID = Conf_GID = 0;
269 Conf_PingTimeout = 120;
270 Conf_PongTimeout = 20;
272 Conf_ConnectRetry = 60;
275 Conf_Channel_Count = 0;
277 Conf_OperCanMode = FALSE;
279 Conf_MaxConnections = -1;
282 /* Initialize server configuration structures */
283 if( InitServers ) for( i = 0; i < MAX_SERVERS; Init_Server_Struct( &Conf_Server[i++] ));
290 /* Read configuration file. */
292 CHAR section[LINE_LEN], str[LINE_LEN], *var, *arg, *ptr;
296 /* Open configuration file */
297 fd = fopen( NGIRCd_ConfFile, "r" );
300 /* No configuration file found! */
301 Config_Error( LOG_ALERT, "Can't read configuration \"%s\": %s", NGIRCd_ConfFile, strerror( errno ));
302 Config_Error( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE );
306 Config_Error( LOG_INFO, "Reading configuration from \"%s\" ...", NGIRCd_ConfFile );
308 /* Clean up server configuration structure: mark all already
309 * configured servers as "once" so that they are deleted
310 * after the next disconnect and delete all unused servers. */
311 for( i = 0; i < MAX_SERVERS; i++ )
313 if( Conf_Server[i].conn_id == NONE ) Init_Server_Struct( &Conf_Server[i] );
314 else Conf_Server[i].once = TRUE;
317 /* Initialize variables */
319 strcpy( section, "" );
320 Init_Server_Struct( &New_Server );
321 New_Server_Idx = NONE;
323 /* Read configuration file */
326 if( ! fgets( str, LINE_LEN, fd )) break;
330 /* Skip comments and empty lines */
331 if( str[0] == ';' || str[0] == '#' || str[0] == '\0' ) continue;
333 /* Is this the beginning of a new section? */
334 if(( str[0] == '[' ) && ( str[strlen( str ) - 1] == ']' ))
336 strlcpy( section, str, sizeof( section ));
337 if( strcasecmp( section, "[GLOBAL]" ) == 0 ) continue;
338 if( strcasecmp( section, "[OPERATOR]" ) == 0 )
340 if( Conf_Oper_Count + 1 > MAX_OPERATORS ) Config_Error( LOG_ERR, "Too many operators configured." );
343 /* Initialize new operator structure */
344 strcpy( Conf_Oper[Conf_Oper_Count].name, "" );
345 strcpy( Conf_Oper[Conf_Oper_Count].pwd, "" );
350 if( strcasecmp( section, "[SERVER]" ) == 0 )
352 /* Check if there is already a server to add */
353 if( New_Server.name[0] )
355 /* Copy data to "real" server structure */
356 assert( New_Server_Idx > NONE );
357 Conf_Server[New_Server_Idx] = New_Server;
360 /* Re-init structure for new server */
361 Init_Server_Struct( &New_Server );
363 /* Search unused item in server configuration structure */
364 for( i = 0; i < MAX_SERVERS; i++ )
366 /* Is this item used? */
367 if( ! Conf_Server[i].name[0] ) break;
369 if( i >= MAX_SERVERS )
371 /* Oops, no free item found! */
372 Config_Error( LOG_ERR, "Too many servers configured." );
373 New_Server_Idx = NONE;
375 else New_Server_Idx = i;
378 if( strcasecmp( section, "[CHANNEL]" ) == 0 )
380 if( Conf_Channel_Count + 1 > MAX_DEFCHANNELS ) Config_Error( LOG_ERR, "Too many pre-defined channels configured." );
383 /* Initialize new channel structure */
384 strcpy( Conf_Channel[Conf_Channel_Count].name, "" );
385 strcpy( Conf_Channel[Conf_Channel_Count].modes, "" );
386 strcpy( Conf_Channel[Conf_Channel_Count].topic, "" );
387 Conf_Channel_Count++;
391 Config_Error( LOG_ERR, "%s, line %d: Unknown section \"%s\"!", NGIRCd_ConfFile, line, section );
394 if( section[0] == 0x1 ) continue;
396 /* Split line into variable name and parameters */
397 ptr = strchr( str, '=' );
400 Config_Error( LOG_ERR, "%s, line %d: Syntax error!", NGIRCd_ConfFile, line );
404 var = str; ngt_TrimStr( var );
405 arg = ptr + 1; ngt_TrimStr( arg );
407 if( strcasecmp( section, "[GLOBAL]" ) == 0 ) Handle_GLOBAL( line, var, arg );
408 else if( strcasecmp( section, "[OPERATOR]" ) == 0 ) Handle_OPERATOR( line, var, arg );
409 else if( strcasecmp( section, "[SERVER]" ) == 0 ) Handle_SERVER( line, var, arg );
410 else if( strcasecmp( section, "[CHANNEL]" ) == 0 ) Handle_CHANNEL( line, var, arg );
411 else Config_Error( LOG_ERR, "%s, line %d: Variable \"%s\" outside section!", NGIRCd_ConfFile, line, var );
414 /* Close configuration file */
417 /* Check if there is still a server to add */
418 if( New_Server.name[0] )
420 /* Copy data to "real" server structure */
421 assert( New_Server_Idx > NONE );
422 Conf_Server[New_Server_Idx] = New_Server;
425 /* If there are no ports configured use the default: 6667 */
426 if( Conf_ListenPorts_Count < 1 )
428 Conf_ListenPorts_Count = 1;
429 Conf_ListenPorts[0] = 6667;
435 Handle_GLOBAL( INT Line, CHAR *Var, CHAR *Arg )
443 assert( Var != NULL );
444 assert( Arg != NULL );
446 if( strcasecmp( Var, "Name" ) == 0 )
449 if( strlcpy( Conf_ServerName, Arg, sizeof( Conf_ServerName )) >= sizeof( Conf_ServerName )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"Name\" too long!", NGIRCd_ConfFile, Line );
452 if( strcasecmp( Var, "Info" ) == 0 )
454 /* Info text of server */
455 if( strlcpy( Conf_ServerInfo, Arg, sizeof( Conf_ServerInfo )) >= sizeof( Conf_ServerInfo )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"Info\" too long!", NGIRCd_ConfFile, Line );
458 if( strcasecmp( Var, "Password" ) == 0 )
460 /* Global server password */
461 if( strlcpy( Conf_ServerPwd, Arg, sizeof( Conf_ServerPwd )) >= sizeof( Conf_ServerPwd )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"Password\" too long!", NGIRCd_ConfFile, Line );
464 if( strcasecmp( Var, "AdminInfo1" ) == 0 )
466 /* Administrative info #1 */
467 if( strlcpy( Conf_ServerAdmin1, Arg, sizeof( Conf_ServerAdmin1 )) >= sizeof( Conf_ServerAdmin1 )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"AdminInfo1\" too long!", NGIRCd_ConfFile, Line );
470 if( strcasecmp( Var, "AdminInfo2" ) == 0 )
472 /* Administrative info #2 */
473 if( strlcpy( Conf_ServerAdmin2, Arg, sizeof( Conf_ServerAdmin2 )) >= sizeof( Conf_ServerAdmin2 )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"AdminInfo2\" too long!", NGIRCd_ConfFile, Line );
476 if( strcasecmp( Var, "AdminEMail" ) == 0 )
478 /* Administrative email contact */
479 if( strlcpy( Conf_ServerAdminMail, Arg, sizeof( Conf_ServerAdminMail )) >= sizeof( Conf_ServerAdminMail )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"AdminEMail\" too long!", NGIRCd_ConfFile, Line );
482 if( strcasecmp( Var, "Ports" ) == 0 )
484 /* Ports on that the server should listen. More port numbers
485 * must be separated by "," */
486 ptr = strtok( Arg, "," );
491 if( Conf_ListenPorts_Count + 1 > MAX_LISTEN_PORTS ) Config_Error( LOG_ERR, "Too many listen ports configured. Port %ld ignored.", port );
494 if( port > 0 && port < 0xFFFF ) Conf_ListenPorts[Conf_ListenPorts_Count++] = (UINT)port;
495 else Config_Error( LOG_ERR, "%s, line %d (section \"Global\"): Illegal port number %ld!", NGIRCd_ConfFile, Line, port );
497 ptr = strtok( NULL, "," );
501 if( strcasecmp( Var, "MotdFile" ) == 0 )
503 /* "Message of the day" (MOTD) file */
504 if( strlcpy( Conf_MotdFile, Arg, sizeof( Conf_MotdFile )) >= sizeof( Conf_MotdFile )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"MotdFile\" too long!", NGIRCd_ConfFile, Line );
507 if( strcasecmp( Var, "ServerUID" ) == 0 )
509 /* UID the daemon should switch to */
510 pwd = getpwnam( Arg );
511 if( pwd ) Conf_UID = pwd->pw_uid;
515 if( ! isdigit( *Arg )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"ServerUID\" is not a number!", NGIRCd_ConfFile, Line );
518 Conf_UID = (UINT)atoi( Arg );
522 if( strcasecmp( Var, "ServerGID" ) == 0 )
524 /* GID the daemon should use */
525 grp = getgrnam( Arg );
526 if( grp ) Conf_GID = grp->gr_gid;
530 if( ! isdigit( *Arg )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"ServerGID\" is not a number!", NGIRCd_ConfFile, Line );
533 Conf_GID = (UINT)atoi( Arg );
537 if( strcasecmp( Var, "PingTimeout" ) == 0 )
540 Conf_PingTimeout = atoi( Arg );
541 if( Conf_PingTimeout < 5 )
543 Config_Error( LOG_WARNING, "%s, line %d: Value of \"PingTimeout\" too low!", NGIRCd_ConfFile, Line );
544 Conf_PingTimeout = 5;
548 if( strcasecmp( Var, "PongTimeout" ) == 0 )
551 Conf_PongTimeout = atoi( Arg );
552 if( Conf_PongTimeout < 5 )
554 Config_Error( LOG_WARNING, "%s, line %d: Value of \"PongTimeout\" too low!", NGIRCd_ConfFile, Line );
555 Conf_PongTimeout = 5;
559 if( strcasecmp( Var, "ConnectRetry" ) == 0 )
561 /* Seconds between connection attempts to other servers */
562 Conf_ConnectRetry = atoi( Arg );
563 if( Conf_ConnectRetry < 5 )
565 Config_Error( LOG_WARNING, "%s, line %d: Value of \"ConnectRetry\" too low!", NGIRCd_ConfFile, Line );
566 Conf_ConnectRetry = 5;
570 if( strcasecmp( Var, "OperCanUseMode" ) == 0 )
572 /* Are IRC operators allowed to use MODE in channels they aren't Op in? */
573 if( strcasecmp( Arg, "yes" ) == 0 ) Conf_OperCanMode = TRUE;
574 else if( strcasecmp( Arg, "true" ) == 0 ) Conf_OperCanMode = TRUE;
575 else if( atoi( Arg ) != 0 ) Conf_OperCanMode = TRUE;
576 else Conf_OperCanMode = FALSE;
579 if( strcasecmp( Var, "MaxConnections" ) == 0 )
581 /* Maximum number of connections. Values <= 0 are equal to "no limit". */
583 if( ! isdigit( *Arg )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"MaxConnections\" is not a number!", NGIRCd_ConfFile, Line );
586 Conf_MaxConnections = atol( Arg );
589 if( strcasecmp( Var, "MaxJoins" ) == 0 )
591 /* Maximum number of channels a user can join. Values <= 0 are equal to "no limit". */
593 if( ! isdigit( *Arg )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"MaxJoins\" is not a number!", NGIRCd_ConfFile, Line );
596 Conf_MaxJoins = atoi( Arg );
600 Config_Error( LOG_ERR, "%s, line %d (section \"Global\"): Unknown variable \"%s\"!", NGIRCd_ConfFile, Line, Var );
601 } /* Handle_GLOBAL */
605 Handle_OPERATOR( INT Line, CHAR *Var, CHAR *Arg )
608 assert( Var != NULL );
609 assert( Arg != NULL );
610 assert( Conf_Oper_Count > 0 );
612 if( strcasecmp( Var, "Name" ) == 0 )
614 /* Name of IRC operator */
615 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( LOG_WARNING, "%s, line %d: Value of \"Name\" too long!", NGIRCd_ConfFile, Line );
618 if( strcasecmp( Var, "Password" ) == 0 )
620 /* Password of IRC operator */
621 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( LOG_WARNING, "%s, line %d: Value of \"Password\" too long!", NGIRCd_ConfFile, Line );
625 Config_Error( LOG_ERR, "%s, line %d (section \"Operator\"): Unknown variable \"%s\"!", NGIRCd_ConfFile, Line, Var );
626 } /* Handle_OPERATOR */
630 Handle_SERVER( INT Line, CHAR *Var, CHAR *Arg )
635 assert( Var != NULL );
636 assert( Arg != NULL );
638 /* Ignore server block if no space is left in server configuration structure */
639 if( New_Server_Idx <= NONE ) return;
641 if( strcasecmp( Var, "Host" ) == 0 )
643 /* Hostname of the server */
644 if( strlcpy( New_Server.host, Arg, sizeof( New_Server.host )) >= sizeof( New_Server.host )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"Host\" too long!", NGIRCd_ConfFile, Line );
647 if( strcasecmp( Var, "Name" ) == 0 )
649 /* Name of the server ("Nick"/"ID") */
650 if( strlcpy( New_Server.name, Arg, sizeof( New_Server.name )) >= sizeof( New_Server.name )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"Name\" too long!", NGIRCd_ConfFile, Line );
653 if( strcasecmp( Var, "MyPassword" ) == 0 )
655 /* Password of this server which is sent to the peer */
656 if( strlcpy( New_Server.pwd_in, Arg, sizeof( New_Server.pwd_in )) >= sizeof( New_Server.pwd_in )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"MyPassword\" too long!", NGIRCd_ConfFile, Line );
659 if( strcasecmp( Var, "PeerPassword" ) == 0 )
661 /* Passwort of the peer which must be received */
662 if( strlcpy( New_Server.pwd_out, Arg, sizeof( New_Server.pwd_out )) >= sizeof( New_Server.pwd_out )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"PeerPassword\" too long!", NGIRCd_ConfFile, Line );
665 if( strcasecmp( Var, "Port" ) == 0 )
667 /* Port to which this server should connect */
669 if( port > 0 && port < 0xFFFF ) New_Server.port = (INT)port;
670 else Config_Error( LOG_ERR, "%s, line %d (section \"Server\"): Illegal port number %ld!", NGIRCd_ConfFile, Line, port );
673 if( strcasecmp( Var, "Group" ) == 0 )
677 if( ! isdigit( *Arg )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"Group\" is not a number!", NGIRCd_ConfFile, Line );
680 New_Server.group = atoi( Arg );
684 Config_Error( LOG_ERR, "%s, line %d (section \"Server\"): Unknown variable \"%s\"!", NGIRCd_ConfFile, Line, Var );
685 } /* Handle_SERVER */
689 Handle_CHANNEL( INT Line, CHAR *Var, CHAR *Arg )
692 assert( Var != NULL );
693 assert( Arg != NULL );
695 if( strcasecmp( Var, "Name" ) == 0 )
697 /* Name of the channel */
698 if( strlcpy( Conf_Channel[Conf_Channel_Count - 1].name, Arg, sizeof( Conf_Channel[Conf_Channel_Count - 1].name )) >= sizeof( Conf_Channel[Conf_Channel_Count - 1].name )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"Name\" too long!", NGIRCd_ConfFile, Line );
701 if( strcasecmp( Var, "Modes" ) == 0 )
704 if( strlcpy( Conf_Channel[Conf_Channel_Count - 1].modes, Arg, sizeof( Conf_Channel[Conf_Channel_Count - 1].modes )) >= sizeof( Conf_Channel[Conf_Channel_Count - 1].modes )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"Modes\" too long!", NGIRCd_ConfFile, Line );
707 if( strcasecmp( Var, "Topic" ) == 0 )
710 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 )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"Topic\" too long!", NGIRCd_ConfFile, Line );
714 Config_Error( LOG_ERR, "%s, line %d (section \"Channel\"): Unknown variable \"%s\"!", NGIRCd_ConfFile, Line, Var );
715 } /* Handle_CHANNEL */
719 Validate_Config( BOOLEAN Configtest )
721 /* Validate configuration settings. */
724 INT i, servers, servers_once;
727 if( ! Conf_ServerName[0] )
729 /* No server name configured! */
730 Config_Error( LOG_ALERT, "No server name configured in \"%s\" ('ServerName')!", NGIRCd_ConfFile );
733 Config_Error( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE );
739 if( ! Conf_ServerAdminMail[0] )
741 /* No administrative contact configured! */
742 Config_Error( LOG_ALERT, "No administrator email address configured in \"%s\" ('AdminEMail')!", NGIRCd_ConfFile );
745 Config_Error( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE );
751 if( ! Conf_ServerAdmin1[0] && ! Conf_ServerAdmin2[0] && ! Conf_ServerAdminMail[0] )
753 /* No administrative information configured! */
754 Config_Error( LOG_WARNING, "No administrative information configured but required by RFC!" );
757 if(( Conf_MaxConnections > (LONG)FD_SETSIZE ) || ( Conf_MaxConnections < 1 ))
759 Conf_MaxConnections = (LONG)FD_SETSIZE;
760 Config_Error( LOG_ERR, "Setting MaxConnections to %ld, select() can't handle more file descriptors!", Conf_MaxConnections );
763 Config_Error( LOG_WARN, "Don't know how many file descriptors select() can handle on this system, don't set MaxConnections too high!" );
767 servers = servers_once = 0;
768 for( i = 0; i < MAX_SERVERS; i++ )
770 if( Conf_Server[i].name[0] )
773 if( Conf_Server[i].once ) servers_once++;
776 Log( LOG_DEBUG, "Configuration: Operators=%d, Servers=%d[%d], Channels=%d", Conf_Oper_Count, servers, servers_once, Conf_Channel_Count );
778 } /* Validate_Config */
782 LOCAL VOID Config_Error( CONST INT Level, CONST CHAR *Format, ... )
784 LOCAL VOID Config_Error( Level, Format, va_alist )
790 /* Error! Write to console and/or logfile. */
792 CHAR msg[MAX_LOG_MSG_LEN];
795 assert( Format != NULL );
798 va_start( ap, Format );
802 vsnprintf( msg, MAX_LOG_MSG_LEN, Format, ap );
805 /* During "normal operations" the log functions of the daemon should
806 * be used, but during testing of the configuration file, all messages
807 * should go directly to the console: */
808 if( Use_Log ) Log( Level, "%s", msg );
814 Init_Server_Struct( CONF_SERVER *Server )
816 /* Initialize server configuration structur to default values */
818 assert( Server != NULL );
820 strcpy( Server->host, "" );
821 strcpy( Server->ip, "" );
822 strcpy( Server->name, "" );
823 strcpy( Server->pwd_in, "" );
824 strcpy( Server->pwd_out, "" );
826 Server->group = NONE;
827 Server->lasttry = time( NULL ) - Conf_ConnectRetry + STARTUP_DELAY;
828 Server->res_stat = NULL;
829 Server->once = FALSE;
830 Server->conn_id = NONE;
831 } /* Init_Server_Struct */