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.69 2005/03/02 16:07:31 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( " PidFile = %s\n", Conf_PidFile);
127 printf( " Ports = " );
128 for( i = 0; i < Conf_ListenPorts_Count; i++ )
130 if( i != 0 ) printf( ", " );
131 printf( "%u", Conf_ListenPorts[i] );
134 printf( " Listen = %s\n", Conf_ListenAddress );
135 pwd = getpwuid( Conf_UID );
136 if( pwd ) printf( " ServerUID = %s\n", pwd->pw_name );
137 else printf( " ServerUID = %ld\n", (LONG)Conf_UID );
138 grp = getgrgid( Conf_GID );
139 if( grp ) printf( " ServerGID = %s\n", grp->gr_name );
140 else printf( " ServerGID = %ld\n", (LONG)Conf_GID );
141 printf( " PingTimeout = %d\n", Conf_PingTimeout );
142 printf( " PongTimeout = %d\n", Conf_PongTimeout );
143 printf( " ConnectRetry = %d\n", Conf_ConnectRetry );
144 printf( " OperCanUseMode = %s\n", Conf_OperCanMode == TRUE ? "yes" : "no" );
145 if( Conf_MaxConnections > 0 ) printf( " MaxConnections = %ld\n", Conf_MaxConnections );
146 else printf( " MaxConnections = -1\n" );
147 if( Conf_MaxConnectionsIP > 0 ) printf( " MaxConnectionsIP = %d\n", Conf_MaxConnectionsIP );
148 else printf( " MaxConnectionsIP = -1\n" );
149 if( Conf_MaxJoins > 0 ) printf( " MaxJoins = %d\n", Conf_MaxJoins );
150 else printf( " MaxJoins = -1\n" );
153 for( i = 0; i < Conf_Oper_Count; i++ )
155 if( ! Conf_Oper[i].name[0] ) continue;
157 /* Valid "Operator" section */
158 puts( "[OPERATOR]" );
159 printf( " Name = %s\n", Conf_Oper[i].name );
160 printf( " Password = %s\n", Conf_Oper[i].pwd );
161 if ( Conf_Oper[i].mask ) printf( " Mask = %s\n", Conf_Oper[i].mask );
165 for( i = 0; i < MAX_SERVERS; i++ )
167 if( ! Conf_Server[i].name[0] ) continue;
169 /* Valid "Server" section */
171 printf( " Name = %s\n", Conf_Server[i].name );
172 printf( " Host = %s\n", Conf_Server[i].host );
173 printf( " Port = %d\n", Conf_Server[i].port );
174 printf( " MyPassword = %s\n", Conf_Server[i].pwd_in );
175 printf( " PeerPassword = %s\n", Conf_Server[i].pwd_out );
176 printf( " Group = %d\n", Conf_Server[i].group );
180 for( i = 0; i < Conf_Channel_Count; i++ )
182 if( ! Conf_Channel[i].name[0] ) continue;
184 /* Valid "Channel" section */
186 printf( " Name = %s\n", Conf_Channel[i].name );
187 printf( " Modes = %s\n", Conf_Channel[i].modes );
188 printf( " Topic = %s\n", Conf_Channel[i].topic );
197 Conf_UnsetServer( CONN_ID Idx )
199 /* Set next time for next connection attempt, if this is a server
200 * link that is (still) configured here. If the server is set as
201 * "once", delete it from our configuration.
202 * Non-Server-Connections will be silently ignored. */
206 /* Check all our configured servers */
207 for( i = 0; i < MAX_SERVERS; i++ )
209 if( Conf_Server[i].conn_id != Idx ) continue;
211 /* Gotcha! Mark server configuration as "unused": */
212 Conf_Server[i].conn_id = NONE;
214 if( Conf_Server[i].flags & CONF_SFLAG_ONCE )
216 /* Delete configuration here */
217 Init_Server_Struct( &Conf_Server[i] );
221 /* Set time for next connect attempt */
222 if( Conf_Server[i].lasttry < time( NULL ) - Conf_ConnectRetry )
224 /* Okay, the connection was established "long enough": */
225 Conf_Server[i].lasttry = time( NULL ) - Conf_ConnectRetry + RECONNECT_DELAY;
229 } /* Conf_UnsetServer */
233 Conf_SetServer( INT ConfServer, CONN_ID Idx )
235 /* Set connection for specified configured server */
237 assert( ConfServer > NONE );
238 assert( Idx > NONE );
240 Conf_Server[ConfServer].conn_id = Idx;
241 } /* Conf_SetServer */
245 Conf_GetServer( CONN_ID Idx )
247 /* Get index of server in configuration structure */
251 assert( Idx > NONE );
253 for( i = 0; i < MAX_SERVERS; i++ )
255 if( Conf_Server[i].conn_id == Idx ) return i;
258 } /* Conf_GetServer */
262 Conf_EnableServer( CHAR *Name, INT Port )
264 /* Enable specified server and adjust port */
268 assert( Name != NULL );
270 for( i = 0; i < MAX_SERVERS; i++ )
272 if( strcasecmp( Conf_Server[i].name, Name ) == 0 )
274 /* Gotcha! Set port and enable server: */
275 Conf_Server[i].port = Port;
276 Conf_Server[i].flags &= ~CONF_SFLAG_DISABLED;
281 } /* Conf_EnableServer */
285 Conf_DisableServer( CHAR *Name )
287 /* Enable specified server and adjust port */
291 assert( Name != NULL );
293 for( i = 0; i < MAX_SERVERS; i++ )
295 if( strcasecmp( Conf_Server[i].name, Name ) == 0 )
297 /* Gotcha! Disable and disconnect server: */
298 Conf_Server[i].flags |= CONF_SFLAG_DISABLED;
299 if( Conf_Server[i].conn_id > NONE ) Conn_Close( Conf_Server[i].conn_id, NULL, "Server link terminated on operator request", TRUE );
304 } /* Conf_DisableServer */
308 Conf_AddServer( CHAR *Name, INT Port, CHAR *Host, CHAR *MyPwd, CHAR *PeerPwd )
310 /* Add new server to configuration */
314 assert( Name != NULL );
315 assert( Host != NULL );
316 assert( MyPwd != NULL );
317 assert( PeerPwd != NULL );
319 /* Search unused item in server configuration structure */
320 for( i = 0; i < MAX_SERVERS; i++ )
322 /* Is this item used? */
323 if( ! Conf_Server[i].name[0] ) break;
325 if( i >= MAX_SERVERS ) return FALSE;
327 Init_Server_Struct( &Conf_Server[i] );
328 strlcpy( Conf_Server[i].name, Name, sizeof( Conf_Server[i].name ));
329 strlcpy( Conf_Server[i].host, Host, sizeof( Conf_Server[i].host ));
330 strlcpy( Conf_Server[i].pwd_out, MyPwd, sizeof( Conf_Server[i].pwd_out ));
331 strlcpy( Conf_Server[i].pwd_in, PeerPwd, sizeof( Conf_Server[i].pwd_in ));
332 Conf_Server[i].port = Port;
333 Conf_Server[i].flags = CONF_SFLAG_ONCE;
336 } /* Conf_AddServer */
340 Set_Defaults( BOOLEAN InitServers )
342 /* Initialize configuration variables with default values. */
346 strcpy( Conf_ServerName, "" );
347 sprintf( Conf_ServerInfo, "%s %s", PACKAGE_NAME, PACKAGE_VERSION );
348 strcpy( Conf_ServerPwd, "" );
350 strcpy( Conf_ServerAdmin1, "" );
351 strcpy( Conf_ServerAdmin2, "" );
352 strcpy( Conf_ServerAdminMail, "" );
354 strlcpy( Conf_MotdFile, SYSCONFDIR, sizeof( Conf_MotdFile ));
355 strlcat( Conf_MotdFile, MOTD_FILE, sizeof( Conf_MotdFile ));
357 strlcpy( Conf_MotdPhrase, MOTD_PHRASE, sizeof( Conf_MotdPhrase ));
359 strlcpy( Conf_Chroot, CHROOT_DIR, sizeof( Conf_Chroot ));
361 strlcpy( Conf_PidFile, PID_FILE, sizeof( Conf_PidFile ));
363 Conf_ListenPorts_Count = 0;
364 strcpy( Conf_ListenAddress, "" );
366 Conf_UID = Conf_GID = 0;
368 Conf_PingTimeout = 120;
369 Conf_PongTimeout = 20;
371 Conf_ConnectRetry = 60;
374 Conf_Channel_Count = 0;
376 Conf_OperCanMode = FALSE;
378 Conf_MaxConnections = -1;
379 Conf_MaxConnectionsIP = 5;
382 /* Initialize server configuration structures */
383 if( InitServers ) for( i = 0; i < MAX_SERVERS; Init_Server_Struct( &Conf_Server[i++] ));
390 /* Read configuration file. */
392 CHAR section[LINE_LEN], str[LINE_LEN], *var, *arg, *ptr;
396 /* Open configuration file */
397 fd = fopen( NGIRCd_ConfFile, "r" );
400 /* No configuration file found! */
401 Config_Error( LOG_ALERT, "Can't read configuration \"%s\": %s", NGIRCd_ConfFile, strerror( errno ));
402 Config_Error( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME );
406 Config_Error( LOG_INFO, "Reading configuration from \"%s\" ...", NGIRCd_ConfFile );
408 /* Clean up server configuration structure: mark all already
409 * configured servers as "once" so that they are deleted
410 * after the next disconnect and delete all unused servers.
411 * And delete all servers which are "duplicates" of servers
412 * that are already marked as "once" (such servers have been
413 * created by the last rehash but are now useless). */
414 for( i = 0; i < MAX_SERVERS; i++ )
416 if( Conf_Server[i].conn_id == NONE ) Init_Server_Struct( &Conf_Server[i] );
419 /* This structure is in use ... */
420 if( Conf_Server[i].flags & CONF_SFLAG_ONCE )
422 /* Check for duplicates */
423 for( n = 0; n < MAX_SERVERS; n++ )
425 if( n == i ) continue;
427 if( Conf_Server[i].conn_id == Conf_Server[n].conn_id )
429 Init_Server_Struct( &Conf_Server[n] );
430 Log( LOG_DEBUG, "Deleted unused duplicate server %d (kept %d).", n, i );
436 /* Mark server as "once" */
437 Conf_Server[i].flags |= CONF_SFLAG_ONCE;
438 Log( LOG_DEBUG, "Marked server %d as \"once\"", i );
443 /* Initialize variables */
445 strcpy( section, "" );
446 Init_Server_Struct( &New_Server );
447 New_Server_Idx = NONE;
449 /* Read configuration file */
452 if( ! fgets( str, LINE_LEN, fd )) break;
456 /* Skip comments and empty lines */
457 if( str[0] == ';' || str[0] == '#' || str[0] == '\0' ) continue;
459 /* Is this the beginning of a new section? */
460 if(( str[0] == '[' ) && ( str[strlen( str ) - 1] == ']' ))
462 strlcpy( section, str, sizeof( section ));
463 if( strcasecmp( section, "[GLOBAL]" ) == 0 ) continue;
464 if( strcasecmp( section, "[OPERATOR]" ) == 0 )
466 if( Conf_Oper_Count + 1 > MAX_OPERATORS ) Config_Error( LOG_ERR, "Too many operators configured." );
469 /* Initialize new operator structure */
470 Conf_Oper[Conf_Oper_Count].name[0] = '\0';
471 Conf_Oper[Conf_Oper_Count].pwd[0] = '\0';
472 if (Conf_Oper[Conf_Oper_Count].mask) {
473 free(Conf_Oper[Conf_Oper_Count].mask );
474 Conf_Oper[Conf_Oper_Count].mask = NULL;
480 if( strcasecmp( section, "[SERVER]" ) == 0 )
482 /* Check if there is already a server to add */
483 if( New_Server.name[0] )
485 /* Copy data to "real" server structure */
486 assert( New_Server_Idx > NONE );
487 Conf_Server[New_Server_Idx] = New_Server;
490 /* Re-init structure for new server */
491 Init_Server_Struct( &New_Server );
493 /* Search unused item in server configuration structure */
494 for( i = 0; i < MAX_SERVERS; i++ )
496 /* Is this item used? */
497 if( ! Conf_Server[i].name[0] ) break;
499 if( i >= MAX_SERVERS )
501 /* Oops, no free item found! */
502 Config_Error( LOG_ERR, "Too many servers configured." );
503 New_Server_Idx = NONE;
505 else New_Server_Idx = i;
508 if( strcasecmp( section, "[CHANNEL]" ) == 0 )
510 if( Conf_Channel_Count + 1 > MAX_DEFCHANNELS ) Config_Error( LOG_ERR, "Too many pre-defined channels configured." );
513 /* Initialize new channel structure */
514 strcpy( Conf_Channel[Conf_Channel_Count].name, "" );
515 strcpy( Conf_Channel[Conf_Channel_Count].modes, "" );
516 strcpy( Conf_Channel[Conf_Channel_Count].topic, "" );
517 Conf_Channel_Count++;
521 Config_Error( LOG_ERR, "%s, line %d: Unknown section \"%s\"!", NGIRCd_ConfFile, line, section );
524 if( section[0] == 0x1 ) continue;
526 /* Split line into variable name and parameters */
527 ptr = strchr( str, '=' );
530 Config_Error( LOG_ERR, "%s, line %d: Syntax error!", NGIRCd_ConfFile, line );
534 var = str; ngt_TrimStr( var );
535 arg = ptr + 1; ngt_TrimStr( arg );
537 if( strcasecmp( section, "[GLOBAL]" ) == 0 ) Handle_GLOBAL( line, var, arg );
538 else if( strcasecmp( section, "[OPERATOR]" ) == 0 ) Handle_OPERATOR( line, var, arg );
539 else if( strcasecmp( section, "[SERVER]" ) == 0 ) Handle_SERVER( line, var, arg );
540 else if( strcasecmp( section, "[CHANNEL]" ) == 0 ) Handle_CHANNEL( line, var, arg );
541 else Config_Error( LOG_ERR, "%s, line %d: Variable \"%s\" outside section!", NGIRCd_ConfFile, line, var );
544 /* Close configuration file */
547 /* Check if there is still a server to add */
548 if( New_Server.name[0] )
550 /* Copy data to "real" server structure */
551 assert( New_Server_Idx > NONE );
552 Conf_Server[New_Server_Idx] = New_Server;
555 /* If there are no ports configured use the default: 6667 */
556 if( Conf_ListenPorts_Count < 1 )
558 Conf_ListenPorts_Count = 1;
559 Conf_ListenPorts[0] = 6667;
565 Handle_GLOBAL( INT Line, CHAR *Var, CHAR *Arg )
573 assert( Var != NULL );
574 assert( Arg != NULL );
576 if( strcasecmp( Var, "Name" ) == 0 )
579 if( strlcpy( Conf_ServerName, Arg, sizeof( Conf_ServerName )) >= sizeof( Conf_ServerName ))
580 Config_Error_TooLong( Line, Var );
584 if( strcasecmp( Var, "Info" ) == 0 )
586 /* Info text of server */
587 if( strlcpy( Conf_ServerInfo, Arg, sizeof( Conf_ServerInfo )) >= sizeof( Conf_ServerInfo ))
588 Config_Error_TooLong ( Line, Var );
592 if( strcasecmp( Var, "Password" ) == 0 )
594 /* Global server password */
595 if( strlcpy( Conf_ServerPwd, Arg, sizeof( Conf_ServerPwd )) >= sizeof( Conf_ServerPwd ))
596 Config_Error_TooLong( Line, Var );
600 if( strcasecmp( Var, "AdminInfo1" ) == 0 )
602 /* Administrative info #1 */
603 if( strlcpy( Conf_ServerAdmin1, Arg, sizeof( Conf_ServerAdmin1 )) >= sizeof( Conf_ServerAdmin1 )) Config_Error_TooLong ( Line, Var );
606 if( strcasecmp( Var, "AdminInfo2" ) == 0 )
608 /* Administrative info #2 */
609 if( strlcpy( Conf_ServerAdmin2, Arg, sizeof( Conf_ServerAdmin2 )) >= sizeof( Conf_ServerAdmin2 )) Config_Error_TooLong ( Line, Var );
612 if( strcasecmp( Var, "AdminEMail" ) == 0 )
614 /* Administrative email contact */
615 if( strlcpy( Conf_ServerAdminMail, Arg, sizeof( Conf_ServerAdminMail )) >= sizeof( Conf_ServerAdminMail )) Config_Error_TooLong( Line, Var );
618 if( strcasecmp( Var, "Ports" ) == 0 )
620 /* Ports on that the server should listen. More port numbers
621 * must be separated by "," */
622 ptr = strtok( Arg, "," );
627 if( Conf_ListenPorts_Count + 1 > MAX_LISTEN_PORTS ) Config_Error( LOG_ERR, "Too many listen ports configured. Port %ld ignored.", port );
630 if( port > 0 && port < 0xFFFF ) Conf_ListenPorts[Conf_ListenPorts_Count++] = (UINT)port;
631 else Config_Error( LOG_ERR, "%s, line %d (section \"Global\"): Illegal port number %ld!", NGIRCd_ConfFile, Line, port );
633 ptr = strtok( NULL, "," );
637 if( strcasecmp( Var, "MotdFile" ) == 0 )
639 /* "Message of the day" (MOTD) file */
640 if( strlcpy( Conf_MotdFile, Arg, sizeof( Conf_MotdFile )) >= sizeof( Conf_MotdFile ))
641 Config_Error_TooLong( Line, Var );
645 if( strcasecmp( Var, "MotdPhrase" ) == 0 )
647 /* "Message of the day" phrase (instead of file) */
648 if( strlcpy( Conf_MotdPhrase, Arg, sizeof( Conf_MotdPhrase )) >= sizeof( Conf_MotdPhrase ))
649 Config_Error_TooLong( Line, Var );
653 if( strcasecmp( Var, "ChrootDir" ) == 0 )
655 /* directory for chroot() */
656 if( strlcpy( Conf_Chroot, Arg, sizeof( Conf_Chroot )) >= sizeof( Conf_Chroot ))
657 Config_Error_TooLong( Line, Var );
662 if ( strcasecmp( Var, "PidFile" ) == 0 )
664 /* name of pidfile */
665 if( strlcpy( Conf_PidFile, Arg, sizeof( Conf_PidFile )) >= sizeof( Conf_PidFile ))
666 Config_Error_TooLong( Line, Var );
671 if( strcasecmp( Var, "ServerUID" ) == 0 )
673 /* UID the daemon should switch to */
674 pwd = getpwnam( Arg );
675 if( pwd ) Conf_UID = pwd->pw_uid;
679 if( ! isdigit( (INT)*Arg )) Config_Error_NaN( Line, Var );
682 Conf_UID = (UINT)atoi( Arg );
686 if( strcasecmp( Var, "ServerGID" ) == 0 )
688 /* GID the daemon should use */
689 grp = getgrnam( Arg );
690 if( grp ) Conf_GID = grp->gr_gid;
694 if( ! isdigit( (INT)*Arg )) Config_Error_NaN( Line, Var );
697 Conf_GID = (UINT)atoi( Arg );
701 if( strcasecmp( Var, "PingTimeout" ) == 0 )
704 Conf_PingTimeout = atoi( Arg );
705 if( Conf_PingTimeout < 5 )
707 Config_Error( LOG_WARNING, "%s, line %d: Value of \"PingTimeout\" too low!", NGIRCd_ConfFile, Line );
708 Conf_PingTimeout = 5;
712 if( strcasecmp( Var, "PongTimeout" ) == 0 )
715 Conf_PongTimeout = atoi( Arg );
716 if( Conf_PongTimeout < 5 )
718 Config_Error( LOG_WARNING, "%s, line %d: Value of \"PongTimeout\" too low!", NGIRCd_ConfFile, Line );
719 Conf_PongTimeout = 5;
723 if( strcasecmp( Var, "ConnectRetry" ) == 0 )
725 /* Seconds between connection attempts to other servers */
726 Conf_ConnectRetry = atoi( Arg );
727 if( Conf_ConnectRetry < 5 )
729 Config_Error( LOG_WARNING, "%s, line %d: Value of \"ConnectRetry\" too low!", NGIRCd_ConfFile, Line );
730 Conf_ConnectRetry = 5;
734 if( strcasecmp( Var, "OperCanUseMode" ) == 0 )
736 /* Are IRC operators allowed to use MODE in channels they aren't Op in? */
737 if( strcasecmp( Arg, "yes" ) == 0 ) Conf_OperCanMode = TRUE;
738 else if( strcasecmp( Arg, "true" ) == 0 ) Conf_OperCanMode = TRUE;
739 else if( atoi( Arg ) != 0 ) Conf_OperCanMode = TRUE;
740 else Conf_OperCanMode = FALSE;
743 if( strcasecmp( Var, "MaxConnections" ) == 0 )
745 /* Maximum number of connections. Values <= 0 are equal to "no limit". */
747 if( ! isdigit( (INT)*Arg )) Config_Error_NaN( Line, Var);
750 Conf_MaxConnections = atol( Arg );
753 if( strcasecmp( Var, "MaxConnectionsIP" ) == 0 )
755 /* Maximum number of simoultanous connections from one IP. Values <= 0 are equal to "no limit". */
757 if( ! isdigit( (INT)*Arg )) Config_Error_NaN( Line, Var );
760 Conf_MaxConnectionsIP = atoi( Arg );
763 if( strcasecmp( Var, "MaxJoins" ) == 0 )
765 /* Maximum number of channels a user can join. Values <= 0 are equal to "no limit". */
767 if( ! isdigit( (INT)*Arg )) Config_Error_NaN( Line, Var );
770 Conf_MaxJoins = atoi( Arg );
773 if( strcasecmp( Var, "Listen" ) == 0 )
775 /* IP-Address to bind sockets */
776 if( strlcpy( Conf_ListenAddress, Arg, sizeof( Conf_ListenAddress )) >= sizeof( Conf_ListenAddress ))
778 Config_Error_TooLong( Line, Var );
783 Config_Error( LOG_ERR, "%s, line %d (section \"Global\"): Unknown variable \"%s\"!", NGIRCd_ConfFile, Line, Var );
784 } /* Handle_GLOBAL */
788 Handle_OPERATOR( INT Line, CHAR *Var, CHAR *Arg )
792 assert( Var != NULL );
793 assert( Arg != NULL );
794 assert( Conf_Oper_Count > 0 );
796 if( strcasecmp( Var, "Name" ) == 0 )
798 /* Name of IRC operator */
799 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 );
802 if( strcasecmp( Var, "Password" ) == 0 )
804 /* Password of IRC operator */
805 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 );
808 if( strcasecmp( Var, "Mask" ) == 0 )
810 if (Conf_Oper[Conf_Oper_Count - 1].mask) return; /* Hostname already configured */
811 len = strlen( Arg ) + 1;
812 Conf_Oper[Conf_Oper_Count - 1].mask = malloc( len );
813 if (! Conf_Oper[Conf_Oper_Count - 1].mask) {
814 Config_Error( LOG_ERR, "%s, line %d: Cannot allocate memory for operator mask: %s", NGIRCd_ConfFile, Line, strerror(errno) );
818 strlcpy( Conf_Oper[Conf_Oper_Count - 1].mask, Arg, len);
821 Config_Error( LOG_ERR, "%s, line %d (section \"Operator\"): Unknown variable \"%s\"!", NGIRCd_ConfFile, Line, Var );
822 } /* Handle_OPERATOR */
826 Handle_SERVER( INT Line, CHAR *Var, CHAR *Arg )
831 assert( Var != NULL );
832 assert( Arg != NULL );
834 /* Ignore server block if no space is left in server configuration structure */
835 if( New_Server_Idx <= NONE ) return;
837 if( strcasecmp( Var, "Host" ) == 0 )
839 /* Hostname of the server */
840 if( strlcpy( New_Server.host, Arg, sizeof( New_Server.host )) >= sizeof( New_Server.host ))
841 Config_Error_TooLong ( Line, Var );
845 if( strcasecmp( Var, "Name" ) == 0 )
847 /* Name of the server ("Nick"/"ID") */
848 if( strlcpy( New_Server.name, Arg, sizeof( New_Server.name )) >= sizeof( New_Server.name ))
849 Config_Error_TooLong( Line, Var );
852 if( strcasecmp( Var, "MyPassword" ) == 0 )
854 /* Password of this server which is sent to the peer */
855 if( strlcpy( New_Server.pwd_in, Arg, sizeof( New_Server.pwd_in )) >= sizeof( New_Server.pwd_in )) Config_Error_TooLong( Line, Var );
858 if( strcasecmp( Var, "PeerPassword" ) == 0 )
860 /* Passwort of the peer which must be received */
861 if( strlcpy( New_Server.pwd_out, Arg, sizeof( New_Server.pwd_out )) >= sizeof( New_Server.pwd_out )) Config_Error_TooLong( Line, Var );
864 if( strcasecmp( Var, "Port" ) == 0 )
866 /* Port to which this server should connect */
868 if( port > 0 && port < 0xFFFF ) New_Server.port = (INT)port;
869 else Config_Error( LOG_ERR, "%s, line %d (section \"Server\"): Illegal port number %ld!", NGIRCd_ConfFile, Line, port );
872 if( strcasecmp( Var, "Group" ) == 0 )
876 if( ! isdigit( (INT)*Arg )) Config_Error_NaN( Line, Var );
879 New_Server.group = atoi( Arg );
883 Config_Error( LOG_ERR, "%s, line %d (section \"Server\"): Unknown variable \"%s\"!", NGIRCd_ConfFile, Line, Var );
884 } /* Handle_SERVER */
888 Handle_CHANNEL( INT Line, CHAR *Var, CHAR *Arg )
891 assert( Var != NULL );
892 assert( Arg != NULL );
894 if( strcasecmp( Var, "Name" ) == 0 )
896 /* Name of the channel */
897 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 ))
898 Config_Error_TooLong( Line, Var );
901 if( strcasecmp( Var, "Modes" ) == 0 )
904 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 ))
905 Config_Error_TooLong( Line, Var );
908 if( strcasecmp( Var, "Topic" ) == 0 )
911 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 ))
912 Config_Error_TooLong( Line, Var );
917 Config_Error( LOG_ERR, "%s, line %d (section \"Channel\"): Unknown variable \"%s\"!", NGIRCd_ConfFile, Line, Var );
918 } /* Handle_CHANNEL */
922 Validate_Config( BOOLEAN Configtest )
924 /* Validate configuration settings. */
927 INT i, servers, servers_once;
930 if( ! Conf_ServerName[0] )
932 /* No server name configured! */
933 Config_Error( LOG_ALERT, "No server name configured in \"%s\" (section 'Global': 'Name')!", NGIRCd_ConfFile );
936 Config_Error( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME );
941 if( Conf_ServerName[0] && ! strchr( Conf_ServerName, '.' ))
943 /* No dot in server name! */
944 Config_Error( LOG_ALERT, "Invalid server name configured in \"%s\" (section 'Global': 'Name'): Dot missing!", NGIRCd_ConfFile );
947 Config_Error( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME );
953 if( ! Conf_ServerAdminMail[0] )
955 /* No administrative contact configured! */
956 Config_Error( LOG_ALERT, "No administrator email address configured in \"%s\" ('AdminEMail')!", NGIRCd_ConfFile );
959 Config_Error( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME );
965 if( ! Conf_ServerAdmin1[0] && ! Conf_ServerAdmin2[0] && ! Conf_ServerAdminMail[0] )
967 /* No administrative information configured! */
968 Config_Error( LOG_WARNING, "No administrative information configured but required by RFC!" );
971 if(( Conf_MaxConnections > (LONG)FD_SETSIZE ) || ( Conf_MaxConnections < 1 ))
973 Conf_MaxConnections = (LONG)FD_SETSIZE;
974 Config_Error( LOG_ERR, "Setting MaxConnections to %ld, select() can't handle more file descriptors!", Conf_MaxConnections );
977 Config_Error( LOG_WARN, "Don't know how many file descriptors select() can handle on this system, don't set MaxConnections too high!" );
981 servers = servers_once = 0;
982 for( i = 0; i < MAX_SERVERS; i++ )
984 if( Conf_Server[i].name[0] )
987 if( Conf_Server[i].flags & CONF_SFLAG_ONCE ) servers_once++;
990 Log( LOG_DEBUG, "Configuration: Operators=%d, Servers=%d[%d], Channels=%d", Conf_Oper_Count, servers, servers_once, Conf_Channel_Count );
992 } /* Validate_Config */
996 Config_Error_TooLong ( CONST INT Line, CONST CHAR *Item )
998 Config_Error( LOG_WARNING, "%s, line %d: Value of \"%s\" too long!", NGIRCd_ConfFile, Line, Item );
1002 Config_Error_NaN( CONST INT Line, CONST CHAR *Item )
1004 Config_Error( LOG_WARNING, "%s, line %d: Value of \"%s\" is not a number!", NGIRCd_ConfFile, Line, Item );
1008 LOCAL VOID Config_Error( CONST INT Level, CONST CHAR *Format, ... )
1010 LOCAL VOID Config_Error( Level, Format, va_alist )
1016 /* Error! Write to console and/or logfile. */
1018 CHAR msg[MAX_LOG_MSG_LEN];
1021 assert( Format != NULL );
1024 va_start( ap, Format );
1028 vsnprintf( msg, MAX_LOG_MSG_LEN, Format, ap );
1031 /* During "normal operations" the log functions of the daemon should
1032 * be used, but during testing of the configuration file, all messages
1033 * should go directly to the console: */
1034 if( Use_Log ) Log( Level, "%s", msg );
1036 } /* Config_Error */
1040 Init_Server_Struct( CONF_SERVER *Server )
1042 /* Initialize server configuration structur to default values */
1044 assert( Server != NULL );
1046 memset( Server, 0, sizeof (CONF_SERVER) );
1048 Server->group = NONE;
1049 Server->lasttry = time( NULL ) - Conf_ConnectRetry + STARTUP_DELAY;
1051 if( NGIRCd_Passive ) Server->flags = CONF_SFLAG_DISABLED;
1053 Server->conn_id = NONE;
1054 } /* Init_Server_Struct */