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.67 2005/01/20 00:13:08 alex Exp $";
34 #include <sys/types.h>
53 LOCAL BOOLEAN Use_Log = TRUE;
54 LOCAL CONF_SERVER New_Server;
55 LOCAL INT New_Server_Idx;
58 LOCAL VOID Set_Defaults PARAMS(( BOOLEAN InitServers ));
59 LOCAL VOID Read_Config PARAMS(( VOID ));
60 LOCAL VOID Validate_Config PARAMS(( BOOLEAN TestOnly ));
62 LOCAL VOID Handle_GLOBAL PARAMS(( INT Line, CHAR *Var, CHAR *Arg ));
63 LOCAL VOID Handle_OPERATOR PARAMS(( INT Line, CHAR *Var, CHAR *Arg ));
64 LOCAL VOID Handle_SERVER PARAMS(( INT Line, CHAR *Var, CHAR *Arg ));
65 LOCAL VOID Handle_CHANNEL PARAMS(( INT Line, CHAR *Var, CHAR *Arg ));
67 LOCAL VOID Config_Error PARAMS(( CONST INT Level, CONST CHAR *Format, ... ));
69 LOCAL VOID Config_Error_NaN PARAMS(( INT LINE, CONST CHAR *Value ));
70 LOCAL VOID Config_Error_TooLong PARAMS(( INT LINE, CONST CHAR *Value ));
72 LOCAL VOID Init_Server_Struct PARAMS(( CONF_SERVER *Server ));
80 Validate_Config( FALSE );
87 Set_Defaults( FALSE );
89 Validate_Config( FALSE );
96 /* Read configuration, validate and output it. */
103 Set_Defaults( TRUE );
106 Validate_Config( TRUE );
108 /* If stdin is a valid tty wait for a key: */
109 if( isatty( fileno( stdout )))
111 puts( "OK, press enter to see a dump of your service configuration ..." );
114 else puts( "Ok, dump of your server configuration follows:\n" );
117 printf( " Name = %s\n", Conf_ServerName );
118 printf( " Info = %s\n", Conf_ServerInfo );
119 printf( " Password = %s\n", Conf_ServerPwd );
120 printf( " AdminInfo1 = %s\n", Conf_ServerAdmin1 );
121 printf( " AdminInfo2 = %s\n", Conf_ServerAdmin2 );
122 printf( " AdminEMail = %s\n", Conf_ServerAdminMail );
123 printf( " MotdFile = %s\n", Conf_MotdFile );
124 printf( " MotdPhrase = %s\n", Conf_MotdPhrase );
125 printf( " ChrootDir= %s\n", Conf_Chroot );
126 printf( " Ports = " );
127 for( i = 0; i < Conf_ListenPorts_Count; i++ )
129 if( i != 0 ) printf( ", " );
130 printf( "%u", Conf_ListenPorts[i] );
133 printf( " Listen = %s\n", Conf_ListenAddress );
134 pwd = getpwuid( Conf_UID );
135 if( pwd ) printf( " ServerUID = %s\n", pwd->pw_name );
136 else printf( " ServerUID = %ld\n", (LONG)Conf_UID );
137 grp = getgrgid( Conf_GID );
138 if( grp ) printf( " ServerGID = %s\n", grp->gr_name );
139 else printf( " ServerGID = %ld\n", (LONG)Conf_GID );
140 printf( " PingTimeout = %d\n", Conf_PingTimeout );
141 printf( " PongTimeout = %d\n", Conf_PongTimeout );
142 printf( " ConnectRetry = %d\n", Conf_ConnectRetry );
143 printf( " OperCanUseMode = %s\n", Conf_OperCanMode == TRUE ? "yes" : "no" );
144 if( Conf_MaxConnections > 0 ) printf( " MaxConnections = %ld\n", Conf_MaxConnections );
145 else printf( " MaxConnections = -1\n" );
146 if( Conf_MaxConnectionsIP > 0 ) printf( " MaxConnectionsIP = %d\n", Conf_MaxConnectionsIP );
147 else printf( " MaxConnectionsIP = -1\n" );
148 if( Conf_MaxJoins > 0 ) printf( " MaxJoins = %d\n", Conf_MaxJoins );
149 else printf( " MaxJoins = -1\n" );
152 for( i = 0; i < Conf_Oper_Count; i++ )
154 if( ! Conf_Oper[i].name[0] ) continue;
156 /* Valid "Operator" section */
157 puts( "[OPERATOR]" );
158 printf( " Name = %s\n", Conf_Oper[i].name );
159 printf( " Password = %s\n", Conf_Oper[i].pwd );
163 for( i = 0; i < MAX_SERVERS; i++ )
165 if( ! Conf_Server[i].name[0] ) continue;
167 /* Valid "Server" section */
169 printf( " Name = %s\n", Conf_Server[i].name );
170 printf( " Host = %s\n", Conf_Server[i].host );
171 printf( " Port = %d\n", Conf_Server[i].port );
172 printf( " MyPassword = %s\n", Conf_Server[i].pwd_in );
173 printf( " PeerPassword = %s\n", Conf_Server[i].pwd_out );
174 printf( " Group = %d\n", Conf_Server[i].group );
178 for( i = 0; i < Conf_Channel_Count; i++ )
180 if( ! Conf_Channel[i].name[0] ) continue;
182 /* Valid "Channel" section */
184 printf( " Name = %s\n", Conf_Channel[i].name );
185 printf( " Modes = %s\n", Conf_Channel[i].modes );
186 printf( " Topic = %s\n", Conf_Channel[i].topic );
195 Conf_UnsetServer( CONN_ID Idx )
197 /* Set next time for next connection attempt, if this is a server
198 * link that is (still) configured here. If the server is set as
199 * "once", delete it from our configuration.
200 * Non-Server-Connections will be silently ignored. */
204 /* Check all our configured servers */
205 for( i = 0; i < MAX_SERVERS; i++ )
207 if( Conf_Server[i].conn_id != Idx ) continue;
209 /* Gotcha! Mark server configuration as "unused": */
210 Conf_Server[i].conn_id = NONE;
212 if( Conf_Server[i].flags & CONF_SFLAG_ONCE )
214 /* Delete configuration here */
215 Init_Server_Struct( &Conf_Server[i] );
219 /* Set time for next connect attempt */
220 if( Conf_Server[i].lasttry < time( NULL ) - Conf_ConnectRetry )
222 /* Okay, the connection was established "long enough": */
223 Conf_Server[i].lasttry = time( NULL ) - Conf_ConnectRetry + RECONNECT_DELAY;
227 } /* Conf_UnsetServer */
231 Conf_SetServer( INT ConfServer, CONN_ID Idx )
233 /* Set connection for specified configured server */
235 assert( ConfServer > NONE );
236 assert( Idx > NONE );
238 Conf_Server[ConfServer].conn_id = Idx;
239 } /* Conf_SetServer */
243 Conf_GetServer( CONN_ID Idx )
245 /* Get index of server in configuration structure */
249 assert( Idx > NONE );
251 for( i = 0; i < MAX_SERVERS; i++ )
253 if( Conf_Server[i].conn_id == Idx ) return i;
256 } /* Conf_GetServer */
260 Conf_EnableServer( CHAR *Name, INT Port )
262 /* Enable specified server and adjust port */
266 assert( Name != NULL );
268 for( i = 0; i < MAX_SERVERS; i++ )
270 if( strcasecmp( Conf_Server[i].name, Name ) == 0 )
272 /* Gotcha! Set port and enable server: */
273 Conf_Server[i].port = Port;
274 Conf_Server[i].flags &= ~CONF_SFLAG_DISABLED;
279 } /* Conf_EnableServer */
283 Conf_DisableServer( CHAR *Name )
285 /* Enable specified server and adjust port */
289 assert( Name != NULL );
291 for( i = 0; i < MAX_SERVERS; i++ )
293 if( strcasecmp( Conf_Server[i].name, Name ) == 0 )
295 /* Gotcha! Disable and disconnect server: */
296 Conf_Server[i].flags |= CONF_SFLAG_DISABLED;
297 if( Conf_Server[i].conn_id > NONE ) Conn_Close( Conf_Server[i].conn_id, NULL, "Server link terminated on operator request", TRUE );
302 } /* Conf_DisableServer */
306 Conf_AddServer( CHAR *Name, INT Port, CHAR *Host, CHAR *MyPwd, CHAR *PeerPwd )
308 /* Add new server to configuration */
312 assert( Name != NULL );
313 assert( Host != NULL );
314 assert( MyPwd != NULL );
315 assert( PeerPwd != NULL );
317 /* Search unused item in server configuration structure */
318 for( i = 0; i < MAX_SERVERS; i++ )
320 /* Is this item used? */
321 if( ! Conf_Server[i].name[0] ) break;
323 if( i >= MAX_SERVERS ) return FALSE;
325 Init_Server_Struct( &Conf_Server[i] );
326 strlcpy( Conf_Server[i].name, Name, sizeof( Conf_Server[i].name ));
327 strlcpy( Conf_Server[i].host, Host, sizeof( Conf_Server[i].host ));
328 strlcpy( Conf_Server[i].pwd_out, MyPwd, sizeof( Conf_Server[i].pwd_out ));
329 strlcpy( Conf_Server[i].pwd_in, PeerPwd, sizeof( Conf_Server[i].pwd_in ));
330 Conf_Server[i].port = Port;
331 Conf_Server[i].flags = CONF_SFLAG_ONCE;
334 } /* Conf_AddServer */
338 Set_Defaults( BOOLEAN InitServers )
340 /* Initialize configuration variables with default values. */
344 strcpy( Conf_ServerName, "" );
345 sprintf( Conf_ServerInfo, "%s %s", PACKAGE_NAME, PACKAGE_VERSION );
346 strcpy( Conf_ServerPwd, "" );
348 strcpy( Conf_ServerAdmin1, "" );
349 strcpy( Conf_ServerAdmin2, "" );
350 strcpy( Conf_ServerAdminMail, "" );
352 strlcpy( Conf_MotdFile, SYSCONFDIR, sizeof( Conf_MotdFile ));
353 strlcat( Conf_MotdFile, MOTD_FILE, sizeof( Conf_MotdFile ));
355 strlcpy( Conf_MotdPhrase, MOTD_PHRASE, sizeof( Conf_MotdPhrase ));
357 strlcpy( Conf_Chroot, CHROOT_DIR, sizeof( Conf_Chroot ));
359 Conf_ListenPorts_Count = 0;
360 strcpy( Conf_ListenAddress, "" );
362 Conf_UID = Conf_GID = 0;
364 Conf_PingTimeout = 120;
365 Conf_PongTimeout = 20;
367 Conf_ConnectRetry = 60;
370 Conf_Channel_Count = 0;
372 Conf_OperCanMode = FALSE;
374 Conf_MaxConnections = -1;
375 Conf_MaxConnectionsIP = 5;
378 /* Initialize server configuration structures */
379 if( InitServers ) for( i = 0; i < MAX_SERVERS; Init_Server_Struct( &Conf_Server[i++] ));
386 /* Read configuration file. */
388 CHAR section[LINE_LEN], str[LINE_LEN], *var, *arg, *ptr;
392 /* Open configuration file */
393 fd = fopen( NGIRCd_ConfFile, "r" );
396 /* No configuration file found! */
397 Config_Error( LOG_ALERT, "Can't read configuration \"%s\": %s", NGIRCd_ConfFile, strerror( errno ));
398 Config_Error( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME );
402 Config_Error( LOG_INFO, "Reading configuration from \"%s\" ...", NGIRCd_ConfFile );
404 /* Clean up server configuration structure: mark all already
405 * configured servers as "once" so that they are deleted
406 * after the next disconnect and delete all unused servers.
407 * And delete all servers which are "duplicates" of servers
408 * that are already marked as "once" (such servers have been
409 * created by the last rehash but are now useless). */
410 for( i = 0; i < MAX_SERVERS; i++ )
412 if( Conf_Server[i].conn_id == NONE ) Init_Server_Struct( &Conf_Server[i] );
415 /* This structure is in use ... */
416 if( Conf_Server[i].flags & CONF_SFLAG_ONCE )
418 /* Check for duplicates */
419 for( n = 0; n < MAX_SERVERS; n++ )
421 if( n == i ) continue;
423 if( Conf_Server[i].conn_id == Conf_Server[n].conn_id )
425 Init_Server_Struct( &Conf_Server[n] );
426 Log( LOG_DEBUG, "Deleted unused duplicate server %d (kept %d).", n, i );
432 /* Mark server as "once" */
433 Conf_Server[i].flags |= CONF_SFLAG_ONCE;
434 Log( LOG_DEBUG, "Marked server %d as \"once\"", i );
439 /* Initialize variables */
441 strcpy( section, "" );
442 Init_Server_Struct( &New_Server );
443 New_Server_Idx = NONE;
445 /* Read configuration file */
448 if( ! fgets( str, LINE_LEN, fd )) break;
452 /* Skip comments and empty lines */
453 if( str[0] == ';' || str[0] == '#' || str[0] == '\0' ) continue;
455 /* Is this the beginning of a new section? */
456 if(( str[0] == '[' ) && ( str[strlen( str ) - 1] == ']' ))
458 strlcpy( section, str, sizeof( section ));
459 if( strcasecmp( section, "[GLOBAL]" ) == 0 ) continue;
460 if( strcasecmp( section, "[OPERATOR]" ) == 0 )
462 if( Conf_Oper_Count + 1 > MAX_OPERATORS ) Config_Error( LOG_ERR, "Too many operators configured." );
465 /* Initialize new operator structure */
466 strcpy( Conf_Oper[Conf_Oper_Count].name, "" );
467 strcpy( Conf_Oper[Conf_Oper_Count].pwd, "" );
472 if( strcasecmp( section, "[SERVER]" ) == 0 )
474 /* Check if there is already a server to add */
475 if( New_Server.name[0] )
477 /* Copy data to "real" server structure */
478 assert( New_Server_Idx > NONE );
479 Conf_Server[New_Server_Idx] = New_Server;
482 /* Re-init structure for new server */
483 Init_Server_Struct( &New_Server );
485 /* Search unused item in server configuration structure */
486 for( i = 0; i < MAX_SERVERS; i++ )
488 /* Is this item used? */
489 if( ! Conf_Server[i].name[0] ) break;
491 if( i >= MAX_SERVERS )
493 /* Oops, no free item found! */
494 Config_Error( LOG_ERR, "Too many servers configured." );
495 New_Server_Idx = NONE;
497 else New_Server_Idx = i;
500 if( strcasecmp( section, "[CHANNEL]" ) == 0 )
502 if( Conf_Channel_Count + 1 > MAX_DEFCHANNELS ) Config_Error( LOG_ERR, "Too many pre-defined channels configured." );
505 /* Initialize new channel structure */
506 strcpy( Conf_Channel[Conf_Channel_Count].name, "" );
507 strcpy( Conf_Channel[Conf_Channel_Count].modes, "" );
508 strcpy( Conf_Channel[Conf_Channel_Count].topic, "" );
509 Conf_Channel_Count++;
513 Config_Error( LOG_ERR, "%s, line %d: Unknown section \"%s\"!", NGIRCd_ConfFile, line, section );
516 if( section[0] == 0x1 ) continue;
518 /* Split line into variable name and parameters */
519 ptr = strchr( str, '=' );
522 Config_Error( LOG_ERR, "%s, line %d: Syntax error!", NGIRCd_ConfFile, line );
526 var = str; ngt_TrimStr( var );
527 arg = ptr + 1; ngt_TrimStr( arg );
529 if( strcasecmp( section, "[GLOBAL]" ) == 0 ) Handle_GLOBAL( line, var, arg );
530 else if( strcasecmp( section, "[OPERATOR]" ) == 0 ) Handle_OPERATOR( line, var, arg );
531 else if( strcasecmp( section, "[SERVER]" ) == 0 ) Handle_SERVER( line, var, arg );
532 else if( strcasecmp( section, "[CHANNEL]" ) == 0 ) Handle_CHANNEL( line, var, arg );
533 else Config_Error( LOG_ERR, "%s, line %d: Variable \"%s\" outside section!", NGIRCd_ConfFile, line, var );
536 /* Close configuration file */
539 /* Check if there is still a server to add */
540 if( New_Server.name[0] )
542 /* Copy data to "real" server structure */
543 assert( New_Server_Idx > NONE );
544 Conf_Server[New_Server_Idx] = New_Server;
547 /* If there are no ports configured use the default: 6667 */
548 if( Conf_ListenPorts_Count < 1 )
550 Conf_ListenPorts_Count = 1;
551 Conf_ListenPorts[0] = 6667;
557 Handle_GLOBAL( INT Line, CHAR *Var, CHAR *Arg )
565 assert( Var != NULL );
566 assert( Arg != NULL );
568 if( strcasecmp( Var, "Name" ) == 0 )
571 if( strlcpy( Conf_ServerName, Arg, sizeof( Conf_ServerName )) >= sizeof( Conf_ServerName ))
572 Config_Error_TooLong( Line, Var );
576 if( strcasecmp( Var, "Info" ) == 0 )
578 /* Info text of server */
579 if( strlcpy( Conf_ServerInfo, Arg, sizeof( Conf_ServerInfo )) >= sizeof( Conf_ServerInfo ))
580 Config_Error_TooLong ( Line, Var );
584 if( strcasecmp( Var, "Password" ) == 0 )
586 /* Global server password */
587 if( strlcpy( Conf_ServerPwd, Arg, sizeof( Conf_ServerPwd )) >= sizeof( Conf_ServerPwd ))
588 Config_Error_TooLong( Line, Var );
592 if( strcasecmp( Var, "AdminInfo1" ) == 0 )
594 /* Administrative info #1 */
595 if( strlcpy( Conf_ServerAdmin1, Arg, sizeof( Conf_ServerAdmin1 )) >= sizeof( Conf_ServerAdmin1 )) Config_Error_TooLong ( Line, Var );
598 if( strcasecmp( Var, "AdminInfo2" ) == 0 )
600 /* Administrative info #2 */
601 if( strlcpy( Conf_ServerAdmin2, Arg, sizeof( Conf_ServerAdmin2 )) >= sizeof( Conf_ServerAdmin2 )) Config_Error_TooLong ( Line, Var );
604 if( strcasecmp( Var, "AdminEMail" ) == 0 )
606 /* Administrative email contact */
607 if( strlcpy( Conf_ServerAdminMail, Arg, sizeof( Conf_ServerAdminMail )) >= sizeof( Conf_ServerAdminMail )) Config_Error_TooLong( Line, Var );
610 if( strcasecmp( Var, "Ports" ) == 0 )
612 /* Ports on that the server should listen. More port numbers
613 * must be separated by "," */
614 ptr = strtok( Arg, "," );
619 if( Conf_ListenPorts_Count + 1 > MAX_LISTEN_PORTS ) Config_Error( LOG_ERR, "Too many listen ports configured. Port %ld ignored.", port );
622 if( port > 0 && port < 0xFFFF ) Conf_ListenPorts[Conf_ListenPorts_Count++] = (UINT)port;
623 else Config_Error( LOG_ERR, "%s, line %d (section \"Global\"): Illegal port number %ld!", NGIRCd_ConfFile, Line, port );
625 ptr = strtok( NULL, "," );
629 if( strcasecmp( Var, "MotdFile" ) == 0 )
631 /* "Message of the day" (MOTD) file */
632 if( strlcpy( Conf_MotdFile, Arg, sizeof( Conf_MotdFile )) >= sizeof( Conf_MotdFile ))
633 Config_Error_TooLong( Line, Var );
637 if( strcasecmp( Var, "MotdPhrase" ) == 0 )
639 /* "Message of the day" phrase (instead of file) */
640 if( strlcpy( Conf_MotdPhrase, Arg, sizeof( Conf_MotdPhrase )) >= sizeof( Conf_MotdPhrase ))
641 Config_Error_TooLong( Line, Var );
645 if( strcasecmp( Var, "ChrootDir" ) == 0 )
647 /* directory for chroot() */
648 if( strlcpy( Conf_Chroot, Arg, sizeof( Conf_Chroot )) >= sizeof( Conf_Chroot ))
649 Config_Error_TooLong( Line, Var );
653 if( strcasecmp( Var, "ServerUID" ) == 0 )
655 /* UID the daemon should switch to */
656 pwd = getpwnam( Arg );
657 if( pwd ) Conf_UID = pwd->pw_uid;
661 if( ! isdigit( (INT)*Arg )) Config_Error_NaN( Line, Var );
664 Conf_UID = (UINT)atoi( Arg );
668 if( strcasecmp( Var, "ServerGID" ) == 0 )
670 /* GID the daemon should use */
671 grp = getgrnam( Arg );
672 if( grp ) Conf_GID = grp->gr_gid;
676 if( ! isdigit( (INT)*Arg )) Config_Error_NaN( Line, Var );
679 Conf_GID = (UINT)atoi( Arg );
683 if( strcasecmp( Var, "PingTimeout" ) == 0 )
686 Conf_PingTimeout = atoi( Arg );
687 if( Conf_PingTimeout < 5 )
689 Config_Error( LOG_WARNING, "%s, line %d: Value of \"PingTimeout\" too low!", NGIRCd_ConfFile, Line );
690 Conf_PingTimeout = 5;
694 if( strcasecmp( Var, "PongTimeout" ) == 0 )
697 Conf_PongTimeout = atoi( Arg );
698 if( Conf_PongTimeout < 5 )
700 Config_Error( LOG_WARNING, "%s, line %d: Value of \"PongTimeout\" too low!", NGIRCd_ConfFile, Line );
701 Conf_PongTimeout = 5;
705 if( strcasecmp( Var, "ConnectRetry" ) == 0 )
707 /* Seconds between connection attempts to other servers */
708 Conf_ConnectRetry = atoi( Arg );
709 if( Conf_ConnectRetry < 5 )
711 Config_Error( LOG_WARNING, "%s, line %d: Value of \"ConnectRetry\" too low!", NGIRCd_ConfFile, Line );
712 Conf_ConnectRetry = 5;
716 if( strcasecmp( Var, "OperCanUseMode" ) == 0 )
718 /* Are IRC operators allowed to use MODE in channels they aren't Op in? */
719 if( strcasecmp( Arg, "yes" ) == 0 ) Conf_OperCanMode = TRUE;
720 else if( strcasecmp( Arg, "true" ) == 0 ) Conf_OperCanMode = TRUE;
721 else if( atoi( Arg ) != 0 ) Conf_OperCanMode = TRUE;
722 else Conf_OperCanMode = FALSE;
725 if( strcasecmp( Var, "MaxConnections" ) == 0 )
727 /* Maximum number of connections. Values <= 0 are equal to "no limit". */
729 if( ! isdigit( (INT)*Arg )) Config_Error_NaN( Line, Var);
732 Conf_MaxConnections = atol( Arg );
735 if( strcasecmp( Var, "MaxConnectionsIP" ) == 0 )
737 /* Maximum number of simoultanous connections from one IP. Values <= 0 are equal to "no limit". */
739 if( ! isdigit( (INT)*Arg )) Config_Error_NaN( Line, Var );
742 Conf_MaxConnectionsIP = atoi( Arg );
745 if( strcasecmp( Var, "MaxJoins" ) == 0 )
747 /* Maximum number of channels a user can join. Values <= 0 are equal to "no limit". */
749 if( ! isdigit( (INT)*Arg )) Config_Error_NaN( Line, Var );
752 Conf_MaxJoins = atoi( Arg );
755 if( strcasecmp( Var, "Listen" ) == 0 )
757 /* IP-Address to bind sockets */
758 if( strlcpy( Conf_ListenAddress, Arg, sizeof( Conf_ListenAddress )) >= sizeof( Conf_ListenAddress ))
760 Config_Error_TooLong( Line, Var );
765 Config_Error( LOG_ERR, "%s, line %d (section \"Global\"): Unknown variable \"%s\"!", NGIRCd_ConfFile, Line, Var );
766 } /* Handle_GLOBAL */
770 Handle_OPERATOR( INT Line, CHAR *Var, CHAR *Arg )
773 assert( Var != NULL );
774 assert( Arg != NULL );
775 assert( Conf_Oper_Count > 0 );
777 if( strcasecmp( Var, "Name" ) == 0 )
779 /* Name of IRC operator */
780 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 );
783 if( strcasecmp( Var, "Password" ) == 0 )
785 /* Password of IRC operator */
786 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 );
790 Config_Error( LOG_ERR, "%s, line %d (section \"Operator\"): Unknown variable \"%s\"!", NGIRCd_ConfFile, Line, Var );
791 } /* Handle_OPERATOR */
795 Handle_SERVER( INT Line, CHAR *Var, CHAR *Arg )
800 assert( Var != NULL );
801 assert( Arg != NULL );
803 /* Ignore server block if no space is left in server configuration structure */
804 if( New_Server_Idx <= NONE ) return;
806 if( strcasecmp( Var, "Host" ) == 0 )
808 /* Hostname of the server */
809 if( strlcpy( New_Server.host, Arg, sizeof( New_Server.host )) >= sizeof( New_Server.host ))
810 Config_Error_TooLong ( Line, Var );
814 if( strcasecmp( Var, "Name" ) == 0 )
816 /* Name of the server ("Nick"/"ID") */
817 if( strlcpy( New_Server.name, Arg, sizeof( New_Server.name )) >= sizeof( New_Server.name ))
818 Config_Error_TooLong( Line, Var );
821 if( strcasecmp( Var, "MyPassword" ) == 0 )
823 /* Password of this server which is sent to the peer */
824 if( strlcpy( New_Server.pwd_in, Arg, sizeof( New_Server.pwd_in )) >= sizeof( New_Server.pwd_in )) Config_Error_TooLong( Line, Var );
827 if( strcasecmp( Var, "PeerPassword" ) == 0 )
829 /* Passwort of the peer which must be received */
830 if( strlcpy( New_Server.pwd_out, Arg, sizeof( New_Server.pwd_out )) >= sizeof( New_Server.pwd_out )) Config_Error_TooLong( Line, Var );
833 if( strcasecmp( Var, "Port" ) == 0 )
835 /* Port to which this server should connect */
837 if( port > 0 && port < 0xFFFF ) New_Server.port = (INT)port;
838 else Config_Error( LOG_ERR, "%s, line %d (section \"Server\"): Illegal port number %ld!", NGIRCd_ConfFile, Line, port );
841 if( strcasecmp( Var, "Group" ) == 0 )
845 if( ! isdigit( (INT)*Arg )) Config_Error_NaN( Line, Var );
848 New_Server.group = atoi( Arg );
852 Config_Error( LOG_ERR, "%s, line %d (section \"Server\"): Unknown variable \"%s\"!", NGIRCd_ConfFile, Line, Var );
853 } /* Handle_SERVER */
857 Handle_CHANNEL( INT Line, CHAR *Var, CHAR *Arg )
860 assert( Var != NULL );
861 assert( Arg != NULL );
863 if( strcasecmp( Var, "Name" ) == 0 )
865 /* Name of the channel */
866 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 ))
867 Config_Error_TooLong( Line, Var );
870 if( strcasecmp( Var, "Modes" ) == 0 )
873 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 ))
874 Config_Error_TooLong( Line, Var );
877 if( strcasecmp( Var, "Topic" ) == 0 )
880 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 ))
881 Config_Error_TooLong( Line, Var );
886 Config_Error( LOG_ERR, "%s, line %d (section \"Channel\"): Unknown variable \"%s\"!", NGIRCd_ConfFile, Line, Var );
887 } /* Handle_CHANNEL */
891 Validate_Config( BOOLEAN Configtest )
893 /* Validate configuration settings. */
896 INT i, servers, servers_once;
899 if( ! Conf_ServerName[0] )
901 /* No server name configured! */
902 Config_Error( LOG_ALERT, "No server name configured in \"%s\" (section 'Global': 'Name')!", NGIRCd_ConfFile );
905 Config_Error( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME );
910 if( Conf_ServerName[0] && ! strchr( Conf_ServerName, '.' ))
912 /* No dot in server name! */
913 Config_Error( LOG_ALERT, "Invalid server name configured in \"%s\" (section 'Global': 'Name'): Dot missing!", NGIRCd_ConfFile );
916 Config_Error( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME );
922 if( ! Conf_ServerAdminMail[0] )
924 /* No administrative contact configured! */
925 Config_Error( LOG_ALERT, "No administrator email address configured in \"%s\" ('AdminEMail')!", NGIRCd_ConfFile );
928 Config_Error( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME );
934 if( ! Conf_ServerAdmin1[0] && ! Conf_ServerAdmin2[0] && ! Conf_ServerAdminMail[0] )
936 /* No administrative information configured! */
937 Config_Error( LOG_WARNING, "No administrative information configured but required by RFC!" );
940 if(( Conf_MaxConnections > (LONG)FD_SETSIZE ) || ( Conf_MaxConnections < 1 ))
942 Conf_MaxConnections = (LONG)FD_SETSIZE;
943 Config_Error( LOG_ERR, "Setting MaxConnections to %ld, select() can't handle more file descriptors!", Conf_MaxConnections );
946 Config_Error( LOG_WARN, "Don't know how many file descriptors select() can handle on this system, don't set MaxConnections too high!" );
950 servers = servers_once = 0;
951 for( i = 0; i < MAX_SERVERS; i++ )
953 if( Conf_Server[i].name[0] )
956 if( Conf_Server[i].flags & CONF_SFLAG_ONCE ) servers_once++;
959 Log( LOG_DEBUG, "Configuration: Operators=%d, Servers=%d[%d], Channels=%d", Conf_Oper_Count, servers, servers_once, Conf_Channel_Count );
961 } /* Validate_Config */
965 Config_Error_TooLong ( CONST INT Line, CONST CHAR *Item )
967 Config_Error( LOG_WARNING, "%s, line %d: Value of \"%s\" too long!", NGIRCd_ConfFile, Line, Item );
971 Config_Error_NaN( CONST INT Line, CONST CHAR *Item )
973 Config_Error( LOG_WARNING, "%s, line %d: Value of \"%s\" is not a number!", NGIRCd_ConfFile, Line, Item );
977 LOCAL VOID Config_Error( CONST INT Level, CONST CHAR *Format, ... )
979 LOCAL VOID Config_Error( Level, Format, va_alist )
985 /* Error! Write to console and/or logfile. */
987 CHAR msg[MAX_LOG_MSG_LEN];
990 assert( Format != NULL );
993 va_start( ap, Format );
997 vsnprintf( msg, MAX_LOG_MSG_LEN, Format, ap );
1000 /* During "normal operations" the log functions of the daemon should
1001 * be used, but during testing of the configuration file, all messages
1002 * should go directly to the console: */
1003 if( Use_Log ) Log( Level, "%s", msg );
1005 } /* Config_Error */
1009 Init_Server_Struct( CONF_SERVER *Server )
1011 /* Initialize server configuration structur to default values */
1013 assert( Server != NULL );
1015 memset( Server, 0, sizeof (CONF_SERVER) );
1017 Server->group = NONE;
1018 Server->lasttry = time( NULL ) - Conf_ConnectRetry + STARTUP_DELAY;
1020 if( NGIRCd_Passive ) Server->flags = CONF_SFLAG_DISABLED;
1022 Server->conn_id = NONE;
1023 } /* Init_Server_Struct */