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 112102b1 2005-02-04 alex static char UNUSED id[] = "$Id: conf.c,v 1.68 2005/02/04 14:24:21 alex 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 f86083a0 2002-03-27 alex LOCAL BOOLEAN Use_Log = TRUE;
54 a2544e49 2002-12-30 alex LOCAL CONF_SERVER New_Server;
55 a2544e49 2002-12-30 alex LOCAL INT New_Server_Idx;
58 a2544e49 2002-12-30 alex LOCAL VOID Set_Defaults PARAMS(( BOOLEAN InitServers ));
59 c2f60abe 2002-05-27 alex LOCAL VOID Read_Config PARAMS(( VOID ));
60 b7be46ed 2002-12-18 alex LOCAL VOID Validate_Config PARAMS(( BOOLEAN TestOnly ));
62 c2f60abe 2002-05-27 alex LOCAL VOID Handle_GLOBAL PARAMS(( INT Line, CHAR *Var, CHAR *Arg ));
63 c2f60abe 2002-05-27 alex LOCAL VOID Handle_OPERATOR PARAMS(( INT Line, CHAR *Var, CHAR *Arg ));
64 c2f60abe 2002-05-27 alex LOCAL VOID Handle_SERVER PARAMS(( INT Line, CHAR *Var, CHAR *Arg ));
65 c2f60abe 2002-05-27 alex LOCAL VOID Handle_CHANNEL PARAMS(( INT Line, CHAR *Var, CHAR *Arg ));
67 c2f60abe 2002-05-27 alex LOCAL VOID Config_Error PARAMS(( CONST INT Level, CONST CHAR *Format, ... ));
69 a6d7fb87 2005-01-20 alex LOCAL VOID Config_Error_NaN PARAMS(( INT LINE, CONST CHAR *Value ));
70 a6d7fb87 2005-01-20 alex LOCAL VOID Config_Error_TooLong PARAMS(( INT LINE, CONST CHAR *Value ));
72 a2544e49 2002-12-30 alex LOCAL VOID Init_Server_Struct PARAMS(( CONF_SERVER *Server ));
76 c2f60abe 2002-05-27 alex Conf_Init( VOID )
78 a2544e49 2002-12-30 alex Set_Defaults( TRUE );
79 f86083a0 2002-03-27 alex Read_Config( );
80 b7be46ed 2002-12-18 alex Validate_Config( FALSE );
81 f86083a0 2002-03-27 alex } /* Config_Init */
85 a2544e49 2002-12-30 alex Conf_Rehash( VOID )
87 a2544e49 2002-12-30 alex Set_Defaults( FALSE );
88 a2544e49 2002-12-30 alex Read_Config( );
89 a2544e49 2002-12-30 alex Validate_Config( FALSE );
90 a2544e49 2002-12-30 alex } /* Config_Rehash */
94 c2f60abe 2002-05-27 alex 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 f86083a0 2002-03-27 alex Use_Log = FALSE;
103 a2544e49 2002-12-30 alex Set_Defaults( TRUE );
105 f86083a0 2002-03-27 alex Read_Config( );
106 b7be46ed 2002-12-18 alex Validate_Config( TRUE );
108 6725d789 2002-12-12 alex /* If stdin is a valid tty wait for a key: */
109 f86083a0 2002-03-27 alex if( isatty( fileno( stdout )))
111 f86083a0 2002-03-27 alex puts( "OK, press enter to see a dump of your service configuration ..." );
112 f86083a0 2002-03-27 alex getchar( );
114 f86083a0 2002-03-27 alex else puts( "Ok, dump of your server configuration follows:\n" );
116 f86083a0 2002-03-27 alex puts( "[GLOBAL]" );
117 1e692e58 2004-09-24 alex printf( " Name = %s\n", Conf_ServerName );
118 1e692e58 2004-09-24 alex printf( " Info = %s\n", Conf_ServerInfo );
119 0e01a37a 2003-04-27 alex printf( " Password = %s\n", Conf_ServerPwd );
120 b615d128 2002-09-16 alex printf( " AdminInfo1 = %s\n", Conf_ServerAdmin1 );
121 b615d128 2002-09-16 alex printf( " AdminInfo2 = %s\n", Conf_ServerAdmin2 );
122 b615d128 2002-09-16 alex printf( " AdminEMail = %s\n", Conf_ServerAdminMail );
123 f86083a0 2002-03-27 alex printf( " MotdFile = %s\n", Conf_MotdFile );
124 7281b8dd 2004-05-07 alex printf( " MotdPhrase = %s\n", Conf_MotdPhrase );
125 112102b1 2005-02-04 alex printf( " ChrootDir = %s\n", Conf_Chroot );
126 112102b1 2005-02-04 alex printf( " PidFile = %s\n", Conf_PidFile);
127 7bbdfb3d 2002-11-18 alex printf( " Ports = " );
128 f86083a0 2002-03-27 alex for( i = 0; i < Conf_ListenPorts_Count; i++ )
130 f86083a0 2002-03-27 alex if( i != 0 ) printf( ", " );
131 1c2d0ae5 2002-03-29 alex printf( "%u", Conf_ListenPorts[i] );
133 1c2d0ae5 2002-03-29 alex puts( "" );
134 e33ab903 2003-09-11 alex printf( " Listen = %s\n", Conf_ListenAddress );
135 ae39724a 2002-11-08 alex pwd = getpwuid( Conf_UID );
136 ae39724a 2002-11-08 alex if( pwd ) printf( " ServerUID = %s\n", pwd->pw_name );
137 ae39724a 2002-11-08 alex else printf( " ServerUID = %ld\n", (LONG)Conf_UID );
138 ae39724a 2002-11-08 alex grp = getgrgid( Conf_GID );
139 ae39724a 2002-11-08 alex if( grp ) printf( " ServerGID = %s\n", grp->gr_name );
140 ae39724a 2002-11-08 alex else printf( " ServerGID = %ld\n", (LONG)Conf_GID );
141 f86083a0 2002-03-27 alex printf( " PingTimeout = %d\n", Conf_PingTimeout );
142 f86083a0 2002-03-27 alex printf( " PongTimeout = %d\n", Conf_PongTimeout );
143 f86083a0 2002-03-27 alex printf( " ConnectRetry = %d\n", Conf_ConnectRetry );
144 7e1b3b91 2002-09-02 alex printf( " OperCanUseMode = %s\n", Conf_OperCanMode == TRUE ? "yes" : "no" );
145 0d32a3b4 2002-11-02 alex if( Conf_MaxConnections > 0 ) printf( " MaxConnections = %ld\n", Conf_MaxConnections );
146 0d32a3b4 2002-11-02 alex else printf( " MaxConnections = -1\n" );
147 2981fe9e 2003-11-05 alex if( Conf_MaxConnectionsIP > 0 ) printf( " MaxConnectionsIP = %d\n", Conf_MaxConnectionsIP );
148 2981fe9e 2003-11-05 alex else printf( " MaxConnectionsIP = -1\n" );
149 8b7b23cf 2002-12-13 alex if( Conf_MaxJoins > 0 ) printf( " MaxJoins = %d\n", Conf_MaxJoins );
150 8b7b23cf 2002-12-13 alex else printf( " MaxJoins = -1\n" );
151 f86083a0 2002-03-27 alex puts( "" );
153 f86083a0 2002-03-27 alex for( i = 0; i < Conf_Oper_Count; i++ )
155 c23535bc 2002-05-22 alex if( ! Conf_Oper[i].name[0] ) continue;
157 6725d789 2002-12-12 alex /* Valid "Operator" section */
158 f86083a0 2002-03-27 alex puts( "[OPERATOR]" );
159 f86083a0 2002-03-27 alex printf( " Name = %s\n", Conf_Oper[i].name );
160 f86083a0 2002-03-27 alex printf( " Password = %s\n", Conf_Oper[i].pwd );
161 f86083a0 2002-03-27 alex puts( "" );
164 a2544e49 2002-12-30 alex for( i = 0; i < MAX_SERVERS; i++ )
166 c23535bc 2002-05-22 alex if( ! Conf_Server[i].name[0] ) continue;
168 6725d789 2002-12-12 alex /* Valid "Server" section */
169 f86083a0 2002-03-27 alex puts( "[SERVER]" );
170 f86083a0 2002-03-27 alex printf( " Name = %s\n", Conf_Server[i].name );
171 f86083a0 2002-03-27 alex printf( " Host = %s\n", Conf_Server[i].host );
172 f86083a0 2002-03-27 alex printf( " Port = %d\n", Conf_Server[i].port );
173 b2615bcc 2002-11-19 alex printf( " MyPassword = %s\n", Conf_Server[i].pwd_in );
174 b2615bcc 2002-11-19 alex printf( " PeerPassword = %s\n", Conf_Server[i].pwd_out );
175 f86083a0 2002-03-27 alex printf( " Group = %d\n", Conf_Server[i].group );
176 f86083a0 2002-03-27 alex puts( "" );
179 040f5422 2002-05-21 alex for( i = 0; i < Conf_Channel_Count; i++ )
181 c23535bc 2002-05-22 alex if( ! Conf_Channel[i].name[0] ) continue;
183 6725d789 2002-12-12 alex /* Valid "Channel" section */
184 040f5422 2002-05-21 alex puts( "[CHANNEL]" );
185 040f5422 2002-05-21 alex printf( " Name = %s\n", Conf_Channel[i].name );
186 040f5422 2002-05-21 alex printf( " Modes = %s\n", Conf_Channel[i].modes );
187 040f5422 2002-05-21 alex printf( " Topic = %s\n", Conf_Channel[i].topic );
188 040f5422 2002-05-21 alex puts( "" );
192 f86083a0 2002-03-27 alex } /* Conf_Test */
195 a2544e49 2002-12-30 alex GLOBAL VOID
196 a2544e49 2002-12-30 alex Conf_UnsetServer( CONN_ID Idx )
198 a2544e49 2002-12-30 alex /* Set next time for next connection attempt, if this is a server
199 a2544e49 2002-12-30 alex * link that is (still) configured here. If the server is set as
200 a2544e49 2002-12-30 alex * "once", delete it from our configuration.
201 a2544e49 2002-12-30 alex * Non-Server-Connections will be silently ignored. */
205 a2544e49 2002-12-30 alex /* Check all our configured servers */
206 a2544e49 2002-12-30 alex for( i = 0; i < MAX_SERVERS; i++ )
208 a2544e49 2002-12-30 alex if( Conf_Server[i].conn_id != Idx ) continue;
210 a2544e49 2002-12-30 alex /* Gotcha! Mark server configuration as "unused": */
211 a2544e49 2002-12-30 alex Conf_Server[i].conn_id = NONE;
213 281f7583 2002-12-31 alex if( Conf_Server[i].flags & CONF_SFLAG_ONCE )
215 a2544e49 2002-12-30 alex /* Delete configuration here */
216 a2544e49 2002-12-30 alex Init_Server_Struct( &Conf_Server[i] );
220 a2544e49 2002-12-30 alex /* Set time for next connect attempt */
221 a2544e49 2002-12-30 alex if( Conf_Server[i].lasttry < time( NULL ) - Conf_ConnectRetry )
223 a2544e49 2002-12-30 alex /* Okay, the connection was established "long enough": */
224 a2544e49 2002-12-30 alex Conf_Server[i].lasttry = time( NULL ) - Conf_ConnectRetry + RECONNECT_DELAY;
228 a2544e49 2002-12-30 alex } /* Conf_UnsetServer */
231 a2544e49 2002-12-30 alex GLOBAL VOID
232 a2544e49 2002-12-30 alex Conf_SetServer( INT ConfServer, CONN_ID Idx )
234 a2544e49 2002-12-30 alex /* Set connection for specified configured server */
236 a2544e49 2002-12-30 alex assert( ConfServer > NONE );
237 a2544e49 2002-12-30 alex assert( Idx > NONE );
239 a2544e49 2002-12-30 alex Conf_Server[ConfServer].conn_id = Idx;
240 a2544e49 2002-12-30 alex } /* Conf_SetServer */
244 a2544e49 2002-12-30 alex Conf_GetServer( CONN_ID Idx )
246 a2544e49 2002-12-30 alex /* Get index of server in configuration structure */
250 a2544e49 2002-12-30 alex assert( Idx > NONE );
252 a2544e49 2002-12-30 alex for( i = 0; i < MAX_SERVERS; i++ )
254 a2544e49 2002-12-30 alex if( Conf_Server[i].conn_id == Idx ) return i;
256 a2544e49 2002-12-30 alex return NONE;
257 a2544e49 2002-12-30 alex } /* Conf_GetServer */
260 281f7583 2002-12-31 alex GLOBAL BOOLEAN
261 281f7583 2002-12-31 alex Conf_EnableServer( CHAR *Name, INT Port )
263 281f7583 2002-12-31 alex /* Enable specified server and adjust port */
267 281f7583 2002-12-31 alex assert( Name != NULL );
269 281f7583 2002-12-31 alex for( i = 0; i < MAX_SERVERS; i++ )
271 281f7583 2002-12-31 alex if( strcasecmp( Conf_Server[i].name, Name ) == 0 )
273 281f7583 2002-12-31 alex /* Gotcha! Set port and enable server: */
274 281f7583 2002-12-31 alex Conf_Server[i].port = Port;
275 281f7583 2002-12-31 alex Conf_Server[i].flags &= ~CONF_SFLAG_DISABLED;
276 281f7583 2002-12-31 alex return TRUE;
279 281f7583 2002-12-31 alex return FALSE;
280 281f7583 2002-12-31 alex } /* Conf_EnableServer */
283 281f7583 2002-12-31 alex GLOBAL BOOLEAN
284 281f7583 2002-12-31 alex Conf_DisableServer( CHAR *Name )
286 281f7583 2002-12-31 alex /* Enable specified server and adjust port */
290 281f7583 2002-12-31 alex assert( Name != NULL );
292 281f7583 2002-12-31 alex for( i = 0; i < MAX_SERVERS; i++ )
294 281f7583 2002-12-31 alex if( strcasecmp( Conf_Server[i].name, Name ) == 0 )
296 281f7583 2002-12-31 alex /* Gotcha! Disable and disconnect server: */
297 281f7583 2002-12-31 alex Conf_Server[i].flags |= CONF_SFLAG_DISABLED;
298 281f7583 2002-12-31 alex if( Conf_Server[i].conn_id > NONE ) Conn_Close( Conf_Server[i].conn_id, NULL, "Server link terminated on operator request", TRUE );
299 281f7583 2002-12-31 alex return TRUE;
302 281f7583 2002-12-31 alex return FALSE;
303 281f7583 2002-12-31 alex } /* Conf_DisableServer */
306 281f7583 2002-12-31 alex GLOBAL BOOLEAN
307 281f7583 2002-12-31 alex Conf_AddServer( CHAR *Name, INT Port, CHAR *Host, CHAR *MyPwd, CHAR *PeerPwd )
309 281f7583 2002-12-31 alex /* Add new server to configuration */
313 281f7583 2002-12-31 alex assert( Name != NULL );
314 281f7583 2002-12-31 alex assert( Host != NULL );
315 281f7583 2002-12-31 alex assert( MyPwd != NULL );
316 281f7583 2002-12-31 alex assert( PeerPwd != NULL );
318 281f7583 2002-12-31 alex /* Search unused item in server configuration structure */
319 281f7583 2002-12-31 alex for( i = 0; i < MAX_SERVERS; i++ )
321 281f7583 2002-12-31 alex /* Is this item used? */
322 281f7583 2002-12-31 alex if( ! Conf_Server[i].name[0] ) break;
324 281f7583 2002-12-31 alex if( i >= MAX_SERVERS ) return FALSE;
326 281f7583 2002-12-31 alex Init_Server_Struct( &Conf_Server[i] );
327 281f7583 2002-12-31 alex strlcpy( Conf_Server[i].name, Name, sizeof( Conf_Server[i].name ));
328 281f7583 2002-12-31 alex strlcpy( Conf_Server[i].host, Host, sizeof( Conf_Server[i].host ));
329 281f7583 2002-12-31 alex strlcpy( Conf_Server[i].pwd_out, MyPwd, sizeof( Conf_Server[i].pwd_out ));
330 281f7583 2002-12-31 alex strlcpy( Conf_Server[i].pwd_in, PeerPwd, sizeof( Conf_Server[i].pwd_in ));
331 281f7583 2002-12-31 alex Conf_Server[i].port = Port;
332 281f7583 2002-12-31 alex Conf_Server[i].flags = CONF_SFLAG_ONCE;
334 281f7583 2002-12-31 alex return TRUE;
335 281f7583 2002-12-31 alex } /* Conf_AddServer */
339 a2544e49 2002-12-30 alex Set_Defaults( BOOLEAN InitServers )
341 6725d789 2002-12-12 alex /* Initialize configuration variables with default values. */
345 9856253d 2001-12-30 alex strcpy( Conf_ServerName, "" );
346 62796722 2003-03-31 alex sprintf( Conf_ServerInfo, "%s %s", PACKAGE_NAME, PACKAGE_VERSION );
347 ed406b4a 2002-01-03 alex strcpy( Conf_ServerPwd, "" );
349 b615d128 2002-09-16 alex strcpy( Conf_ServerAdmin1, "" );
350 b615d128 2002-09-16 alex strcpy( Conf_ServerAdmin2, "" );
351 b615d128 2002-09-16 alex strcpy( Conf_ServerAdminMail, "" );
353 6626395c 2002-12-26 alex strlcpy( Conf_MotdFile, SYSCONFDIR, sizeof( Conf_MotdFile ));
354 6626395c 2002-12-26 alex strlcat( Conf_MotdFile, MOTD_FILE, sizeof( Conf_MotdFile ));
356 7281b8dd 2004-05-07 alex strlcpy( Conf_MotdPhrase, MOTD_PHRASE, sizeof( Conf_MotdPhrase ));
358 7281b8dd 2004-05-07 alex strlcpy( Conf_Chroot, CHROOT_DIR, sizeof( Conf_Chroot ));
360 112102b1 2005-02-04 alex strlcpy( Conf_PidFile, PID_FILE, sizeof( Conf_PidFile ));
362 9856253d 2001-12-30 alex Conf_ListenPorts_Count = 0;
363 e33ab903 2003-09-11 alex strcpy( Conf_ListenAddress, "" );
365 1c2d0ae5 2002-03-29 alex Conf_UID = Conf_GID = 0;
367 08cf5607 2001-12-26 alex Conf_PingTimeout = 120;
368 281d8e45 2002-03-25 alex Conf_PongTimeout = 20;
370 03d971d9 2002-01-02 alex Conf_ConnectRetry = 60;
372 03d971d9 2002-01-02 alex Conf_Oper_Count = 0;
373 040f5422 2002-05-21 alex Conf_Channel_Count = 0;
375 7e1b3b91 2002-09-02 alex Conf_OperCanMode = FALSE;
377 8b7b23cf 2002-12-13 alex Conf_MaxConnections = -1;
378 2981fe9e 2003-11-05 alex Conf_MaxConnectionsIP = 5;
379 8b7b23cf 2002-12-13 alex Conf_MaxJoins = 10;
381 a2544e49 2002-12-30 alex /* Initialize server configuration structures */
382 a2544e49 2002-12-30 alex if( InitServers ) for( i = 0; i < MAX_SERVERS; Init_Server_Struct( &Conf_Server[i++] ));
383 f86083a0 2002-03-27 alex } /* Set_Defaults */
387 c2f60abe 2002-05-27 alex Read_Config( VOID )
389 6725d789 2002-12-12 alex /* Read configuration file. */
391 03d971d9 2002-01-02 alex CHAR section[LINE_LEN], str[LINE_LEN], *var, *arg, *ptr;
392 02a22611 2003-03-27 alex INT line, i, n;
395 a2544e49 2002-12-30 alex /* Open configuration file */
396 f86083a0 2002-03-27 alex fd = fopen( NGIRCd_ConfFile, "r" );
399 6725d789 2002-12-12 alex /* No configuration file found! */
400 f86083a0 2002-03-27 alex Config_Error( LOG_ALERT, "Can't read configuration \"%s\": %s", NGIRCd_ConfFile, strerror( errno ));
401 62796722 2003-03-31 alex Config_Error( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME );
405 03ec91f9 2002-11-22 alex Config_Error( LOG_INFO, "Reading configuration from \"%s\" ...", NGIRCd_ConfFile );
407 a2544e49 2002-12-30 alex /* Clean up server configuration structure: mark all already
408 a2544e49 2002-12-30 alex * configured servers as "once" so that they are deleted
409 02a22611 2003-03-27 alex * after the next disconnect and delete all unused servers.
410 02a22611 2003-03-27 alex * And delete all servers which are "duplicates" of servers
411 02a22611 2003-03-27 alex * that are already marked as "once" (such servers have been
412 02a22611 2003-03-27 alex * created by the last rehash but are now useless). */
413 a2544e49 2002-12-30 alex for( i = 0; i < MAX_SERVERS; i++ )
415 a2544e49 2002-12-30 alex if( Conf_Server[i].conn_id == NONE ) Init_Server_Struct( &Conf_Server[i] );
418 02a22611 2003-03-27 alex /* This structure is in use ... */
419 02a22611 2003-03-27 alex if( Conf_Server[i].flags & CONF_SFLAG_ONCE )
421 02a22611 2003-03-27 alex /* Check for duplicates */
422 02a22611 2003-03-27 alex for( n = 0; n < MAX_SERVERS; n++ )
424 02a22611 2003-03-27 alex if( n == i ) continue;
426 02a22611 2003-03-27 alex if( Conf_Server[i].conn_id == Conf_Server[n].conn_id )
428 02a22611 2003-03-27 alex Init_Server_Struct( &Conf_Server[n] );
429 02a22611 2003-03-27 alex Log( LOG_DEBUG, "Deleted unused duplicate server %d (kept %d).", n, i );
435 02a22611 2003-03-27 alex /* Mark server as "once" */
436 02a22611 2003-03-27 alex Conf_Server[i].flags |= CONF_SFLAG_ONCE;
437 0b91df05 2003-04-20 alex Log( LOG_DEBUG, "Marked server %d as \"once\"", i );
442 a2544e49 2002-12-30 alex /* Initialize variables */
444 03d971d9 2002-01-02 alex strcpy( section, "" );
445 a2544e49 2002-12-30 alex Init_Server_Struct( &New_Server );
446 a2544e49 2002-12-30 alex New_Server_Idx = NONE;
448 a2544e49 2002-12-30 alex /* Read configuration file */
449 9856253d 2001-12-30 alex while( TRUE )
451 804b1ec4 2001-12-31 alex if( ! fgets( str, LINE_LEN, fd )) break;
452 9856253d 2001-12-30 alex ngt_TrimStr( str );
455 6725d789 2002-12-12 alex /* Skip comments and empty lines */
456 9856253d 2001-12-30 alex if( str[0] == ';' || str[0] == '#' || str[0] == '\0' ) continue;
458 6725d789 2002-12-12 alex /* Is this the beginning of a new section? */
459 03d971d9 2002-01-02 alex if(( str[0] == '[' ) && ( str[strlen( str ) - 1] == ']' ))
461 695631b2 2002-12-26 alex strlcpy( section, str, sizeof( section ));
462 03d971d9 2002-01-02 alex if( strcasecmp( section, "[GLOBAL]" ) == 0 ) continue;
463 03d971d9 2002-01-02 alex if( strcasecmp( section, "[OPERATOR]" ) == 0 )
465 f86083a0 2002-03-27 alex if( Conf_Oper_Count + 1 > MAX_OPERATORS ) Config_Error( LOG_ERR, "Too many operators configured." );
468 6725d789 2002-12-12 alex /* Initialize new operator structure */
469 03d971d9 2002-01-02 alex strcpy( Conf_Oper[Conf_Oper_Count].name, "" );
470 03d971d9 2002-01-02 alex strcpy( Conf_Oper[Conf_Oper_Count].pwd, "" );
471 03d971d9 2002-01-02 alex Conf_Oper_Count++;
475 03d971d9 2002-01-02 alex if( strcasecmp( section, "[SERVER]" ) == 0 )
477 a2544e49 2002-12-30 alex /* Check if there is already a server to add */
478 a2544e49 2002-12-30 alex if( New_Server.name[0] )
480 a2544e49 2002-12-30 alex /* Copy data to "real" server structure */
481 a2544e49 2002-12-30 alex assert( New_Server_Idx > NONE );
482 a2544e49 2002-12-30 alex Conf_Server[New_Server_Idx] = New_Server;
485 a2544e49 2002-12-30 alex /* Re-init structure for new server */
486 a2544e49 2002-12-30 alex Init_Server_Struct( &New_Server );
488 a2544e49 2002-12-30 alex /* Search unused item in server configuration structure */
489 a2544e49 2002-12-30 alex for( i = 0; i < MAX_SERVERS; i++ )
491 a2544e49 2002-12-30 alex /* Is this item used? */
492 a2544e49 2002-12-30 alex if( ! Conf_Server[i].name[0] ) break;
494 a2544e49 2002-12-30 alex if( i >= MAX_SERVERS )
496 a2544e49 2002-12-30 alex /* Oops, no free item found! */
497 a2544e49 2002-12-30 alex Config_Error( LOG_ERR, "Too many servers configured." );
498 a2544e49 2002-12-30 alex New_Server_Idx = NONE;
500 a2544e49 2002-12-30 alex else New_Server_Idx = i;
503 040f5422 2002-05-21 alex if( strcasecmp( section, "[CHANNEL]" ) == 0 )
505 040f5422 2002-05-21 alex if( Conf_Channel_Count + 1 > MAX_DEFCHANNELS ) Config_Error( LOG_ERR, "Too many pre-defined channels configured." );
508 6725d789 2002-12-12 alex /* Initialize new channel structure */
509 040f5422 2002-05-21 alex strcpy( Conf_Channel[Conf_Channel_Count].name, "" );
510 040f5422 2002-05-21 alex strcpy( Conf_Channel[Conf_Channel_Count].modes, "" );
511 040f5422 2002-05-21 alex strcpy( Conf_Channel[Conf_Channel_Count].topic, "" );
512 040f5422 2002-05-21 alex Conf_Channel_Count++;
516 f86083a0 2002-03-27 alex Config_Error( LOG_ERR, "%s, line %d: Unknown section \"%s\"!", NGIRCd_ConfFile, line, section );
517 03d971d9 2002-01-02 alex section[0] = 0x1;
519 03d971d9 2002-01-02 alex if( section[0] == 0x1 ) continue;
521 6725d789 2002-12-12 alex /* Split line into variable name and parameters */
522 9856253d 2001-12-30 alex ptr = strchr( str, '=' );
523 9856253d 2001-12-30 alex if( ! ptr )
525 f86083a0 2002-03-27 alex Config_Error( LOG_ERR, "%s, line %d: Syntax error!", NGIRCd_ConfFile, line );
528 9856253d 2001-12-30 alex *ptr = '\0';
529 9856253d 2001-12-30 alex var = str; ngt_TrimStr( var );
530 9856253d 2001-12-30 alex arg = ptr + 1; ngt_TrimStr( arg );
532 03d971d9 2002-01-02 alex if( strcasecmp( section, "[GLOBAL]" ) == 0 ) Handle_GLOBAL( line, var, arg );
533 03d971d9 2002-01-02 alex else if( strcasecmp( section, "[OPERATOR]" ) == 0 ) Handle_OPERATOR( line, var, arg );
534 03d971d9 2002-01-02 alex else if( strcasecmp( section, "[SERVER]" ) == 0 ) Handle_SERVER( line, var, arg );
535 040f5422 2002-05-21 alex else if( strcasecmp( section, "[CHANNEL]" ) == 0 ) Handle_CHANNEL( line, var, arg );
536 f86083a0 2002-03-27 alex else Config_Error( LOG_ERR, "%s, line %d: Variable \"%s\" outside section!", NGIRCd_ConfFile, line, var );
539 a2544e49 2002-12-30 alex /* Close configuration file */
540 03d971d9 2002-01-02 alex fclose( fd );
542 a2544e49 2002-12-30 alex /* Check if there is still a server to add */
543 a2544e49 2002-12-30 alex if( New_Server.name[0] )
545 a2544e49 2002-12-30 alex /* Copy data to "real" server structure */
546 a2544e49 2002-12-30 alex assert( New_Server_Idx > NONE );
547 a2544e49 2002-12-30 alex Conf_Server[New_Server_Idx] = New_Server;
550 6725d789 2002-12-12 alex /* If there are no ports configured use the default: 6667 */
551 1c99b837 2002-03-30 alex if( Conf_ListenPorts_Count < 1 )
553 1c99b837 2002-03-30 alex Conf_ListenPorts_Count = 1;
554 1c99b837 2002-03-30 alex Conf_ListenPorts[0] = 6667;
556 03d971d9 2002-01-02 alex } /* Read_Config */
560 c2f60abe 2002-05-27 alex Handle_GLOBAL( INT Line, CHAR *Var, CHAR *Arg )
562 ae39724a 2002-11-08 alex struct passwd *pwd;
563 ae39724a 2002-11-08 alex struct group *grp;
567 03d971d9 2002-01-02 alex assert( Line > 0 );
568 03d971d9 2002-01-02 alex assert( Var != NULL );
569 03d971d9 2002-01-02 alex assert( Arg != NULL );
571 03d971d9 2002-01-02 alex if( strcasecmp( Var, "Name" ) == 0 )
573 6725d789 2002-12-12 alex /* Server name */
574 a6d7fb87 2005-01-20 alex if( strlcpy( Conf_ServerName, Arg, sizeof( Conf_ServerName )) >= sizeof( Conf_ServerName ))
575 a6d7fb87 2005-01-20 alex Config_Error_TooLong( Line, Var );
579 03d971d9 2002-01-02 alex if( strcasecmp( Var, "Info" ) == 0 )
581 6725d789 2002-12-12 alex /* Info text of server */
582 a6d7fb87 2005-01-20 alex if( strlcpy( Conf_ServerInfo, Arg, sizeof( Conf_ServerInfo )) >= sizeof( Conf_ServerInfo ))
583 a6d7fb87 2005-01-20 alex Config_Error_TooLong ( Line, Var );
587 ed406b4a 2002-01-03 alex if( strcasecmp( Var, "Password" ) == 0 )
589 6725d789 2002-12-12 alex /* Global server password */
590 a6d7fb87 2005-01-20 alex if( strlcpy( Conf_ServerPwd, Arg, sizeof( Conf_ServerPwd )) >= sizeof( Conf_ServerPwd ))
591 a6d7fb87 2005-01-20 alex Config_Error_TooLong( Line, Var );
595 b615d128 2002-09-16 alex if( strcasecmp( Var, "AdminInfo1" ) == 0 )
597 6725d789 2002-12-12 alex /* Administrative info #1 */
598 a6d7fb87 2005-01-20 alex if( strlcpy( Conf_ServerAdmin1, Arg, sizeof( Conf_ServerAdmin1 )) >= sizeof( Conf_ServerAdmin1 )) Config_Error_TooLong ( Line, Var );
601 b615d128 2002-09-16 alex if( strcasecmp( Var, "AdminInfo2" ) == 0 )
603 6725d789 2002-12-12 alex /* Administrative info #2 */
604 a6d7fb87 2005-01-20 alex if( strlcpy( Conf_ServerAdmin2, Arg, sizeof( Conf_ServerAdmin2 )) >= sizeof( Conf_ServerAdmin2 )) Config_Error_TooLong ( Line, Var );
607 b615d128 2002-09-16 alex if( strcasecmp( Var, "AdminEMail" ) == 0 )
609 6725d789 2002-12-12 alex /* Administrative email contact */
610 a6d7fb87 2005-01-20 alex if( strlcpy( Conf_ServerAdminMail, Arg, sizeof( Conf_ServerAdminMail )) >= sizeof( Conf_ServerAdminMail )) Config_Error_TooLong( Line, Var );
613 03d971d9 2002-01-02 alex if( strcasecmp( Var, "Ports" ) == 0 )
615 6725d789 2002-12-12 alex /* Ports on that the server should listen. More port numbers
616 6725d789 2002-12-12 alex * must be separated by "," */
617 03d971d9 2002-01-02 alex ptr = strtok( Arg, "," );
618 03d971d9 2002-01-02 alex while( ptr )
620 03d971d9 2002-01-02 alex ngt_TrimStr( ptr );
621 03d971d9 2002-01-02 alex port = atol( ptr );
622 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 );
625 1c2d0ae5 2002-03-29 alex if( port > 0 && port < 0xFFFF ) Conf_ListenPorts[Conf_ListenPorts_Count++] = (UINT)port;
626 f86083a0 2002-03-27 alex else Config_Error( LOG_ERR, "%s, line %d (section \"Global\"): Illegal port number %ld!", NGIRCd_ConfFile, Line, port );
628 03d971d9 2002-01-02 alex ptr = strtok( NULL, "," );
632 03d971d9 2002-01-02 alex if( strcasecmp( Var, "MotdFile" ) == 0 )
634 6725d789 2002-12-12 alex /* "Message of the day" (MOTD) file */
635 a6d7fb87 2005-01-20 alex if( strlcpy( Conf_MotdFile, Arg, sizeof( Conf_MotdFile )) >= sizeof( Conf_MotdFile ))
636 a6d7fb87 2005-01-20 alex Config_Error_TooLong( Line, Var );
640 7281b8dd 2004-05-07 alex if( strcasecmp( Var, "MotdPhrase" ) == 0 )
642 7281b8dd 2004-05-07 alex /* "Message of the day" phrase (instead of file) */
643 a6d7fb87 2005-01-20 alex if( strlcpy( Conf_MotdPhrase, Arg, sizeof( Conf_MotdPhrase )) >= sizeof( Conf_MotdPhrase ))
644 a6d7fb87 2005-01-20 alex Config_Error_TooLong( Line, Var );
648 7281b8dd 2004-05-07 alex if( strcasecmp( Var, "ChrootDir" ) == 0 )
650 7281b8dd 2004-05-07 alex /* directory for chroot() */
651 a6d7fb87 2005-01-20 alex if( strlcpy( Conf_Chroot, Arg, sizeof( Conf_Chroot )) >= sizeof( Conf_Chroot ))
652 a6d7fb87 2005-01-20 alex Config_Error_TooLong( Line, Var );
657 112102b1 2005-02-04 alex if ( strcasecmp( Var, "PidFile" ) == 0 )
659 112102b1 2005-02-04 alex /* name of pidfile */
660 112102b1 2005-02-04 alex if( strlcpy( Conf_PidFile, Arg, sizeof( Conf_PidFile )) >= sizeof( Conf_PidFile ))
661 112102b1 2005-02-04 alex Config_Error_TooLong( Line, Var );
666 1c2d0ae5 2002-03-29 alex if( strcasecmp( Var, "ServerUID" ) == 0 )
668 6725d789 2002-12-12 alex /* UID the daemon should switch to */
669 ae39724a 2002-11-08 alex pwd = getpwnam( Arg );
670 ae39724a 2002-11-08 alex if( pwd ) Conf_UID = pwd->pw_uid;
673 2e02da29 2002-11-30 alex #ifdef HAVE_ISDIGIT
674 a6d7fb87 2005-01-20 alex if( ! isdigit( (INT)*Arg )) Config_Error_NaN( Line, Var );
677 2e02da29 2002-11-30 alex Conf_UID = (UINT)atoi( Arg );
681 1c2d0ae5 2002-03-29 alex if( strcasecmp( Var, "ServerGID" ) == 0 )
683 6725d789 2002-12-12 alex /* GID the daemon should use */
684 ae39724a 2002-11-08 alex grp = getgrnam( Arg );
685 ae39724a 2002-11-08 alex if( grp ) Conf_GID = grp->gr_gid;
688 2e02da29 2002-11-30 alex #ifdef HAVE_ISDIGIT
689 a6d7fb87 2005-01-20 alex if( ! isdigit( (INT)*Arg )) Config_Error_NaN( Line, Var );
692 2e02da29 2002-11-30 alex Conf_GID = (UINT)atoi( Arg );
696 03d971d9 2002-01-02 alex if( strcasecmp( Var, "PingTimeout" ) == 0 )
698 6725d789 2002-12-12 alex /* PING timeout */
699 03d971d9 2002-01-02 alex Conf_PingTimeout = atoi( Arg );
700 2e02da29 2002-11-30 alex if( Conf_PingTimeout < 5 )
702 2e02da29 2002-11-30 alex Config_Error( LOG_WARNING, "%s, line %d: Value of \"PingTimeout\" too low!", NGIRCd_ConfFile, Line );
703 2e02da29 2002-11-30 alex Conf_PingTimeout = 5;
707 03d971d9 2002-01-02 alex if( strcasecmp( Var, "PongTimeout" ) == 0 )
709 6725d789 2002-12-12 alex /* PONG timeout */
710 03d971d9 2002-01-02 alex Conf_PongTimeout = atoi( Arg );
711 2e02da29 2002-11-30 alex if( Conf_PongTimeout < 5 )
713 2e02da29 2002-11-30 alex Config_Error( LOG_WARNING, "%s, line %d: Value of \"PongTimeout\" too low!", NGIRCd_ConfFile, Line );
714 2e02da29 2002-11-30 alex Conf_PongTimeout = 5;
718 03d971d9 2002-01-02 alex if( strcasecmp( Var, "ConnectRetry" ) == 0 )
720 6725d789 2002-12-12 alex /* Seconds between connection attempts to other servers */
721 03d971d9 2002-01-02 alex Conf_ConnectRetry = atoi( Arg );
722 2e02da29 2002-11-30 alex if( Conf_ConnectRetry < 5 )
724 2e02da29 2002-11-30 alex Config_Error( LOG_WARNING, "%s, line %d: Value of \"ConnectRetry\" too low!", NGIRCd_ConfFile, Line );
725 2e02da29 2002-11-30 alex Conf_ConnectRetry = 5;
729 7e1b3b91 2002-09-02 alex if( strcasecmp( Var, "OperCanUseMode" ) == 0 )
731 6725d789 2002-12-12 alex /* Are IRC operators allowed to use MODE in channels they aren't Op in? */
732 7e1b3b91 2002-09-02 alex if( strcasecmp( Arg, "yes" ) == 0 ) Conf_OperCanMode = TRUE;
733 7e1b3b91 2002-09-02 alex else if( strcasecmp( Arg, "true" ) == 0 ) Conf_OperCanMode = TRUE;
734 7e1b3b91 2002-09-02 alex else if( atoi( Arg ) != 0 ) Conf_OperCanMode = TRUE;
735 7e1b3b91 2002-09-02 alex else Conf_OperCanMode = FALSE;
738 0d32a3b4 2002-11-02 alex if( strcasecmp( Var, "MaxConnections" ) == 0 )
740 6725d789 2002-12-12 alex /* Maximum number of connections. Values <= 0 are equal to "no limit". */
741 2e02da29 2002-11-30 alex #ifdef HAVE_ISDIGIT
742 a6d7fb87 2005-01-20 alex if( ! isdigit( (INT)*Arg )) Config_Error_NaN( Line, Var);
745 0d32a3b4 2002-11-02 alex Conf_MaxConnections = atol( Arg );
748 2981fe9e 2003-11-05 alex if( strcasecmp( Var, "MaxConnectionsIP" ) == 0 )
750 2981fe9e 2003-11-05 alex /* Maximum number of simoultanous connections from one IP. Values <= 0 are equal to "no limit". */
751 2981fe9e 2003-11-05 alex #ifdef HAVE_ISDIGIT
752 a6d7fb87 2005-01-20 alex if( ! isdigit( (INT)*Arg )) Config_Error_NaN( Line, Var );
755 2981fe9e 2003-11-05 alex Conf_MaxConnectionsIP = atoi( Arg );
758 8b7b23cf 2002-12-13 alex if( strcasecmp( Var, "MaxJoins" ) == 0 )
760 8b7b23cf 2002-12-13 alex /* Maximum number of channels a user can join. Values <= 0 are equal to "no limit". */
761 8b7b23cf 2002-12-13 alex #ifdef HAVE_ISDIGIT
762 a6d7fb87 2005-01-20 alex if( ! isdigit( (INT)*Arg )) Config_Error_NaN( Line, Var );
765 8b7b23cf 2002-12-13 alex Conf_MaxJoins = atoi( Arg );
768 e33ab903 2003-09-11 alex if( strcasecmp( Var, "Listen" ) == 0 )
770 e33ab903 2003-09-11 alex /* IP-Address to bind sockets */
771 e33ab903 2003-09-11 alex if( strlcpy( Conf_ListenAddress, Arg, sizeof( Conf_ListenAddress )) >= sizeof( Conf_ListenAddress ))
773 a6d7fb87 2005-01-20 alex Config_Error_TooLong( Line, Var );
778 f86083a0 2002-03-27 alex Config_Error( LOG_ERR, "%s, line %d (section \"Global\"): Unknown variable \"%s\"!", NGIRCd_ConfFile, Line, Var );
779 03d971d9 2002-01-02 alex } /* Handle_GLOBAL */
783 c2f60abe 2002-05-27 alex Handle_OPERATOR( INT Line, CHAR *Var, CHAR *Arg )
785 03d971d9 2002-01-02 alex assert( Line > 0 );
786 03d971d9 2002-01-02 alex assert( Var != NULL );
787 03d971d9 2002-01-02 alex assert( Arg != NULL );
788 03d971d9 2002-01-02 alex assert( Conf_Oper_Count > 0 );
790 03d971d9 2002-01-02 alex if( strcasecmp( Var, "Name" ) == 0 )
792 6725d789 2002-12-12 alex /* Name of IRC operator */
793 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 );
796 03d971d9 2002-01-02 alex if( strcasecmp( Var, "Password" ) == 0 )
798 6725d789 2002-12-12 alex /* Password of IRC operator */
799 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 );
803 f86083a0 2002-03-27 alex Config_Error( LOG_ERR, "%s, line %d (section \"Operator\"): Unknown variable \"%s\"!", NGIRCd_ConfFile, Line, Var );
804 03d971d9 2002-01-02 alex } /* Handle_OPERATOR */
808 c2f60abe 2002-05-27 alex Handle_SERVER( INT Line, CHAR *Var, CHAR *Arg )
812 03d971d9 2002-01-02 alex assert( Line > 0 );
813 03d971d9 2002-01-02 alex assert( Var != NULL );
814 03d971d9 2002-01-02 alex assert( Arg != NULL );
816 a2544e49 2002-12-30 alex /* Ignore server block if no space is left in server configuration structure */
817 a2544e49 2002-12-30 alex if( New_Server_Idx <= NONE ) return;
819 03d971d9 2002-01-02 alex if( strcasecmp( Var, "Host" ) == 0 )
821 6725d789 2002-12-12 alex /* Hostname of the server */
822 a6d7fb87 2005-01-20 alex if( strlcpy( New_Server.host, Arg, sizeof( New_Server.host )) >= sizeof( New_Server.host ))
823 a6d7fb87 2005-01-20 alex Config_Error_TooLong ( Line, Var );
827 03d971d9 2002-01-02 alex if( strcasecmp( Var, "Name" ) == 0 )
829 6725d789 2002-12-12 alex /* Name of the server ("Nick"/"ID") */
830 a6d7fb87 2005-01-20 alex if( strlcpy( New_Server.name, Arg, sizeof( New_Server.name )) >= sizeof( New_Server.name ))
831 a6d7fb87 2005-01-20 alex Config_Error_TooLong( Line, Var );
834 b2615bcc 2002-11-19 alex if( strcasecmp( Var, "MyPassword" ) == 0 )
836 6725d789 2002-12-12 alex /* Password of this server which is sent to the peer */
837 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 );
840 b2615bcc 2002-11-19 alex if( strcasecmp( Var, "PeerPassword" ) == 0 )
842 6725d789 2002-12-12 alex /* Passwort of the peer which must be received */
843 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 );
846 03d971d9 2002-01-02 alex if( strcasecmp( Var, "Port" ) == 0 )
848 6725d789 2002-12-12 alex /* Port to which this server should connect */
849 03d971d9 2002-01-02 alex port = atol( Arg );
850 a2544e49 2002-12-30 alex if( port > 0 && port < 0xFFFF ) New_Server.port = (INT)port;
851 f86083a0 2002-03-27 alex else Config_Error( LOG_ERR, "%s, line %d (section \"Server\"): Illegal port number %ld!", NGIRCd_ConfFile, Line, port );
854 d67d94ea 2002-03-10 alex if( strcasecmp( Var, "Group" ) == 0 )
856 6725d789 2002-12-12 alex /* Server group */
857 2e02da29 2002-11-30 alex #ifdef HAVE_ISDIGIT
858 a6d7fb87 2005-01-20 alex if( ! isdigit( (INT)*Arg )) Config_Error_NaN( Line, Var );
861 a2544e49 2002-12-30 alex New_Server.group = atoi( Arg );
865 f86083a0 2002-03-27 alex Config_Error( LOG_ERR, "%s, line %d (section \"Server\"): Unknown variable \"%s\"!", NGIRCd_ConfFile, Line, Var );
866 03d971d9 2002-01-02 alex } /* Handle_SERVER */
870 c2f60abe 2002-05-27 alex Handle_CHANNEL( INT Line, CHAR *Var, CHAR *Arg )
872 040f5422 2002-05-21 alex assert( Line > 0 );
873 040f5422 2002-05-21 alex assert( Var != NULL );
874 040f5422 2002-05-21 alex assert( Arg != NULL );
876 040f5422 2002-05-21 alex if( strcasecmp( Var, "Name" ) == 0 )
878 6725d789 2002-12-12 alex /* Name of the channel */
879 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 ))
880 a6d7fb87 2005-01-20 alex Config_Error_TooLong( Line, Var );
883 040f5422 2002-05-21 alex if( strcasecmp( Var, "Modes" ) == 0 )
885 6725d789 2002-12-12 alex /* Initial modes */
886 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 ))
887 a6d7fb87 2005-01-20 alex Config_Error_TooLong( Line, Var );
890 040f5422 2002-05-21 alex if( strcasecmp( Var, "Topic" ) == 0 )
892 6725d789 2002-12-12 alex /* Initial topic */
893 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 ))
894 a6d7fb87 2005-01-20 alex Config_Error_TooLong( Line, Var );
899 040f5422 2002-05-21 alex Config_Error( LOG_ERR, "%s, line %d (section \"Channel\"): Unknown variable \"%s\"!", NGIRCd_ConfFile, Line, Var );
900 040f5422 2002-05-21 alex } /* Handle_CHANNEL */
904 b7be46ed 2002-12-18 alex Validate_Config( BOOLEAN Configtest )
906 6725d789 2002-12-12 alex /* Validate configuration settings. */
908 a2544e49 2002-12-30 alex #ifdef DEBUG
909 a2544e49 2002-12-30 alex INT i, servers, servers_once;
912 9856253d 2001-12-30 alex if( ! Conf_ServerName[0] )
914 6725d789 2002-12-12 alex /* No server name configured! */
915 05170bc9 2003-12-19 alex Config_Error( LOG_ALERT, "No server name configured in \"%s\" (section 'Global': 'Name')!", NGIRCd_ConfFile );
916 b7be46ed 2002-12-18 alex if( ! Configtest )
918 62796722 2003-03-31 alex Config_Error( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME );
923 05170bc9 2003-12-19 alex if( Conf_ServerName[0] && ! strchr( Conf_ServerName, '.' ))
925 e541da2a 2003-04-29 alex /* No dot in server name! */
926 05170bc9 2003-12-19 alex Config_Error( LOG_ALERT, "Invalid server name configured in \"%s\" (section 'Global': 'Name'): Dot missing!", NGIRCd_ConfFile );
927 e541da2a 2003-04-29 alex if( ! Configtest )
929 e541da2a 2003-04-29 alex Config_Error( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME );
934 b615d128 2002-09-16 alex #ifdef STRICT_RFC
935 12cad28e 2002-10-21 alex if( ! Conf_ServerAdminMail[0] )
937 6725d789 2002-12-12 alex /* No administrative contact configured! */
938 b615d128 2002-09-16 alex Config_Error( LOG_ALERT, "No administrator email address configured in \"%s\" ('AdminEMail')!", NGIRCd_ConfFile );
939 b7be46ed 2002-12-18 alex if( ! Configtest )
941 62796722 2003-03-31 alex Config_Error( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME );
947 33bda862 2002-09-19 alex if( ! Conf_ServerAdmin1[0] && ! Conf_ServerAdmin2[0] && ! Conf_ServerAdminMail[0] )
949 6725d789 2002-12-12 alex /* No administrative information configured! */
950 b7be46ed 2002-12-18 alex Config_Error( LOG_WARNING, "No administrative information configured but required by RFC!" );
952 b7be46ed 2002-12-18 alex #ifdef FD_SETSIZE
953 3e4f58e4 2002-12-18 alex if(( Conf_MaxConnections > (LONG)FD_SETSIZE ) || ( Conf_MaxConnections < 1 ))
955 b7be46ed 2002-12-18 alex Conf_MaxConnections = (LONG)FD_SETSIZE;
956 b7be46ed 2002-12-18 alex Config_Error( LOG_ERR, "Setting MaxConnections to %ld, select() can't handle more file descriptors!", Conf_MaxConnections );
959 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!" );
962 a2544e49 2002-12-30 alex #ifdef DEBUG
963 a2544e49 2002-12-30 alex servers = servers_once = 0;
964 a2544e49 2002-12-30 alex for( i = 0; i < MAX_SERVERS; i++ )
966 a2544e49 2002-12-30 alex if( Conf_Server[i].name[0] )
969 281f7583 2002-12-31 alex if( Conf_Server[i].flags & CONF_SFLAG_ONCE ) servers_once++;
972 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 );
974 9856253d 2001-12-30 alex } /* Validate_Config */
978 a6d7fb87 2005-01-20 alex Config_Error_TooLong ( CONST INT Line, CONST CHAR *Item )
980 a6d7fb87 2005-01-20 alex Config_Error( LOG_WARNING, "%s, line %d: Value of \"%s\" too long!", NGIRCd_ConfFile, Line, Item );
984 a6d7fb87 2005-01-20 alex Config_Error_NaN( CONST INT Line, CONST CHAR *Item )
986 a6d7fb87 2005-01-20 alex Config_Error( LOG_WARNING, "%s, line %d: Value of \"%s\" is not a number!", NGIRCd_ConfFile, Line, Item );
989 f7327524 2002-05-30 alex #ifdef PROTOTYPES
990 f7327524 2002-05-30 alex LOCAL VOID Config_Error( CONST INT Level, CONST CHAR *Format, ... )
992 f7327524 2002-05-30 alex LOCAL VOID Config_Error( Level, Format, va_alist )
993 f7327524 2002-05-30 alex CONST INT Level;
994 f7327524 2002-05-30 alex CONST CHAR *Format;
998 6725d789 2002-12-12 alex /* Error! Write to console and/or logfile. */
1000 f86083a0 2002-03-27 alex CHAR msg[MAX_LOG_MSG_LEN];
1001 f86083a0 2002-03-27 alex va_list ap;
1003 f86083a0 2002-03-27 alex assert( Format != NULL );
1005 f7327524 2002-05-30 alex #ifdef PROTOTYPES
1006 f86083a0 2002-03-27 alex va_start( ap, Format );
1008 f7327524 2002-05-30 alex va_start( ap );
1010 f86083a0 2002-03-27 alex vsnprintf( msg, MAX_LOG_MSG_LEN, Format, ap );
1011 f86083a0 2002-03-27 alex va_end( ap );
1013 6725d789 2002-12-12 alex /* During "normal operations" the log functions of the daemon should
1014 6725d789 2002-12-12 alex * be used, but during testing of the configuration file, all messages
1015 6725d789 2002-12-12 alex * should go directly to the console: */
1016 ec474a4b 2002-10-04 alex if( Use_Log ) Log( Level, "%s", msg );
1017 f86083a0 2002-03-27 alex else puts( msg );
1018 f86083a0 2002-03-27 alex } /* Config_Error */
1021 a2544e49 2002-12-30 alex LOCAL VOID
1022 a2544e49 2002-12-30 alex Init_Server_Struct( CONF_SERVER *Server )
1024 a2544e49 2002-12-30 alex /* Initialize server configuration structur to default values */
1026 a2544e49 2002-12-30 alex assert( Server != NULL );
1028 a6d7fb87 2005-01-20 alex memset( Server, 0, sizeof (CONF_SERVER) );
1030 a2544e49 2002-12-30 alex Server->group = NONE;
1031 a2544e49 2002-12-30 alex Server->lasttry = time( NULL ) - Conf_ConnectRetry + STARTUP_DELAY;
1033 281f7583 2002-12-31 alex if( NGIRCd_Passive ) Server->flags = CONF_SFLAG_DISABLED;
1035 a2544e49 2002-12-30 alex Server->conn_id = NONE;
1036 a2544e49 2002-12-30 alex } /* Init_Server_Struct */
1039 cbc1e59f 2001-12-12 alex /* -eof- */