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.62 2003/12/19 14:32:59 alex Exp $";
29 #include <sys/types.h>
48 LOCAL BOOLEAN Use_Log = TRUE;
49 LOCAL CONF_SERVER New_Server;
50 LOCAL INT New_Server_Idx;
53 LOCAL VOID Set_Defaults PARAMS(( BOOLEAN InitServers ));
54 LOCAL VOID Read_Config PARAMS(( VOID ));
55 LOCAL VOID Validate_Config PARAMS(( BOOLEAN TestOnly ));
57 LOCAL VOID Handle_GLOBAL PARAMS(( INT Line, CHAR *Var, CHAR *Arg ));
58 LOCAL VOID Handle_OPERATOR PARAMS(( INT Line, CHAR *Var, CHAR *Arg ));
59 LOCAL VOID Handle_SERVER PARAMS(( INT Line, CHAR *Var, CHAR *Arg ));
60 LOCAL VOID Handle_CHANNEL PARAMS(( INT Line, CHAR *Var, CHAR *Arg ));
62 LOCAL VOID Config_Error PARAMS(( CONST INT Level, CONST CHAR *Format, ... ));
64 LOCAL VOID Init_Server_Struct PARAMS(( CONF_SERVER *Server ));
72 Validate_Config( FALSE );
79 Set_Defaults( FALSE );
81 Validate_Config( FALSE );
88 /* Read configuration, validate and output it. */
98 Validate_Config( TRUE );
100 /* If stdin is a valid tty wait for a key: */
101 if( isatty( fileno( stdout )))
103 puts( "OK, press enter to see a dump of your service configuration ..." );
106 else puts( "Ok, dump of your server configuration follows:\n" );
109 printf( " ServerName = %s\n", Conf_ServerName );
110 printf( " ServerInfo = %s\n", Conf_ServerInfo );
111 printf( " Password = %s\n", Conf_ServerPwd );
112 printf( " AdminInfo1 = %s\n", Conf_ServerAdmin1 );
113 printf( " AdminInfo2 = %s\n", Conf_ServerAdmin2 );
114 printf( " AdminEMail = %s\n", Conf_ServerAdminMail );
115 printf( " MotdFile = %s\n", Conf_MotdFile );
116 printf( " Ports = " );
117 for( i = 0; i < Conf_ListenPorts_Count; i++ )
119 if( i != 0 ) printf( ", " );
120 printf( "%u", Conf_ListenPorts[i] );
123 printf( " Listen = %s\n", Conf_ListenAddress );
124 pwd = getpwuid( Conf_UID );
125 if( pwd ) printf( " ServerUID = %s\n", pwd->pw_name );
126 else printf( " ServerUID = %ld\n", (LONG)Conf_UID );
127 grp = getgrgid( Conf_GID );
128 if( grp ) printf( " ServerGID = %s\n", grp->gr_name );
129 else printf( " ServerGID = %ld\n", (LONG)Conf_GID );
130 printf( " PingTimeout = %d\n", Conf_PingTimeout );
131 printf( " PongTimeout = %d\n", Conf_PongTimeout );
132 printf( " ConnectRetry = %d\n", Conf_ConnectRetry );
133 printf( " OperCanUseMode = %s\n", Conf_OperCanMode == TRUE ? "yes" : "no" );
134 if( Conf_MaxConnections > 0 ) printf( " MaxConnections = %ld\n", Conf_MaxConnections );
135 else printf( " MaxConnections = -1\n" );
136 if( Conf_MaxConnectionsIP > 0 ) printf( " MaxConnectionsIP = %d\n", Conf_MaxConnectionsIP );
137 else printf( " MaxConnectionsIP = -1\n" );
138 if( Conf_MaxJoins > 0 ) printf( " MaxJoins = %d\n", Conf_MaxJoins );
139 else printf( " MaxJoins = -1\n" );
142 for( i = 0; i < Conf_Oper_Count; i++ )
144 if( ! Conf_Oper[i].name[0] ) continue;
146 /* Valid "Operator" section */
147 puts( "[OPERATOR]" );
148 printf( " Name = %s\n", Conf_Oper[i].name );
149 printf( " Password = %s\n", Conf_Oper[i].pwd );
153 for( i = 0; i < MAX_SERVERS; i++ )
155 if( ! Conf_Server[i].name[0] ) continue;
157 /* Valid "Server" section */
159 printf( " Name = %s\n", Conf_Server[i].name );
160 printf( " Host = %s\n", Conf_Server[i].host );
161 printf( " Port = %d\n", Conf_Server[i].port );
162 printf( " MyPassword = %s\n", Conf_Server[i].pwd_in );
163 printf( " PeerPassword = %s\n", Conf_Server[i].pwd_out );
164 printf( " Group = %d\n", Conf_Server[i].group );
168 for( i = 0; i < Conf_Channel_Count; i++ )
170 if( ! Conf_Channel[i].name[0] ) continue;
172 /* Valid "Channel" section */
174 printf( " Name = %s\n", Conf_Channel[i].name );
175 printf( " Modes = %s\n", Conf_Channel[i].modes );
176 printf( " Topic = %s\n", Conf_Channel[i].topic );
185 Conf_UnsetServer( CONN_ID Idx )
187 /* Set next time for next connection attempt, if this is a server
188 * link that is (still) configured here. If the server is set as
189 * "once", delete it from our configuration.
190 * Non-Server-Connections will be silently ignored. */
194 /* Check all our configured servers */
195 for( i = 0; i < MAX_SERVERS; i++ )
197 if( Conf_Server[i].conn_id != Idx ) continue;
199 /* Gotcha! Mark server configuration as "unused": */
200 Conf_Server[i].conn_id = NONE;
202 if( Conf_Server[i].flags & CONF_SFLAG_ONCE )
204 /* Delete configuration here */
205 Init_Server_Struct( &Conf_Server[i] );
209 /* Set time for next connect attempt */
210 if( Conf_Server[i].lasttry < time( NULL ) - Conf_ConnectRetry )
212 /* Okay, the connection was established "long enough": */
213 Conf_Server[i].lasttry = time( NULL ) - Conf_ConnectRetry + RECONNECT_DELAY;
217 } /* Conf_UnsetServer */
221 Conf_SetServer( INT ConfServer, CONN_ID Idx )
223 /* Set connection for specified configured server */
225 assert( ConfServer > NONE );
226 assert( Idx > NONE );
228 Conf_Server[ConfServer].conn_id = Idx;
229 } /* Conf_SetServer */
233 Conf_GetServer( CONN_ID Idx )
235 /* Get index of server in configuration structure */
239 assert( Idx > NONE );
241 for( i = 0; i < MAX_SERVERS; i++ )
243 if( Conf_Server[i].conn_id == Idx ) return i;
246 } /* Conf_GetServer */
250 Conf_EnableServer( CHAR *Name, INT Port )
252 /* Enable specified server and adjust port */
256 assert( Name != NULL );
258 for( i = 0; i < MAX_SERVERS; i++ )
260 if( strcasecmp( Conf_Server[i].name, Name ) == 0 )
262 /* Gotcha! Set port and enable server: */
263 Conf_Server[i].port = Port;
264 Conf_Server[i].flags &= ~CONF_SFLAG_DISABLED;
269 } /* Conf_EnableServer */
273 Conf_DisableServer( CHAR *Name )
275 /* Enable specified server and adjust port */
279 assert( Name != NULL );
281 for( i = 0; i < MAX_SERVERS; i++ )
283 if( strcasecmp( Conf_Server[i].name, Name ) == 0 )
285 /* Gotcha! Disable and disconnect server: */
286 Conf_Server[i].flags |= CONF_SFLAG_DISABLED;
287 if( Conf_Server[i].conn_id > NONE ) Conn_Close( Conf_Server[i].conn_id, NULL, "Server link terminated on operator request", TRUE );
292 } /* Conf_DisableServer */
296 Conf_AddServer( CHAR *Name, INT Port, CHAR *Host, CHAR *MyPwd, CHAR *PeerPwd )
298 /* Add new server to configuration */
302 assert( Name != NULL );
303 assert( Host != NULL );
304 assert( MyPwd != NULL );
305 assert( PeerPwd != NULL );
307 /* Search unused item in server configuration structure */
308 for( i = 0; i < MAX_SERVERS; i++ )
310 /* Is this item used? */
311 if( ! Conf_Server[i].name[0] ) break;
313 if( i >= MAX_SERVERS ) return FALSE;
315 Init_Server_Struct( &Conf_Server[i] );
316 strlcpy( Conf_Server[i].name, Name, sizeof( Conf_Server[i].name ));
317 strlcpy( Conf_Server[i].host, Host, sizeof( Conf_Server[i].host ));
318 strlcpy( Conf_Server[i].pwd_out, MyPwd, sizeof( Conf_Server[i].pwd_out ));
319 strlcpy( Conf_Server[i].pwd_in, PeerPwd, sizeof( Conf_Server[i].pwd_in ));
320 Conf_Server[i].port = Port;
321 Conf_Server[i].flags = CONF_SFLAG_ONCE;
324 } /* Conf_AddServer */
328 Set_Defaults( BOOLEAN InitServers )
330 /* Initialize configuration variables with default values. */
334 strcpy( Conf_ServerName, "" );
335 sprintf( Conf_ServerInfo, "%s %s", PACKAGE_NAME, PACKAGE_VERSION );
336 strcpy( Conf_ServerPwd, "" );
338 strcpy( Conf_ServerAdmin1, "" );
339 strcpy( Conf_ServerAdmin2, "" );
340 strcpy( Conf_ServerAdminMail, "" );
342 strlcpy( Conf_MotdFile, SYSCONFDIR, sizeof( Conf_MotdFile ));
343 strlcat( Conf_MotdFile, MOTD_FILE, sizeof( Conf_MotdFile ));
345 Conf_ListenPorts_Count = 0;
346 strcpy( Conf_ListenAddress, "" );
348 Conf_UID = Conf_GID = 0;
350 Conf_PingTimeout = 120;
351 Conf_PongTimeout = 20;
353 Conf_ConnectRetry = 60;
356 Conf_Channel_Count = 0;
358 Conf_OperCanMode = FALSE;
360 Conf_MaxConnections = -1;
361 Conf_MaxConnectionsIP = 5;
364 /* Initialize server configuration structures */
365 if( InitServers ) for( i = 0; i < MAX_SERVERS; Init_Server_Struct( &Conf_Server[i++] ));
372 /* Read configuration file. */
374 CHAR section[LINE_LEN], str[LINE_LEN], *var, *arg, *ptr;
378 /* Open configuration file */
379 fd = fopen( NGIRCd_ConfFile, "r" );
382 /* No configuration file found! */
383 Config_Error( LOG_ALERT, "Can't read configuration \"%s\": %s", NGIRCd_ConfFile, strerror( errno ));
384 Config_Error( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME );
388 Config_Error( LOG_INFO, "Reading configuration from \"%s\" ...", NGIRCd_ConfFile );
390 /* Clean up server configuration structure: mark all already
391 * configured servers as "once" so that they are deleted
392 * after the next disconnect and delete all unused servers.
393 * And delete all servers which are "duplicates" of servers
394 * that are already marked as "once" (such servers have been
395 * created by the last rehash but are now useless). */
396 for( i = 0; i < MAX_SERVERS; i++ )
398 if( Conf_Server[i].conn_id == NONE ) Init_Server_Struct( &Conf_Server[i] );
401 /* This structure is in use ... */
402 if( Conf_Server[i].flags & CONF_SFLAG_ONCE )
404 /* Check for duplicates */
405 for( n = 0; n < MAX_SERVERS; n++ )
407 if( n == i ) continue;
409 if( Conf_Server[i].conn_id == Conf_Server[n].conn_id )
411 Init_Server_Struct( &Conf_Server[n] );
412 Log( LOG_DEBUG, "Deleted unused duplicate server %d (kept %d).", n, i );
418 /* Mark server as "once" */
419 Conf_Server[i].flags |= CONF_SFLAG_ONCE;
420 Log( LOG_DEBUG, "Marked server %d as \"once\"", i );
425 /* Initialize variables */
427 strcpy( section, "" );
428 Init_Server_Struct( &New_Server );
429 New_Server_Idx = NONE;
431 /* Read configuration file */
434 if( ! fgets( str, LINE_LEN, fd )) break;
438 /* Skip comments and empty lines */
439 if( str[0] == ';' || str[0] == '#' || str[0] == '\0' ) continue;
441 /* Is this the beginning of a new section? */
442 if(( str[0] == '[' ) && ( str[strlen( str ) - 1] == ']' ))
444 strlcpy( section, str, sizeof( section ));
445 if( strcasecmp( section, "[GLOBAL]" ) == 0 ) continue;
446 if( strcasecmp( section, "[OPERATOR]" ) == 0 )
448 if( Conf_Oper_Count + 1 > MAX_OPERATORS ) Config_Error( LOG_ERR, "Too many operators configured." );
451 /* Initialize new operator structure */
452 strcpy( Conf_Oper[Conf_Oper_Count].name, "" );
453 strcpy( Conf_Oper[Conf_Oper_Count].pwd, "" );
458 if( strcasecmp( section, "[SERVER]" ) == 0 )
460 /* Check if there is already a server to add */
461 if( New_Server.name[0] )
463 /* Copy data to "real" server structure */
464 assert( New_Server_Idx > NONE );
465 Conf_Server[New_Server_Idx] = New_Server;
468 /* Re-init structure for new server */
469 Init_Server_Struct( &New_Server );
471 /* Search unused item in server configuration structure */
472 for( i = 0; i < MAX_SERVERS; i++ )
474 /* Is this item used? */
475 if( ! Conf_Server[i].name[0] ) break;
477 if( i >= MAX_SERVERS )
479 /* Oops, no free item found! */
480 Config_Error( LOG_ERR, "Too many servers configured." );
481 New_Server_Idx = NONE;
483 else New_Server_Idx = i;
486 if( strcasecmp( section, "[CHANNEL]" ) == 0 )
488 if( Conf_Channel_Count + 1 > MAX_DEFCHANNELS ) Config_Error( LOG_ERR, "Too many pre-defined channels configured." );
491 /* Initialize new channel structure */
492 strcpy( Conf_Channel[Conf_Channel_Count].name, "" );
493 strcpy( Conf_Channel[Conf_Channel_Count].modes, "" );
494 strcpy( Conf_Channel[Conf_Channel_Count].topic, "" );
495 Conf_Channel_Count++;
499 Config_Error( LOG_ERR, "%s, line %d: Unknown section \"%s\"!", NGIRCd_ConfFile, line, section );
502 if( section[0] == 0x1 ) continue;
504 /* Split line into variable name and parameters */
505 ptr = strchr( str, '=' );
508 Config_Error( LOG_ERR, "%s, line %d: Syntax error!", NGIRCd_ConfFile, line );
512 var = str; ngt_TrimStr( var );
513 arg = ptr + 1; ngt_TrimStr( arg );
515 if( strcasecmp( section, "[GLOBAL]" ) == 0 ) Handle_GLOBAL( line, var, arg );
516 else if( strcasecmp( section, "[OPERATOR]" ) == 0 ) Handle_OPERATOR( line, var, arg );
517 else if( strcasecmp( section, "[SERVER]" ) == 0 ) Handle_SERVER( line, var, arg );
518 else if( strcasecmp( section, "[CHANNEL]" ) == 0 ) Handle_CHANNEL( line, var, arg );
519 else Config_Error( LOG_ERR, "%s, line %d: Variable \"%s\" outside section!", NGIRCd_ConfFile, line, var );
522 /* Close configuration file */
525 /* Check if there is still a server to add */
526 if( New_Server.name[0] )
528 /* Copy data to "real" server structure */
529 assert( New_Server_Idx > NONE );
530 Conf_Server[New_Server_Idx] = New_Server;
533 /* If there are no ports configured use the default: 6667 */
534 if( Conf_ListenPorts_Count < 1 )
536 Conf_ListenPorts_Count = 1;
537 Conf_ListenPorts[0] = 6667;
543 Handle_GLOBAL( INT Line, CHAR *Var, CHAR *Arg )
551 assert( Var != NULL );
552 assert( Arg != NULL );
554 if( strcasecmp( Var, "Name" ) == 0 )
557 if( strlcpy( Conf_ServerName, Arg, sizeof( Conf_ServerName )) >= sizeof( Conf_ServerName )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"Name\" too long!", NGIRCd_ConfFile, Line );
560 if( strcasecmp( Var, "Info" ) == 0 )
562 /* Info text of server */
563 if( strlcpy( Conf_ServerInfo, Arg, sizeof( Conf_ServerInfo )) >= sizeof( Conf_ServerInfo )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"Info\" too long!", NGIRCd_ConfFile, Line );
566 if( strcasecmp( Var, "Password" ) == 0 )
568 /* Global server password */
569 if( strlcpy( Conf_ServerPwd, Arg, sizeof( Conf_ServerPwd )) >= sizeof( Conf_ServerPwd )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"Password\" too long!", NGIRCd_ConfFile, Line );
572 if( strcasecmp( Var, "AdminInfo1" ) == 0 )
574 /* Administrative info #1 */
575 if( strlcpy( Conf_ServerAdmin1, Arg, sizeof( Conf_ServerAdmin1 )) >= sizeof( Conf_ServerAdmin1 )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"AdminInfo1\" too long!", NGIRCd_ConfFile, Line );
578 if( strcasecmp( Var, "AdminInfo2" ) == 0 )
580 /* Administrative info #2 */
581 if( strlcpy( Conf_ServerAdmin2, Arg, sizeof( Conf_ServerAdmin2 )) >= sizeof( Conf_ServerAdmin2 )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"AdminInfo2\" too long!", NGIRCd_ConfFile, Line );
584 if( strcasecmp( Var, "AdminEMail" ) == 0 )
586 /* Administrative email contact */
587 if( strlcpy( Conf_ServerAdminMail, Arg, sizeof( Conf_ServerAdminMail )) >= sizeof( Conf_ServerAdminMail )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"AdminEMail\" too long!", NGIRCd_ConfFile, Line );
590 if( strcasecmp( Var, "Ports" ) == 0 )
592 /* Ports on that the server should listen. More port numbers
593 * must be separated by "," */
594 ptr = strtok( Arg, "," );
599 if( Conf_ListenPorts_Count + 1 > MAX_LISTEN_PORTS ) Config_Error( LOG_ERR, "Too many listen ports configured. Port %ld ignored.", port );
602 if( port > 0 && port < 0xFFFF ) Conf_ListenPorts[Conf_ListenPorts_Count++] = (UINT)port;
603 else Config_Error( LOG_ERR, "%s, line %d (section \"Global\"): Illegal port number %ld!", NGIRCd_ConfFile, Line, port );
605 ptr = strtok( NULL, "," );
609 if( strcasecmp( Var, "MotdFile" ) == 0 )
611 /* "Message of the day" (MOTD) file */
612 if( strlcpy( Conf_MotdFile, Arg, sizeof( Conf_MotdFile )) >= sizeof( Conf_MotdFile )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"MotdFile\" too long!", NGIRCd_ConfFile, Line );
615 if( strcasecmp( Var, "ServerUID" ) == 0 )
617 /* UID the daemon should switch to */
618 pwd = getpwnam( Arg );
619 if( pwd ) Conf_UID = pwd->pw_uid;
623 if( ! isdigit( *Arg )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"ServerUID\" is not a number!", NGIRCd_ConfFile, Line );
626 Conf_UID = (UINT)atoi( Arg );
630 if( strcasecmp( Var, "ServerGID" ) == 0 )
632 /* GID the daemon should use */
633 grp = getgrnam( Arg );
634 if( grp ) Conf_GID = grp->gr_gid;
638 if( ! isdigit( *Arg )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"ServerGID\" is not a number!", NGIRCd_ConfFile, Line );
641 Conf_GID = (UINT)atoi( Arg );
645 if( strcasecmp( Var, "PingTimeout" ) == 0 )
648 Conf_PingTimeout = atoi( Arg );
649 if( Conf_PingTimeout < 5 )
651 Config_Error( LOG_WARNING, "%s, line %d: Value of \"PingTimeout\" too low!", NGIRCd_ConfFile, Line );
652 Conf_PingTimeout = 5;
656 if( strcasecmp( Var, "PongTimeout" ) == 0 )
659 Conf_PongTimeout = atoi( Arg );
660 if( Conf_PongTimeout < 5 )
662 Config_Error( LOG_WARNING, "%s, line %d: Value of \"PongTimeout\" too low!", NGIRCd_ConfFile, Line );
663 Conf_PongTimeout = 5;
667 if( strcasecmp( Var, "ConnectRetry" ) == 0 )
669 /* Seconds between connection attempts to other servers */
670 Conf_ConnectRetry = atoi( Arg );
671 if( Conf_ConnectRetry < 5 )
673 Config_Error( LOG_WARNING, "%s, line %d: Value of \"ConnectRetry\" too low!", NGIRCd_ConfFile, Line );
674 Conf_ConnectRetry = 5;
678 if( strcasecmp( Var, "OperCanUseMode" ) == 0 )
680 /* Are IRC operators allowed to use MODE in channels they aren't Op in? */
681 if( strcasecmp( Arg, "yes" ) == 0 ) Conf_OperCanMode = TRUE;
682 else if( strcasecmp( Arg, "true" ) == 0 ) Conf_OperCanMode = TRUE;
683 else if( atoi( Arg ) != 0 ) Conf_OperCanMode = TRUE;
684 else Conf_OperCanMode = FALSE;
687 if( strcasecmp( Var, "MaxConnections" ) == 0 )
689 /* Maximum number of connections. Values <= 0 are equal to "no limit". */
691 if( ! isdigit( *Arg )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"MaxConnections\" is not a number!", NGIRCd_ConfFile, Line );
694 Conf_MaxConnections = atol( Arg );
697 if( strcasecmp( Var, "MaxConnectionsIP" ) == 0 )
699 /* Maximum number of simoultanous connections from one IP. Values <= 0 are equal to "no limit". */
701 if( ! isdigit( *Arg )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"MaxConnectionsIP\" is not a number!", NGIRCd_ConfFile, Line );
704 Conf_MaxConnectionsIP = atoi( Arg );
707 if( strcasecmp( Var, "MaxJoins" ) == 0 )
709 /* Maximum number of channels a user can join. Values <= 0 are equal to "no limit". */
711 if( ! isdigit( *Arg )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"MaxJoins\" is not a number!", NGIRCd_ConfFile, Line );
714 Conf_MaxJoins = atoi( Arg );
717 if( strcasecmp( Var, "Listen" ) == 0 )
719 /* IP-Address to bind sockets */
720 if( strlcpy( Conf_ListenAddress, Arg, sizeof( Conf_ListenAddress )) >= sizeof( Conf_ListenAddress ))
722 Config_Error( LOG_WARNING, "%s, line %d: Value of \"Listen\" too long!", NGIRCd_ConfFile, Line );
727 Config_Error( LOG_ERR, "%s, line %d (section \"Global\"): Unknown variable \"%s\"!", NGIRCd_ConfFile, Line, Var );
728 } /* Handle_GLOBAL */
732 Handle_OPERATOR( INT Line, CHAR *Var, CHAR *Arg )
735 assert( Var != NULL );
736 assert( Arg != NULL );
737 assert( Conf_Oper_Count > 0 );
739 if( strcasecmp( Var, "Name" ) == 0 )
741 /* Name of IRC operator */
742 if( strlcpy( Conf_Oper[Conf_Oper_Count - 1].name, Arg, sizeof( Conf_Oper[Conf_Oper_Count - 1].name )) >= sizeof( Conf_Oper[Conf_Oper_Count - 1].name )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"Name\" too long!", NGIRCd_ConfFile, Line );
745 if( strcasecmp( Var, "Password" ) == 0 )
747 /* Password of IRC operator */
748 if( strlcpy( Conf_Oper[Conf_Oper_Count - 1].pwd, Arg, sizeof( Conf_Oper[Conf_Oper_Count - 1].pwd )) >= sizeof( Conf_Oper[Conf_Oper_Count - 1].pwd )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"Password\" too long!", NGIRCd_ConfFile, Line );
752 Config_Error( LOG_ERR, "%s, line %d (section \"Operator\"): Unknown variable \"%s\"!", NGIRCd_ConfFile, Line, Var );
753 } /* Handle_OPERATOR */
757 Handle_SERVER( INT Line, CHAR *Var, CHAR *Arg )
762 assert( Var != NULL );
763 assert( Arg != NULL );
765 /* Ignore server block if no space is left in server configuration structure */
766 if( New_Server_Idx <= NONE ) return;
768 if( strcasecmp( Var, "Host" ) == 0 )
770 /* Hostname of the server */
771 if( strlcpy( New_Server.host, Arg, sizeof( New_Server.host )) >= sizeof( New_Server.host )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"Host\" too long!", NGIRCd_ConfFile, Line );
774 if( strcasecmp( Var, "Name" ) == 0 )
776 /* Name of the server ("Nick"/"ID") */
777 if( strlcpy( New_Server.name, Arg, sizeof( New_Server.name )) >= sizeof( New_Server.name )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"Name\" too long!", NGIRCd_ConfFile, Line );
780 if( strcasecmp( Var, "MyPassword" ) == 0 )
782 /* Password of this server which is sent to the peer */
783 if( strlcpy( New_Server.pwd_in, Arg, sizeof( New_Server.pwd_in )) >= sizeof( New_Server.pwd_in )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"MyPassword\" too long!", NGIRCd_ConfFile, Line );
786 if( strcasecmp( Var, "PeerPassword" ) == 0 )
788 /* Passwort of the peer which must be received */
789 if( strlcpy( New_Server.pwd_out, Arg, sizeof( New_Server.pwd_out )) >= sizeof( New_Server.pwd_out )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"PeerPassword\" too long!", NGIRCd_ConfFile, Line );
792 if( strcasecmp( Var, "Port" ) == 0 )
794 /* Port to which this server should connect */
796 if( port > 0 && port < 0xFFFF ) New_Server.port = (INT)port;
797 else Config_Error( LOG_ERR, "%s, line %d (section \"Server\"): Illegal port number %ld!", NGIRCd_ConfFile, Line, port );
800 if( strcasecmp( Var, "Group" ) == 0 )
804 if( ! isdigit( *Arg )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"Group\" is not a number!", NGIRCd_ConfFile, Line );
807 New_Server.group = atoi( Arg );
811 Config_Error( LOG_ERR, "%s, line %d (section \"Server\"): Unknown variable \"%s\"!", NGIRCd_ConfFile, Line, Var );
812 } /* Handle_SERVER */
816 Handle_CHANNEL( INT Line, CHAR *Var, CHAR *Arg )
819 assert( Var != NULL );
820 assert( Arg != NULL );
822 if( strcasecmp( Var, "Name" ) == 0 )
824 /* Name of the channel */
825 if( strlcpy( Conf_Channel[Conf_Channel_Count - 1].name, Arg, sizeof( Conf_Channel[Conf_Channel_Count - 1].name )) >= sizeof( Conf_Channel[Conf_Channel_Count - 1].name )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"Name\" too long!", NGIRCd_ConfFile, Line );
828 if( strcasecmp( Var, "Modes" ) == 0 )
831 if( strlcpy( Conf_Channel[Conf_Channel_Count - 1].modes, Arg, sizeof( Conf_Channel[Conf_Channel_Count - 1].modes )) >= sizeof( Conf_Channel[Conf_Channel_Count - 1].modes )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"Modes\" too long!", NGIRCd_ConfFile, Line );
834 if( strcasecmp( Var, "Topic" ) == 0 )
837 if( strlcpy( Conf_Channel[Conf_Channel_Count - 1].topic, Arg, sizeof( Conf_Channel[Conf_Channel_Count - 1].topic )) >= sizeof( Conf_Channel[Conf_Channel_Count - 1].topic )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"Topic\" too long!", NGIRCd_ConfFile, Line );
841 Config_Error( LOG_ERR, "%s, line %d (section \"Channel\"): Unknown variable \"%s\"!", NGIRCd_ConfFile, Line, Var );
842 } /* Handle_CHANNEL */
846 Validate_Config( BOOLEAN Configtest )
848 /* Validate configuration settings. */
851 INT i, servers, servers_once;
854 if( ! Conf_ServerName[0] )
856 /* No server name configured! */
857 Config_Error( LOG_ALERT, "No server name configured in \"%s\" (section 'Global': 'Name')!", NGIRCd_ConfFile );
860 Config_Error( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME );
865 if( Conf_ServerName[0] && ! strchr( Conf_ServerName, '.' ))
867 /* No dot in server name! */
868 Config_Error( LOG_ALERT, "Invalid server name configured in \"%s\" (section 'Global': 'Name'): Dot missing!", NGIRCd_ConfFile );
871 Config_Error( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME );
877 if( ! Conf_ServerAdminMail[0] )
879 /* No administrative contact configured! */
880 Config_Error( LOG_ALERT, "No administrator email address configured in \"%s\" ('AdminEMail')!", NGIRCd_ConfFile );
883 Config_Error( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME );
889 if( ! Conf_ServerAdmin1[0] && ! Conf_ServerAdmin2[0] && ! Conf_ServerAdminMail[0] )
891 /* No administrative information configured! */
892 Config_Error( LOG_WARNING, "No administrative information configured but required by RFC!" );
895 if(( Conf_MaxConnections > (LONG)FD_SETSIZE ) || ( Conf_MaxConnections < 1 ))
897 Conf_MaxConnections = (LONG)FD_SETSIZE;
898 Config_Error( LOG_ERR, "Setting MaxConnections to %ld, select() can't handle more file descriptors!", Conf_MaxConnections );
901 Config_Error( LOG_WARN, "Don't know how many file descriptors select() can handle on this system, don't set MaxConnections too high!" );
905 servers = servers_once = 0;
906 for( i = 0; i < MAX_SERVERS; i++ )
908 if( Conf_Server[i].name[0] )
911 if( Conf_Server[i].flags & CONF_SFLAG_ONCE ) servers_once++;
914 Log( LOG_DEBUG, "Configuration: Operators=%d, Servers=%d[%d], Channels=%d", Conf_Oper_Count, servers, servers_once, Conf_Channel_Count );
916 } /* Validate_Config */
920 LOCAL VOID Config_Error( CONST INT Level, CONST CHAR *Format, ... )
922 LOCAL VOID Config_Error( Level, Format, va_alist )
928 /* Error! Write to console and/or logfile. */
930 CHAR msg[MAX_LOG_MSG_LEN];
933 assert( Format != NULL );
936 va_start( ap, Format );
940 vsnprintf( msg, MAX_LOG_MSG_LEN, Format, ap );
943 /* During "normal operations" the log functions of the daemon should
944 * be used, but during testing of the configuration file, all messages
945 * should go directly to the console: */
946 if( Use_Log ) Log( Level, "%s", msg );
952 Init_Server_Struct( CONF_SERVER *Server )
954 /* Initialize server configuration structur to default values */
956 assert( Server != NULL );
958 strcpy( Server->host, "" );
959 strcpy( Server->ip, "" );
960 strcpy( Server->name, "" );
961 strcpy( Server->pwd_in, "" );
962 strcpy( Server->pwd_out, "" );
964 Server->group = NONE;
965 Server->lasttry = time( NULL ) - Conf_ConnectRetry + STARTUP_DELAY;
966 Server->res_stat = NULL;
967 if( NGIRCd_Passive ) Server->flags = CONF_SFLAG_DISABLED;
968 else Server->flags = 0;
969 Server->conn_id = NONE;
970 } /* Init_Server_Struct */