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.54 2003/03/27 01:21:38 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( " ServerPwd = %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 pwd = getpwuid( Conf_UID );
124 if( pwd ) printf( " ServerUID = %s\n", pwd->pw_name );
125 else printf( " ServerUID = %ld\n", (LONG)Conf_UID );
126 grp = getgrgid( Conf_GID );
127 if( grp ) printf( " ServerGID = %s\n", grp->gr_name );
128 else printf( " ServerGID = %ld\n", (LONG)Conf_GID );
129 printf( " PingTimeout = %d\n", Conf_PingTimeout );
130 printf( " PongTimeout = %d\n", Conf_PongTimeout );
131 printf( " ConnectRetry = %d\n", Conf_ConnectRetry );
132 printf( " OperCanUseMode = %s\n", Conf_OperCanMode == TRUE ? "yes" : "no" );
133 if( Conf_MaxConnections > 0 ) printf( " MaxConnections = %ld\n", Conf_MaxConnections );
134 else printf( " MaxConnections = -1\n" );
135 if( Conf_MaxJoins > 0 ) printf( " MaxJoins = %d\n", Conf_MaxJoins );
136 else printf( " MaxJoins = -1\n" );
139 for( i = 0; i < Conf_Oper_Count; i++ )
141 if( ! Conf_Oper[i].name[0] ) continue;
143 /* Valid "Operator" section */
144 puts( "[OPERATOR]" );
145 printf( " Name = %s\n", Conf_Oper[i].name );
146 printf( " Password = %s\n", Conf_Oper[i].pwd );
150 for( i = 0; i < MAX_SERVERS; i++ )
152 if( ! Conf_Server[i].name[0] ) continue;
154 /* Valid "Server" section */
156 printf( " Name = %s\n", Conf_Server[i].name );
157 printf( " Host = %s\n", Conf_Server[i].host );
158 printf( " Port = %d\n", Conf_Server[i].port );
159 printf( " MyPassword = %s\n", Conf_Server[i].pwd_in );
160 printf( " PeerPassword = %s\n", Conf_Server[i].pwd_out );
161 printf( " Group = %d\n", Conf_Server[i].group );
165 for( i = 0; i < Conf_Channel_Count; i++ )
167 if( ! Conf_Channel[i].name[0] ) continue;
169 /* Valid "Channel" section */
171 printf( " Name = %s\n", Conf_Channel[i].name );
172 printf( " Modes = %s\n", Conf_Channel[i].modes );
173 printf( " Topic = %s\n", Conf_Channel[i].topic );
182 Conf_UnsetServer( CONN_ID Idx )
184 /* Set next time for next connection attempt, if this is a server
185 * link that is (still) configured here. If the server is set as
186 * "once", delete it from our configuration.
187 * Non-Server-Connections will be silently ignored. */
191 /* Check all our configured servers */
192 for( i = 0; i < MAX_SERVERS; i++ )
194 if( Conf_Server[i].conn_id != Idx ) continue;
196 /* Gotcha! Mark server configuration as "unused": */
197 Conf_Server[i].conn_id = NONE;
199 if( Conf_Server[i].flags & CONF_SFLAG_ONCE )
201 /* Delete configuration here */
202 Init_Server_Struct( &Conf_Server[i] );
206 /* Set time for next connect attempt */
207 if( Conf_Server[i].lasttry < time( NULL ) - Conf_ConnectRetry )
209 /* Okay, the connection was established "long enough": */
210 Conf_Server[i].lasttry = time( NULL ) - Conf_ConnectRetry + RECONNECT_DELAY;
214 } /* Conf_UnsetServer */
218 Conf_SetServer( INT ConfServer, CONN_ID Idx )
220 /* Set connection for specified configured server */
222 assert( ConfServer > NONE );
223 assert( Idx > NONE );
225 Conf_Server[ConfServer].conn_id = Idx;
226 } /* Conf_SetServer */
230 Conf_GetServer( CONN_ID Idx )
232 /* Get index of server in configuration structure */
236 assert( Idx > NONE );
238 for( i = 0; i < MAX_SERVERS; i++ )
240 if( Conf_Server[i].conn_id == Idx ) return i;
243 } /* Conf_GetServer */
247 Conf_EnableServer( CHAR *Name, INT Port )
249 /* Enable specified server and adjust port */
253 assert( Name != NULL );
255 for( i = 0; i < MAX_SERVERS; i++ )
257 if( strcasecmp( Conf_Server[i].name, Name ) == 0 )
259 /* Gotcha! Set port and enable server: */
260 Conf_Server[i].port = Port;
261 Conf_Server[i].flags &= ~CONF_SFLAG_DISABLED;
266 } /* Conf_EnableServer */
270 Conf_DisableServer( CHAR *Name )
272 /* Enable specified server and adjust port */
276 assert( Name != NULL );
278 for( i = 0; i < MAX_SERVERS; i++ )
280 if( strcasecmp( Conf_Server[i].name, Name ) == 0 )
282 /* Gotcha! Disable and disconnect server: */
283 Conf_Server[i].flags |= CONF_SFLAG_DISABLED;
284 if( Conf_Server[i].conn_id > NONE ) Conn_Close( Conf_Server[i].conn_id, NULL, "Server link terminated on operator request", TRUE );
289 } /* Conf_DisableServer */
293 Conf_AddServer( CHAR *Name, INT Port, CHAR *Host, CHAR *MyPwd, CHAR *PeerPwd )
295 /* Add new server to configuration */
299 assert( Name != NULL );
300 assert( Host != NULL );
301 assert( MyPwd != NULL );
302 assert( PeerPwd != NULL );
304 /* Search unused item in server configuration structure */
305 for( i = 0; i < MAX_SERVERS; i++ )
307 /* Is this item used? */
308 if( ! Conf_Server[i].name[0] ) break;
310 if( i >= MAX_SERVERS ) return FALSE;
312 Init_Server_Struct( &Conf_Server[i] );
313 strlcpy( Conf_Server[i].name, Name, sizeof( Conf_Server[i].name ));
314 strlcpy( Conf_Server[i].host, Host, sizeof( Conf_Server[i].host ));
315 strlcpy( Conf_Server[i].pwd_out, MyPwd, sizeof( Conf_Server[i].pwd_out ));
316 strlcpy( Conf_Server[i].pwd_in, PeerPwd, sizeof( Conf_Server[i].pwd_in ));
317 Conf_Server[i].port = Port;
318 Conf_Server[i].flags = CONF_SFLAG_ONCE;
321 } /* Conf_AddServer */
325 Set_Defaults( BOOLEAN InitServers )
327 /* Initialize configuration variables with default values. */
331 strcpy( Conf_ServerName, "" );
332 sprintf( Conf_ServerInfo, "%s %s", PACKAGE, VERSION );
333 strcpy( Conf_ServerPwd, "" );
335 strcpy( Conf_ServerAdmin1, "" );
336 strcpy( Conf_ServerAdmin2, "" );
337 strcpy( Conf_ServerAdminMail, "" );
339 strlcpy( Conf_MotdFile, SYSCONFDIR, sizeof( Conf_MotdFile ));
340 strlcat( Conf_MotdFile, MOTD_FILE, sizeof( Conf_MotdFile ));
342 Conf_ListenPorts_Count = 0;
344 Conf_UID = Conf_GID = 0;
346 Conf_PingTimeout = 120;
347 Conf_PongTimeout = 20;
349 Conf_ConnectRetry = 60;
352 Conf_Channel_Count = 0;
354 Conf_OperCanMode = FALSE;
356 Conf_MaxConnections = -1;
359 /* Initialize server configuration structures */
360 if( InitServers ) for( i = 0; i < MAX_SERVERS; Init_Server_Struct( &Conf_Server[i++] ));
367 /* Read configuration file. */
369 CHAR section[LINE_LEN], str[LINE_LEN], *var, *arg, *ptr;
373 /* Open configuration file */
374 fd = fopen( NGIRCd_ConfFile, "r" );
377 /* No configuration file found! */
378 Config_Error( LOG_ALERT, "Can't read configuration \"%s\": %s", NGIRCd_ConfFile, strerror( errno ));
379 Config_Error( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE );
383 Config_Error( LOG_INFO, "Reading configuration from \"%s\" ...", NGIRCd_ConfFile );
385 /* Clean up server configuration structure: mark all already
386 * configured servers as "once" so that they are deleted
387 * after the next disconnect and delete all unused servers.
388 * And delete all servers which are "duplicates" of servers
389 * that are already marked as "once" (such servers have been
390 * created by the last rehash but are now useless). */
391 for( i = 0; i < MAX_SERVERS; i++ )
393 if( Conf_Server[i].conn_id == NONE ) Init_Server_Struct( &Conf_Server[i] );
396 /* This structure is in use ... */
397 if( Conf_Server[i].flags & CONF_SFLAG_ONCE )
399 /* Check for duplicates */
400 for( n = 0; n < MAX_SERVERS; n++ )
402 if( n == i ) continue;
404 if( Conf_Server[i].conn_id == Conf_Server[n].conn_id )
406 Init_Server_Struct( &Conf_Server[n] );
407 Log( LOG_DEBUG, "Deleted unused duplicate server %d (kept %d).", n, i );
413 /* Mark server as "once" */
414 Conf_Server[i].flags |= CONF_SFLAG_ONCE;
415 Log( LOG_DEBUG, "Market server %d as \"once\"", i );
420 /* Initialize variables */
422 strcpy( section, "" );
423 Init_Server_Struct( &New_Server );
424 New_Server_Idx = NONE;
426 /* Read configuration file */
429 if( ! fgets( str, LINE_LEN, fd )) break;
433 /* Skip comments and empty lines */
434 if( str[0] == ';' || str[0] == '#' || str[0] == '\0' ) continue;
436 /* Is this the beginning of a new section? */
437 if(( str[0] == '[' ) && ( str[strlen( str ) - 1] == ']' ))
439 strlcpy( section, str, sizeof( section ));
440 if( strcasecmp( section, "[GLOBAL]" ) == 0 ) continue;
441 if( strcasecmp( section, "[OPERATOR]" ) == 0 )
443 if( Conf_Oper_Count + 1 > MAX_OPERATORS ) Config_Error( LOG_ERR, "Too many operators configured." );
446 /* Initialize new operator structure */
447 strcpy( Conf_Oper[Conf_Oper_Count].name, "" );
448 strcpy( Conf_Oper[Conf_Oper_Count].pwd, "" );
453 if( strcasecmp( section, "[SERVER]" ) == 0 )
455 /* Check if there is already a server to add */
456 if( New_Server.name[0] )
458 /* Copy data to "real" server structure */
459 assert( New_Server_Idx > NONE );
460 Conf_Server[New_Server_Idx] = New_Server;
463 /* Re-init structure for new server */
464 Init_Server_Struct( &New_Server );
466 /* Search unused item in server configuration structure */
467 for( i = 0; i < MAX_SERVERS; i++ )
469 /* Is this item used? */
470 if( ! Conf_Server[i].name[0] ) break;
472 if( i >= MAX_SERVERS )
474 /* Oops, no free item found! */
475 Config_Error( LOG_ERR, "Too many servers configured." );
476 New_Server_Idx = NONE;
478 else New_Server_Idx = i;
481 if( strcasecmp( section, "[CHANNEL]" ) == 0 )
483 if( Conf_Channel_Count + 1 > MAX_DEFCHANNELS ) Config_Error( LOG_ERR, "Too many pre-defined channels configured." );
486 /* Initialize new channel structure */
487 strcpy( Conf_Channel[Conf_Channel_Count].name, "" );
488 strcpy( Conf_Channel[Conf_Channel_Count].modes, "" );
489 strcpy( Conf_Channel[Conf_Channel_Count].topic, "" );
490 Conf_Channel_Count++;
494 Config_Error( LOG_ERR, "%s, line %d: Unknown section \"%s\"!", NGIRCd_ConfFile, line, section );
497 if( section[0] == 0x1 ) continue;
499 /* Split line into variable name and parameters */
500 ptr = strchr( str, '=' );
503 Config_Error( LOG_ERR, "%s, line %d: Syntax error!", NGIRCd_ConfFile, line );
507 var = str; ngt_TrimStr( var );
508 arg = ptr + 1; ngt_TrimStr( arg );
510 if( strcasecmp( section, "[GLOBAL]" ) == 0 ) Handle_GLOBAL( line, var, arg );
511 else if( strcasecmp( section, "[OPERATOR]" ) == 0 ) Handle_OPERATOR( line, var, arg );
512 else if( strcasecmp( section, "[SERVER]" ) == 0 ) Handle_SERVER( line, var, arg );
513 else if( strcasecmp( section, "[CHANNEL]" ) == 0 ) Handle_CHANNEL( line, var, arg );
514 else Config_Error( LOG_ERR, "%s, line %d: Variable \"%s\" outside section!", NGIRCd_ConfFile, line, var );
517 /* Close configuration file */
520 /* Check if there is still a server to add */
521 if( New_Server.name[0] )
523 /* Copy data to "real" server structure */
524 assert( New_Server_Idx > NONE );
525 Conf_Server[New_Server_Idx] = New_Server;
528 /* If there are no ports configured use the default: 6667 */
529 if( Conf_ListenPorts_Count < 1 )
531 Conf_ListenPorts_Count = 1;
532 Conf_ListenPorts[0] = 6667;
538 Handle_GLOBAL( INT Line, CHAR *Var, CHAR *Arg )
546 assert( Var != NULL );
547 assert( Arg != NULL );
549 if( strcasecmp( Var, "Name" ) == 0 )
552 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 );
555 if( strcasecmp( Var, "Info" ) == 0 )
557 /* Info text of server */
558 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 );
561 if( strcasecmp( Var, "Password" ) == 0 )
563 /* Global server password */
564 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 );
567 if( strcasecmp( Var, "AdminInfo1" ) == 0 )
569 /* Administrative info #1 */
570 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 );
573 if( strcasecmp( Var, "AdminInfo2" ) == 0 )
575 /* Administrative info #2 */
576 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 );
579 if( strcasecmp( Var, "AdminEMail" ) == 0 )
581 /* Administrative email contact */
582 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 );
585 if( strcasecmp( Var, "Ports" ) == 0 )
587 /* Ports on that the server should listen. More port numbers
588 * must be separated by "," */
589 ptr = strtok( Arg, "," );
594 if( Conf_ListenPorts_Count + 1 > MAX_LISTEN_PORTS ) Config_Error( LOG_ERR, "Too many listen ports configured. Port %ld ignored.", port );
597 if( port > 0 && port < 0xFFFF ) Conf_ListenPorts[Conf_ListenPorts_Count++] = (UINT)port;
598 else Config_Error( LOG_ERR, "%s, line %d (section \"Global\"): Illegal port number %ld!", NGIRCd_ConfFile, Line, port );
600 ptr = strtok( NULL, "," );
604 if( strcasecmp( Var, "MotdFile" ) == 0 )
606 /* "Message of the day" (MOTD) file */
607 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 );
610 if( strcasecmp( Var, "ServerUID" ) == 0 )
612 /* UID the daemon should switch to */
613 pwd = getpwnam( Arg );
614 if( pwd ) Conf_UID = pwd->pw_uid;
618 if( ! isdigit( *Arg )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"ServerUID\" is not a number!", NGIRCd_ConfFile, Line );
621 Conf_UID = (UINT)atoi( Arg );
625 if( strcasecmp( Var, "ServerGID" ) == 0 )
627 /* GID the daemon should use */
628 grp = getgrnam( Arg );
629 if( grp ) Conf_GID = grp->gr_gid;
633 if( ! isdigit( *Arg )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"ServerGID\" is not a number!", NGIRCd_ConfFile, Line );
636 Conf_GID = (UINT)atoi( Arg );
640 if( strcasecmp( Var, "PingTimeout" ) == 0 )
643 Conf_PingTimeout = atoi( Arg );
644 if( Conf_PingTimeout < 5 )
646 Config_Error( LOG_WARNING, "%s, line %d: Value of \"PingTimeout\" too low!", NGIRCd_ConfFile, Line );
647 Conf_PingTimeout = 5;
651 if( strcasecmp( Var, "PongTimeout" ) == 0 )
654 Conf_PongTimeout = atoi( Arg );
655 if( Conf_PongTimeout < 5 )
657 Config_Error( LOG_WARNING, "%s, line %d: Value of \"PongTimeout\" too low!", NGIRCd_ConfFile, Line );
658 Conf_PongTimeout = 5;
662 if( strcasecmp( Var, "ConnectRetry" ) == 0 )
664 /* Seconds between connection attempts to other servers */
665 Conf_ConnectRetry = atoi( Arg );
666 if( Conf_ConnectRetry < 5 )
668 Config_Error( LOG_WARNING, "%s, line %d: Value of \"ConnectRetry\" too low!", NGIRCd_ConfFile, Line );
669 Conf_ConnectRetry = 5;
673 if( strcasecmp( Var, "OperCanUseMode" ) == 0 )
675 /* Are IRC operators allowed to use MODE in channels they aren't Op in? */
676 if( strcasecmp( Arg, "yes" ) == 0 ) Conf_OperCanMode = TRUE;
677 else if( strcasecmp( Arg, "true" ) == 0 ) Conf_OperCanMode = TRUE;
678 else if( atoi( Arg ) != 0 ) Conf_OperCanMode = TRUE;
679 else Conf_OperCanMode = FALSE;
682 if( strcasecmp( Var, "MaxConnections" ) == 0 )
684 /* Maximum number of connections. Values <= 0 are equal to "no limit". */
686 if( ! isdigit( *Arg )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"MaxConnections\" is not a number!", NGIRCd_ConfFile, Line );
689 Conf_MaxConnections = atol( Arg );
692 if( strcasecmp( Var, "MaxJoins" ) == 0 )
694 /* Maximum number of channels a user can join. Values <= 0 are equal to "no limit". */
696 if( ! isdigit( *Arg )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"MaxJoins\" is not a number!", NGIRCd_ConfFile, Line );
699 Conf_MaxJoins = atoi( Arg );
703 Config_Error( LOG_ERR, "%s, line %d (section \"Global\"): Unknown variable \"%s\"!", NGIRCd_ConfFile, Line, Var );
704 } /* Handle_GLOBAL */
708 Handle_OPERATOR( INT Line, CHAR *Var, CHAR *Arg )
711 assert( Var != NULL );
712 assert( Arg != NULL );
713 assert( Conf_Oper_Count > 0 );
715 if( strcasecmp( Var, "Name" ) == 0 )
717 /* Name of IRC operator */
718 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 );
721 if( strcasecmp( Var, "Password" ) == 0 )
723 /* Password of IRC operator */
724 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 );
728 Config_Error( LOG_ERR, "%s, line %d (section \"Operator\"): Unknown variable \"%s\"!", NGIRCd_ConfFile, Line, Var );
729 } /* Handle_OPERATOR */
733 Handle_SERVER( INT Line, CHAR *Var, CHAR *Arg )
738 assert( Var != NULL );
739 assert( Arg != NULL );
741 /* Ignore server block if no space is left in server configuration structure */
742 if( New_Server_Idx <= NONE ) return;
744 if( strcasecmp( Var, "Host" ) == 0 )
746 /* Hostname of the server */
747 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 );
750 if( strcasecmp( Var, "Name" ) == 0 )
752 /* Name of the server ("Nick"/"ID") */
753 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 );
756 if( strcasecmp( Var, "MyPassword" ) == 0 )
758 /* Password of this server which is sent to the peer */
759 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 );
762 if( strcasecmp( Var, "PeerPassword" ) == 0 )
764 /* Passwort of the peer which must be received */
765 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 );
768 if( strcasecmp( Var, "Port" ) == 0 )
770 /* Port to which this server should connect */
772 if( port > 0 && port < 0xFFFF ) New_Server.port = (INT)port;
773 else Config_Error( LOG_ERR, "%s, line %d (section \"Server\"): Illegal port number %ld!", NGIRCd_ConfFile, Line, port );
776 if( strcasecmp( Var, "Group" ) == 0 )
780 if( ! isdigit( *Arg )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"Group\" is not a number!", NGIRCd_ConfFile, Line );
783 New_Server.group = atoi( Arg );
787 Config_Error( LOG_ERR, "%s, line %d (section \"Server\"): Unknown variable \"%s\"!", NGIRCd_ConfFile, Line, Var );
788 } /* Handle_SERVER */
792 Handle_CHANNEL( INT Line, CHAR *Var, CHAR *Arg )
795 assert( Var != NULL );
796 assert( Arg != NULL );
798 if( strcasecmp( Var, "Name" ) == 0 )
800 /* Name of the channel */
801 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 );
804 if( strcasecmp( Var, "Modes" ) == 0 )
807 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 );
810 if( strcasecmp( Var, "Topic" ) == 0 )
813 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 );
817 Config_Error( LOG_ERR, "%s, line %d (section \"Channel\"): Unknown variable \"%s\"!", NGIRCd_ConfFile, Line, Var );
818 } /* Handle_CHANNEL */
822 Validate_Config( BOOLEAN Configtest )
824 /* Validate configuration settings. */
827 INT i, servers, servers_once;
830 if( ! Conf_ServerName[0] )
832 /* No server name configured! */
833 Config_Error( LOG_ALERT, "No server name configured in \"%s\" ('ServerName')!", NGIRCd_ConfFile );
836 Config_Error( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE );
842 if( ! Conf_ServerAdminMail[0] )
844 /* No administrative contact configured! */
845 Config_Error( LOG_ALERT, "No administrator email address configured in \"%s\" ('AdminEMail')!", NGIRCd_ConfFile );
848 Config_Error( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE );
854 if( ! Conf_ServerAdmin1[0] && ! Conf_ServerAdmin2[0] && ! Conf_ServerAdminMail[0] )
856 /* No administrative information configured! */
857 Config_Error( LOG_WARNING, "No administrative information configured but required by RFC!" );
860 if(( Conf_MaxConnections > (LONG)FD_SETSIZE ) || ( Conf_MaxConnections < 1 ))
862 Conf_MaxConnections = (LONG)FD_SETSIZE;
863 Config_Error( LOG_ERR, "Setting MaxConnections to %ld, select() can't handle more file descriptors!", Conf_MaxConnections );
866 Config_Error( LOG_WARN, "Don't know how many file descriptors select() can handle on this system, don't set MaxConnections too high!" );
870 servers = servers_once = 0;
871 for( i = 0; i < MAX_SERVERS; i++ )
873 if( Conf_Server[i].name[0] )
876 if( Conf_Server[i].flags & CONF_SFLAG_ONCE ) servers_once++;
879 Log( LOG_DEBUG, "Configuration: Operators=%d, Servers=%d[%d], Channels=%d", Conf_Oper_Count, servers, servers_once, Conf_Channel_Count );
881 } /* Validate_Config */
885 LOCAL VOID Config_Error( CONST INT Level, CONST CHAR *Format, ... )
887 LOCAL VOID Config_Error( Level, Format, va_alist )
893 /* Error! Write to console and/or logfile. */
895 CHAR msg[MAX_LOG_MSG_LEN];
898 assert( Format != NULL );
901 va_start( ap, Format );
905 vsnprintf( msg, MAX_LOG_MSG_LEN, Format, ap );
908 /* During "normal operations" the log functions of the daemon should
909 * be used, but during testing of the configuration file, all messages
910 * should go directly to the console: */
911 if( Use_Log ) Log( Level, "%s", msg );
917 Init_Server_Struct( CONF_SERVER *Server )
919 /* Initialize server configuration structur to default values */
921 assert( Server != NULL );
923 strcpy( Server->host, "" );
924 strcpy( Server->ip, "" );
925 strcpy( Server->name, "" );
926 strcpy( Server->pwd_in, "" );
927 strcpy( Server->pwd_out, "" );
929 Server->group = NONE;
930 Server->lasttry = time( NULL ) - Conf_ConnectRetry + STARTUP_DELAY;
931 Server->res_stat = NULL;
932 if( NGIRCd_Passive ) Server->flags = CONF_SFLAG_DISABLED;
933 else Server->flags = 0;
934 Server->conn_id = NONE;
935 } /* Init_Server_Struct */