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.64 2004/05/07 11:19:21 alex Exp $";
30 #include <sys/types.h>
49 LOCAL BOOLEAN Use_Log = TRUE;
50 LOCAL CONF_SERVER New_Server;
51 LOCAL INT New_Server_Idx;
54 LOCAL VOID Set_Defaults PARAMS(( BOOLEAN InitServers ));
55 LOCAL VOID Read_Config PARAMS(( VOID ));
56 LOCAL VOID Validate_Config PARAMS(( BOOLEAN TestOnly ));
58 LOCAL VOID Handle_GLOBAL PARAMS(( INT Line, CHAR *Var, CHAR *Arg ));
59 LOCAL VOID Handle_OPERATOR PARAMS(( INT Line, CHAR *Var, CHAR *Arg ));
60 LOCAL VOID Handle_SERVER PARAMS(( INT Line, CHAR *Var, CHAR *Arg ));
61 LOCAL VOID Handle_CHANNEL PARAMS(( INT Line, CHAR *Var, CHAR *Arg ));
63 LOCAL VOID Config_Error PARAMS(( CONST INT Level, CONST CHAR *Format, ... ));
65 LOCAL VOID Init_Server_Struct PARAMS(( CONF_SERVER *Server ));
73 Validate_Config( FALSE );
80 Set_Defaults( FALSE );
82 Validate_Config( FALSE );
89 /* Read configuration, validate and output it. */
99 Validate_Config( TRUE );
101 /* If stdin is a valid tty wait for a key: */
102 if( isatty( fileno( stdout )))
104 puts( "OK, press enter to see a dump of your service configuration ..." );
107 else puts( "Ok, dump of your server configuration follows:\n" );
110 printf( " ServerName = %s\n", Conf_ServerName );
111 printf( " ServerInfo = %s\n", Conf_ServerInfo );
112 printf( " Password = %s\n", Conf_ServerPwd );
113 printf( " AdminInfo1 = %s\n", Conf_ServerAdmin1 );
114 printf( " AdminInfo2 = %s\n", Conf_ServerAdmin2 );
115 printf( " AdminEMail = %s\n", Conf_ServerAdminMail );
116 printf( " MotdFile = %s\n", Conf_MotdFile );
117 printf( " MotdPhrase = %s\n", Conf_MotdPhrase );
118 printf( " ChrootDir= %s\n", Conf_Chroot );
119 printf( " Ports = " );
120 for( i = 0; i < Conf_ListenPorts_Count; i++ )
122 if( i != 0 ) printf( ", " );
123 printf( "%u", Conf_ListenPorts[i] );
126 printf( " Listen = %s\n", Conf_ListenAddress );
127 pwd = getpwuid( Conf_UID );
128 if( pwd ) printf( " ServerUID = %s\n", pwd->pw_name );
129 else printf( " ServerUID = %ld\n", (LONG)Conf_UID );
130 grp = getgrgid( Conf_GID );
131 if( grp ) printf( " ServerGID = %s\n", grp->gr_name );
132 else printf( " ServerGID = %ld\n", (LONG)Conf_GID );
133 printf( " PingTimeout = %d\n", Conf_PingTimeout );
134 printf( " PongTimeout = %d\n", Conf_PongTimeout );
135 printf( " ConnectRetry = %d\n", Conf_ConnectRetry );
136 printf( " OperCanUseMode = %s\n", Conf_OperCanMode == TRUE ? "yes" : "no" );
137 if( Conf_MaxConnections > 0 ) printf( " MaxConnections = %ld\n", Conf_MaxConnections );
138 else printf( " MaxConnections = -1\n" );
139 if( Conf_MaxConnectionsIP > 0 ) printf( " MaxConnectionsIP = %d\n", Conf_MaxConnectionsIP );
140 else printf( " MaxConnectionsIP = -1\n" );
141 if( Conf_MaxJoins > 0 ) printf( " MaxJoins = %d\n", Conf_MaxJoins );
142 else printf( " MaxJoins = -1\n" );
145 for( i = 0; i < Conf_Oper_Count; i++ )
147 if( ! Conf_Oper[i].name[0] ) continue;
149 /* Valid "Operator" section */
150 puts( "[OPERATOR]" );
151 printf( " Name = %s\n", Conf_Oper[i].name );
152 printf( " Password = %s\n", Conf_Oper[i].pwd );
156 for( i = 0; i < MAX_SERVERS; i++ )
158 if( ! Conf_Server[i].name[0] ) continue;
160 /* Valid "Server" section */
162 printf( " Name = %s\n", Conf_Server[i].name );
163 printf( " Host = %s\n", Conf_Server[i].host );
164 printf( " Port = %d\n", Conf_Server[i].port );
165 printf( " MyPassword = %s\n", Conf_Server[i].pwd_in );
166 printf( " PeerPassword = %s\n", Conf_Server[i].pwd_out );
167 printf( " Group = %d\n", Conf_Server[i].group );
171 for( i = 0; i < Conf_Channel_Count; i++ )
173 if( ! Conf_Channel[i].name[0] ) continue;
175 /* Valid "Channel" section */
177 printf( " Name = %s\n", Conf_Channel[i].name );
178 printf( " Modes = %s\n", Conf_Channel[i].modes );
179 printf( " Topic = %s\n", Conf_Channel[i].topic );
188 Conf_UnsetServer( CONN_ID Idx )
190 /* Set next time for next connection attempt, if this is a server
191 * link that is (still) configured here. If the server is set as
192 * "once", delete it from our configuration.
193 * Non-Server-Connections will be silently ignored. */
197 /* Check all our configured servers */
198 for( i = 0; i < MAX_SERVERS; i++ )
200 if( Conf_Server[i].conn_id != Idx ) continue;
202 /* Gotcha! Mark server configuration as "unused": */
203 Conf_Server[i].conn_id = NONE;
205 if( Conf_Server[i].flags & CONF_SFLAG_ONCE )
207 /* Delete configuration here */
208 Init_Server_Struct( &Conf_Server[i] );
212 /* Set time for next connect attempt */
213 if( Conf_Server[i].lasttry < time( NULL ) - Conf_ConnectRetry )
215 /* Okay, the connection was established "long enough": */
216 Conf_Server[i].lasttry = time( NULL ) - Conf_ConnectRetry + RECONNECT_DELAY;
220 } /* Conf_UnsetServer */
224 Conf_SetServer( INT ConfServer, CONN_ID Idx )
226 /* Set connection for specified configured server */
228 assert( ConfServer > NONE );
229 assert( Idx > NONE );
231 Conf_Server[ConfServer].conn_id = Idx;
232 } /* Conf_SetServer */
236 Conf_GetServer( CONN_ID Idx )
238 /* Get index of server in configuration structure */
242 assert( Idx > NONE );
244 for( i = 0; i < MAX_SERVERS; i++ )
246 if( Conf_Server[i].conn_id == Idx ) return i;
249 } /* Conf_GetServer */
253 Conf_EnableServer( CHAR *Name, INT Port )
255 /* Enable specified server and adjust port */
259 assert( Name != NULL );
261 for( i = 0; i < MAX_SERVERS; i++ )
263 if( strcasecmp( Conf_Server[i].name, Name ) == 0 )
265 /* Gotcha! Set port and enable server: */
266 Conf_Server[i].port = Port;
267 Conf_Server[i].flags &= ~CONF_SFLAG_DISABLED;
272 } /* Conf_EnableServer */
276 Conf_DisableServer( CHAR *Name )
278 /* Enable specified server and adjust port */
282 assert( Name != NULL );
284 for( i = 0; i < MAX_SERVERS; i++ )
286 if( strcasecmp( Conf_Server[i].name, Name ) == 0 )
288 /* Gotcha! Disable and disconnect server: */
289 Conf_Server[i].flags |= CONF_SFLAG_DISABLED;
290 if( Conf_Server[i].conn_id > NONE ) Conn_Close( Conf_Server[i].conn_id, NULL, "Server link terminated on operator request", TRUE );
295 } /* Conf_DisableServer */
299 Conf_AddServer( CHAR *Name, INT Port, CHAR *Host, CHAR *MyPwd, CHAR *PeerPwd )
301 /* Add new server to configuration */
305 assert( Name != NULL );
306 assert( Host != NULL );
307 assert( MyPwd != NULL );
308 assert( PeerPwd != NULL );
310 /* Search unused item in server configuration structure */
311 for( i = 0; i < MAX_SERVERS; i++ )
313 /* Is this item used? */
314 if( ! Conf_Server[i].name[0] ) break;
316 if( i >= MAX_SERVERS ) return FALSE;
318 Init_Server_Struct( &Conf_Server[i] );
319 strlcpy( Conf_Server[i].name, Name, sizeof( Conf_Server[i].name ));
320 strlcpy( Conf_Server[i].host, Host, sizeof( Conf_Server[i].host ));
321 strlcpy( Conf_Server[i].pwd_out, MyPwd, sizeof( Conf_Server[i].pwd_out ));
322 strlcpy( Conf_Server[i].pwd_in, PeerPwd, sizeof( Conf_Server[i].pwd_in ));
323 Conf_Server[i].port = Port;
324 Conf_Server[i].flags = CONF_SFLAG_ONCE;
327 } /* Conf_AddServer */
331 Set_Defaults( BOOLEAN InitServers )
333 /* Initialize configuration variables with default values. */
337 strcpy( Conf_ServerName, "" );
338 sprintf( Conf_ServerInfo, "%s %s", PACKAGE_NAME, PACKAGE_VERSION );
339 strcpy( Conf_ServerPwd, "" );
341 strcpy( Conf_ServerAdmin1, "" );
342 strcpy( Conf_ServerAdmin2, "" );
343 strcpy( Conf_ServerAdminMail, "" );
345 strlcpy( Conf_MotdFile, SYSCONFDIR, sizeof( Conf_MotdFile ));
346 strlcat( Conf_MotdFile, MOTD_FILE, sizeof( Conf_MotdFile ));
348 strlcpy( Conf_MotdPhrase, MOTD_PHRASE, sizeof( Conf_MotdPhrase ));
350 strlcpy( Conf_Chroot, CHROOT_DIR, sizeof( Conf_Chroot ));
352 Conf_ListenPorts_Count = 0;
353 strcpy( Conf_ListenAddress, "" );
355 Conf_UID = Conf_GID = 0;
357 Conf_PingTimeout = 120;
358 Conf_PongTimeout = 20;
360 Conf_ConnectRetry = 60;
363 Conf_Channel_Count = 0;
365 Conf_OperCanMode = FALSE;
367 Conf_MaxConnections = -1;
368 Conf_MaxConnectionsIP = 5;
371 /* Initialize server configuration structures */
372 if( InitServers ) for( i = 0; i < MAX_SERVERS; Init_Server_Struct( &Conf_Server[i++] ));
379 /* Read configuration file. */
381 CHAR section[LINE_LEN], str[LINE_LEN], *var, *arg, *ptr;
385 /* Open configuration file */
386 fd = fopen( NGIRCd_ConfFile, "r" );
389 /* No configuration file found! */
390 Config_Error( LOG_ALERT, "Can't read configuration \"%s\": %s", NGIRCd_ConfFile, strerror( errno ));
391 Config_Error( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME );
395 Config_Error( LOG_INFO, "Reading configuration from \"%s\" ...", NGIRCd_ConfFile );
397 /* Clean up server configuration structure: mark all already
398 * configured servers as "once" so that they are deleted
399 * after the next disconnect and delete all unused servers.
400 * And delete all servers which are "duplicates" of servers
401 * that are already marked as "once" (such servers have been
402 * created by the last rehash but are now useless). */
403 for( i = 0; i < MAX_SERVERS; i++ )
405 if( Conf_Server[i].conn_id == NONE ) Init_Server_Struct( &Conf_Server[i] );
408 /* This structure is in use ... */
409 if( Conf_Server[i].flags & CONF_SFLAG_ONCE )
411 /* Check for duplicates */
412 for( n = 0; n < MAX_SERVERS; n++ )
414 if( n == i ) continue;
416 if( Conf_Server[i].conn_id == Conf_Server[n].conn_id )
418 Init_Server_Struct( &Conf_Server[n] );
419 Log( LOG_DEBUG, "Deleted unused duplicate server %d (kept %d).", n, i );
425 /* Mark server as "once" */
426 Conf_Server[i].flags |= CONF_SFLAG_ONCE;
427 Log( LOG_DEBUG, "Marked server %d as \"once\"", i );
432 /* Initialize variables */
434 strcpy( section, "" );
435 Init_Server_Struct( &New_Server );
436 New_Server_Idx = NONE;
438 /* Read configuration file */
441 if( ! fgets( str, LINE_LEN, fd )) break;
445 /* Skip comments and empty lines */
446 if( str[0] == ';' || str[0] == '#' || str[0] == '\0' ) continue;
448 /* Is this the beginning of a new section? */
449 if(( str[0] == '[' ) && ( str[strlen( str ) - 1] == ']' ))
451 strlcpy( section, str, sizeof( section ));
452 if( strcasecmp( section, "[GLOBAL]" ) == 0 ) continue;
453 if( strcasecmp( section, "[OPERATOR]" ) == 0 )
455 if( Conf_Oper_Count + 1 > MAX_OPERATORS ) Config_Error( LOG_ERR, "Too many operators configured." );
458 /* Initialize new operator structure */
459 strcpy( Conf_Oper[Conf_Oper_Count].name, "" );
460 strcpy( Conf_Oper[Conf_Oper_Count].pwd, "" );
465 if( strcasecmp( section, "[SERVER]" ) == 0 )
467 /* Check if there is already a server to add */
468 if( New_Server.name[0] )
470 /* Copy data to "real" server structure */
471 assert( New_Server_Idx > NONE );
472 Conf_Server[New_Server_Idx] = New_Server;
475 /* Re-init structure for new server */
476 Init_Server_Struct( &New_Server );
478 /* Search unused item in server configuration structure */
479 for( i = 0; i < MAX_SERVERS; i++ )
481 /* Is this item used? */
482 if( ! Conf_Server[i].name[0] ) break;
484 if( i >= MAX_SERVERS )
486 /* Oops, no free item found! */
487 Config_Error( LOG_ERR, "Too many servers configured." );
488 New_Server_Idx = NONE;
490 else New_Server_Idx = i;
493 if( strcasecmp( section, "[CHANNEL]" ) == 0 )
495 if( Conf_Channel_Count + 1 > MAX_DEFCHANNELS ) Config_Error( LOG_ERR, "Too many pre-defined channels configured." );
498 /* Initialize new channel structure */
499 strcpy( Conf_Channel[Conf_Channel_Count].name, "" );
500 strcpy( Conf_Channel[Conf_Channel_Count].modes, "" );
501 strcpy( Conf_Channel[Conf_Channel_Count].topic, "" );
502 Conf_Channel_Count++;
506 Config_Error( LOG_ERR, "%s, line %d: Unknown section \"%s\"!", NGIRCd_ConfFile, line, section );
509 if( section[0] == 0x1 ) continue;
511 /* Split line into variable name and parameters */
512 ptr = strchr( str, '=' );
515 Config_Error( LOG_ERR, "%s, line %d: Syntax error!", NGIRCd_ConfFile, line );
519 var = str; ngt_TrimStr( var );
520 arg = ptr + 1; ngt_TrimStr( arg );
522 if( strcasecmp( section, "[GLOBAL]" ) == 0 ) Handle_GLOBAL( line, var, arg );
523 else if( strcasecmp( section, "[OPERATOR]" ) == 0 ) Handle_OPERATOR( line, var, arg );
524 else if( strcasecmp( section, "[SERVER]" ) == 0 ) Handle_SERVER( line, var, arg );
525 else if( strcasecmp( section, "[CHANNEL]" ) == 0 ) Handle_CHANNEL( line, var, arg );
526 else Config_Error( LOG_ERR, "%s, line %d: Variable \"%s\" outside section!", NGIRCd_ConfFile, line, var );
529 /* Close configuration file */
532 /* Check if there is still a server to add */
533 if( New_Server.name[0] )
535 /* Copy data to "real" server structure */
536 assert( New_Server_Idx > NONE );
537 Conf_Server[New_Server_Idx] = New_Server;
540 /* If there are no ports configured use the default: 6667 */
541 if( Conf_ListenPorts_Count < 1 )
543 Conf_ListenPorts_Count = 1;
544 Conf_ListenPorts[0] = 6667;
550 Handle_GLOBAL( INT Line, CHAR *Var, CHAR *Arg )
558 assert( Var != NULL );
559 assert( Arg != NULL );
561 if( strcasecmp( Var, "Name" ) == 0 )
564 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 );
567 if( strcasecmp( Var, "Info" ) == 0 )
569 /* Info text of server */
570 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 );
573 if( strcasecmp( Var, "Password" ) == 0 )
575 /* Global server password */
576 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 );
579 if( strcasecmp( Var, "AdminInfo1" ) == 0 )
581 /* Administrative info #1 */
582 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 );
585 if( strcasecmp( Var, "AdminInfo2" ) == 0 )
587 /* Administrative info #2 */
588 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 );
591 if( strcasecmp( Var, "AdminEMail" ) == 0 )
593 /* Administrative email contact */
594 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 );
597 if( strcasecmp( Var, "Ports" ) == 0 )
599 /* Ports on that the server should listen. More port numbers
600 * must be separated by "," */
601 ptr = strtok( Arg, "," );
606 if( Conf_ListenPorts_Count + 1 > MAX_LISTEN_PORTS ) Config_Error( LOG_ERR, "Too many listen ports configured. Port %ld ignored.", port );
609 if( port > 0 && port < 0xFFFF ) Conf_ListenPorts[Conf_ListenPorts_Count++] = (UINT)port;
610 else Config_Error( LOG_ERR, "%s, line %d (section \"Global\"): Illegal port number %ld!", NGIRCd_ConfFile, Line, port );
612 ptr = strtok( NULL, "," );
616 if( strcasecmp( Var, "MotdFile" ) == 0 )
618 /* "Message of the day" (MOTD) file */
619 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 );
622 if( strcasecmp( Var, "MotdPhrase" ) == 0 )
624 /* "Message of the day" phrase (instead of file) */
625 if( strlcpy( Conf_MotdPhrase, Arg, sizeof( Conf_MotdPhrase )) >= sizeof( Conf_MotdPhrase )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"MotdPhrase\" too long!", NGIRCd_ConfFile, Line );
628 if( strcasecmp( Var, "ChrootDir" ) == 0 )
630 /* directory for chroot() */
631 if( strlcpy( Conf_Chroot, Arg, sizeof( Conf_Chroot )) >= sizeof( Conf_Chroot )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"ChrootDir\" too long!", NGIRCd_ConfFile, Line );
634 if( strcasecmp( Var, "ServerUID" ) == 0 )
636 /* UID the daemon should switch to */
637 pwd = getpwnam( Arg );
638 if( pwd ) Conf_UID = pwd->pw_uid;
642 if( ! isdigit( (INT)*Arg )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"ServerUID\" is not a number!", NGIRCd_ConfFile, Line );
645 Conf_UID = (UINT)atoi( Arg );
649 if( strcasecmp( Var, "ServerGID" ) == 0 )
651 /* GID the daemon should use */
652 grp = getgrnam( Arg );
653 if( grp ) Conf_GID = grp->gr_gid;
657 if( ! isdigit( (INT)*Arg )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"ServerGID\" is not a number!", NGIRCd_ConfFile, Line );
660 Conf_GID = (UINT)atoi( Arg );
664 if( strcasecmp( Var, "PingTimeout" ) == 0 )
667 Conf_PingTimeout = atoi( Arg );
668 if( Conf_PingTimeout < 5 )
670 Config_Error( LOG_WARNING, "%s, line %d: Value of \"PingTimeout\" too low!", NGIRCd_ConfFile, Line );
671 Conf_PingTimeout = 5;
675 if( strcasecmp( Var, "PongTimeout" ) == 0 )
678 Conf_PongTimeout = atoi( Arg );
679 if( Conf_PongTimeout < 5 )
681 Config_Error( LOG_WARNING, "%s, line %d: Value of \"PongTimeout\" too low!", NGIRCd_ConfFile, Line );
682 Conf_PongTimeout = 5;
686 if( strcasecmp( Var, "ConnectRetry" ) == 0 )
688 /* Seconds between connection attempts to other servers */
689 Conf_ConnectRetry = atoi( Arg );
690 if( Conf_ConnectRetry < 5 )
692 Config_Error( LOG_WARNING, "%s, line %d: Value of \"ConnectRetry\" too low!", NGIRCd_ConfFile, Line );
693 Conf_ConnectRetry = 5;
697 if( strcasecmp( Var, "OperCanUseMode" ) == 0 )
699 /* Are IRC operators allowed to use MODE in channels they aren't Op in? */
700 if( strcasecmp( Arg, "yes" ) == 0 ) Conf_OperCanMode = TRUE;
701 else if( strcasecmp( Arg, "true" ) == 0 ) Conf_OperCanMode = TRUE;
702 else if( atoi( Arg ) != 0 ) Conf_OperCanMode = TRUE;
703 else Conf_OperCanMode = FALSE;
706 if( strcasecmp( Var, "MaxConnections" ) == 0 )
708 /* Maximum number of connections. Values <= 0 are equal to "no limit". */
710 if( ! isdigit( (INT)*Arg )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"MaxConnections\" is not a number!", NGIRCd_ConfFile, Line );
713 Conf_MaxConnections = atol( Arg );
716 if( strcasecmp( Var, "MaxConnectionsIP" ) == 0 )
718 /* Maximum number of simoultanous connections from one IP. Values <= 0 are equal to "no limit". */
720 if( ! isdigit( (INT)*Arg )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"MaxConnectionsIP\" is not a number!", NGIRCd_ConfFile, Line );
723 Conf_MaxConnectionsIP = atoi( Arg );
726 if( strcasecmp( Var, "MaxJoins" ) == 0 )
728 /* Maximum number of channels a user can join. Values <= 0 are equal to "no limit". */
730 if( ! isdigit( (INT)*Arg )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"MaxJoins\" is not a number!", NGIRCd_ConfFile, Line );
733 Conf_MaxJoins = atoi( Arg );
736 if( strcasecmp( Var, "Listen" ) == 0 )
738 /* IP-Address to bind sockets */
739 if( strlcpy( Conf_ListenAddress, Arg, sizeof( Conf_ListenAddress )) >= sizeof( Conf_ListenAddress ))
741 Config_Error( LOG_WARNING, "%s, line %d: Value of \"Listen\" too long!", NGIRCd_ConfFile, Line );
746 Config_Error( LOG_ERR, "%s, line %d (section \"Global\"): Unknown variable \"%s\"!", NGIRCd_ConfFile, Line, Var );
747 } /* Handle_GLOBAL */
751 Handle_OPERATOR( INT Line, CHAR *Var, CHAR *Arg )
754 assert( Var != NULL );
755 assert( Arg != NULL );
756 assert( Conf_Oper_Count > 0 );
758 if( strcasecmp( Var, "Name" ) == 0 )
760 /* Name of IRC operator */
761 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 );
764 if( strcasecmp( Var, "Password" ) == 0 )
766 /* Password of IRC operator */
767 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 );
771 Config_Error( LOG_ERR, "%s, line %d (section \"Operator\"): Unknown variable \"%s\"!", NGIRCd_ConfFile, Line, Var );
772 } /* Handle_OPERATOR */
776 Handle_SERVER( INT Line, CHAR *Var, CHAR *Arg )
781 assert( Var != NULL );
782 assert( Arg != NULL );
784 /* Ignore server block if no space is left in server configuration structure */
785 if( New_Server_Idx <= NONE ) return;
787 if( strcasecmp( Var, "Host" ) == 0 )
789 /* Hostname of the server */
790 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 );
793 if( strcasecmp( Var, "Name" ) == 0 )
795 /* Name of the server ("Nick"/"ID") */
796 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 );
799 if( strcasecmp( Var, "MyPassword" ) == 0 )
801 /* Password of this server which is sent to the peer */
802 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 );
805 if( strcasecmp( Var, "PeerPassword" ) == 0 )
807 /* Passwort of the peer which must be received */
808 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 );
811 if( strcasecmp( Var, "Port" ) == 0 )
813 /* Port to which this server should connect */
815 if( port > 0 && port < 0xFFFF ) New_Server.port = (INT)port;
816 else Config_Error( LOG_ERR, "%s, line %d (section \"Server\"): Illegal port number %ld!", NGIRCd_ConfFile, Line, port );
819 if( strcasecmp( Var, "Group" ) == 0 )
823 if( ! isdigit( (INT)*Arg )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"Group\" is not a number!", NGIRCd_ConfFile, Line );
826 New_Server.group = atoi( Arg );
830 Config_Error( LOG_ERR, "%s, line %d (section \"Server\"): Unknown variable \"%s\"!", NGIRCd_ConfFile, Line, Var );
831 } /* Handle_SERVER */
835 Handle_CHANNEL( INT Line, CHAR *Var, CHAR *Arg )
838 assert( Var != NULL );
839 assert( Arg != NULL );
841 if( strcasecmp( Var, "Name" ) == 0 )
843 /* Name of the channel */
844 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 );
847 if( strcasecmp( Var, "Modes" ) == 0 )
850 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 );
853 if( strcasecmp( Var, "Topic" ) == 0 )
856 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 );
860 Config_Error( LOG_ERR, "%s, line %d (section \"Channel\"): Unknown variable \"%s\"!", NGIRCd_ConfFile, Line, Var );
861 } /* Handle_CHANNEL */
865 Validate_Config( BOOLEAN Configtest )
867 /* Validate configuration settings. */
870 INT i, servers, servers_once;
873 if( ! Conf_ServerName[0] )
875 /* No server name configured! */
876 Config_Error( LOG_ALERT, "No server name configured in \"%s\" (section 'Global': 'Name')!", NGIRCd_ConfFile );
879 Config_Error( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME );
884 if( Conf_ServerName[0] && ! strchr( Conf_ServerName, '.' ))
886 /* No dot in server name! */
887 Config_Error( LOG_ALERT, "Invalid server name configured in \"%s\" (section 'Global': 'Name'): Dot missing!", NGIRCd_ConfFile );
890 Config_Error( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME );
896 if( ! Conf_ServerAdminMail[0] )
898 /* No administrative contact configured! */
899 Config_Error( LOG_ALERT, "No administrator email address configured in \"%s\" ('AdminEMail')!", NGIRCd_ConfFile );
902 Config_Error( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME );
908 if( ! Conf_ServerAdmin1[0] && ! Conf_ServerAdmin2[0] && ! Conf_ServerAdminMail[0] )
910 /* No administrative information configured! */
911 Config_Error( LOG_WARNING, "No administrative information configured but required by RFC!" );
914 if(( Conf_MaxConnections > (LONG)FD_SETSIZE ) || ( Conf_MaxConnections < 1 ))
916 Conf_MaxConnections = (LONG)FD_SETSIZE;
917 Config_Error( LOG_ERR, "Setting MaxConnections to %ld, select() can't handle more file descriptors!", Conf_MaxConnections );
920 Config_Error( LOG_WARN, "Don't know how many file descriptors select() can handle on this system, don't set MaxConnections too high!" );
924 servers = servers_once = 0;
925 for( i = 0; i < MAX_SERVERS; i++ )
927 if( Conf_Server[i].name[0] )
930 if( Conf_Server[i].flags & CONF_SFLAG_ONCE ) servers_once++;
933 Log( LOG_DEBUG, "Configuration: Operators=%d, Servers=%d[%d], Channels=%d", Conf_Oper_Count, servers, servers_once, Conf_Channel_Count );
935 } /* Validate_Config */
939 LOCAL VOID Config_Error( CONST INT Level, CONST CHAR *Format, ... )
941 LOCAL VOID Config_Error( Level, Format, va_alist )
947 /* Error! Write to console and/or logfile. */
949 CHAR msg[MAX_LOG_MSG_LEN];
952 assert( Format != NULL );
955 va_start( ap, Format );
959 vsnprintf( msg, MAX_LOG_MSG_LEN, Format, ap );
962 /* During "normal operations" the log functions of the daemon should
963 * be used, but during testing of the configuration file, all messages
964 * should go directly to the console: */
965 if( Use_Log ) Log( Level, "%s", msg );
971 Init_Server_Struct( CONF_SERVER *Server )
973 /* Initialize server configuration structur to default values */
975 assert( Server != NULL );
977 strcpy( Server->host, "" );
978 strcpy( Server->ip, "" );
979 strcpy( Server->name, "" );
980 strcpy( Server->pwd_in, "" );
981 strcpy( Server->pwd_out, "" );
983 Server->group = NONE;
984 Server->lasttry = time( NULL ) - Conf_ConnectRetry + STARTUP_DELAY;
985 Server->res_stat = NULL;
986 if( NGIRCd_Passive ) Server->flags = CONF_SFLAG_DISABLED;
987 else Server->flags = 0;
988 Server->conn_id = NONE;
989 } /* Init_Server_Struct */