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.77.2.1 2005/10/11 19:28:47 alex Exp $";
34 #include <sys/types.h>
53 LOCAL bool Use_Log = true;
54 LOCAL CONF_SERVER New_Server;
55 LOCAL int New_Server_Idx;
58 LOCAL void Set_Defaults PARAMS(( bool InitServers ));
59 LOCAL void Read_Config PARAMS(( void ));
60 LOCAL void Validate_Config PARAMS(( bool 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(( const int LINE, const char *Value ));
70 LOCAL void Config_Error_TooLong PARAMS(( const 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 and stdout ("you can read our nice message and we can
109 * read in your keypress") are valid tty's, wait for a key: */
110 if( isatty( fileno( stdin )) && isatty( fileno( stdout )))
112 puts( "OK, press enter to see a dump of your service configuration ..." );
115 else puts( "Ok, dump of your server configuration follows:\n" );
118 printf( " Name = %s\n", Conf_ServerName );
119 printf( " Info = %s\n", Conf_ServerInfo );
120 printf( " Password = %s\n", Conf_ServerPwd );
121 printf( " AdminInfo1 = %s\n", Conf_ServerAdmin1 );
122 printf( " AdminInfo2 = %s\n", Conf_ServerAdmin2 );
123 printf( " AdminEMail = %s\n", Conf_ServerAdminMail );
124 printf( " MotdFile = %s\n", Conf_MotdFile );
125 printf( " MotdPhrase = %s\n", Conf_MotdPhrase );
126 printf( " ChrootDir = %s\n", Conf_Chroot );
127 printf( " PidFile = %s\n", Conf_PidFile);
128 printf( " Ports = " );
129 for( i = 0; i < Conf_ListenPorts_Count; i++ )
131 if( i != 0 ) printf( ", " );
132 printf( "%u", (unsigned int) Conf_ListenPorts[i] );
135 printf( " Listen = %s\n", Conf_ListenAddress );
136 pwd = getpwuid( Conf_UID );
137 if( pwd ) printf( " ServerUID = %s\n", pwd->pw_name );
138 else printf( " ServerUID = %ld\n", (long)Conf_UID );
139 grp = getgrgid( Conf_GID );
140 if( grp ) printf( " ServerGID = %s\n", grp->gr_name );
141 else printf( " ServerGID = %ld\n", (long)Conf_GID );
142 printf( " PingTimeout = %d\n", Conf_PingTimeout );
143 printf( " PongTimeout = %d\n", Conf_PongTimeout );
144 printf( " ConnectRetry = %d\n", Conf_ConnectRetry );
145 printf( " OperCanUseMode = %s\n", Conf_OperCanMode == true? "yes" : "no" );
146 printf( " OperServerMode = %s\n", Conf_OperServerMode == true? "yes" : "no" );
147 if( Conf_MaxConnections > 0 ) printf( " MaxConnections = %ld\n", Conf_MaxConnections );
148 else printf( " MaxConnections = -1\n" );
149 if( Conf_MaxConnectionsIP > 0 ) printf( " MaxConnectionsIP = %d\n", Conf_MaxConnectionsIP );
150 else printf( " MaxConnectionsIP = -1\n" );
151 if( Conf_MaxJoins > 0 ) printf( " MaxJoins = %d\n", Conf_MaxJoins );
152 else printf( " MaxJoins = -1\n" );
155 for( i = 0; i < Conf_Oper_Count; i++ )
157 if( ! Conf_Oper[i].name[0] ) continue;
159 /* Valid "Operator" section */
160 puts( "[OPERATOR]" );
161 printf( " Name = %s\n", Conf_Oper[i].name );
162 printf( " Password = %s\n", Conf_Oper[i].pwd );
163 if ( Conf_Oper[i].mask ) printf( " Mask = %s\n", Conf_Oper[i].mask );
167 for( i = 0; i < MAX_SERVERS; i++ )
169 if( ! Conf_Server[i].name[0] ) continue;
171 /* Valid "Server" section */
173 printf( " Name = %s\n", Conf_Server[i].name );
174 printf( " Host = %s\n", Conf_Server[i].host );
175 printf( " Port = %d\n", Conf_Server[i].port );
176 printf( " MyPassword = %s\n", Conf_Server[i].pwd_in );
177 printf( " PeerPassword = %s\n", Conf_Server[i].pwd_out );
178 printf( " Group = %d\n", Conf_Server[i].group );
182 for( i = 0; i < Conf_Channel_Count; i++ )
184 if( ! Conf_Channel[i].name[0] ) continue;
186 /* Valid "Channel" section */
188 printf( " Name = %s\n", Conf_Channel[i].name );
189 printf( " Modes = %s\n", Conf_Channel[i].modes );
190 printf( " Topic = %s\n", Conf_Channel[i].topic );
199 Conf_UnsetServer( CONN_ID Idx )
201 /* Set next time for next connection attempt, if this is a server
202 * link that is (still) configured here. If the server is set as
203 * "once", delete it from our configuration.
204 * Non-Server-Connections will be silently ignored. */
209 /* Check all our configured servers */
210 for( i = 0; i < MAX_SERVERS; i++ )
212 if( Conf_Server[i].conn_id != Idx ) continue;
214 /* Gotcha! Mark server configuration as "unused": */
215 Conf_Server[i].conn_id = NONE;
217 if( Conf_Server[i].flags & CONF_SFLAG_ONCE )
219 /* Delete configuration here */
220 Init_Server_Struct( &Conf_Server[i] );
224 /* Set time for next connect attempt */
226 if (Conf_Server[i].lasttry < t - Conf_ConnectRetry) {
227 /* The connection has been "long", so we don't
228 * require the next attempt to be delayed. */
229 Conf_Server[i].lasttry =
230 t - Conf_ConnectRetry + RECONNECT_DELAY;
232 Conf_Server[i].lasttry = t;
235 } /* Conf_UnsetServer */
239 Conf_SetServer( int ConfServer, CONN_ID Idx )
241 /* Set connection for specified configured server */
243 assert( ConfServer > NONE );
244 assert( Idx > NONE );
246 Conf_Server[ConfServer].conn_id = Idx;
247 } /* Conf_SetServer */
251 Conf_GetServer( CONN_ID Idx )
253 /* Get index of server in configuration structure */
257 assert( Idx > NONE );
259 for( i = 0; i < MAX_SERVERS; i++ )
261 if( Conf_Server[i].conn_id == Idx ) return i;
264 } /* Conf_GetServer */
268 Conf_EnableServer( char *Name, UINT16 Port )
270 /* Enable specified server and adjust port */
274 assert( Name != NULL );
276 for( i = 0; i < MAX_SERVERS; i++ )
278 if( strcasecmp( Conf_Server[i].name, Name ) == 0 )
280 /* Gotcha! Set port and enable server: */
281 Conf_Server[i].port = Port;
282 Conf_Server[i].flags &= ~CONF_SFLAG_DISABLED;
287 } /* Conf_EnableServer */
291 Conf_DisableServer( char *Name )
293 /* Enable specified server and adjust port */
297 assert( Name != NULL );
299 for( i = 0; i < MAX_SERVERS; i++ )
301 if( strcasecmp( Conf_Server[i].name, Name ) == 0 )
303 /* Gotcha! Disable and disconnect server: */
304 Conf_Server[i].flags |= CONF_SFLAG_DISABLED;
305 if( Conf_Server[i].conn_id > NONE ) Conn_Close( Conf_Server[i].conn_id, NULL, "Server link terminated on operator request", true);
310 } /* Conf_DisableServer */
314 Conf_AddServer( char *Name, UINT16 Port, char *Host, char *MyPwd, char *PeerPwd )
316 /* Add new server to configuration */
320 assert( Name != NULL );
321 assert( Host != NULL );
322 assert( MyPwd != NULL );
323 assert( PeerPwd != NULL );
325 /* Search unused item in server configuration structure */
326 for( i = 0; i < MAX_SERVERS; i++ )
328 /* Is this item used? */
329 if( ! Conf_Server[i].name[0] ) break;
331 if( i >= MAX_SERVERS ) return false;
333 Init_Server_Struct( &Conf_Server[i] );
334 strlcpy( Conf_Server[i].name, Name, sizeof( Conf_Server[i].name ));
335 strlcpy( Conf_Server[i].host, Host, sizeof( Conf_Server[i].host ));
336 strlcpy( Conf_Server[i].pwd_out, MyPwd, sizeof( Conf_Server[i].pwd_out ));
337 strlcpy( Conf_Server[i].pwd_in, PeerPwd, sizeof( Conf_Server[i].pwd_in ));
338 Conf_Server[i].port = Port;
339 Conf_Server[i].flags = CONF_SFLAG_ONCE;
342 } /* Conf_AddServer */
346 Set_Defaults( bool InitServers )
348 /* Initialize configuration variables with default values. */
352 strcpy( Conf_ServerName, "" );
353 snprintf( Conf_ServerInfo, sizeof Conf_ServerInfo, "%s %s", PACKAGE_NAME, PACKAGE_VERSION );
354 strcpy( Conf_ServerPwd, "" );
356 strcpy( Conf_ServerAdmin1, "" );
357 strcpy( Conf_ServerAdmin2, "" );
358 strcpy( Conf_ServerAdminMail, "" );
360 strlcpy( Conf_MotdFile, SYSCONFDIR, sizeof( Conf_MotdFile ));
361 strlcat( Conf_MotdFile, MOTD_FILE, sizeof( Conf_MotdFile ));
363 strlcpy( Conf_MotdPhrase, MOTD_PHRASE, sizeof( Conf_MotdPhrase ));
365 strlcpy( Conf_Chroot, CHROOT_DIR, sizeof( Conf_Chroot ));
367 strlcpy( Conf_PidFile, PID_FILE, sizeof( Conf_PidFile ));
369 Conf_ListenPorts_Count = 0;
370 strcpy( Conf_ListenAddress, "" );
372 Conf_UID = Conf_GID = 0;
374 Conf_PingTimeout = 120;
375 Conf_PongTimeout = 20;
377 Conf_ConnectRetry = 60;
380 Conf_Channel_Count = 0;
382 Conf_OperCanMode = false;
383 Conf_OperServerMode = false;
385 Conf_MaxConnections = -1;
386 Conf_MaxConnectionsIP = 5;
389 /* Initialize server configuration structures */
390 if( InitServers ) for( i = 0; i < MAX_SERVERS; Init_Server_Struct( &Conf_Server[i++] ));
397 /* Read configuration file. */
399 char section[LINE_LEN], str[LINE_LEN], *var, *arg, *ptr;
403 /* Open configuration file */
404 fd = fopen( NGIRCd_ConfFile, "r" );
407 /* No configuration file found! */
408 Config_Error( LOG_ALERT, "Can't read configuration \"%s\": %s", NGIRCd_ConfFile, strerror( errno ));
409 Config_Error( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME );
413 Config_Error( LOG_INFO, "Reading configuration from \"%s\" ...", NGIRCd_ConfFile );
415 /* Clean up server configuration structure: mark all already
416 * configured servers as "once" so that they are deleted
417 * after the next disconnect and delete all unused servers.
418 * And delete all servers which are "duplicates" of servers
419 * that are already marked as "once" (such servers have been
420 * created by the last rehash but are now useless). */
421 for( i = 0; i < MAX_SERVERS; i++ )
423 if( Conf_Server[i].conn_id == NONE ) Init_Server_Struct( &Conf_Server[i] );
426 /* This structure is in use ... */
427 if( Conf_Server[i].flags & CONF_SFLAG_ONCE )
429 /* Check for duplicates */
430 for( n = 0; n < MAX_SERVERS; n++ )
432 if( n == i ) continue;
434 if( Conf_Server[i].conn_id == Conf_Server[n].conn_id )
436 Init_Server_Struct( &Conf_Server[n] );
437 Log( LOG_DEBUG, "Deleted unused duplicate server %d (kept %d).", n, i );
443 /* Mark server as "once" */
444 Conf_Server[i].flags |= CONF_SFLAG_ONCE;
445 Log( LOG_DEBUG, "Marked server %d as \"once\"", i );
450 /* Initialize variables */
452 strcpy( section, "" );
453 Init_Server_Struct( &New_Server );
454 New_Server_Idx = NONE;
456 /* Read configuration file */
459 if( ! fgets( str, LINE_LEN, fd )) break;
463 /* Skip comments and empty lines */
464 if( str[0] == ';' || str[0] == '#' || str[0] == '\0' ) continue;
466 /* Is this the beginning of a new section? */
467 if(( str[0] == '[' ) && ( str[strlen( str ) - 1] == ']' ))
469 strlcpy( section, str, sizeof( section ));
470 if( strcasecmp( section, "[GLOBAL]" ) == 0 ) continue;
471 if( strcasecmp( section, "[OPERATOR]" ) == 0 )
473 if( Conf_Oper_Count + 1 > MAX_OPERATORS ) Config_Error( LOG_ERR, "Too many operators configured." );
476 /* Initialize new operator structure */
477 Conf_Oper[Conf_Oper_Count].name[0] = '\0';
478 Conf_Oper[Conf_Oper_Count].pwd[0] = '\0';
479 if (Conf_Oper[Conf_Oper_Count].mask) {
480 free(Conf_Oper[Conf_Oper_Count].mask );
481 Conf_Oper[Conf_Oper_Count].mask = NULL;
487 if( strcasecmp( section, "[SERVER]" ) == 0 )
489 /* Check if there is already a server to add */
490 if( New_Server.name[0] )
492 /* Copy data to "real" server structure */
493 assert( New_Server_Idx > NONE );
494 Conf_Server[New_Server_Idx] = New_Server;
497 /* Re-init structure for new server */
498 Init_Server_Struct( &New_Server );
500 /* Search unused item in server configuration structure */
501 for( i = 0; i < MAX_SERVERS; i++ )
503 /* Is this item used? */
504 if( ! Conf_Server[i].name[0] ) break;
506 if( i >= MAX_SERVERS )
508 /* Oops, no free item found! */
509 Config_Error( LOG_ERR, "Too many servers configured." );
510 New_Server_Idx = NONE;
512 else New_Server_Idx = i;
515 if( strcasecmp( section, "[CHANNEL]" ) == 0 )
517 if( Conf_Channel_Count + 1 > MAX_DEFCHANNELS ) Config_Error( LOG_ERR, "Too many pre-defined channels configured." );
520 /* Initialize new channel structure */
521 strcpy( Conf_Channel[Conf_Channel_Count].name, "" );
522 strcpy( Conf_Channel[Conf_Channel_Count].modes, "" );
523 strcpy( Conf_Channel[Conf_Channel_Count].topic, "" );
524 Conf_Channel_Count++;
528 Config_Error( LOG_ERR, "%s, line %d: Unknown section \"%s\"!", NGIRCd_ConfFile, line, section );
531 if( section[0] == 0x1 ) continue;
533 /* Split line into variable name and parameters */
534 ptr = strchr( str, '=' );
537 Config_Error( LOG_ERR, "%s, line %d: Syntax error!", NGIRCd_ConfFile, line );
541 var = str; ngt_TrimStr( var );
542 arg = ptr + 1; ngt_TrimStr( arg );
544 if( strcasecmp( section, "[GLOBAL]" ) == 0 ) Handle_GLOBAL( line, var, arg );
545 else if( strcasecmp( section, "[OPERATOR]" ) == 0 ) Handle_OPERATOR( line, var, arg );
546 else if( strcasecmp( section, "[SERVER]" ) == 0 ) Handle_SERVER( line, var, arg );
547 else if( strcasecmp( section, "[CHANNEL]" ) == 0 ) Handle_CHANNEL( line, var, arg );
548 else Config_Error( LOG_ERR, "%s, line %d: Variable \"%s\" outside section!", NGIRCd_ConfFile, line, var );
551 /* Close configuration file */
554 /* Check if there is still a server to add */
555 if( New_Server.name[0] )
557 /* Copy data to "real" server structure */
558 assert( New_Server_Idx > NONE );
559 Conf_Server[New_Server_Idx] = New_Server;
562 /* If there are no ports configured use the default: 6667 */
563 if( Conf_ListenPorts_Count < 1 )
565 Conf_ListenPorts_Count = 1;
566 Conf_ListenPorts[0] = 6667;
572 Check_ArgIsTrue( const char *Arg )
574 if( strcasecmp( Arg, "yes" ) == 0 ) return true;
575 if( strcasecmp( Arg, "true" ) == 0 ) return true;
576 if( atoi( Arg ) != 0 ) return true;
579 } /* Check_ArgIsTrue */
583 Handle_GLOBAL( int Line, char *Var, char *Arg )
591 assert( Var != NULL );
592 assert( Arg != NULL );
594 if( strcasecmp( Var, "Name" ) == 0 )
597 if( strlcpy( Conf_ServerName, Arg, sizeof( Conf_ServerName )) >= sizeof( Conf_ServerName ))
598 Config_Error_TooLong( Line, Var );
602 if( strcasecmp( Var, "Info" ) == 0 )
604 /* Info text of server */
605 if( strlcpy( Conf_ServerInfo, Arg, sizeof( Conf_ServerInfo )) >= sizeof( Conf_ServerInfo ))
606 Config_Error_TooLong ( Line, Var );
610 if( strcasecmp( Var, "Password" ) == 0 )
612 /* Global server password */
613 if( strlcpy( Conf_ServerPwd, Arg, sizeof( Conf_ServerPwd )) >= sizeof( Conf_ServerPwd ))
614 Config_Error_TooLong( Line, Var );
618 if( strcasecmp( Var, "AdminInfo1" ) == 0 )
620 /* Administrative info #1 */
621 if( strlcpy( Conf_ServerAdmin1, Arg, sizeof( Conf_ServerAdmin1 )) >= sizeof( Conf_ServerAdmin1 )) Config_Error_TooLong ( Line, Var );
624 if( strcasecmp( Var, "AdminInfo2" ) == 0 )
626 /* Administrative info #2 */
627 if( strlcpy( Conf_ServerAdmin2, Arg, sizeof( Conf_ServerAdmin2 )) >= sizeof( Conf_ServerAdmin2 )) Config_Error_TooLong ( Line, Var );
630 if( strcasecmp( Var, "AdminEMail" ) == 0 )
632 /* Administrative email contact */
633 if( strlcpy( Conf_ServerAdminMail, Arg, sizeof( Conf_ServerAdminMail )) >= sizeof( Conf_ServerAdminMail )) Config_Error_TooLong( Line, Var );
636 if( strcasecmp( Var, "Ports" ) == 0 )
638 /* Ports on that the server should listen. More port numbers
639 * must be separated by "," */
640 ptr = strtok( Arg, "," );
645 if( Conf_ListenPorts_Count + 1 > MAX_LISTEN_PORTS ) Config_Error( LOG_ERR, "Too many listen ports configured. Port %ld ignored.", port );
648 if( port > 0 && port < 0xFFFF ) Conf_ListenPorts[Conf_ListenPorts_Count++] = (UINT16)port;
649 else Config_Error( LOG_ERR, "%s, line %d (section \"Global\"): Illegal port number %ld!", NGIRCd_ConfFile, Line, port );
651 ptr = strtok( NULL, "," );
655 if( strcasecmp( Var, "MotdFile" ) == 0 )
657 /* "Message of the day" (MOTD) file */
658 if( strlcpy( Conf_MotdFile, Arg, sizeof( Conf_MotdFile )) >= sizeof( Conf_MotdFile ))
659 Config_Error_TooLong( Line, Var );
663 if( strcasecmp( Var, "MotdPhrase" ) == 0 )
665 /* "Message of the day" phrase (instead of file) */
666 if( strlcpy( Conf_MotdPhrase, Arg, sizeof( Conf_MotdPhrase )) >= sizeof( Conf_MotdPhrase ))
667 Config_Error_TooLong( Line, Var );
671 if( strcasecmp( Var, "ChrootDir" ) == 0 )
673 /* directory for chroot() */
674 if( strlcpy( Conf_Chroot, Arg, sizeof( Conf_Chroot )) >= sizeof( Conf_Chroot ))
675 Config_Error_TooLong( Line, Var );
680 if ( strcasecmp( Var, "PidFile" ) == 0 )
682 /* name of pidfile */
683 if( strlcpy( Conf_PidFile, Arg, sizeof( Conf_PidFile )) >= sizeof( Conf_PidFile ))
684 Config_Error_TooLong( Line, Var );
689 if( strcasecmp( Var, "ServerUID" ) == 0 )
691 /* UID the daemon should switch to */
692 pwd = getpwnam( Arg );
693 if( pwd ) Conf_UID = pwd->pw_uid;
697 if( ! isdigit( (int)*Arg )) Config_Error_NaN( Line, Var );
700 Conf_UID = (unsigned int)atoi( Arg );
704 if( strcasecmp( Var, "ServerGID" ) == 0 )
706 /* GID the daemon should use */
707 grp = getgrnam( Arg );
708 if( grp ) Conf_GID = grp->gr_gid;
712 if( ! isdigit( (int)*Arg )) Config_Error_NaN( Line, Var );
715 Conf_GID = (unsigned int)atoi( Arg );
719 if( strcasecmp( Var, "PingTimeout" ) == 0 )
722 Conf_PingTimeout = atoi( Arg );
723 if( Conf_PingTimeout < 5 )
725 Config_Error( LOG_WARNING, "%s, line %d: Value of \"PingTimeout\" too low!", NGIRCd_ConfFile, Line );
726 Conf_PingTimeout = 5;
730 if( strcasecmp( Var, "PongTimeout" ) == 0 )
733 Conf_PongTimeout = atoi( Arg );
734 if( Conf_PongTimeout < 5 )
736 Config_Error( LOG_WARNING, "%s, line %d: Value of \"PongTimeout\" too low!", NGIRCd_ConfFile, Line );
737 Conf_PongTimeout = 5;
741 if( strcasecmp( Var, "ConnectRetry" ) == 0 )
743 /* Seconds between connection attempts to other servers */
744 Conf_ConnectRetry = atoi( Arg );
745 if( Conf_ConnectRetry < 5 )
747 Config_Error( LOG_WARNING, "%s, line %d: Value of \"ConnectRetry\" too low!", NGIRCd_ConfFile, Line );
748 Conf_ConnectRetry = 5;
752 if( strcasecmp( Var, "OperCanUseMode" ) == 0 )
754 /* Are IRC operators allowed to use MODE in channels they aren't Op in? */
755 Conf_OperCanMode = Check_ArgIsTrue( Arg );
758 if( strcasecmp( Var, "OperServerMode" ) == 0 )
760 /* Mask IRC operator as if coming from the server? (ircd-irc2 compat hack) */
761 Conf_OperServerMode = Check_ArgIsTrue( Arg );
764 if( strcasecmp( Var, "MaxConnections" ) == 0 )
766 /* Maximum number of connections. Values <= 0 are equal to "no limit". */
768 if( ! isdigit( (int)*Arg )) Config_Error_NaN( Line, Var);
771 Conf_MaxConnections = atol( Arg );
774 if( strcasecmp( Var, "MaxConnectionsIP" ) == 0 )
776 /* Maximum number of simoultanous connections from one IP. Values <= 0 are equal to "no limit". */
778 if( ! isdigit( (int)*Arg )) Config_Error_NaN( Line, Var );
781 Conf_MaxConnectionsIP = atoi( Arg );
784 if( strcasecmp( Var, "MaxJoins" ) == 0 )
786 /* Maximum number of channels a user can join. Values <= 0 are equal to "no limit". */
788 if( ! isdigit( (int)*Arg )) Config_Error_NaN( Line, Var );
791 Conf_MaxJoins = atoi( Arg );
794 if( strcasecmp( Var, "Listen" ) == 0 )
796 /* IP-Address to bind sockets */
797 if( strlcpy( Conf_ListenAddress, Arg, sizeof( Conf_ListenAddress )) >= sizeof( Conf_ListenAddress ))
799 Config_Error_TooLong( Line, Var );
804 Config_Error( LOG_ERR, "%s, line %d (section \"Global\"): Unknown variable \"%s\"!", NGIRCd_ConfFile, Line, Var );
805 } /* Handle_GLOBAL */
809 Handle_OPERATOR( int Line, char *Var, char *Arg )
812 assert( Var != NULL );
813 assert( Arg != NULL );
814 assert( Conf_Oper_Count > 0 );
816 if( strcasecmp( Var, "Name" ) == 0 )
818 /* Name of IRC operator */
819 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 );
822 if( strcasecmp( Var, "Password" ) == 0 )
824 /* Password of IRC operator */
825 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 );
828 if( strcasecmp( Var, "Mask" ) == 0 )
830 if (Conf_Oper[Conf_Oper_Count - 1].mask) return; /* Hostname already configured */
831 Conf_Oper[Conf_Oper_Count - 1].mask = strdup( Arg );
832 if (! Conf_Oper[Conf_Oper_Count - 1].mask) {
833 Config_Error( LOG_ERR, "%s, line %d: Cannot allocate memory for operator mask: %s", NGIRCd_ConfFile, Line, strerror(errno) );
839 Config_Error( LOG_ERR, "%s, line %d (section \"Operator\"): Unknown variable \"%s\"!", NGIRCd_ConfFile, Line, Var );
840 } /* Handle_OPERATOR */
844 Handle_SERVER( int Line, char *Var, char *Arg )
849 assert( Var != NULL );
850 assert( Arg != NULL );
852 /* Ignore server block if no space is left in server configuration structure */
853 if( New_Server_Idx <= NONE ) return;
855 if( strcasecmp( Var, "Host" ) == 0 )
857 /* Hostname of the server */
858 if( strlcpy( New_Server.host, Arg, sizeof( New_Server.host )) >= sizeof( New_Server.host ))
859 Config_Error_TooLong ( Line, Var );
863 if( strcasecmp( Var, "Name" ) == 0 )
865 /* Name of the server ("Nick"/"ID") */
866 if( strlcpy( New_Server.name, Arg, sizeof( New_Server.name )) >= sizeof( New_Server.name ))
867 Config_Error_TooLong( Line, Var );
870 if( strcasecmp( Var, "MyPassword" ) == 0 )
872 /* Password of this server which is sent to the peer */
873 if( strlcpy( New_Server.pwd_in, Arg, sizeof( New_Server.pwd_in )) >= sizeof( New_Server.pwd_in )) Config_Error_TooLong( Line, Var );
876 if( strcasecmp( Var, "PeerPassword" ) == 0 )
878 /* Passwort of the peer which must be received */
879 if( strlcpy( New_Server.pwd_out, Arg, sizeof( New_Server.pwd_out )) >= sizeof( New_Server.pwd_out )) Config_Error_TooLong( Line, Var );
882 if( strcasecmp( Var, "Port" ) == 0 )
884 /* Port to which this server should connect */
886 if( port > 0 && port < 0xFFFF ) New_Server.port = (UINT16)port;
887 else Config_Error( LOG_ERR, "%s, line %d (section \"Server\"): Illegal port number %ld!", NGIRCd_ConfFile, Line, port );
890 if( strcasecmp( Var, "Group" ) == 0 )
894 if( ! isdigit( (int)*Arg )) Config_Error_NaN( Line, Var );
897 New_Server.group = atoi( Arg );
901 Config_Error( LOG_ERR, "%s, line %d (section \"Server\"): Unknown variable \"%s\"!", NGIRCd_ConfFile, Line, Var );
902 } /* Handle_SERVER */
906 Handle_CHANNEL( int Line, char *Var, char *Arg )
909 assert( Var != NULL );
910 assert( Arg != NULL );
912 if( strcasecmp( Var, "Name" ) == 0 )
914 /* Name of the channel */
915 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 ))
916 Config_Error_TooLong( Line, Var );
919 if( strcasecmp( Var, "Modes" ) == 0 )
922 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 ))
923 Config_Error_TooLong( Line, Var );
926 if( strcasecmp( Var, "Topic" ) == 0 )
929 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 ))
930 Config_Error_TooLong( Line, Var );
935 Config_Error( LOG_ERR, "%s, line %d (section \"Channel\"): Unknown variable \"%s\"!", NGIRCd_ConfFile, Line, Var );
936 } /* Handle_CHANNEL */
940 Validate_Config( bool Configtest )
942 /* Validate configuration settings. */
945 int i, servers, servers_once;
948 if( ! Conf_ServerName[0] )
950 /* No server name configured! */
951 Config_Error( LOG_ALERT, "No server name configured in \"%s\" (section 'Global': 'Name')!", NGIRCd_ConfFile );
954 Config_Error( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME );
959 if( Conf_ServerName[0] && ! strchr( Conf_ServerName, '.' ))
961 /* No dot in server name! */
962 Config_Error( LOG_ALERT, "Invalid server name configured in \"%s\" (section 'Global': 'Name'): Dot missing!", NGIRCd_ConfFile );
965 Config_Error( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME );
971 if( ! Conf_ServerAdminMail[0] )
973 /* No administrative contact configured! */
974 Config_Error( LOG_ALERT, "No administrator email address configured in \"%s\" ('AdminEMail')!", NGIRCd_ConfFile );
977 Config_Error( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME );
983 if( ! Conf_ServerAdmin1[0] && ! Conf_ServerAdmin2[0] && ! Conf_ServerAdminMail[0] )
985 /* No administrative information configured! */
986 Config_Error( LOG_WARNING, "No administrative information configured but required by RFC!" );
989 if(( Conf_MaxConnections > (long)FD_SETSIZE ) || ( Conf_MaxConnections < 1 ))
991 Conf_MaxConnections = (long)FD_SETSIZE;
992 Config_Error( LOG_ERR, "Setting MaxConnections to %ld, select() can't handle more file descriptors!", Conf_MaxConnections );
995 Config_Error( LOG_WARN, "Don't know how many file descriptors select() can handle on this system, don't set MaxConnections too high!" );
999 servers = servers_once = 0;
1000 for( i = 0; i < MAX_SERVERS; i++ )
1002 if( Conf_Server[i].name[0] )
1005 if( Conf_Server[i].flags & CONF_SFLAG_ONCE ) servers_once++;
1008 Log( LOG_DEBUG, "Configuration: Operators=%d, Servers=%d[%d], Channels=%d", Conf_Oper_Count, servers, servers_once, Conf_Channel_Count );
1010 } /* Validate_Config */
1014 Config_Error_TooLong ( const int Line, const char *Item )
1016 Config_Error( LOG_WARNING, "%s, line %d: Value of \"%s\" too long!", NGIRCd_ConfFile, Line, Item );
1020 Config_Error_NaN( const int Line, const char *Item )
1022 Config_Error( LOG_WARNING, "%s, line %d: Value of \"%s\" is not a number!", NGIRCd_ConfFile, Line, Item );
1026 LOCAL void Config_Error( const int Level, const char *Format, ... )
1028 LOCAL void Config_Error( Level, Format, va_alist )
1034 /* Error! Write to console and/or logfile. */
1036 char msg[MAX_LOG_MSG_LEN];
1039 assert( Format != NULL );
1042 va_start( ap, Format );
1046 vsnprintf( msg, MAX_LOG_MSG_LEN, Format, ap );
1049 /* During "normal operations" the log functions of the daemon should
1050 * be used, but during testing of the configuration file, all messages
1051 * should go directly to the console: */
1052 if( Use_Log ) Log( Level, "%s", msg );
1054 } /* Config_Error */
1058 Init_Server_Struct( CONF_SERVER *Server )
1060 /* Initialize server configuration structur to default values */
1062 assert( Server != NULL );
1064 memset( Server, 0, sizeof (CONF_SERVER) );
1066 Server->group = NONE;
1067 Server->lasttry = time( NULL ) - Conf_ConnectRetry + STARTUP_DELAY;
1069 if( NGIRCd_Passive ) Server->flags = CONF_SFLAG_DISABLED;
1071 Server->conn_id = NONE;
1072 } /* Init_Server_Struct */