2 cbc1e59f 2001-12-12 alex * ngIRCd -- The Next Generation IRC Daemon
3 6725d789 2002-12-12 alex * Copyright (c)2001,2002 Alexander Barton (alex@barton.de)
5 6725d789 2002-12-12 alex * This program is free software; you can redistribute it and/or modify
6 6725d789 2002-12-12 alex * it under the terms of the GNU General Public License as published by
7 6725d789 2002-12-12 alex * the Free Software Foundation; either version 2 of the License, or
8 6725d789 2002-12-12 alex * (at your option) any later version.
9 6725d789 2002-12-12 alex * Please read the file COPYING, README and AUTHORS for more information.
11 6725d789 2002-12-12 alex * Configuration management (reading, parsing & validation)
15 ca33cbda 2002-03-12 alex #include "portab.h"
17 77faf14b 2005-04-16 fw static char UNUSED id[] = "$Id: conf.c,v 1.76 2005/04/16 09:23:01 fw Exp $";
19 ca33cbda 2002-03-12 alex #include "imp.h"
20 cbc1e59f 2001-12-12 alex #include <assert.h>
21 9856253d 2001-12-30 alex #include <errno.h>
22 c1f32e82 2004-10-20 alex #ifdef PROTOTYPES
23 c1f32e82 2004-10-20 alex # include <stdarg.h>
25 c1f32e82 2004-10-20 alex # include <varargs.h>
27 9856253d 2001-12-30 alex #include <stdio.h>
28 b20fa7c6 2002-01-01 alex #include <stdlib.h>
29 9856253d 2001-12-30 alex #include <string.h>
30 cdb694ae 2004-01-17 alex #include <strings.h>
31 f86083a0 2002-03-27 alex #include <unistd.h>
32 ae39724a 2002-11-08 alex #include <pwd.h>
33 ae39724a 2002-11-08 alex #include <grp.h>
34 ae39724a 2002-11-08 alex #include <sys/types.h>
35 b7be46ed 2002-12-18 alex #include <unistd.h>
37 2e02da29 2002-11-30 alex #ifdef HAVE_CTYPE_H
38 2e02da29 2002-11-30 alex # include <ctype.h>
41 f86083a0 2002-03-27 alex #include "ngircd.h"
42 c2f60abe 2002-05-27 alex #include "conn.h"
43 9856253d 2001-12-30 alex #include "client.h"
44 ca33cbda 2002-03-12 alex #include "defines.h"
45 9856253d 2001-12-30 alex #include "log.h"
46 c2f60abe 2002-05-27 alex #include "resolve.h"
47 9856253d 2001-12-30 alex #include "tool.h"
49 ca33cbda 2002-03-12 alex #include "exp.h"
50 cbc1e59f 2001-12-12 alex #include "conf.h"
53 8adff592 2005-03-19 fw LOCAL bool Use_Log = true;
54 a2544e49 2002-12-30 alex LOCAL CONF_SERVER New_Server;
55 8adff592 2005-03-19 fw LOCAL int New_Server_Idx;
58 8adff592 2005-03-19 fw LOCAL void Set_Defaults PARAMS(( bool InitServers ));
59 8adff592 2005-03-19 fw LOCAL void Read_Config PARAMS(( void ));
60 8adff592 2005-03-19 fw LOCAL void Validate_Config PARAMS(( bool TestOnly ));
62 8adff592 2005-03-19 fw LOCAL void Handle_GLOBAL PARAMS(( int Line, char *Var, char *Arg ));
63 8adff592 2005-03-19 fw LOCAL void Handle_OPERATOR PARAMS(( int Line, char *Var, char *Arg ));
64 8adff592 2005-03-19 fw LOCAL void Handle_SERVER PARAMS(( int Line, char *Var, char *Arg ));
65 8adff592 2005-03-19 fw LOCAL void Handle_CHANNEL PARAMS(( int Line, char *Var, char *Arg ));
67 8adff592 2005-03-19 fw LOCAL void Config_Error PARAMS(( const int Level, const char *Format, ... ));
69 8adff592 2005-03-19 fw LOCAL void Config_Error_NaN PARAMS(( const int LINE, const char *Value ));
70 8adff592 2005-03-19 fw LOCAL void Config_Error_TooLong PARAMS(( const int LINE, const char *Value ));
72 8adff592 2005-03-19 fw LOCAL void Init_Server_Struct PARAMS(( CONF_SERVER *Server ));
76 8adff592 2005-03-19 fw Conf_Init( void )
78 8adff592 2005-03-19 fw Set_Defaults( true );
79 f86083a0 2002-03-27 alex Read_Config( );
80 8adff592 2005-03-19 fw Validate_Config( false );
81 f86083a0 2002-03-27 alex } /* Config_Init */
85 8adff592 2005-03-19 fw Conf_Rehash( void )
87 8adff592 2005-03-19 fw Set_Defaults( false );
88 a2544e49 2002-12-30 alex Read_Config( );
89 8adff592 2005-03-19 fw Validate_Config( false );
90 a2544e49 2002-12-30 alex } /* Config_Rehash */
94 8adff592 2005-03-19 fw Conf_Test( void )
96 6725d789 2002-12-12 alex /* Read configuration, validate and output it. */
98 ae39724a 2002-11-08 alex struct passwd *pwd;
99 ae39724a 2002-11-08 alex struct group *grp;
102 8adff592 2005-03-19 fw Use_Log = false;
103 8adff592 2005-03-19 fw Set_Defaults( true );
105 f86083a0 2002-03-27 alex Read_Config( );
106 8adff592 2005-03-19 fw Validate_Config( true );
108 f6df13d5 2005-03-22 alex /* If stdin and stdout ("you can read our nice message and we can
109 f6df13d5 2005-03-22 alex * read in your keypress") are valid tty's, wait for a key: */
110 f6df13d5 2005-03-22 alex if( isatty( fileno( stdin )) && isatty( fileno( stdout )))
112 f86083a0 2002-03-27 alex puts( "OK, press enter to see a dump of your service configuration ..." );
113 f86083a0 2002-03-27 alex getchar( );
115 f86083a0 2002-03-27 alex else puts( "Ok, dump of your server configuration follows:\n" );
117 f86083a0 2002-03-27 alex puts( "[GLOBAL]" );
118 1e692e58 2004-09-24 alex printf( " Name = %s\n", Conf_ServerName );
119 1e692e58 2004-09-24 alex printf( " Info = %s\n", Conf_ServerInfo );
120 0e01a37a 2003-04-27 alex printf( " Password = %s\n", Conf_ServerPwd );
121 b615d128 2002-09-16 alex printf( " AdminInfo1 = %s\n", Conf_ServerAdmin1 );
122 b615d128 2002-09-16 alex printf( " AdminInfo2 = %s\n", Conf_ServerAdmin2 );
123 b615d128 2002-09-16 alex printf( " AdminEMail = %s\n", Conf_ServerAdminMail );
124 f86083a0 2002-03-27 alex printf( " MotdFile = %s\n", Conf_MotdFile );
125 7281b8dd 2004-05-07 alex printf( " MotdPhrase = %s\n", Conf_MotdPhrase );
126 112102b1 2005-02-04 alex printf( " ChrootDir = %s\n", Conf_Chroot );
127 112102b1 2005-02-04 alex printf( " PidFile = %s\n", Conf_PidFile);
128 7bbdfb3d 2002-11-18 alex printf( " Ports = " );
129 f86083a0 2002-03-27 alex for( i = 0; i < Conf_ListenPorts_Count; i++ )
131 f86083a0 2002-03-27 alex if( i != 0 ) printf( ", " );
132 326607ee 2005-03-20 fw printf( "%u", (unsigned int) Conf_ListenPorts[i] );
134 1c2d0ae5 2002-03-29 alex puts( "" );
135 e33ab903 2003-09-11 alex printf( " Listen = %s\n", Conf_ListenAddress );
136 ae39724a 2002-11-08 alex pwd = getpwuid( Conf_UID );
137 ae39724a 2002-11-08 alex if( pwd ) printf( " ServerUID = %s\n", pwd->pw_name );
138 8adff592 2005-03-19 fw else printf( " ServerUID = %ld\n", (long)Conf_UID );
139 ae39724a 2002-11-08 alex grp = getgrgid( Conf_GID );
140 ae39724a 2002-11-08 alex if( grp ) printf( " ServerGID = %s\n", grp->gr_name );
141 8adff592 2005-03-19 fw else printf( " ServerGID = %ld\n", (long)Conf_GID );
142 f86083a0 2002-03-27 alex printf( " PingTimeout = %d\n", Conf_PingTimeout );
143 f86083a0 2002-03-27 alex printf( " PongTimeout = %d\n", Conf_PongTimeout );
144 f86083a0 2002-03-27 alex printf( " ConnectRetry = %d\n", Conf_ConnectRetry );
145 8adff592 2005-03-19 fw printf( " OperCanUseMode = %s\n", Conf_OperCanMode == true? "yes" : "no" );
146 8adff592 2005-03-19 fw printf( " OperServerMode = %s\n", Conf_OperServerMode == true? "yes" : "no" );
147 0d32a3b4 2002-11-02 alex if( Conf_MaxConnections > 0 ) printf( " MaxConnections = %ld\n", Conf_MaxConnections );
148 0d32a3b4 2002-11-02 alex else printf( " MaxConnections = -1\n" );
149 2981fe9e 2003-11-05 alex if( Conf_MaxConnectionsIP > 0 ) printf( " MaxConnectionsIP = %d\n", Conf_MaxConnectionsIP );
150 2981fe9e 2003-11-05 alex else printf( " MaxConnectionsIP = -1\n" );
151 8b7b23cf 2002-12-13 alex if( Conf_MaxJoins > 0 ) printf( " MaxJoins = %d\n", Conf_MaxJoins );
152 8b7b23cf 2002-12-13 alex else printf( " MaxJoins = -1\n" );
153 f86083a0 2002-03-27 alex puts( "" );
155 f86083a0 2002-03-27 alex for( i = 0; i < Conf_Oper_Count; i++ )
157 c23535bc 2002-05-22 alex if( ! Conf_Oper[i].name[0] ) continue;
159 6725d789 2002-12-12 alex /* Valid "Operator" section */
160 f86083a0 2002-03-27 alex puts( "[OPERATOR]" );
161 f86083a0 2002-03-27 alex printf( " Name = %s\n", Conf_Oper[i].name );
162 f86083a0 2002-03-27 alex printf( " Password = %s\n", Conf_Oper[i].pwd );
163 490c9d04 2005-03-02 alex if ( Conf_Oper[i].mask ) printf( " Mask = %s\n", Conf_Oper[i].mask );
164 f86083a0 2002-03-27 alex puts( "" );
167 a2544e49 2002-12-30 alex for( i = 0; i < MAX_SERVERS; i++ )
169 c23535bc 2002-05-22 alex if( ! Conf_Server[i].name[0] ) continue;
171 6725d789 2002-12-12 alex /* Valid "Server" section */
172 f86083a0 2002-03-27 alex puts( "[SERVER]" );
173 f86083a0 2002-03-27 alex printf( " Name = %s\n", Conf_Server[i].name );
174 f86083a0 2002-03-27 alex printf( " Host = %s\n", Conf_Server[i].host );
175 f86083a0 2002-03-27 alex printf( " Port = %d\n", Conf_Server[i].port );
176 b2615bcc 2002-11-19 alex printf( " MyPassword = %s\n", Conf_Server[i].pwd_in );
177 b2615bcc 2002-11-19 alex printf( " PeerPassword = %s\n", Conf_Server[i].pwd_out );
178 f86083a0 2002-03-27 alex printf( " Group = %d\n", Conf_Server[i].group );
179 f86083a0 2002-03-27 alex puts( "" );
182 040f5422 2002-05-21 alex for( i = 0; i < Conf_Channel_Count; i++ )
184 c23535bc 2002-05-22 alex if( ! Conf_Channel[i].name[0] ) continue;
186 6725d789 2002-12-12 alex /* Valid "Channel" section */
187 040f5422 2002-05-21 alex puts( "[CHANNEL]" );
188 040f5422 2002-05-21 alex printf( " Name = %s\n", Conf_Channel[i].name );
189 040f5422 2002-05-21 alex printf( " Modes = %s\n", Conf_Channel[i].modes );
190 040f5422 2002-05-21 alex printf( " Topic = %s\n", Conf_Channel[i].topic );
191 040f5422 2002-05-21 alex puts( "" );
195 f86083a0 2002-03-27 alex } /* Conf_Test */
199 a2544e49 2002-12-30 alex Conf_UnsetServer( CONN_ID Idx )
201 a2544e49 2002-12-30 alex /* Set next time for next connection attempt, if this is a server
202 a2544e49 2002-12-30 alex * link that is (still) configured here. If the server is set as
203 a2544e49 2002-12-30 alex * "once", delete it from our configuration.
204 a2544e49 2002-12-30 alex * Non-Server-Connections will be silently ignored. */
208 a2544e49 2002-12-30 alex /* Check all our configured servers */
209 a2544e49 2002-12-30 alex for( i = 0; i < MAX_SERVERS; i++ )
211 a2544e49 2002-12-30 alex if( Conf_Server[i].conn_id != Idx ) continue;
213 a2544e49 2002-12-30 alex /* Gotcha! Mark server configuration as "unused": */
214 a2544e49 2002-12-30 alex Conf_Server[i].conn_id = NONE;
216 281f7583 2002-12-31 alex if( Conf_Server[i].flags & CONF_SFLAG_ONCE )
218 a2544e49 2002-12-30 alex /* Delete configuration here */
219 a2544e49 2002-12-30 alex Init_Server_Struct( &Conf_Server[i] );
223 a2544e49 2002-12-30 alex /* Set time for next connect attempt */
224 a2544e49 2002-12-30 alex if( Conf_Server[i].lasttry < time( NULL ) - Conf_ConnectRetry )
226 a2544e49 2002-12-30 alex /* Okay, the connection was established "long enough": */
227 a2544e49 2002-12-30 alex Conf_Server[i].lasttry = time( NULL ) - Conf_ConnectRetry + RECONNECT_DELAY;
231 a2544e49 2002-12-30 alex } /* Conf_UnsetServer */
235 8adff592 2005-03-19 fw Conf_SetServer( int ConfServer, CONN_ID Idx )
237 a2544e49 2002-12-30 alex /* Set connection for specified configured server */
239 a2544e49 2002-12-30 alex assert( ConfServer > NONE );
240 a2544e49 2002-12-30 alex assert( Idx > NONE );
242 a2544e49 2002-12-30 alex Conf_Server[ConfServer].conn_id = Idx;
243 a2544e49 2002-12-30 alex } /* Conf_SetServer */
247 a2544e49 2002-12-30 alex Conf_GetServer( CONN_ID Idx )
249 a2544e49 2002-12-30 alex /* Get index of server in configuration structure */
253 a2544e49 2002-12-30 alex assert( Idx > NONE );
255 a2544e49 2002-12-30 alex for( i = 0; i < MAX_SERVERS; i++ )
257 a2544e49 2002-12-30 alex if( Conf_Server[i].conn_id == Idx ) return i;
259 a2544e49 2002-12-30 alex return NONE;
260 a2544e49 2002-12-30 alex } /* Conf_GetServer */
264 8adff592 2005-03-19 fw Conf_EnableServer( char *Name, UINT16 Port )
266 281f7583 2002-12-31 alex /* Enable specified server and adjust port */
270 281f7583 2002-12-31 alex assert( Name != NULL );
272 281f7583 2002-12-31 alex for( i = 0; i < MAX_SERVERS; i++ )
274 281f7583 2002-12-31 alex if( strcasecmp( Conf_Server[i].name, Name ) == 0 )
276 281f7583 2002-12-31 alex /* Gotcha! Set port and enable server: */
277 281f7583 2002-12-31 alex Conf_Server[i].port = Port;
278 281f7583 2002-12-31 alex Conf_Server[i].flags &= ~CONF_SFLAG_DISABLED;
282 8adff592 2005-03-19 fw return false;
283 281f7583 2002-12-31 alex } /* Conf_EnableServer */
287 8adff592 2005-03-19 fw Conf_DisableServer( char *Name )
289 281f7583 2002-12-31 alex /* Enable specified server and adjust port */
293 281f7583 2002-12-31 alex assert( Name != NULL );
295 281f7583 2002-12-31 alex for( i = 0; i < MAX_SERVERS; i++ )
297 281f7583 2002-12-31 alex if( strcasecmp( Conf_Server[i].name, Name ) == 0 )
299 281f7583 2002-12-31 alex /* Gotcha! Disable and disconnect server: */
300 281f7583 2002-12-31 alex Conf_Server[i].flags |= CONF_SFLAG_DISABLED;
301 8adff592 2005-03-19 fw if( Conf_Server[i].conn_id > NONE ) Conn_Close( Conf_Server[i].conn_id, NULL, "Server link terminated on operator request", true);
305 8adff592 2005-03-19 fw return false;
306 281f7583 2002-12-31 alex } /* Conf_DisableServer */
310 8adff592 2005-03-19 fw Conf_AddServer( char *Name, UINT16 Port, char *Host, char *MyPwd, char *PeerPwd )
312 281f7583 2002-12-31 alex /* Add new server to configuration */
316 281f7583 2002-12-31 alex assert( Name != NULL );
317 281f7583 2002-12-31 alex assert( Host != NULL );
318 281f7583 2002-12-31 alex assert( MyPwd != NULL );
319 281f7583 2002-12-31 alex assert( PeerPwd != NULL );
321 281f7583 2002-12-31 alex /* Search unused item in server configuration structure */
322 281f7583 2002-12-31 alex for( i = 0; i < MAX_SERVERS; i++ )
324 281f7583 2002-12-31 alex /* Is this item used? */
325 281f7583 2002-12-31 alex if( ! Conf_Server[i].name[0] ) break;
327 8adff592 2005-03-19 fw if( i >= MAX_SERVERS ) return false;
329 281f7583 2002-12-31 alex Init_Server_Struct( &Conf_Server[i] );
330 281f7583 2002-12-31 alex strlcpy( Conf_Server[i].name, Name, sizeof( Conf_Server[i].name ));
331 281f7583 2002-12-31 alex strlcpy( Conf_Server[i].host, Host, sizeof( Conf_Server[i].host ));
332 281f7583 2002-12-31 alex strlcpy( Conf_Server[i].pwd_out, MyPwd, sizeof( Conf_Server[i].pwd_out ));
333 281f7583 2002-12-31 alex strlcpy( Conf_Server[i].pwd_in, PeerPwd, sizeof( Conf_Server[i].pwd_in ));
334 281f7583 2002-12-31 alex Conf_Server[i].port = Port;
335 281f7583 2002-12-31 alex Conf_Server[i].flags = CONF_SFLAG_ONCE;
338 281f7583 2002-12-31 alex } /* Conf_AddServer */
342 8adff592 2005-03-19 fw Set_Defaults( bool InitServers )
344 6725d789 2002-12-12 alex /* Initialize configuration variables with default values. */
348 9856253d 2001-12-30 alex strcpy( Conf_ServerName, "" );
349 62796722 2003-03-31 alex sprintf( Conf_ServerInfo, "%s %s", PACKAGE_NAME, PACKAGE_VERSION );
350 ed406b4a 2002-01-03 alex strcpy( Conf_ServerPwd, "" );
352 b615d128 2002-09-16 alex strcpy( Conf_ServerAdmin1, "" );
353 b615d128 2002-09-16 alex strcpy( Conf_ServerAdmin2, "" );
354 b615d128 2002-09-16 alex strcpy( Conf_ServerAdminMail, "" );
356 6626395c 2002-12-26 alex strlcpy( Conf_MotdFile, SYSCONFDIR, sizeof( Conf_MotdFile ));
357 6626395c 2002-12-26 alex strlcat( Conf_MotdFile, MOTD_FILE, sizeof( Conf_MotdFile ));
359 7281b8dd 2004-05-07 alex strlcpy( Conf_MotdPhrase, MOTD_PHRASE, sizeof( Conf_MotdPhrase ));
361 7281b8dd 2004-05-07 alex strlcpy( Conf_Chroot, CHROOT_DIR, sizeof( Conf_Chroot ));
363 112102b1 2005-02-04 alex strlcpy( Conf_PidFile, PID_FILE, sizeof( Conf_PidFile ));
365 9856253d 2001-12-30 alex Conf_ListenPorts_Count = 0;
366 e33ab903 2003-09-11 alex strcpy( Conf_ListenAddress, "" );
368 1c2d0ae5 2002-03-29 alex Conf_UID = Conf_GID = 0;
370 08cf5607 2001-12-26 alex Conf_PingTimeout = 120;
371 281d8e45 2002-03-25 alex Conf_PongTimeout = 20;
373 03d971d9 2002-01-02 alex Conf_ConnectRetry = 60;
375 03d971d9 2002-01-02 alex Conf_Oper_Count = 0;
376 040f5422 2002-05-21 alex Conf_Channel_Count = 0;
378 8adff592 2005-03-19 fw Conf_OperCanMode = false;
379 8adff592 2005-03-19 fw Conf_OperServerMode = false;
381 8b7b23cf 2002-12-13 alex Conf_MaxConnections = -1;
382 2981fe9e 2003-11-05 alex Conf_MaxConnectionsIP = 5;
383 8b7b23cf 2002-12-13 alex Conf_MaxJoins = 10;
385 a2544e49 2002-12-30 alex /* Initialize server configuration structures */
386 a2544e49 2002-12-30 alex if( InitServers ) for( i = 0; i < MAX_SERVERS; Init_Server_Struct( &Conf_Server[i++] ));
387 f86083a0 2002-03-27 alex } /* Set_Defaults */
391 8adff592 2005-03-19 fw Read_Config( void )
393 6725d789 2002-12-12 alex /* Read configuration file. */
395 8adff592 2005-03-19 fw char section[LINE_LEN], str[LINE_LEN], *var, *arg, *ptr;
396 8adff592 2005-03-19 fw int line, i, n;
399 a2544e49 2002-12-30 alex /* Open configuration file */
400 f86083a0 2002-03-27 alex fd = fopen( NGIRCd_ConfFile, "r" );
403 6725d789 2002-12-12 alex /* No configuration file found! */
404 f86083a0 2002-03-27 alex Config_Error( LOG_ALERT, "Can't read configuration \"%s\": %s", NGIRCd_ConfFile, strerror( errno ));
405 62796722 2003-03-31 alex Config_Error( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME );
409 03ec91f9 2002-11-22 alex Config_Error( LOG_INFO, "Reading configuration from \"%s\" ...", NGIRCd_ConfFile );
411 a2544e49 2002-12-30 alex /* Clean up server configuration structure: mark all already
412 a2544e49 2002-12-30 alex * configured servers as "once" so that they are deleted
413 02a22611 2003-03-27 alex * after the next disconnect and delete all unused servers.
414 02a22611 2003-03-27 alex * And delete all servers which are "duplicates" of servers
415 02a22611 2003-03-27 alex * that are already marked as "once" (such servers have been
416 02a22611 2003-03-27 alex * created by the last rehash but are now useless). */
417 a2544e49 2002-12-30 alex for( i = 0; i < MAX_SERVERS; i++ )
419 a2544e49 2002-12-30 alex if( Conf_Server[i].conn_id == NONE ) Init_Server_Struct( &Conf_Server[i] );
422 02a22611 2003-03-27 alex /* This structure is in use ... */
423 02a22611 2003-03-27 alex if( Conf_Server[i].flags & CONF_SFLAG_ONCE )
425 02a22611 2003-03-27 alex /* Check for duplicates */
426 02a22611 2003-03-27 alex for( n = 0; n < MAX_SERVERS; n++ )
428 02a22611 2003-03-27 alex if( n == i ) continue;
430 02a22611 2003-03-27 alex if( Conf_Server[i].conn_id == Conf_Server[n].conn_id )
432 02a22611 2003-03-27 alex Init_Server_Struct( &Conf_Server[n] );
433 02a22611 2003-03-27 alex Log( LOG_DEBUG, "Deleted unused duplicate server %d (kept %d).", n, i );
439 02a22611 2003-03-27 alex /* Mark server as "once" */
440 02a22611 2003-03-27 alex Conf_Server[i].flags |= CONF_SFLAG_ONCE;
441 0b91df05 2003-04-20 alex Log( LOG_DEBUG, "Marked server %d as \"once\"", i );
446 a2544e49 2002-12-30 alex /* Initialize variables */
448 03d971d9 2002-01-02 alex strcpy( section, "" );
449 a2544e49 2002-12-30 alex Init_Server_Struct( &New_Server );
450 a2544e49 2002-12-30 alex New_Server_Idx = NONE;
452 a2544e49 2002-12-30 alex /* Read configuration file */
453 8adff592 2005-03-19 fw while( true )
455 804b1ec4 2001-12-31 alex if( ! fgets( str, LINE_LEN, fd )) break;
456 9856253d 2001-12-30 alex ngt_TrimStr( str );
459 6725d789 2002-12-12 alex /* Skip comments and empty lines */
460 9856253d 2001-12-30 alex if( str[0] == ';' || str[0] == '#' || str[0] == '\0' ) continue;
462 6725d789 2002-12-12 alex /* Is this the beginning of a new section? */
463 03d971d9 2002-01-02 alex if(( str[0] == '[' ) && ( str[strlen( str ) - 1] == ']' ))
465 695631b2 2002-12-26 alex strlcpy( section, str, sizeof( section ));
466 03d971d9 2002-01-02 alex if( strcasecmp( section, "[GLOBAL]" ) == 0 ) continue;
467 03d971d9 2002-01-02 alex if( strcasecmp( section, "[OPERATOR]" ) == 0 )
469 f86083a0 2002-03-27 alex if( Conf_Oper_Count + 1 > MAX_OPERATORS ) Config_Error( LOG_ERR, "Too many operators configured." );
472 6725d789 2002-12-12 alex /* Initialize new operator structure */
473 490c9d04 2005-03-02 alex Conf_Oper[Conf_Oper_Count].name[0] = '\0';
474 490c9d04 2005-03-02 alex Conf_Oper[Conf_Oper_Count].pwd[0] = '\0';
475 490c9d04 2005-03-02 alex if (Conf_Oper[Conf_Oper_Count].mask) {
476 490c9d04 2005-03-02 alex free(Conf_Oper[Conf_Oper_Count].mask );
477 490c9d04 2005-03-02 alex Conf_Oper[Conf_Oper_Count].mask = NULL;
479 03d971d9 2002-01-02 alex Conf_Oper_Count++;
483 03d971d9 2002-01-02 alex if( strcasecmp( section, "[SERVER]" ) == 0 )
485 a2544e49 2002-12-30 alex /* Check if there is already a server to add */
486 a2544e49 2002-12-30 alex if( New_Server.name[0] )
488 a2544e49 2002-12-30 alex /* Copy data to "real" server structure */
489 a2544e49 2002-12-30 alex assert( New_Server_Idx > NONE );
490 a2544e49 2002-12-30 alex Conf_Server[New_Server_Idx] = New_Server;
493 a2544e49 2002-12-30 alex /* Re-init structure for new server */
494 a2544e49 2002-12-30 alex Init_Server_Struct( &New_Server );
496 a2544e49 2002-12-30 alex /* Search unused item in server configuration structure */
497 a2544e49 2002-12-30 alex for( i = 0; i < MAX_SERVERS; i++ )
499 a2544e49 2002-12-30 alex /* Is this item used? */
500 a2544e49 2002-12-30 alex if( ! Conf_Server[i].name[0] ) break;
502 a2544e49 2002-12-30 alex if( i >= MAX_SERVERS )
504 a2544e49 2002-12-30 alex /* Oops, no free item found! */
505 a2544e49 2002-12-30 alex Config_Error( LOG_ERR, "Too many servers configured." );
506 a2544e49 2002-12-30 alex New_Server_Idx = NONE;
508 a2544e49 2002-12-30 alex else New_Server_Idx = i;
511 040f5422 2002-05-21 alex if( strcasecmp( section, "[CHANNEL]" ) == 0 )
513 040f5422 2002-05-21 alex if( Conf_Channel_Count + 1 > MAX_DEFCHANNELS ) Config_Error( LOG_ERR, "Too many pre-defined channels configured." );
516 6725d789 2002-12-12 alex /* Initialize new channel structure */
517 040f5422 2002-05-21 alex strcpy( Conf_Channel[Conf_Channel_Count].name, "" );
518 040f5422 2002-05-21 alex strcpy( Conf_Channel[Conf_Channel_Count].modes, "" );
519 040f5422 2002-05-21 alex strcpy( Conf_Channel[Conf_Channel_Count].topic, "" );
520 040f5422 2002-05-21 alex Conf_Channel_Count++;
524 f86083a0 2002-03-27 alex Config_Error( LOG_ERR, "%s, line %d: Unknown section \"%s\"!", NGIRCd_ConfFile, line, section );
525 03d971d9 2002-01-02 alex section[0] = 0x1;
527 03d971d9 2002-01-02 alex if( section[0] == 0x1 ) continue;
529 6725d789 2002-12-12 alex /* Split line into variable name and parameters */
530 9856253d 2001-12-30 alex ptr = strchr( str, '=' );
531 9856253d 2001-12-30 alex if( ! ptr )
533 f86083a0 2002-03-27 alex Config_Error( LOG_ERR, "%s, line %d: Syntax error!", NGIRCd_ConfFile, line );
536 9856253d 2001-12-30 alex *ptr = '\0';
537 9856253d 2001-12-30 alex var = str; ngt_TrimStr( var );
538 9856253d 2001-12-30 alex arg = ptr + 1; ngt_TrimStr( arg );
540 03d971d9 2002-01-02 alex if( strcasecmp( section, "[GLOBAL]" ) == 0 ) Handle_GLOBAL( line, var, arg );
541 03d971d9 2002-01-02 alex else if( strcasecmp( section, "[OPERATOR]" ) == 0 ) Handle_OPERATOR( line, var, arg );
542 03d971d9 2002-01-02 alex else if( strcasecmp( section, "[SERVER]" ) == 0 ) Handle_SERVER( line, var, arg );
543 040f5422 2002-05-21 alex else if( strcasecmp( section, "[CHANNEL]" ) == 0 ) Handle_CHANNEL( line, var, arg );
544 f86083a0 2002-03-27 alex else Config_Error( LOG_ERR, "%s, line %d: Variable \"%s\" outside section!", NGIRCd_ConfFile, line, var );
547 a2544e49 2002-12-30 alex /* Close configuration file */
548 03d971d9 2002-01-02 alex fclose( fd );
550 a2544e49 2002-12-30 alex /* Check if there is still a server to add */
551 a2544e49 2002-12-30 alex if( New_Server.name[0] )
553 a2544e49 2002-12-30 alex /* Copy data to "real" server structure */
554 a2544e49 2002-12-30 alex assert( New_Server_Idx > NONE );
555 a2544e49 2002-12-30 alex Conf_Server[New_Server_Idx] = New_Server;
558 6725d789 2002-12-12 alex /* If there are no ports configured use the default: 6667 */
559 1c99b837 2002-03-30 alex if( Conf_ListenPorts_Count < 1 )
561 1c99b837 2002-03-30 alex Conf_ListenPorts_Count = 1;
562 1c99b837 2002-03-30 alex Conf_ListenPorts[0] = 6667;
564 03d971d9 2002-01-02 alex } /* Read_Config */
568 1d08d51e 2005-03-15 alex Check_ArgIsTrue( const char *Arg )
570 8adff592 2005-03-19 fw if( strcasecmp( Arg, "yes" ) == 0 ) return true;
571 8adff592 2005-03-19 fw if( strcasecmp( Arg, "true" ) == 0 ) return true;
572 8adff592 2005-03-19 fw if( atoi( Arg ) != 0 ) return true;
574 8adff592 2005-03-19 fw return false;
575 1d08d51e 2005-03-15 alex } /* Check_ArgIsTrue */
579 8adff592 2005-03-19 fw Handle_GLOBAL( int Line, char *Var, char *Arg )
581 ae39724a 2002-11-08 alex struct passwd *pwd;
582 ae39724a 2002-11-08 alex struct group *grp;
586 03d971d9 2002-01-02 alex assert( Line > 0 );
587 03d971d9 2002-01-02 alex assert( Var != NULL );
588 03d971d9 2002-01-02 alex assert( Arg != NULL );
590 03d971d9 2002-01-02 alex if( strcasecmp( Var, "Name" ) == 0 )
592 6725d789 2002-12-12 alex /* Server name */
593 a6d7fb87 2005-01-20 alex if( strlcpy( Conf_ServerName, Arg, sizeof( Conf_ServerName )) >= sizeof( Conf_ServerName ))
594 a6d7fb87 2005-01-20 alex Config_Error_TooLong( Line, Var );
598 03d971d9 2002-01-02 alex if( strcasecmp( Var, "Info" ) == 0 )
600 6725d789 2002-12-12 alex /* Info text of server */
601 a6d7fb87 2005-01-20 alex if( strlcpy( Conf_ServerInfo, Arg, sizeof( Conf_ServerInfo )) >= sizeof( Conf_ServerInfo ))
602 a6d7fb87 2005-01-20 alex Config_Error_TooLong ( Line, Var );
606 ed406b4a 2002-01-03 alex if( strcasecmp( Var, "Password" ) == 0 )
608 6725d789 2002-12-12 alex /* Global server password */
609 a6d7fb87 2005-01-20 alex if( strlcpy( Conf_ServerPwd, Arg, sizeof( Conf_ServerPwd )) >= sizeof( Conf_ServerPwd ))
610 a6d7fb87 2005-01-20 alex Config_Error_TooLong( Line, Var );
614 b615d128 2002-09-16 alex if( strcasecmp( Var, "AdminInfo1" ) == 0 )
616 6725d789 2002-12-12 alex /* Administrative info #1 */
617 a6d7fb87 2005-01-20 alex if( strlcpy( Conf_ServerAdmin1, Arg, sizeof( Conf_ServerAdmin1 )) >= sizeof( Conf_ServerAdmin1 )) Config_Error_TooLong ( Line, Var );
620 b615d128 2002-09-16 alex if( strcasecmp( Var, "AdminInfo2" ) == 0 )
622 6725d789 2002-12-12 alex /* Administrative info #2 */
623 a6d7fb87 2005-01-20 alex if( strlcpy( Conf_ServerAdmin2, Arg, sizeof( Conf_ServerAdmin2 )) >= sizeof( Conf_ServerAdmin2 )) Config_Error_TooLong ( Line, Var );
626 b615d128 2002-09-16 alex if( strcasecmp( Var, "AdminEMail" ) == 0 )
628 6725d789 2002-12-12 alex /* Administrative email contact */
629 a6d7fb87 2005-01-20 alex if( strlcpy( Conf_ServerAdminMail, Arg, sizeof( Conf_ServerAdminMail )) >= sizeof( Conf_ServerAdminMail )) Config_Error_TooLong( Line, Var );
632 03d971d9 2002-01-02 alex if( strcasecmp( Var, "Ports" ) == 0 )
634 6725d789 2002-12-12 alex /* Ports on that the server should listen. More port numbers
635 6725d789 2002-12-12 alex * must be separated by "," */
636 03d971d9 2002-01-02 alex ptr = strtok( Arg, "," );
637 03d971d9 2002-01-02 alex while( ptr )
639 03d971d9 2002-01-02 alex ngt_TrimStr( ptr );
640 03d971d9 2002-01-02 alex port = atol( ptr );
641 f86083a0 2002-03-27 alex if( Conf_ListenPorts_Count + 1 > MAX_LISTEN_PORTS ) Config_Error( LOG_ERR, "Too many listen ports configured. Port %ld ignored.", port );
644 8adff592 2005-03-19 fw if( port > 0 && port < 0xFFFF ) Conf_ListenPorts[Conf_ListenPorts_Count++] = (UINT16)port;
645 f86083a0 2002-03-27 alex else Config_Error( LOG_ERR, "%s, line %d (section \"Global\"): Illegal port number %ld!", NGIRCd_ConfFile, Line, port );
647 03d971d9 2002-01-02 alex ptr = strtok( NULL, "," );
651 03d971d9 2002-01-02 alex if( strcasecmp( Var, "MotdFile" ) == 0 )
653 6725d789 2002-12-12 alex /* "Message of the day" (MOTD) file */
654 a6d7fb87 2005-01-20 alex if( strlcpy( Conf_MotdFile, Arg, sizeof( Conf_MotdFile )) >= sizeof( Conf_MotdFile ))
655 a6d7fb87 2005-01-20 alex Config_Error_TooLong( Line, Var );
659 7281b8dd 2004-05-07 alex if( strcasecmp( Var, "MotdPhrase" ) == 0 )
661 7281b8dd 2004-05-07 alex /* "Message of the day" phrase (instead of file) */
662 a6d7fb87 2005-01-20 alex if( strlcpy( Conf_MotdPhrase, Arg, sizeof( Conf_MotdPhrase )) >= sizeof( Conf_MotdPhrase ))
663 a6d7fb87 2005-01-20 alex Config_Error_TooLong( Line, Var );
667 7281b8dd 2004-05-07 alex if( strcasecmp( Var, "ChrootDir" ) == 0 )
669 7281b8dd 2004-05-07 alex /* directory for chroot() */
670 a6d7fb87 2005-01-20 alex if( strlcpy( Conf_Chroot, Arg, sizeof( Conf_Chroot )) >= sizeof( Conf_Chroot ))
671 a6d7fb87 2005-01-20 alex Config_Error_TooLong( Line, Var );
676 112102b1 2005-02-04 alex if ( strcasecmp( Var, "PidFile" ) == 0 )
678 112102b1 2005-02-04 alex /* name of pidfile */
679 112102b1 2005-02-04 alex if( strlcpy( Conf_PidFile, Arg, sizeof( Conf_PidFile )) >= sizeof( Conf_PidFile ))
680 112102b1 2005-02-04 alex Config_Error_TooLong( Line, Var );
685 1c2d0ae5 2002-03-29 alex if( strcasecmp( Var, "ServerUID" ) == 0 )
687 6725d789 2002-12-12 alex /* UID the daemon should switch to */
688 ae39724a 2002-11-08 alex pwd = getpwnam( Arg );
689 ae39724a 2002-11-08 alex if( pwd ) Conf_UID = pwd->pw_uid;
692 2e02da29 2002-11-30 alex #ifdef HAVE_ISDIGIT
693 8adff592 2005-03-19 fw if( ! isdigit( (int)*Arg )) Config_Error_NaN( Line, Var );
696 8adff592 2005-03-19 fw Conf_UID = (unsigned int)atoi( Arg );
700 1c2d0ae5 2002-03-29 alex if( strcasecmp( Var, "ServerGID" ) == 0 )
702 6725d789 2002-12-12 alex /* GID the daemon should use */
703 ae39724a 2002-11-08 alex grp = getgrnam( Arg );
704 ae39724a 2002-11-08 alex if( grp ) Conf_GID = grp->gr_gid;
707 2e02da29 2002-11-30 alex #ifdef HAVE_ISDIGIT
708 8adff592 2005-03-19 fw if( ! isdigit( (int)*Arg )) Config_Error_NaN( Line, Var );
711 8adff592 2005-03-19 fw Conf_GID = (unsigned int)atoi( Arg );
715 03d971d9 2002-01-02 alex if( strcasecmp( Var, "PingTimeout" ) == 0 )
717 6725d789 2002-12-12 alex /* PING timeout */
718 03d971d9 2002-01-02 alex Conf_PingTimeout = atoi( Arg );
719 2e02da29 2002-11-30 alex if( Conf_PingTimeout < 5 )
721 2e02da29 2002-11-30 alex Config_Error( LOG_WARNING, "%s, line %d: Value of \"PingTimeout\" too low!", NGIRCd_ConfFile, Line );
722 2e02da29 2002-11-30 alex Conf_PingTimeout = 5;
726 03d971d9 2002-01-02 alex if( strcasecmp( Var, "PongTimeout" ) == 0 )
728 6725d789 2002-12-12 alex /* PONG timeout */
729 03d971d9 2002-01-02 alex Conf_PongTimeout = atoi( Arg );
730 2e02da29 2002-11-30 alex if( Conf_PongTimeout < 5 )
732 2e02da29 2002-11-30 alex Config_Error( LOG_WARNING, "%s, line %d: Value of \"PongTimeout\" too low!", NGIRCd_ConfFile, Line );
733 2e02da29 2002-11-30 alex Conf_PongTimeout = 5;
737 03d971d9 2002-01-02 alex if( strcasecmp( Var, "ConnectRetry" ) == 0 )
739 6725d789 2002-12-12 alex /* Seconds between connection attempts to other servers */
740 03d971d9 2002-01-02 alex Conf_ConnectRetry = atoi( Arg );
741 2e02da29 2002-11-30 alex if( Conf_ConnectRetry < 5 )
743 2e02da29 2002-11-30 alex Config_Error( LOG_WARNING, "%s, line %d: Value of \"ConnectRetry\" too low!", NGIRCd_ConfFile, Line );
744 2e02da29 2002-11-30 alex Conf_ConnectRetry = 5;
748 7e1b3b91 2002-09-02 alex if( strcasecmp( Var, "OperCanUseMode" ) == 0 )
750 6725d789 2002-12-12 alex /* Are IRC operators allowed to use MODE in channels they aren't Op in? */
751 1d08d51e 2005-03-15 alex Conf_OperCanMode = Check_ArgIsTrue( Arg );
754 1d08d51e 2005-03-15 alex if( strcasecmp( Var, "OperServerMode" ) == 0 )
756 1d08d51e 2005-03-15 alex /* Mask IRC operator as if coming from the server? (ircd-irc2 compat hack) */
757 1d08d51e 2005-03-15 alex Conf_OperServerMode = Check_ArgIsTrue( Arg );
760 0d32a3b4 2002-11-02 alex if( strcasecmp( Var, "MaxConnections" ) == 0 )
762 6725d789 2002-12-12 alex /* Maximum number of connections. Values <= 0 are equal to "no limit". */
763 2e02da29 2002-11-30 alex #ifdef HAVE_ISDIGIT
764 8adff592 2005-03-19 fw if( ! isdigit( (int)*Arg )) Config_Error_NaN( Line, Var);
767 0d32a3b4 2002-11-02 alex Conf_MaxConnections = atol( Arg );
770 2981fe9e 2003-11-05 alex if( strcasecmp( Var, "MaxConnectionsIP" ) == 0 )
772 2981fe9e 2003-11-05 alex /* Maximum number of simoultanous connections from one IP. Values <= 0 are equal to "no limit". */
773 2981fe9e 2003-11-05 alex #ifdef HAVE_ISDIGIT
774 8adff592 2005-03-19 fw if( ! isdigit( (int)*Arg )) Config_Error_NaN( Line, Var );
777 2981fe9e 2003-11-05 alex Conf_MaxConnectionsIP = atoi( Arg );
780 8b7b23cf 2002-12-13 alex if( strcasecmp( Var, "MaxJoins" ) == 0 )
782 8b7b23cf 2002-12-13 alex /* Maximum number of channels a user can join. Values <= 0 are equal to "no limit". */
783 8b7b23cf 2002-12-13 alex #ifdef HAVE_ISDIGIT
784 8adff592 2005-03-19 fw if( ! isdigit( (int)*Arg )) Config_Error_NaN( Line, Var );
787 8b7b23cf 2002-12-13 alex Conf_MaxJoins = atoi( Arg );
790 e33ab903 2003-09-11 alex if( strcasecmp( Var, "Listen" ) == 0 )
792 e33ab903 2003-09-11 alex /* IP-Address to bind sockets */
793 e33ab903 2003-09-11 alex if( strlcpy( Conf_ListenAddress, Arg, sizeof( Conf_ListenAddress )) >= sizeof( Conf_ListenAddress ))
795 a6d7fb87 2005-01-20 alex Config_Error_TooLong( Line, Var );
800 f86083a0 2002-03-27 alex Config_Error( LOG_ERR, "%s, line %d (section \"Global\"): Unknown variable \"%s\"!", NGIRCd_ConfFile, Line, Var );
801 03d971d9 2002-01-02 alex } /* Handle_GLOBAL */
805 8adff592 2005-03-19 fw Handle_OPERATOR( int Line, char *Var, char *Arg )
807 03d971d9 2002-01-02 alex assert( Line > 0 );
808 03d971d9 2002-01-02 alex assert( Var != NULL );
809 03d971d9 2002-01-02 alex assert( Arg != NULL );
810 03d971d9 2002-01-02 alex assert( Conf_Oper_Count > 0 );
812 03d971d9 2002-01-02 alex if( strcasecmp( Var, "Name" ) == 0 )
814 6725d789 2002-12-12 alex /* Name of IRC operator */
815 a6d7fb87 2005-01-20 alex if( strlcpy( Conf_Oper[Conf_Oper_Count - 1].name, Arg, sizeof( Conf_Oper[Conf_Oper_Count - 1].name )) >= sizeof( Conf_Oper[Conf_Oper_Count - 1].name )) Config_Error_TooLong( Line, Var );
818 03d971d9 2002-01-02 alex if( strcasecmp( Var, "Password" ) == 0 )
820 6725d789 2002-12-12 alex /* Password of IRC operator */
821 a6d7fb87 2005-01-20 alex if( strlcpy( Conf_Oper[Conf_Oper_Count - 1].pwd, Arg, sizeof( Conf_Oper[Conf_Oper_Count - 1].pwd )) >= sizeof( Conf_Oper[Conf_Oper_Count - 1].pwd )) Config_Error_TooLong( Line, Var );
824 490c9d04 2005-03-02 alex if( strcasecmp( Var, "Mask" ) == 0 )
826 490c9d04 2005-03-02 alex if (Conf_Oper[Conf_Oper_Count - 1].mask) return; /* Hostname already configured */
827 77faf14b 2005-04-16 fw Conf_Oper[Conf_Oper_Count - 1].mask = strdup( Arg );
828 490c9d04 2005-03-02 alex if (! Conf_Oper[Conf_Oper_Count - 1].mask) {
829 490c9d04 2005-03-02 alex Config_Error( LOG_ERR, "%s, line %d: Cannot allocate memory for operator mask: %s", NGIRCd_ConfFile, Line, strerror(errno) );
835 f86083a0 2002-03-27 alex Config_Error( LOG_ERR, "%s, line %d (section \"Operator\"): Unknown variable \"%s\"!", NGIRCd_ConfFile, Line, Var );
836 03d971d9 2002-01-02 alex } /* Handle_OPERATOR */
840 8adff592 2005-03-19 fw Handle_SERVER( int Line, char *Var, char *Arg )
844 03d971d9 2002-01-02 alex assert( Line > 0 );
845 03d971d9 2002-01-02 alex assert( Var != NULL );
846 03d971d9 2002-01-02 alex assert( Arg != NULL );
848 a2544e49 2002-12-30 alex /* Ignore server block if no space is left in server configuration structure */
849 a2544e49 2002-12-30 alex if( New_Server_Idx <= NONE ) return;
851 03d971d9 2002-01-02 alex if( strcasecmp( Var, "Host" ) == 0 )
853 6725d789 2002-12-12 alex /* Hostname of the server */
854 a6d7fb87 2005-01-20 alex if( strlcpy( New_Server.host, Arg, sizeof( New_Server.host )) >= sizeof( New_Server.host ))
855 a6d7fb87 2005-01-20 alex Config_Error_TooLong ( Line, Var );
859 03d971d9 2002-01-02 alex if( strcasecmp( Var, "Name" ) == 0 )
861 6725d789 2002-12-12 alex /* Name of the server ("Nick"/"ID") */
862 a6d7fb87 2005-01-20 alex if( strlcpy( New_Server.name, Arg, sizeof( New_Server.name )) >= sizeof( New_Server.name ))
863 a6d7fb87 2005-01-20 alex Config_Error_TooLong( Line, Var );
866 b2615bcc 2002-11-19 alex if( strcasecmp( Var, "MyPassword" ) == 0 )
868 6725d789 2002-12-12 alex /* Password of this server which is sent to the peer */
869 a6d7fb87 2005-01-20 alex if( strlcpy( New_Server.pwd_in, Arg, sizeof( New_Server.pwd_in )) >= sizeof( New_Server.pwd_in )) Config_Error_TooLong( Line, Var );
872 b2615bcc 2002-11-19 alex if( strcasecmp( Var, "PeerPassword" ) == 0 )
874 6725d789 2002-12-12 alex /* Passwort of the peer which must be received */
875 a6d7fb87 2005-01-20 alex if( strlcpy( New_Server.pwd_out, Arg, sizeof( New_Server.pwd_out )) >= sizeof( New_Server.pwd_out )) Config_Error_TooLong( Line, Var );
878 03d971d9 2002-01-02 alex if( strcasecmp( Var, "Port" ) == 0 )
880 6725d789 2002-12-12 alex /* Port to which this server should connect */
881 03d971d9 2002-01-02 alex port = atol( Arg );
882 8adff592 2005-03-19 fw if( port > 0 && port < 0xFFFF ) New_Server.port = (UINT16)port;
883 f86083a0 2002-03-27 alex else Config_Error( LOG_ERR, "%s, line %d (section \"Server\"): Illegal port number %ld!", NGIRCd_ConfFile, Line, port );
886 d67d94ea 2002-03-10 alex if( strcasecmp( Var, "Group" ) == 0 )
888 6725d789 2002-12-12 alex /* Server group */
889 2e02da29 2002-11-30 alex #ifdef HAVE_ISDIGIT
890 8adff592 2005-03-19 fw if( ! isdigit( (int)*Arg )) Config_Error_NaN( Line, Var );
893 a2544e49 2002-12-30 alex New_Server.group = atoi( Arg );
897 f86083a0 2002-03-27 alex Config_Error( LOG_ERR, "%s, line %d (section \"Server\"): Unknown variable \"%s\"!", NGIRCd_ConfFile, Line, Var );
898 03d971d9 2002-01-02 alex } /* Handle_SERVER */
902 8adff592 2005-03-19 fw Handle_CHANNEL( int Line, char *Var, char *Arg )
904 040f5422 2002-05-21 alex assert( Line > 0 );
905 040f5422 2002-05-21 alex assert( Var != NULL );
906 040f5422 2002-05-21 alex assert( Arg != NULL );
908 040f5422 2002-05-21 alex if( strcasecmp( Var, "Name" ) == 0 )
910 6725d789 2002-12-12 alex /* Name of the channel */
911 a6d7fb87 2005-01-20 alex if( strlcpy( Conf_Channel[Conf_Channel_Count - 1].name, Arg, sizeof( Conf_Channel[Conf_Channel_Count - 1].name )) >= sizeof( Conf_Channel[Conf_Channel_Count - 1].name ))
912 a6d7fb87 2005-01-20 alex Config_Error_TooLong( Line, Var );
915 040f5422 2002-05-21 alex if( strcasecmp( Var, "Modes" ) == 0 )
917 6725d789 2002-12-12 alex /* Initial modes */
918 a6d7fb87 2005-01-20 alex if( strlcpy( Conf_Channel[Conf_Channel_Count - 1].modes, Arg, sizeof( Conf_Channel[Conf_Channel_Count - 1].modes )) >= sizeof( Conf_Channel[Conf_Channel_Count - 1].modes ))
919 a6d7fb87 2005-01-20 alex Config_Error_TooLong( Line, Var );
922 040f5422 2002-05-21 alex if( strcasecmp( Var, "Topic" ) == 0 )
924 6725d789 2002-12-12 alex /* Initial topic */
925 a6d7fb87 2005-01-20 alex if( strlcpy( Conf_Channel[Conf_Channel_Count - 1].topic, Arg, sizeof( Conf_Channel[Conf_Channel_Count - 1].topic )) >= sizeof( Conf_Channel[Conf_Channel_Count - 1].topic ))
926 a6d7fb87 2005-01-20 alex Config_Error_TooLong( Line, Var );
931 040f5422 2002-05-21 alex Config_Error( LOG_ERR, "%s, line %d (section \"Channel\"): Unknown variable \"%s\"!", NGIRCd_ConfFile, Line, Var );
932 040f5422 2002-05-21 alex } /* Handle_CHANNEL */
936 8adff592 2005-03-19 fw Validate_Config( bool Configtest )
938 6725d789 2002-12-12 alex /* Validate configuration settings. */
940 a2544e49 2002-12-30 alex #ifdef DEBUG
941 8adff592 2005-03-19 fw int i, servers, servers_once;
944 9856253d 2001-12-30 alex if( ! Conf_ServerName[0] )
946 6725d789 2002-12-12 alex /* No server name configured! */
947 05170bc9 2003-12-19 alex Config_Error( LOG_ALERT, "No server name configured in \"%s\" (section 'Global': 'Name')!", NGIRCd_ConfFile );
948 b7be46ed 2002-12-18 alex if( ! Configtest )
950 62796722 2003-03-31 alex Config_Error( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME );
955 05170bc9 2003-12-19 alex if( Conf_ServerName[0] && ! strchr( Conf_ServerName, '.' ))
957 e541da2a 2003-04-29 alex /* No dot in server name! */
958 05170bc9 2003-12-19 alex Config_Error( LOG_ALERT, "Invalid server name configured in \"%s\" (section 'Global': 'Name'): Dot missing!", NGIRCd_ConfFile );
959 e541da2a 2003-04-29 alex if( ! Configtest )
961 e541da2a 2003-04-29 alex Config_Error( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME );
966 b615d128 2002-09-16 alex #ifdef STRICT_RFC
967 12cad28e 2002-10-21 alex if( ! Conf_ServerAdminMail[0] )
969 6725d789 2002-12-12 alex /* No administrative contact configured! */
970 b615d128 2002-09-16 alex Config_Error( LOG_ALERT, "No administrator email address configured in \"%s\" ('AdminEMail')!", NGIRCd_ConfFile );
971 b7be46ed 2002-12-18 alex if( ! Configtest )
973 62796722 2003-03-31 alex Config_Error( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME );
979 33bda862 2002-09-19 alex if( ! Conf_ServerAdmin1[0] && ! Conf_ServerAdmin2[0] && ! Conf_ServerAdminMail[0] )
981 6725d789 2002-12-12 alex /* No administrative information configured! */
982 b7be46ed 2002-12-18 alex Config_Error( LOG_WARNING, "No administrative information configured but required by RFC!" );
984 b7be46ed 2002-12-18 alex #ifdef FD_SETSIZE
985 8adff592 2005-03-19 fw if(( Conf_MaxConnections > (long)FD_SETSIZE ) || ( Conf_MaxConnections < 1 ))
987 8adff592 2005-03-19 fw Conf_MaxConnections = (long)FD_SETSIZE;
988 b7be46ed 2002-12-18 alex Config_Error( LOG_ERR, "Setting MaxConnections to %ld, select() can't handle more file descriptors!", Conf_MaxConnections );
991 b7be46ed 2002-12-18 alex Config_Error( LOG_WARN, "Don't know how many file descriptors select() can handle on this system, don't set MaxConnections too high!" );
994 a2544e49 2002-12-30 alex #ifdef DEBUG
995 a2544e49 2002-12-30 alex servers = servers_once = 0;
996 a2544e49 2002-12-30 alex for( i = 0; i < MAX_SERVERS; i++ )
998 a2544e49 2002-12-30 alex if( Conf_Server[i].name[0] )
1000 a2544e49 2002-12-30 alex servers++;
1001 281f7583 2002-12-31 alex if( Conf_Server[i].flags & CONF_SFLAG_ONCE ) servers_once++;
1004 a2544e49 2002-12-30 alex Log( LOG_DEBUG, "Configuration: Operators=%d, Servers=%d[%d], Channels=%d", Conf_Oper_Count, servers, servers_once, Conf_Channel_Count );
1006 9856253d 2001-12-30 alex } /* Validate_Config */
1010 27d93d7d 2005-03-19 fw Config_Error_TooLong ( const int Line, const char *Item )
1012 a6d7fb87 2005-01-20 alex Config_Error( LOG_WARNING, "%s, line %d: Value of \"%s\" too long!", NGIRCd_ConfFile, Line, Item );
1016 27d93d7d 2005-03-19 fw Config_Error_NaN( const int Line, const char *Item )
1018 a6d7fb87 2005-01-20 alex Config_Error( LOG_WARNING, "%s, line %d: Value of \"%s\" is not a number!", NGIRCd_ConfFile, Line, Item );
1021 f7327524 2002-05-30 alex #ifdef PROTOTYPES
1022 8adff592 2005-03-19 fw LOCAL void Config_Error( const int Level, const char *Format, ... )
1024 8adff592 2005-03-19 fw LOCAL void Config_Error( Level, Format, va_alist )
1025 8adff592 2005-03-19 fw const int Level;
1026 8adff592 2005-03-19 fw const char *Format;
1030 6725d789 2002-12-12 alex /* Error! Write to console and/or logfile. */
1032 8adff592 2005-03-19 fw char msg[MAX_LOG_MSG_LEN];
1033 f86083a0 2002-03-27 alex va_list ap;
1035 f86083a0 2002-03-27 alex assert( Format != NULL );
1037 f7327524 2002-05-30 alex #ifdef PROTOTYPES
1038 f86083a0 2002-03-27 alex va_start( ap, Format );
1040 f7327524 2002-05-30 alex va_start( ap );
1042 f86083a0 2002-03-27 alex vsnprintf( msg, MAX_LOG_MSG_LEN, Format, ap );
1043 f86083a0 2002-03-27 alex va_end( ap );
1045 6725d789 2002-12-12 alex /* During "normal operations" the log functions of the daemon should
1046 6725d789 2002-12-12 alex * be used, but during testing of the configuration file, all messages
1047 6725d789 2002-12-12 alex * should go directly to the console: */
1048 ec474a4b 2002-10-04 alex if( Use_Log ) Log( Level, "%s", msg );
1049 f86083a0 2002-03-27 alex else puts( msg );
1050 f86083a0 2002-03-27 alex } /* Config_Error */
1054 a2544e49 2002-12-30 alex Init_Server_Struct( CONF_SERVER *Server )
1056 a2544e49 2002-12-30 alex /* Initialize server configuration structur to default values */
1058 a2544e49 2002-12-30 alex assert( Server != NULL );
1060 a6d7fb87 2005-01-20 alex memset( Server, 0, sizeof (CONF_SERVER) );
1062 a2544e49 2002-12-30 alex Server->group = NONE;
1063 a2544e49 2002-12-30 alex Server->lasttry = time( NULL ) - Conf_ConnectRetry + STARTUP_DELAY;
1065 281f7583 2002-12-31 alex if( NGIRCd_Passive ) Server->flags = CONF_SFLAG_DISABLED;
1067 a2544e49 2002-12-30 alex Server->conn_id = NONE;
1068 a2544e49 2002-12-30 alex } /* Init_Server_Struct */
1071 cbc1e59f 2001-12-12 alex /* -eof- */