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.60 2003/09/11 12:05:28 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( " Password = %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 printf( " Listen = %s\n", Conf_ListenAddress );
124 pwd = getpwuid( Conf_UID );
125 if( pwd ) printf( " ServerUID = %s\n", pwd->pw_name );
126 else printf( " ServerUID = %ld\n", (LONG)Conf_UID );
127 grp = getgrgid( Conf_GID );
128 if( grp ) printf( " ServerGID = %s\n", grp->gr_name );
129 else printf( " ServerGID = %ld\n", (LONG)Conf_GID );
130 printf( " PingTimeout = %d\n", Conf_PingTimeout );
131 printf( " PongTimeout = %d\n", Conf_PongTimeout );
132 printf( " ConnectRetry = %d\n", Conf_ConnectRetry );
133 printf( " OperCanUseMode = %s\n", Conf_OperCanMode == TRUE ? "yes" : "no" );
134 if( Conf_MaxConnections > 0 ) printf( " MaxConnections = %ld\n", Conf_MaxConnections );
135 else printf( " MaxConnections = -1\n" );
136 if( Conf_MaxJoins > 0 ) printf( " MaxJoins = %d\n", Conf_MaxJoins );
137 else printf( " MaxJoins = -1\n" );
140 for( i = 0; i < Conf_Oper_Count; i++ )
142 if( ! Conf_Oper[i].name[0] ) continue;
144 /* Valid "Operator" section */
145 puts( "[OPERATOR]" );
146 printf( " Name = %s\n", Conf_Oper[i].name );
147 printf( " Password = %s\n", Conf_Oper[i].pwd );
151 for( i = 0; i < MAX_SERVERS; i++ )
153 if( ! Conf_Server[i].name[0] ) continue;
155 /* Valid "Server" section */
157 printf( " Name = %s\n", Conf_Server[i].name );
158 printf( " Host = %s\n", Conf_Server[i].host );
159 printf( " Port = %d\n", Conf_Server[i].port );
160 printf( " MyPassword = %s\n", Conf_Server[i].pwd_in );
161 printf( " PeerPassword = %s\n", Conf_Server[i].pwd_out );
162 printf( " Group = %d\n", Conf_Server[i].group );
166 for( i = 0; i < Conf_Channel_Count; i++ )
168 if( ! Conf_Channel[i].name[0] ) continue;
170 /* Valid "Channel" section */
172 printf( " Name = %s\n", Conf_Channel[i].name );
173 printf( " Modes = %s\n", Conf_Channel[i].modes );
174 printf( " Topic = %s\n", Conf_Channel[i].topic );
183 Conf_UnsetServer( CONN_ID Idx )
185 /* Set next time for next connection attempt, if this is a server
186 * link that is (still) configured here. If the server is set as
187 * "once", delete it from our configuration.
188 * Non-Server-Connections will be silently ignored. */
192 /* Check all our configured servers */
193 for( i = 0; i < MAX_SERVERS; i++ )
195 if( Conf_Server[i].conn_id != Idx ) continue;
197 /* Gotcha! Mark server configuration as "unused": */
198 Conf_Server[i].conn_id = NONE;
200 if( Conf_Server[i].flags & CONF_SFLAG_ONCE )
202 /* Delete configuration here */
203 Init_Server_Struct( &Conf_Server[i] );
207 /* Set time for next connect attempt */
208 if( Conf_Server[i].lasttry < time( NULL ) - Conf_ConnectRetry )
210 /* Okay, the connection was established "long enough": */
211 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 Conf_EnableServer( CHAR *Name, INT Port )
250 /* Enable specified server and adjust port */
254 assert( Name != NULL );
256 for( i = 0; i < MAX_SERVERS; i++ )
258 if( strcasecmp( Conf_Server[i].name, Name ) == 0 )
260 /* Gotcha! Set port and enable server: */
261 Conf_Server[i].port = Port;
262 Conf_Server[i].flags &= ~CONF_SFLAG_DISABLED;
267 } /* Conf_EnableServer */
271 Conf_DisableServer( CHAR *Name )
273 /* Enable specified server and adjust port */
277 assert( Name != NULL );
279 for( i = 0; i < MAX_SERVERS; i++ )
281 if( strcasecmp( Conf_Server[i].name, Name ) == 0 )
283 /* Gotcha! Disable and disconnect server: */
284 Conf_Server[i].flags |= CONF_SFLAG_DISABLED;
285 if( Conf_Server[i].conn_id > NONE ) Conn_Close( Conf_Server[i].conn_id, NULL, "Server link terminated on operator request", TRUE );
290 } /* Conf_DisableServer */
294 Conf_AddServer( CHAR *Name, INT Port, CHAR *Host, CHAR *MyPwd, CHAR *PeerPwd )
296 /* Add new server to configuration */
300 assert( Name != NULL );
301 assert( Host != NULL );
302 assert( MyPwd != NULL );
303 assert( PeerPwd != NULL );
305 /* Search unused item in server configuration structure */
306 for( i = 0; i < MAX_SERVERS; i++ )
308 /* Is this item used? */
309 if( ! Conf_Server[i].name[0] ) break;
311 if( i >= MAX_SERVERS ) return FALSE;
313 Init_Server_Struct( &Conf_Server[i] );
314 strlcpy( Conf_Server[i].name, Name, sizeof( Conf_Server[i].name ));
315 strlcpy( Conf_Server[i].host, Host, sizeof( Conf_Server[i].host ));
316 strlcpy( Conf_Server[i].pwd_out, MyPwd, sizeof( Conf_Server[i].pwd_out ));
317 strlcpy( Conf_Server[i].pwd_in, PeerPwd, sizeof( Conf_Server[i].pwd_in ));
318 Conf_Server[i].port = Port;
319 Conf_Server[i].flags = CONF_SFLAG_ONCE;
322 } /* Conf_AddServer */
326 Set_Defaults( BOOLEAN InitServers )
328 /* Initialize configuration variables with default values. */
332 strcpy( Conf_ServerName, "" );
333 sprintf( Conf_ServerInfo, "%s %s", PACKAGE_NAME, PACKAGE_VERSION );
334 strcpy( Conf_ServerPwd, "" );
336 strcpy( Conf_ServerAdmin1, "" );
337 strcpy( Conf_ServerAdmin2, "" );
338 strcpy( Conf_ServerAdminMail, "" );
340 strlcpy( Conf_MotdFile, SYSCONFDIR, sizeof( Conf_MotdFile ));
341 strlcat( Conf_MotdFile, MOTD_FILE, sizeof( Conf_MotdFile ));
343 Conf_ListenPorts_Count = 0;
344 strcpy( Conf_ListenAddress, "" );
346 Conf_UID = Conf_GID = 0;
348 Conf_PingTimeout = 120;
349 Conf_PongTimeout = 20;
351 Conf_ConnectRetry = 60;
354 Conf_Channel_Count = 0;
356 Conf_OperCanMode = FALSE;
358 Conf_MaxConnections = -1;
361 /* Initialize server configuration structures */
362 if( InitServers ) for( i = 0; i < MAX_SERVERS; Init_Server_Struct( &Conf_Server[i++] ));
369 /* Read configuration file. */
371 CHAR section[LINE_LEN], str[LINE_LEN], *var, *arg, *ptr;
375 /* Open configuration file */
376 fd = fopen( NGIRCd_ConfFile, "r" );
379 /* No configuration file found! */
380 Config_Error( LOG_ALERT, "Can't read configuration \"%s\": %s", NGIRCd_ConfFile, strerror( errno ));
381 Config_Error( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME );
385 Config_Error( LOG_INFO, "Reading configuration from \"%s\" ...", NGIRCd_ConfFile );
387 /* Clean up server configuration structure: mark all already
388 * configured servers as "once" so that they are deleted
389 * after the next disconnect and delete all unused servers.
390 * And delete all servers which are "duplicates" of servers
391 * that are already marked as "once" (such servers have been
392 * created by the last rehash but are now useless). */
393 for( i = 0; i < MAX_SERVERS; i++ )
395 if( Conf_Server[i].conn_id == NONE ) Init_Server_Struct( &Conf_Server[i] );
398 /* This structure is in use ... */
399 if( Conf_Server[i].flags & CONF_SFLAG_ONCE )
401 /* Check for duplicates */
402 for( n = 0; n < MAX_SERVERS; n++ )
404 if( n == i ) continue;
406 if( Conf_Server[i].conn_id == Conf_Server[n].conn_id )
408 Init_Server_Struct( &Conf_Server[n] );
409 Log( LOG_DEBUG, "Deleted unused duplicate server %d (kept %d).", n, i );
415 /* Mark server as "once" */
416 Conf_Server[i].flags |= CONF_SFLAG_ONCE;
417 Log( LOG_DEBUG, "Marked server %d as \"once\"", i );
422 /* Initialize variables */
424 strcpy( section, "" );
425 Init_Server_Struct( &New_Server );
426 New_Server_Idx = NONE;
428 /* Read configuration file */
431 if( ! fgets( str, LINE_LEN, fd )) break;
435 /* Skip comments and empty lines */
436 if( str[0] == ';' || str[0] == '#' || str[0] == '\0' ) continue;
438 /* Is this the beginning of a new section? */
439 if(( str[0] == '[' ) && ( str[strlen( str ) - 1] == ']' ))
441 strlcpy( section, str, sizeof( section ));
442 if( strcasecmp( section, "[GLOBAL]" ) == 0 ) continue;
443 if( strcasecmp( section, "[OPERATOR]" ) == 0 )
445 if( Conf_Oper_Count + 1 > MAX_OPERATORS ) Config_Error( LOG_ERR, "Too many operators configured." );
448 /* Initialize new operator structure */
449 strcpy( Conf_Oper[Conf_Oper_Count].name, "" );
450 strcpy( Conf_Oper[Conf_Oper_Count].pwd, "" );
455 if( strcasecmp( section, "[SERVER]" ) == 0 )
457 /* Check if there is already a server to add */
458 if( New_Server.name[0] )
460 /* Copy data to "real" server structure */
461 assert( New_Server_Idx > NONE );
462 Conf_Server[New_Server_Idx] = New_Server;
465 /* Re-init structure for new server */
466 Init_Server_Struct( &New_Server );
468 /* Search unused item in server configuration structure */
469 for( i = 0; i < MAX_SERVERS; i++ )
471 /* Is this item used? */
472 if( ! Conf_Server[i].name[0] ) break;
474 if( i >= MAX_SERVERS )
476 /* Oops, no free item found! */
477 Config_Error( LOG_ERR, "Too many servers configured." );
478 New_Server_Idx = NONE;
480 else New_Server_Idx = i;
483 if( strcasecmp( section, "[CHANNEL]" ) == 0 )
485 if( Conf_Channel_Count + 1 > MAX_DEFCHANNELS ) Config_Error( LOG_ERR, "Too many pre-defined channels configured." );
488 /* Initialize new channel structure */
489 strcpy( Conf_Channel[Conf_Channel_Count].name, "" );
490 strcpy( Conf_Channel[Conf_Channel_Count].modes, "" );
491 strcpy( Conf_Channel[Conf_Channel_Count].topic, "" );
492 Conf_Channel_Count++;
496 Config_Error( LOG_ERR, "%s, line %d: Unknown section \"%s\"!", NGIRCd_ConfFile, line, section );
499 if( section[0] == 0x1 ) continue;
501 /* Split line into variable name and parameters */
502 ptr = strchr( str, '=' );
505 Config_Error( LOG_ERR, "%s, line %d: Syntax error!", NGIRCd_ConfFile, line );
509 var = str; ngt_TrimStr( var );
510 arg = ptr + 1; ngt_TrimStr( arg );
512 if( strcasecmp( section, "[GLOBAL]" ) == 0 ) Handle_GLOBAL( line, var, arg );
513 else if( strcasecmp( section, "[OPERATOR]" ) == 0 ) Handle_OPERATOR( line, var, arg );
514 else if( strcasecmp( section, "[SERVER]" ) == 0 ) Handle_SERVER( line, var, arg );
515 else if( strcasecmp( section, "[CHANNEL]" ) == 0 ) Handle_CHANNEL( line, var, arg );
516 else Config_Error( LOG_ERR, "%s, line %d: Variable \"%s\" outside section!", NGIRCd_ConfFile, line, var );
519 /* Close configuration file */
522 /* Check if there is still a server to add */
523 if( New_Server.name[0] )
525 /* Copy data to "real" server structure */
526 assert( New_Server_Idx > NONE );
527 Conf_Server[New_Server_Idx] = New_Server;
530 /* If there are no ports configured use the default: 6667 */
531 if( Conf_ListenPorts_Count < 1 )
533 Conf_ListenPorts_Count = 1;
534 Conf_ListenPorts[0] = 6667;
540 Handle_GLOBAL( INT Line, CHAR *Var, CHAR *Arg )
548 assert( Var != NULL );
549 assert( Arg != NULL );
551 if( strcasecmp( Var, "Name" ) == 0 )
554 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 );
557 if( strcasecmp( Var, "Info" ) == 0 )
559 /* Info text of server */
560 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 );
563 if( strcasecmp( Var, "Password" ) == 0 )
565 /* Global server password */
566 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 );
569 if( strcasecmp( Var, "AdminInfo1" ) == 0 )
571 /* Administrative info #1 */
572 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 );
575 if( strcasecmp( Var, "AdminInfo2" ) == 0 )
577 /* Administrative info #2 */
578 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 );
581 if( strcasecmp( Var, "AdminEMail" ) == 0 )
583 /* Administrative email contact */
584 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 );
587 if( strcasecmp( Var, "Ports" ) == 0 )
589 /* Ports on that the server should listen. More port numbers
590 * must be separated by "," */
591 ptr = strtok( Arg, "," );
596 if( Conf_ListenPorts_Count + 1 > MAX_LISTEN_PORTS ) Config_Error( LOG_ERR, "Too many listen ports configured. Port %ld ignored.", port );
599 if( port > 0 && port < 0xFFFF ) Conf_ListenPorts[Conf_ListenPorts_Count++] = (UINT)port;
600 else Config_Error( LOG_ERR, "%s, line %d (section \"Global\"): Illegal port number %ld!", NGIRCd_ConfFile, Line, port );
602 ptr = strtok( NULL, "," );
606 if( strcasecmp( Var, "MotdFile" ) == 0 )
608 /* "Message of the day" (MOTD) file */
609 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 );
612 if( strcasecmp( Var, "ServerUID" ) == 0 )
614 /* UID the daemon should switch to */
615 pwd = getpwnam( Arg );
616 if( pwd ) Conf_UID = pwd->pw_uid;
620 if( ! isdigit( *Arg )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"ServerUID\" is not a number!", NGIRCd_ConfFile, Line );
623 Conf_UID = (UINT)atoi( Arg );
627 if( strcasecmp( Var, "ServerGID" ) == 0 )
629 /* GID the daemon should use */
630 grp = getgrnam( Arg );
631 if( grp ) Conf_GID = grp->gr_gid;
635 if( ! isdigit( *Arg )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"ServerGID\" is not a number!", NGIRCd_ConfFile, Line );
638 Conf_GID = (UINT)atoi( Arg );
642 if( strcasecmp( Var, "PingTimeout" ) == 0 )
645 Conf_PingTimeout = atoi( Arg );
646 if( Conf_PingTimeout < 5 )
648 Config_Error( LOG_WARNING, "%s, line %d: Value of \"PingTimeout\" too low!", NGIRCd_ConfFile, Line );
649 Conf_PingTimeout = 5;
653 if( strcasecmp( Var, "PongTimeout" ) == 0 )
656 Conf_PongTimeout = atoi( Arg );
657 if( Conf_PongTimeout < 5 )
659 Config_Error( LOG_WARNING, "%s, line %d: Value of \"PongTimeout\" too low!", NGIRCd_ConfFile, Line );
660 Conf_PongTimeout = 5;
664 if( strcasecmp( Var, "ConnectRetry" ) == 0 )
666 /* Seconds between connection attempts to other servers */
667 Conf_ConnectRetry = atoi( Arg );
668 if( Conf_ConnectRetry < 5 )
670 Config_Error( LOG_WARNING, "%s, line %d: Value of \"ConnectRetry\" too low!", NGIRCd_ConfFile, Line );
671 Conf_ConnectRetry = 5;
675 if( strcasecmp( Var, "OperCanUseMode" ) == 0 )
677 /* Are IRC operators allowed to use MODE in channels they aren't Op in? */
678 if( strcasecmp( Arg, "yes" ) == 0 ) Conf_OperCanMode = TRUE;
679 else if( strcasecmp( Arg, "true" ) == 0 ) Conf_OperCanMode = TRUE;
680 else if( atoi( Arg ) != 0 ) Conf_OperCanMode = TRUE;
681 else Conf_OperCanMode = FALSE;
684 if( strcasecmp( Var, "MaxConnections" ) == 0 )
686 /* Maximum number of connections. Values <= 0 are equal to "no limit". */
688 if( ! isdigit( *Arg )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"MaxConnections\" is not a number!", NGIRCd_ConfFile, Line );
691 Conf_MaxConnections = atol( Arg );
694 if( strcasecmp( Var, "MaxJoins" ) == 0 )
696 /* Maximum number of channels a user can join. Values <= 0 are equal to "no limit". */
698 if( ! isdigit( *Arg )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"MaxJoins\" is not a number!", NGIRCd_ConfFile, Line );
701 Conf_MaxJoins = atoi( Arg );
704 if( strcasecmp( Var, "Listen" ) == 0 )
706 /* IP-Address to bind sockets */
707 if( strlcpy( Conf_ListenAddress, Arg, sizeof( Conf_ListenAddress )) >= sizeof( Conf_ListenAddress ))
709 Config_Error( LOG_WARNING, "%s, line %d: Value of \"Listen\" too long!", NGIRCd_ConfFile, Line );
714 Config_Error( LOG_ERR, "%s, line %d (section \"Global\"): Unknown variable \"%s\"!", NGIRCd_ConfFile, Line, Var );
715 } /* Handle_GLOBAL */
719 Handle_OPERATOR( INT Line, CHAR *Var, CHAR *Arg )
722 assert( Var != NULL );
723 assert( Arg != NULL );
724 assert( Conf_Oper_Count > 0 );
726 if( strcasecmp( Var, "Name" ) == 0 )
728 /* Name of IRC operator */
729 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 );
732 if( strcasecmp( Var, "Password" ) == 0 )
734 /* Password of IRC operator */
735 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 );
739 Config_Error( LOG_ERR, "%s, line %d (section \"Operator\"): Unknown variable \"%s\"!", NGIRCd_ConfFile, Line, Var );
740 } /* Handle_OPERATOR */
744 Handle_SERVER( INT Line, CHAR *Var, CHAR *Arg )
749 assert( Var != NULL );
750 assert( Arg != NULL );
752 /* Ignore server block if no space is left in server configuration structure */
753 if( New_Server_Idx <= NONE ) return;
755 if( strcasecmp( Var, "Host" ) == 0 )
757 /* Hostname of the server */
758 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 );
761 if( strcasecmp( Var, "Name" ) == 0 )
763 /* Name of the server ("Nick"/"ID") */
764 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 );
767 if( strcasecmp( Var, "MyPassword" ) == 0 )
769 /* Password of this server which is sent to the peer */
770 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 );
773 if( strcasecmp( Var, "PeerPassword" ) == 0 )
775 /* Passwort of the peer which must be received */
776 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 );
779 if( strcasecmp( Var, "Port" ) == 0 )
781 /* Port to which this server should connect */
783 if( port > 0 && port < 0xFFFF ) New_Server.port = (INT)port;
784 else Config_Error( LOG_ERR, "%s, line %d (section \"Server\"): Illegal port number %ld!", NGIRCd_ConfFile, Line, port );
787 if( strcasecmp( Var, "Group" ) == 0 )
791 if( ! isdigit( *Arg )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"Group\" is not a number!", NGIRCd_ConfFile, Line );
794 New_Server.group = atoi( Arg );
798 Config_Error( LOG_ERR, "%s, line %d (section \"Server\"): Unknown variable \"%s\"!", NGIRCd_ConfFile, Line, Var );
799 } /* Handle_SERVER */
803 Handle_CHANNEL( INT Line, CHAR *Var, CHAR *Arg )
806 assert( Var != NULL );
807 assert( Arg != NULL );
809 if( strcasecmp( Var, "Name" ) == 0 )
811 /* Name of the channel */
812 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 );
815 if( strcasecmp( Var, "Modes" ) == 0 )
818 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 );
821 if( strcasecmp( Var, "Topic" ) == 0 )
824 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 );
828 Config_Error( LOG_ERR, "%s, line %d (section \"Channel\"): Unknown variable \"%s\"!", NGIRCd_ConfFile, Line, Var );
829 } /* Handle_CHANNEL */
833 Validate_Config( BOOLEAN Configtest )
835 /* Validate configuration settings. */
838 INT i, servers, servers_once;
841 if( ! Conf_ServerName[0] )
843 /* No server name configured! */
844 Config_Error( LOG_ALERT, "No server name configured in \"%s\" ('ServerName')!", NGIRCd_ConfFile );
847 Config_Error( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME );
852 if( ! strchr( Conf_ServerName, '.' ))
854 /* No dot in server name! */
855 Config_Error( LOG_ALERT, "Invalid server name configured in \"%s\" ('ServerName'): Dot missing!", NGIRCd_ConfFile );
858 Config_Error( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME );
864 if( ! Conf_ServerAdminMail[0] )
866 /* No administrative contact configured! */
867 Config_Error( LOG_ALERT, "No administrator email address configured in \"%s\" ('AdminEMail')!", NGIRCd_ConfFile );
870 Config_Error( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME );
876 if( ! Conf_ServerAdmin1[0] && ! Conf_ServerAdmin2[0] && ! Conf_ServerAdminMail[0] )
878 /* No administrative information configured! */
879 Config_Error( LOG_WARNING, "No administrative information configured but required by RFC!" );
882 if(( Conf_MaxConnections > (LONG)FD_SETSIZE ) || ( Conf_MaxConnections < 1 ))
884 Conf_MaxConnections = (LONG)FD_SETSIZE;
885 Config_Error( LOG_ERR, "Setting MaxConnections to %ld, select() can't handle more file descriptors!", Conf_MaxConnections );
888 Config_Error( LOG_WARN, "Don't know how many file descriptors select() can handle on this system, don't set MaxConnections too high!" );
892 servers = servers_once = 0;
893 for( i = 0; i < MAX_SERVERS; i++ )
895 if( Conf_Server[i].name[0] )
898 if( Conf_Server[i].flags & CONF_SFLAG_ONCE ) servers_once++;
901 Log( LOG_DEBUG, "Configuration: Operators=%d, Servers=%d[%d], Channels=%d", Conf_Oper_Count, servers, servers_once, Conf_Channel_Count );
903 } /* Validate_Config */
907 LOCAL VOID Config_Error( CONST INT Level, CONST CHAR *Format, ... )
909 LOCAL VOID Config_Error( Level, Format, va_alist )
915 /* Error! Write to console and/or logfile. */
917 CHAR msg[MAX_LOG_MSG_LEN];
920 assert( Format != NULL );
923 va_start( ap, Format );
927 vsnprintf( msg, MAX_LOG_MSG_LEN, Format, ap );
930 /* During "normal operations" the log functions of the daemon should
931 * be used, but during testing of the configuration file, all messages
932 * should go directly to the console: */
933 if( Use_Log ) Log( Level, "%s", msg );
939 Init_Server_Struct( CONF_SERVER *Server )
941 /* Initialize server configuration structur to default values */
943 assert( Server != NULL );
945 strcpy( Server->host, "" );
946 strcpy( Server->ip, "" );
947 strcpy( Server->name, "" );
948 strcpy( Server->pwd_in, "" );
949 strcpy( Server->pwd_out, "" );
951 Server->group = NONE;
952 Server->lasttry = time( NULL ) - Conf_ConnectRetry + STARTUP_DELAY;
953 Server->res_stat = NULL;
954 if( NGIRCd_Passive ) Server->flags = CONF_SFLAG_DISABLED;
955 else Server->flags = 0;
956 Server->conn_id = NONE;
957 } /* Init_Server_Struct */