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.76 2005/04/16 09:23:01 fw 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. */
208 /* Check all our configured servers */
209 for( i = 0; i < MAX_SERVERS; i++ )
211 if( Conf_Server[i].conn_id != Idx ) continue;
213 /* Gotcha! Mark server configuration as "unused": */
214 Conf_Server[i].conn_id = NONE;
216 if( Conf_Server[i].flags & CONF_SFLAG_ONCE )
218 /* Delete configuration here */
219 Init_Server_Struct( &Conf_Server[i] );
223 /* Set time for next connect attempt */
224 if( Conf_Server[i].lasttry < time( NULL ) - Conf_ConnectRetry )
226 /* Okay, the connection was established "long enough": */
227 Conf_Server[i].lasttry = time( NULL ) - Conf_ConnectRetry + RECONNECT_DELAY;
231 } /* Conf_UnsetServer */
235 Conf_SetServer( int ConfServer, CONN_ID Idx )
237 /* Set connection for specified configured server */
239 assert( ConfServer > NONE );
240 assert( Idx > NONE );
242 Conf_Server[ConfServer].conn_id = Idx;
243 } /* Conf_SetServer */
247 Conf_GetServer( CONN_ID Idx )
249 /* Get index of server in configuration structure */
253 assert( Idx > NONE );
255 for( i = 0; i < MAX_SERVERS; i++ )
257 if( Conf_Server[i].conn_id == Idx ) return i;
260 } /* Conf_GetServer */
264 Conf_EnableServer( char *Name, UINT16 Port )
266 /* Enable specified server and adjust port */
270 assert( Name != NULL );
272 for( i = 0; i < MAX_SERVERS; i++ )
274 if( strcasecmp( Conf_Server[i].name, Name ) == 0 )
276 /* Gotcha! Set port and enable server: */
277 Conf_Server[i].port = Port;
278 Conf_Server[i].flags &= ~CONF_SFLAG_DISABLED;
283 } /* Conf_EnableServer */
287 Conf_DisableServer( char *Name )
289 /* Enable specified server and adjust port */
293 assert( Name != NULL );
295 for( i = 0; i < MAX_SERVERS; i++ )
297 if( strcasecmp( Conf_Server[i].name, Name ) == 0 )
299 /* Gotcha! Disable and disconnect server: */
300 Conf_Server[i].flags |= CONF_SFLAG_DISABLED;
301 if( Conf_Server[i].conn_id > NONE ) Conn_Close( Conf_Server[i].conn_id, NULL, "Server link terminated on operator request", true);
306 } /* Conf_DisableServer */
310 Conf_AddServer( char *Name, UINT16 Port, char *Host, char *MyPwd, char *PeerPwd )
312 /* Add new server to configuration */
316 assert( Name != NULL );
317 assert( Host != NULL );
318 assert( MyPwd != NULL );
319 assert( PeerPwd != NULL );
321 /* Search unused item in server configuration structure */
322 for( i = 0; i < MAX_SERVERS; i++ )
324 /* Is this item used? */
325 if( ! Conf_Server[i].name[0] ) break;
327 if( i >= MAX_SERVERS ) return false;
329 Init_Server_Struct( &Conf_Server[i] );
330 strlcpy( Conf_Server[i].name, Name, sizeof( Conf_Server[i].name ));
331 strlcpy( Conf_Server[i].host, Host, sizeof( Conf_Server[i].host ));
332 strlcpy( Conf_Server[i].pwd_out, MyPwd, sizeof( Conf_Server[i].pwd_out ));
333 strlcpy( Conf_Server[i].pwd_in, PeerPwd, sizeof( Conf_Server[i].pwd_in ));
334 Conf_Server[i].port = Port;
335 Conf_Server[i].flags = CONF_SFLAG_ONCE;
338 } /* Conf_AddServer */
342 Set_Defaults( bool InitServers )
344 /* Initialize configuration variables with default values. */
348 strcpy( Conf_ServerName, "" );
349 sprintf( Conf_ServerInfo, "%s %s", PACKAGE_NAME, PACKAGE_VERSION );
350 strcpy( Conf_ServerPwd, "" );
352 strcpy( Conf_ServerAdmin1, "" );
353 strcpy( Conf_ServerAdmin2, "" );
354 strcpy( Conf_ServerAdminMail, "" );
356 strlcpy( Conf_MotdFile, SYSCONFDIR, sizeof( Conf_MotdFile ));
357 strlcat( Conf_MotdFile, MOTD_FILE, sizeof( Conf_MotdFile ));
359 strlcpy( Conf_MotdPhrase, MOTD_PHRASE, sizeof( Conf_MotdPhrase ));
361 strlcpy( Conf_Chroot, CHROOT_DIR, sizeof( Conf_Chroot ));
363 strlcpy( Conf_PidFile, PID_FILE, sizeof( Conf_PidFile ));
365 Conf_ListenPorts_Count = 0;
366 strcpy( Conf_ListenAddress, "" );
368 Conf_UID = Conf_GID = 0;
370 Conf_PingTimeout = 120;
371 Conf_PongTimeout = 20;
373 Conf_ConnectRetry = 60;
376 Conf_Channel_Count = 0;
378 Conf_OperCanMode = false;
379 Conf_OperServerMode = false;
381 Conf_MaxConnections = -1;
382 Conf_MaxConnectionsIP = 5;
385 /* Initialize server configuration structures */
386 if( InitServers ) for( i = 0; i < MAX_SERVERS; Init_Server_Struct( &Conf_Server[i++] ));
393 /* Read configuration file. */
395 char section[LINE_LEN], str[LINE_LEN], *var, *arg, *ptr;
399 /* Open configuration file */
400 fd = fopen( NGIRCd_ConfFile, "r" );
403 /* No configuration file found! */
404 Config_Error( LOG_ALERT, "Can't read configuration \"%s\": %s", NGIRCd_ConfFile, strerror( errno ));
405 Config_Error( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME );
409 Config_Error( LOG_INFO, "Reading configuration from \"%s\" ...", NGIRCd_ConfFile );
411 /* Clean up server configuration structure: mark all already
412 * configured servers as "once" so that they are deleted
413 * after the next disconnect and delete all unused servers.
414 * And delete all servers which are "duplicates" of servers
415 * that are already marked as "once" (such servers have been
416 * created by the last rehash but are now useless). */
417 for( i = 0; i < MAX_SERVERS; i++ )
419 if( Conf_Server[i].conn_id == NONE ) Init_Server_Struct( &Conf_Server[i] );
422 /* This structure is in use ... */
423 if( Conf_Server[i].flags & CONF_SFLAG_ONCE )
425 /* Check for duplicates */
426 for( n = 0; n < MAX_SERVERS; n++ )
428 if( n == i ) continue;
430 if( Conf_Server[i].conn_id == Conf_Server[n].conn_id )
432 Init_Server_Struct( &Conf_Server[n] );
433 Log( LOG_DEBUG, "Deleted unused duplicate server %d (kept %d).", n, i );
439 /* Mark server as "once" */
440 Conf_Server[i].flags |= CONF_SFLAG_ONCE;
441 Log( LOG_DEBUG, "Marked server %d as \"once\"", i );
446 /* Initialize variables */
448 strcpy( section, "" );
449 Init_Server_Struct( &New_Server );
450 New_Server_Idx = NONE;
452 /* Read configuration file */
455 if( ! fgets( str, LINE_LEN, fd )) break;
459 /* Skip comments and empty lines */
460 if( str[0] == ';' || str[0] == '#' || str[0] == '\0' ) continue;
462 /* Is this the beginning of a new section? */
463 if(( str[0] == '[' ) && ( str[strlen( str ) - 1] == ']' ))
465 strlcpy( section, str, sizeof( section ));
466 if( strcasecmp( section, "[GLOBAL]" ) == 0 ) continue;
467 if( strcasecmp( section, "[OPERATOR]" ) == 0 )
469 if( Conf_Oper_Count + 1 > MAX_OPERATORS ) Config_Error( LOG_ERR, "Too many operators configured." );
472 /* Initialize new operator structure */
473 Conf_Oper[Conf_Oper_Count].name[0] = '\0';
474 Conf_Oper[Conf_Oper_Count].pwd[0] = '\0';
475 if (Conf_Oper[Conf_Oper_Count].mask) {
476 free(Conf_Oper[Conf_Oper_Count].mask );
477 Conf_Oper[Conf_Oper_Count].mask = NULL;
483 if( strcasecmp( section, "[SERVER]" ) == 0 )
485 /* Check if there is already a server to add */
486 if( New_Server.name[0] )
488 /* Copy data to "real" server structure */
489 assert( New_Server_Idx > NONE );
490 Conf_Server[New_Server_Idx] = New_Server;
493 /* Re-init structure for new server */
494 Init_Server_Struct( &New_Server );
496 /* Search unused item in server configuration structure */
497 for( i = 0; i < MAX_SERVERS; i++ )
499 /* Is this item used? */
500 if( ! Conf_Server[i].name[0] ) break;
502 if( i >= MAX_SERVERS )
504 /* Oops, no free item found! */
505 Config_Error( LOG_ERR, "Too many servers configured." );
506 New_Server_Idx = NONE;
508 else New_Server_Idx = i;
511 if( strcasecmp( section, "[CHANNEL]" ) == 0 )
513 if( Conf_Channel_Count + 1 > MAX_DEFCHANNELS ) Config_Error( LOG_ERR, "Too many pre-defined channels configured." );
516 /* Initialize new channel structure */
517 strcpy( Conf_Channel[Conf_Channel_Count].name, "" );
518 strcpy( Conf_Channel[Conf_Channel_Count].modes, "" );
519 strcpy( Conf_Channel[Conf_Channel_Count].topic, "" );
520 Conf_Channel_Count++;
524 Config_Error( LOG_ERR, "%s, line %d: Unknown section \"%s\"!", NGIRCd_ConfFile, line, section );
527 if( section[0] == 0x1 ) continue;
529 /* Split line into variable name and parameters */
530 ptr = strchr( str, '=' );
533 Config_Error( LOG_ERR, "%s, line %d: Syntax error!", NGIRCd_ConfFile, line );
537 var = str; ngt_TrimStr( var );
538 arg = ptr + 1; ngt_TrimStr( arg );
540 if( strcasecmp( section, "[GLOBAL]" ) == 0 ) Handle_GLOBAL( line, var, arg );
541 else if( strcasecmp( section, "[OPERATOR]" ) == 0 ) Handle_OPERATOR( line, var, arg );
542 else if( strcasecmp( section, "[SERVER]" ) == 0 ) Handle_SERVER( line, var, arg );
543 else if( strcasecmp( section, "[CHANNEL]" ) == 0 ) Handle_CHANNEL( line, var, arg );
544 else Config_Error( LOG_ERR, "%s, line %d: Variable \"%s\" outside section!", NGIRCd_ConfFile, line, var );
547 /* Close configuration file */
550 /* Check if there is still a server to add */
551 if( New_Server.name[0] )
553 /* Copy data to "real" server structure */
554 assert( New_Server_Idx > NONE );
555 Conf_Server[New_Server_Idx] = New_Server;
558 /* If there are no ports configured use the default: 6667 */
559 if( Conf_ListenPorts_Count < 1 )
561 Conf_ListenPorts_Count = 1;
562 Conf_ListenPorts[0] = 6667;
568 Check_ArgIsTrue( const char *Arg )
570 if( strcasecmp( Arg, "yes" ) == 0 ) return true;
571 if( strcasecmp( Arg, "true" ) == 0 ) return true;
572 if( atoi( Arg ) != 0 ) return true;
575 } /* Check_ArgIsTrue */
579 Handle_GLOBAL( int Line, char *Var, char *Arg )
587 assert( Var != NULL );
588 assert( Arg != NULL );
590 if( strcasecmp( Var, "Name" ) == 0 )
593 if( strlcpy( Conf_ServerName, Arg, sizeof( Conf_ServerName )) >= sizeof( Conf_ServerName ))
594 Config_Error_TooLong( Line, Var );
598 if( strcasecmp( Var, "Info" ) == 0 )
600 /* Info text of server */
601 if( strlcpy( Conf_ServerInfo, Arg, sizeof( Conf_ServerInfo )) >= sizeof( Conf_ServerInfo ))
602 Config_Error_TooLong ( Line, Var );
606 if( strcasecmp( Var, "Password" ) == 0 )
608 /* Global server password */
609 if( strlcpy( Conf_ServerPwd, Arg, sizeof( Conf_ServerPwd )) >= sizeof( Conf_ServerPwd ))
610 Config_Error_TooLong( Line, Var );
614 if( strcasecmp( Var, "AdminInfo1" ) == 0 )
616 /* Administrative info #1 */
617 if( strlcpy( Conf_ServerAdmin1, Arg, sizeof( Conf_ServerAdmin1 )) >= sizeof( Conf_ServerAdmin1 )) Config_Error_TooLong ( Line, Var );
620 if( strcasecmp( Var, "AdminInfo2" ) == 0 )
622 /* Administrative info #2 */
623 if( strlcpy( Conf_ServerAdmin2, Arg, sizeof( Conf_ServerAdmin2 )) >= sizeof( Conf_ServerAdmin2 )) Config_Error_TooLong ( Line, Var );
626 if( strcasecmp( Var, "AdminEMail" ) == 0 )
628 /* Administrative email contact */
629 if( strlcpy( Conf_ServerAdminMail, Arg, sizeof( Conf_ServerAdminMail )) >= sizeof( Conf_ServerAdminMail )) Config_Error_TooLong( Line, Var );
632 if( strcasecmp( Var, "Ports" ) == 0 )
634 /* Ports on that the server should listen. More port numbers
635 * must be separated by "," */
636 ptr = strtok( Arg, "," );
641 if( Conf_ListenPorts_Count + 1 > MAX_LISTEN_PORTS ) Config_Error( LOG_ERR, "Too many listen ports configured. Port %ld ignored.", port );
644 if( port > 0 && port < 0xFFFF ) Conf_ListenPorts[Conf_ListenPorts_Count++] = (UINT16)port;
645 else Config_Error( LOG_ERR, "%s, line %d (section \"Global\"): Illegal port number %ld!", NGIRCd_ConfFile, Line, port );
647 ptr = strtok( NULL, "," );
651 if( strcasecmp( Var, "MotdFile" ) == 0 )
653 /* "Message of the day" (MOTD) file */
654 if( strlcpy( Conf_MotdFile, Arg, sizeof( Conf_MotdFile )) >= sizeof( Conf_MotdFile ))
655 Config_Error_TooLong( Line, Var );
659 if( strcasecmp( Var, "MotdPhrase" ) == 0 )
661 /* "Message of the day" phrase (instead of file) */
662 if( strlcpy( Conf_MotdPhrase, Arg, sizeof( Conf_MotdPhrase )) >= sizeof( Conf_MotdPhrase ))
663 Config_Error_TooLong( Line, Var );
667 if( strcasecmp( Var, "ChrootDir" ) == 0 )
669 /* directory for chroot() */
670 if( strlcpy( Conf_Chroot, Arg, sizeof( Conf_Chroot )) >= sizeof( Conf_Chroot ))
671 Config_Error_TooLong( Line, Var );
676 if ( strcasecmp( Var, "PidFile" ) == 0 )
678 /* name of pidfile */
679 if( strlcpy( Conf_PidFile, Arg, sizeof( Conf_PidFile )) >= sizeof( Conf_PidFile ))
680 Config_Error_TooLong( Line, Var );
685 if( strcasecmp( Var, "ServerUID" ) == 0 )
687 /* UID the daemon should switch to */
688 pwd = getpwnam( Arg );
689 if( pwd ) Conf_UID = pwd->pw_uid;
693 if( ! isdigit( (int)*Arg )) Config_Error_NaN( Line, Var );
696 Conf_UID = (unsigned int)atoi( Arg );
700 if( strcasecmp( Var, "ServerGID" ) == 0 )
702 /* GID the daemon should use */
703 grp = getgrnam( Arg );
704 if( grp ) Conf_GID = grp->gr_gid;
708 if( ! isdigit( (int)*Arg )) Config_Error_NaN( Line, Var );
711 Conf_GID = (unsigned int)atoi( Arg );
715 if( strcasecmp( Var, "PingTimeout" ) == 0 )
718 Conf_PingTimeout = atoi( Arg );
719 if( Conf_PingTimeout < 5 )
721 Config_Error( LOG_WARNING, "%s, line %d: Value of \"PingTimeout\" too low!", NGIRCd_ConfFile, Line );
722 Conf_PingTimeout = 5;
726 if( strcasecmp( Var, "PongTimeout" ) == 0 )
729 Conf_PongTimeout = atoi( Arg );
730 if( Conf_PongTimeout < 5 )
732 Config_Error( LOG_WARNING, "%s, line %d: Value of \"PongTimeout\" too low!", NGIRCd_ConfFile, Line );
733 Conf_PongTimeout = 5;
737 if( strcasecmp( Var, "ConnectRetry" ) == 0 )
739 /* Seconds between connection attempts to other servers */
740 Conf_ConnectRetry = atoi( Arg );
741 if( Conf_ConnectRetry < 5 )
743 Config_Error( LOG_WARNING, "%s, line %d: Value of \"ConnectRetry\" too low!", NGIRCd_ConfFile, Line );
744 Conf_ConnectRetry = 5;
748 if( strcasecmp( Var, "OperCanUseMode" ) == 0 )
750 /* Are IRC operators allowed to use MODE in channels they aren't Op in? */
751 Conf_OperCanMode = Check_ArgIsTrue( Arg );
754 if( strcasecmp( Var, "OperServerMode" ) == 0 )
756 /* Mask IRC operator as if coming from the server? (ircd-irc2 compat hack) */
757 Conf_OperServerMode = Check_ArgIsTrue( Arg );
760 if( strcasecmp( Var, "MaxConnections" ) == 0 )
762 /* Maximum number of connections. Values <= 0 are equal to "no limit". */
764 if( ! isdigit( (int)*Arg )) Config_Error_NaN( Line, Var);
767 Conf_MaxConnections = atol( Arg );
770 if( strcasecmp( Var, "MaxConnectionsIP" ) == 0 )
772 /* Maximum number of simoultanous connections from one IP. Values <= 0 are equal to "no limit". */
774 if( ! isdigit( (int)*Arg )) Config_Error_NaN( Line, Var );
777 Conf_MaxConnectionsIP = atoi( Arg );
780 if( strcasecmp( Var, "MaxJoins" ) == 0 )
782 /* Maximum number of channels a user can join. Values <= 0 are equal to "no limit". */
784 if( ! isdigit( (int)*Arg )) Config_Error_NaN( Line, Var );
787 Conf_MaxJoins = atoi( Arg );
790 if( strcasecmp( Var, "Listen" ) == 0 )
792 /* IP-Address to bind sockets */
793 if( strlcpy( Conf_ListenAddress, Arg, sizeof( Conf_ListenAddress )) >= sizeof( Conf_ListenAddress ))
795 Config_Error_TooLong( Line, Var );
800 Config_Error( LOG_ERR, "%s, line %d (section \"Global\"): Unknown variable \"%s\"!", NGIRCd_ConfFile, Line, Var );
801 } /* Handle_GLOBAL */
805 Handle_OPERATOR( int Line, char *Var, char *Arg )
808 assert( Var != NULL );
809 assert( Arg != NULL );
810 assert( Conf_Oper_Count > 0 );
812 if( strcasecmp( Var, "Name" ) == 0 )
814 /* Name of IRC operator */
815 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 );
818 if( strcasecmp( Var, "Password" ) == 0 )
820 /* Password of IRC operator */
821 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 );
824 if( strcasecmp( Var, "Mask" ) == 0 )
826 if (Conf_Oper[Conf_Oper_Count - 1].mask) return; /* Hostname already configured */
827 Conf_Oper[Conf_Oper_Count - 1].mask = strdup( Arg );
828 if (! Conf_Oper[Conf_Oper_Count - 1].mask) {
829 Config_Error( LOG_ERR, "%s, line %d: Cannot allocate memory for operator mask: %s", NGIRCd_ConfFile, Line, strerror(errno) );
835 Config_Error( LOG_ERR, "%s, line %d (section \"Operator\"): Unknown variable \"%s\"!", NGIRCd_ConfFile, Line, Var );
836 } /* Handle_OPERATOR */
840 Handle_SERVER( int Line, char *Var, char *Arg )
845 assert( Var != NULL );
846 assert( Arg != NULL );
848 /* Ignore server block if no space is left in server configuration structure */
849 if( New_Server_Idx <= NONE ) return;
851 if( strcasecmp( Var, "Host" ) == 0 )
853 /* Hostname of the server */
854 if( strlcpy( New_Server.host, Arg, sizeof( New_Server.host )) >= sizeof( New_Server.host ))
855 Config_Error_TooLong ( Line, Var );
859 if( strcasecmp( Var, "Name" ) == 0 )
861 /* Name of the server ("Nick"/"ID") */
862 if( strlcpy( New_Server.name, Arg, sizeof( New_Server.name )) >= sizeof( New_Server.name ))
863 Config_Error_TooLong( Line, Var );
866 if( strcasecmp( Var, "MyPassword" ) == 0 )
868 /* Password of this server which is sent to the peer */
869 if( strlcpy( New_Server.pwd_in, Arg, sizeof( New_Server.pwd_in )) >= sizeof( New_Server.pwd_in )) Config_Error_TooLong( Line, Var );
872 if( strcasecmp( Var, "PeerPassword" ) == 0 )
874 /* Passwort of the peer which must be received */
875 if( strlcpy( New_Server.pwd_out, Arg, sizeof( New_Server.pwd_out )) >= sizeof( New_Server.pwd_out )) Config_Error_TooLong( Line, Var );
878 if( strcasecmp( Var, "Port" ) == 0 )
880 /* Port to which this server should connect */
882 if( port > 0 && port < 0xFFFF ) New_Server.port = (UINT16)port;
883 else Config_Error( LOG_ERR, "%s, line %d (section \"Server\"): Illegal port number %ld!", NGIRCd_ConfFile, Line, port );
886 if( strcasecmp( Var, "Group" ) == 0 )
890 if( ! isdigit( (int)*Arg )) Config_Error_NaN( Line, Var );
893 New_Server.group = atoi( Arg );
897 Config_Error( LOG_ERR, "%s, line %d (section \"Server\"): Unknown variable \"%s\"!", NGIRCd_ConfFile, Line, Var );
898 } /* Handle_SERVER */
902 Handle_CHANNEL( int Line, char *Var, char *Arg )
905 assert( Var != NULL );
906 assert( Arg != NULL );
908 if( strcasecmp( Var, "Name" ) == 0 )
910 /* Name of the channel */
911 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 ))
912 Config_Error_TooLong( Line, Var );
915 if( strcasecmp( Var, "Modes" ) == 0 )
918 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 ))
919 Config_Error_TooLong( Line, Var );
922 if( strcasecmp( Var, "Topic" ) == 0 )
925 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 ))
926 Config_Error_TooLong( Line, Var );
931 Config_Error( LOG_ERR, "%s, line %d (section \"Channel\"): Unknown variable \"%s\"!", NGIRCd_ConfFile, Line, Var );
932 } /* Handle_CHANNEL */
936 Validate_Config( bool Configtest )
938 /* Validate configuration settings. */
941 int i, servers, servers_once;
944 if( ! Conf_ServerName[0] )
946 /* No server name configured! */
947 Config_Error( LOG_ALERT, "No server name configured in \"%s\" (section 'Global': 'Name')!", NGIRCd_ConfFile );
950 Config_Error( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME );
955 if( Conf_ServerName[0] && ! strchr( Conf_ServerName, '.' ))
957 /* No dot in server name! */
958 Config_Error( LOG_ALERT, "Invalid server name configured in \"%s\" (section 'Global': 'Name'): Dot missing!", NGIRCd_ConfFile );
961 Config_Error( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME );
967 if( ! Conf_ServerAdminMail[0] )
969 /* No administrative contact configured! */
970 Config_Error( LOG_ALERT, "No administrator email address configured in \"%s\" ('AdminEMail')!", NGIRCd_ConfFile );
973 Config_Error( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME );
979 if( ! Conf_ServerAdmin1[0] && ! Conf_ServerAdmin2[0] && ! Conf_ServerAdminMail[0] )
981 /* No administrative information configured! */
982 Config_Error( LOG_WARNING, "No administrative information configured but required by RFC!" );
985 if(( Conf_MaxConnections > (long)FD_SETSIZE ) || ( Conf_MaxConnections < 1 ))
987 Conf_MaxConnections = (long)FD_SETSIZE;
988 Config_Error( LOG_ERR, "Setting MaxConnections to %ld, select() can't handle more file descriptors!", Conf_MaxConnections );
991 Config_Error( LOG_WARN, "Don't know how many file descriptors select() can handle on this system, don't set MaxConnections too high!" );
995 servers = servers_once = 0;
996 for( i = 0; i < MAX_SERVERS; i++ )
998 if( Conf_Server[i].name[0] )
1001 if( Conf_Server[i].flags & CONF_SFLAG_ONCE ) servers_once++;
1004 Log( LOG_DEBUG, "Configuration: Operators=%d, Servers=%d[%d], Channels=%d", Conf_Oper_Count, servers, servers_once, Conf_Channel_Count );
1006 } /* Validate_Config */
1010 Config_Error_TooLong ( const int Line, const char *Item )
1012 Config_Error( LOG_WARNING, "%s, line %d: Value of \"%s\" too long!", NGIRCd_ConfFile, Line, Item );
1016 Config_Error_NaN( const int Line, const char *Item )
1018 Config_Error( LOG_WARNING, "%s, line %d: Value of \"%s\" is not a number!", NGIRCd_ConfFile, Line, Item );
1022 LOCAL void Config_Error( const int Level, const char *Format, ... )
1024 LOCAL void Config_Error( Level, Format, va_alist )
1030 /* Error! Write to console and/or logfile. */
1032 char msg[MAX_LOG_MSG_LEN];
1035 assert( Format != NULL );
1038 va_start( ap, Format );
1042 vsnprintf( msg, MAX_LOG_MSG_LEN, Format, ap );
1045 /* During "normal operations" the log functions of the daemon should
1046 * be used, but during testing of the configuration file, all messages
1047 * should go directly to the console: */
1048 if( Use_Log ) Log( Level, "%s", msg );
1050 } /* Config_Error */
1054 Init_Server_Struct( CONF_SERVER *Server )
1056 /* Initialize server configuration structur to default values */
1058 assert( Server != NULL );
1060 memset( Server, 0, sizeof (CONF_SERVER) );
1062 Server->group = NONE;
1063 Server->lasttry = time( NULL ) - Conf_ConnectRetry + STARTUP_DELAY;
1065 if( NGIRCd_Passive ) Server->flags = CONF_SFLAG_DISABLED;
1067 Server->conn_id = NONE;
1068 } /* Init_Server_Struct */