Blame


1 cbc1e59f 2001-12-12 alex /*
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)
4 cbc1e59f 2001-12-12 alex *
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.
10 cbc1e59f 2001-12-12 alex *
11 6725d789 2002-12-12 alex * Configuration management (reading, parsing & validation)
12 cbc1e59f 2001-12-12 alex */
13 cbc1e59f 2001-12-12 alex
14 cbc1e59f 2001-12-12 alex
15 ca33cbda 2002-03-12 alex #include "portab.h"
16 cbc1e59f 2001-12-12 alex
17 77faf14b 2005-04-16 fw static char UNUSED id[] = "$Id: conf.c,v 1.76 2005/04/16 09:23:01 fw Exp $";
18 6725d789 2002-12-12 alex
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>
24 c1f32e82 2004-10-20 alex #else
25 c1f32e82 2004-10-20 alex # include <varargs.h>
26 c1f32e82 2004-10-20 alex #endif
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>
36 2e02da29 2002-11-30 alex
37 2e02da29 2002-11-30 alex #ifdef HAVE_CTYPE_H
38 2e02da29 2002-11-30 alex # include <ctype.h>
39 2e02da29 2002-11-30 alex #endif
40 cbc1e59f 2001-12-12 alex
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"
48 9856253d 2001-12-30 alex
49 ca33cbda 2002-03-12 alex #include "exp.h"
50 cbc1e59f 2001-12-12 alex #include "conf.h"
51 cbc1e59f 2001-12-12 alex
52 cbc1e59f 2001-12-12 alex
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;
56 f86083a0 2002-03-27 alex
57 f86083a0 2002-03-27 alex
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 ));
61 03d971d9 2002-01-02 alex
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 ));
66 03d971d9 2002-01-02 alex
67 8adff592 2005-03-19 fw LOCAL void Config_Error PARAMS(( const int Level, const char *Format, ... ));
68 a6d7fb87 2005-01-20 alex
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 ));
71 574ae82c 2001-12-26 alex
72 8adff592 2005-03-19 fw LOCAL void Init_Server_Struct PARAMS(( CONF_SERVER *Server ));
73 574ae82c 2001-12-26 alex
74 a2544e49 2002-12-30 alex
75 8adff592 2005-03-19 fw GLOBAL void
76 8adff592 2005-03-19 fw Conf_Init( void )
77 cbc1e59f 2001-12-12 alex {
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 */
82 9856253d 2001-12-30 alex
83 9856253d 2001-12-30 alex
84 8adff592 2005-03-19 fw GLOBAL void
85 8adff592 2005-03-19 fw Conf_Rehash( void )
86 a2544e49 2002-12-30 alex {
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 */
91 a2544e49 2002-12-30 alex
92 a2544e49 2002-12-30 alex
93 8adff592 2005-03-19 fw GLOBAL int
94 8adff592 2005-03-19 fw Conf_Test( void )
95 f86083a0 2002-03-27 alex {
96 6725d789 2002-12-12 alex /* Read configuration, validate and output it. */
97 f86083a0 2002-03-27 alex
98 ae39724a 2002-11-08 alex struct passwd *pwd;
99 ae39724a 2002-11-08 alex struct group *grp;
100 8adff592 2005-03-19 fw int i;
101 f86083a0 2002-03-27 alex
102 8adff592 2005-03-19 fw Use_Log = false;
103 8adff592 2005-03-19 fw Set_Defaults( true );
104 f86083a0 2002-03-27 alex
105 f86083a0 2002-03-27 alex Read_Config( );
106 8adff592 2005-03-19 fw Validate_Config( true );
107 f86083a0 2002-03-27 alex
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 )))
111 f86083a0 2002-03-27 alex {
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( );
114 f86083a0 2002-03-27 alex }
115 f86083a0 2002-03-27 alex else puts( "Ok, dump of your server configuration follows:\n" );
116 f86083a0 2002-03-27 alex
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++ )
130 f86083a0 2002-03-27 alex {
131 f86083a0 2002-03-27 alex if( i != 0 ) printf( ", " );
132 326607ee 2005-03-20 fw printf( "%u", (unsigned int) Conf_ListenPorts[i] );
133 f86083a0 2002-03-27 alex }
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( "" );
154 f86083a0 2002-03-27 alex
155 f86083a0 2002-03-27 alex for( i = 0; i < Conf_Oper_Count; i++ )
156 f86083a0 2002-03-27 alex {
157 c23535bc 2002-05-22 alex if( ! Conf_Oper[i].name[0] ) continue;
158 c23535bc 2002-05-22 alex
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( "" );
165 f86083a0 2002-03-27 alex }
166 f86083a0 2002-03-27 alex
167 a2544e49 2002-12-30 alex for( i = 0; i < MAX_SERVERS; i++ )
168 f86083a0 2002-03-27 alex {
169 c23535bc 2002-05-22 alex if( ! Conf_Server[i].name[0] ) continue;
170 c23535bc 2002-05-22 alex
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( "" );
180 f86083a0 2002-03-27 alex }
181 040f5422 2002-05-21 alex
182 040f5422 2002-05-21 alex for( i = 0; i < Conf_Channel_Count; i++ )
183 040f5422 2002-05-21 alex {
184 c23535bc 2002-05-22 alex if( ! Conf_Channel[i].name[0] ) continue;
185 c23535bc 2002-05-22 alex
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( "" );
192 040f5422 2002-05-21 alex }
193 f86083a0 2002-03-27 alex
194 f86083a0 2002-03-27 alex return 0;
195 f86083a0 2002-03-27 alex } /* Conf_Test */
196 a2544e49 2002-12-30 alex
197 a2544e49 2002-12-30 alex
198 8adff592 2005-03-19 fw GLOBAL void
199 a2544e49 2002-12-30 alex Conf_UnsetServer( CONN_ID Idx )
200 a2544e49 2002-12-30 alex {
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. */
205 a2544e49 2002-12-30 alex
206 8adff592 2005-03-19 fw int i;
207 a2544e49 2002-12-30 alex
208 a2544e49 2002-12-30 alex /* Check all our configured servers */
209 a2544e49 2002-12-30 alex for( i = 0; i < MAX_SERVERS; i++ )
210 a2544e49 2002-12-30 alex {
211 a2544e49 2002-12-30 alex if( Conf_Server[i].conn_id != Idx ) continue;
212 a2544e49 2002-12-30 alex
213 a2544e49 2002-12-30 alex /* Gotcha! Mark server configuration as "unused": */
214 a2544e49 2002-12-30 alex Conf_Server[i].conn_id = NONE;
215 a2544e49 2002-12-30 alex
216 281f7583 2002-12-31 alex if( Conf_Server[i].flags & CONF_SFLAG_ONCE )
217 a2544e49 2002-12-30 alex {
218 a2544e49 2002-12-30 alex /* Delete configuration here */
219 a2544e49 2002-12-30 alex Init_Server_Struct( &Conf_Server[i] );
220 a2544e49 2002-12-30 alex }
221 a2544e49 2002-12-30 alex else
222 a2544e49 2002-12-30 alex {
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 )
225 a2544e49 2002-12-30 alex {
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;
228 a2544e49 2002-12-30 alex }
229 a2544e49 2002-12-30 alex }
230 a2544e49 2002-12-30 alex }
231 a2544e49 2002-12-30 alex } /* Conf_UnsetServer */
232 f86083a0 2002-03-27 alex
233 f86083a0 2002-03-27 alex
234 8adff592 2005-03-19 fw GLOBAL void
235 8adff592 2005-03-19 fw Conf_SetServer( int ConfServer, CONN_ID Idx )
236 a2544e49 2002-12-30 alex {
237 a2544e49 2002-12-30 alex /* Set connection for specified configured server */
238 a2544e49 2002-12-30 alex
239 a2544e49 2002-12-30 alex assert( ConfServer > NONE );
240 a2544e49 2002-12-30 alex assert( Idx > NONE );
241 a2544e49 2002-12-30 alex
242 a2544e49 2002-12-30 alex Conf_Server[ConfServer].conn_id = Idx;
243 a2544e49 2002-12-30 alex } /* Conf_SetServer */
244 a2544e49 2002-12-30 alex
245 a2544e49 2002-12-30 alex
246 8adff592 2005-03-19 fw GLOBAL int
247 a2544e49 2002-12-30 alex Conf_GetServer( CONN_ID Idx )
248 a2544e49 2002-12-30 alex {
249 a2544e49 2002-12-30 alex /* Get index of server in configuration structure */
250 a061668b 2003-04-21 alex
251 8adff592 2005-03-19 fw int i = 0;
252 a061668b 2003-04-21 alex
253 a2544e49 2002-12-30 alex assert( Idx > NONE );
254 a2544e49 2002-12-30 alex
255 a2544e49 2002-12-30 alex for( i = 0; i < MAX_SERVERS; i++ )
256 a2544e49 2002-12-30 alex {
257 a2544e49 2002-12-30 alex if( Conf_Server[i].conn_id == Idx ) return i;
258 a2544e49 2002-12-30 alex }
259 a2544e49 2002-12-30 alex return NONE;
260 a2544e49 2002-12-30 alex } /* Conf_GetServer */
261 281f7583 2002-12-31 alex
262 281f7583 2002-12-31 alex
263 8adff592 2005-03-19 fw GLOBAL bool
264 8adff592 2005-03-19 fw Conf_EnableServer( char *Name, UINT16 Port )
265 281f7583 2002-12-31 alex {
266 281f7583 2002-12-31 alex /* Enable specified server and adjust port */
267 281f7583 2002-12-31 alex
268 8adff592 2005-03-19 fw int i;
269 281f7583 2002-12-31 alex
270 281f7583 2002-12-31 alex assert( Name != NULL );
271 281f7583 2002-12-31 alex
272 281f7583 2002-12-31 alex for( i = 0; i < MAX_SERVERS; i++ )
273 281f7583 2002-12-31 alex {
274 281f7583 2002-12-31 alex if( strcasecmp( Conf_Server[i].name, Name ) == 0 )
275 281f7583 2002-12-31 alex {
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;
279 8adff592 2005-03-19 fw return true;
280 281f7583 2002-12-31 alex }
281 281f7583 2002-12-31 alex }
282 8adff592 2005-03-19 fw return false;
283 281f7583 2002-12-31 alex } /* Conf_EnableServer */
284 a2544e49 2002-12-30 alex
285 a2544e49 2002-12-30 alex
286 8adff592 2005-03-19 fw GLOBAL bool
287 8adff592 2005-03-19 fw Conf_DisableServer( char *Name )
288 281f7583 2002-12-31 alex {
289 281f7583 2002-12-31 alex /* Enable specified server and adjust port */
290 281f7583 2002-12-31 alex
291 8adff592 2005-03-19 fw int i;
292 281f7583 2002-12-31 alex
293 281f7583 2002-12-31 alex assert( Name != NULL );
294 281f7583 2002-12-31 alex
295 281f7583 2002-12-31 alex for( i = 0; i < MAX_SERVERS; i++ )
296 281f7583 2002-12-31 alex {
297 281f7583 2002-12-31 alex if( strcasecmp( Conf_Server[i].name, Name ) == 0 )
298 281f7583 2002-12-31 alex {
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);
302 8adff592 2005-03-19 fw return true;
303 281f7583 2002-12-31 alex }
304 281f7583 2002-12-31 alex }
305 8adff592 2005-03-19 fw return false;
306 281f7583 2002-12-31 alex } /* Conf_DisableServer */
307 281f7583 2002-12-31 alex
308 281f7583 2002-12-31 alex
309 8adff592 2005-03-19 fw GLOBAL bool
310 8adff592 2005-03-19 fw Conf_AddServer( char *Name, UINT16 Port, char *Host, char *MyPwd, char *PeerPwd )
311 281f7583 2002-12-31 alex {
312 281f7583 2002-12-31 alex /* Add new server to configuration */
313 281f7583 2002-12-31 alex
314 8adff592 2005-03-19 fw int i;
315 281f7583 2002-12-31 alex
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 );
320 281f7583 2002-12-31 alex
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++ )
323 281f7583 2002-12-31 alex {
324 281f7583 2002-12-31 alex /* Is this item used? */
325 281f7583 2002-12-31 alex if( ! Conf_Server[i].name[0] ) break;
326 281f7583 2002-12-31 alex }
327 8adff592 2005-03-19 fw if( i >= MAX_SERVERS ) return false;
328 281f7583 2002-12-31 alex
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;
336 281f7583 2002-12-31 alex
337 8adff592 2005-03-19 fw return true;
338 281f7583 2002-12-31 alex } /* Conf_AddServer */
339 281f7583 2002-12-31 alex
340 281f7583 2002-12-31 alex
341 8adff592 2005-03-19 fw LOCAL void
342 8adff592 2005-03-19 fw Set_Defaults( bool InitServers )
343 f86083a0 2002-03-27 alex {
344 6725d789 2002-12-12 alex /* Initialize configuration variables with default values. */
345 f86083a0 2002-03-27 alex
346 8adff592 2005-03-19 fw int i;
347 a2544e49 2002-12-30 alex
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, "" );
351 9856253d 2001-12-30 alex
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, "" );
355 b615d128 2002-09-16 alex
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 ));
358 7281b8dd 2004-05-07 alex
359 7281b8dd 2004-05-07 alex strlcpy( Conf_MotdPhrase, MOTD_PHRASE, sizeof( Conf_MotdPhrase ));
360 7281b8dd 2004-05-07 alex
361 7281b8dd 2004-05-07 alex strlcpy( Conf_Chroot, CHROOT_DIR, sizeof( Conf_Chroot ));
362 9856253d 2001-12-30 alex
363 112102b1 2005-02-04 alex strlcpy( Conf_PidFile, PID_FILE, sizeof( Conf_PidFile ));
364 112102b1 2005-02-04 alex
365 9856253d 2001-12-30 alex Conf_ListenPorts_Count = 0;
366 e33ab903 2003-09-11 alex strcpy( Conf_ListenAddress, "" );
367 1c2d0ae5 2002-03-29 alex
368 1c2d0ae5 2002-03-29 alex Conf_UID = Conf_GID = 0;
369 574ae82c 2001-12-26 alex
370 08cf5607 2001-12-26 alex Conf_PingTimeout = 120;
371 281d8e45 2002-03-25 alex Conf_PongTimeout = 20;
372 574ae82c 2001-12-26 alex
373 03d971d9 2002-01-02 alex Conf_ConnectRetry = 60;
374 03d971d9 2002-01-02 alex
375 03d971d9 2002-01-02 alex Conf_Oper_Count = 0;
376 040f5422 2002-05-21 alex Conf_Channel_Count = 0;
377 7e1b3b91 2002-09-02 alex
378 8adff592 2005-03-19 fw Conf_OperCanMode = false;
379 8adff592 2005-03-19 fw Conf_OperServerMode = false;
380 0d32a3b4 2002-11-02 alex
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;
384 a2544e49 2002-12-30 alex
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 */
388 03d971d9 2002-01-02 alex
389 cbc1e59f 2001-12-12 alex
390 8adff592 2005-03-19 fw LOCAL void
391 8adff592 2005-03-19 fw Read_Config( void )
392 574ae82c 2001-12-26 alex {
393 6725d789 2002-12-12 alex /* Read configuration file. */
394 9856253d 2001-12-30 alex
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;
397 9856253d 2001-12-30 alex FILE *fd;
398 9856253d 2001-12-30 alex
399 a2544e49 2002-12-30 alex /* Open configuration file */
400 f86083a0 2002-03-27 alex fd = fopen( NGIRCd_ConfFile, "r" );
401 9856253d 2001-12-30 alex if( ! fd )
402 9856253d 2001-12-30 alex {
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 );
406 9856253d 2001-12-30 alex exit( 1 );
407 9856253d 2001-12-30 alex }
408 03ec91f9 2002-11-22 alex
409 03ec91f9 2002-11-22 alex Config_Error( LOG_INFO, "Reading configuration from \"%s\" ...", NGIRCd_ConfFile );
410 9856253d 2001-12-30 alex
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++ )
418 a2544e49 2002-12-30 alex {
419 a2544e49 2002-12-30 alex if( Conf_Server[i].conn_id == NONE ) Init_Server_Struct( &Conf_Server[i] );
420 02a22611 2003-03-27 alex else
421 02a22611 2003-03-27 alex {
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 )
424 02a22611 2003-03-27 alex {
425 02a22611 2003-03-27 alex /* Check for duplicates */
426 02a22611 2003-03-27 alex for( n = 0; n < MAX_SERVERS; n++ )
427 02a22611 2003-03-27 alex {
428 02a22611 2003-03-27 alex if( n == i ) continue;
429 02a22611 2003-03-27 alex
430 02a22611 2003-03-27 alex if( Conf_Server[i].conn_id == Conf_Server[n].conn_id )
431 02a22611 2003-03-27 alex {
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 );
434 02a22611 2003-03-27 alex }
435 02a22611 2003-03-27 alex }
436 02a22611 2003-03-27 alex }
437 02a22611 2003-03-27 alex else
438 02a22611 2003-03-27 alex {
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 );
442 02a22611 2003-03-27 alex }
443 02a22611 2003-03-27 alex }
444 a2544e49 2002-12-30 alex }
445 a2544e49 2002-12-30 alex
446 a2544e49 2002-12-30 alex /* Initialize variables */
447 9856253d 2001-12-30 alex line = 0;
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;
451 a2544e49 2002-12-30 alex
452 a2544e49 2002-12-30 alex /* Read configuration file */
453 8adff592 2005-03-19 fw while( true )
454 9856253d 2001-12-30 alex {
455 804b1ec4 2001-12-31 alex if( ! fgets( str, LINE_LEN, fd )) break;
456 9856253d 2001-12-30 alex ngt_TrimStr( str );
457 9856253d 2001-12-30 alex line++;
458 9856253d 2001-12-30 alex
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;
461 9856253d 2001-12-30 alex
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] == ']' ))
464 03d971d9 2002-01-02 alex {
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 )
468 03d971d9 2002-01-02 alex {
469 f86083a0 2002-03-27 alex if( Conf_Oper_Count + 1 > MAX_OPERATORS ) Config_Error( LOG_ERR, "Too many operators configured." );
470 03d971d9 2002-01-02 alex else
471 03d971d9 2002-01-02 alex {
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;
478 490c9d04 2005-03-02 alex }
479 03d971d9 2002-01-02 alex Conf_Oper_Count++;
480 03d971d9 2002-01-02 alex }
481 03d971d9 2002-01-02 alex continue;
482 03d971d9 2002-01-02 alex }
483 03d971d9 2002-01-02 alex if( strcasecmp( section, "[SERVER]" ) == 0 )
484 03d971d9 2002-01-02 alex {
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] )
487 03d971d9 2002-01-02 alex {
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;
491 a2544e49 2002-12-30 alex }
492 a2544e49 2002-12-30 alex
493 a2544e49 2002-12-30 alex /* Re-init structure for new server */
494 a2544e49 2002-12-30 alex Init_Server_Struct( &New_Server );
495 a2544e49 2002-12-30 alex
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++ )
498 a2544e49 2002-12-30 alex {
499 a2544e49 2002-12-30 alex /* Is this item used? */
500 a2544e49 2002-12-30 alex if( ! Conf_Server[i].name[0] ) break;
501 040f5422 2002-05-21 alex }
502 a2544e49 2002-12-30 alex if( i >= MAX_SERVERS )
503 a2544e49 2002-12-30 alex {
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;
507 a2544e49 2002-12-30 alex }
508 a2544e49 2002-12-30 alex else New_Server_Idx = i;
509 040f5422 2002-05-21 alex continue;
510 040f5422 2002-05-21 alex }
511 040f5422 2002-05-21 alex if( strcasecmp( section, "[CHANNEL]" ) == 0 )
512 040f5422 2002-05-21 alex {
513 040f5422 2002-05-21 alex if( Conf_Channel_Count + 1 > MAX_DEFCHANNELS ) Config_Error( LOG_ERR, "Too many pre-defined channels configured." );
514 040f5422 2002-05-21 alex else
515 040f5422 2002-05-21 alex {
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++;
521 03d971d9 2002-01-02 alex }
522 03d971d9 2002-01-02 alex continue;
523 03d971d9 2002-01-02 alex }
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;
526 03d971d9 2002-01-02 alex }
527 03d971d9 2002-01-02 alex if( section[0] == 0x1 ) continue;
528 03d971d9 2002-01-02 alex
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 )
532 9856253d 2001-12-30 alex {
533 f86083a0 2002-03-27 alex Config_Error( LOG_ERR, "%s, line %d: Syntax error!", NGIRCd_ConfFile, line );
534 9856253d 2001-12-30 alex continue;
535 9856253d 2001-12-30 alex }
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 );
539 03d971d9 2002-01-02 alex
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 );
545 03d971d9 2002-01-02 alex }
546 a2544e49 2002-12-30 alex
547 a2544e49 2002-12-30 alex /* Close configuration file */
548 03d971d9 2002-01-02 alex fclose( fd );
549 a2544e49 2002-12-30 alex
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] )
552 a2544e49 2002-12-30 alex {
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;
556 a2544e49 2002-12-30 alex }
557 1c99b837 2002-03-30 alex
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 )
560 1c99b837 2002-03-30 alex {
561 1c99b837 2002-03-30 alex Conf_ListenPorts_Count = 1;
562 1c99b837 2002-03-30 alex Conf_ListenPorts[0] = 6667;
563 1c99b837 2002-03-30 alex }
564 03d971d9 2002-01-02 alex } /* Read_Config */
565 1d08d51e 2005-03-15 alex
566 1d08d51e 2005-03-15 alex
567 8adff592 2005-03-19 fw LOCAL bool
568 1d08d51e 2005-03-15 alex Check_ArgIsTrue( const char *Arg )
569 1d08d51e 2005-03-15 alex {
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;
573 1d08d51e 2005-03-15 alex
574 8adff592 2005-03-19 fw return false;
575 1d08d51e 2005-03-15 alex } /* Check_ArgIsTrue */
576 03d971d9 2002-01-02 alex
577 03d971d9 2002-01-02 alex
578 8adff592 2005-03-19 fw LOCAL void
579 8adff592 2005-03-19 fw Handle_GLOBAL( int Line, char *Var, char *Arg )
580 03d971d9 2002-01-02 alex {
581 ae39724a 2002-11-08 alex struct passwd *pwd;
582 ae39724a 2002-11-08 alex struct group *grp;
583 8adff592 2005-03-19 fw char *ptr;
584 8adff592 2005-03-19 fw long port;
585 03d971d9 2002-01-02 alex
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 );
589 03d971d9 2002-01-02 alex
590 03d971d9 2002-01-02 alex if( strcasecmp( Var, "Name" ) == 0 )
591 03d971d9 2002-01-02 alex {
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 );
595 a6d7fb87 2005-01-20 alex
596 03d971d9 2002-01-02 alex return;
597 03d971d9 2002-01-02 alex }
598 03d971d9 2002-01-02 alex if( strcasecmp( Var, "Info" ) == 0 )
599 03d971d9 2002-01-02 alex {
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 );
603 a6d7fb87 2005-01-20 alex
604 03d971d9 2002-01-02 alex return;
605 03d971d9 2002-01-02 alex }
606 ed406b4a 2002-01-03 alex if( strcasecmp( Var, "Password" ) == 0 )
607 ed406b4a 2002-01-03 alex {
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 );
611 a6d7fb87 2005-01-20 alex
612 b615d128 2002-09-16 alex return;
613 b615d128 2002-09-16 alex }
614 b615d128 2002-09-16 alex if( strcasecmp( Var, "AdminInfo1" ) == 0 )
615 b615d128 2002-09-16 alex {
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 );
618 b615d128 2002-09-16 alex return;
619 b615d128 2002-09-16 alex }
620 b615d128 2002-09-16 alex if( strcasecmp( Var, "AdminInfo2" ) == 0 )
621 b615d128 2002-09-16 alex {
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 );
624 b615d128 2002-09-16 alex return;
625 b615d128 2002-09-16 alex }
626 b615d128 2002-09-16 alex if( strcasecmp( Var, "AdminEMail" ) == 0 )
627 b615d128 2002-09-16 alex {
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 );
630 ed406b4a 2002-01-03 alex return;
631 ed406b4a 2002-01-03 alex }
632 03d971d9 2002-01-02 alex if( strcasecmp( Var, "Ports" ) == 0 )
633 03d971d9 2002-01-02 alex {
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 )
638 9856253d 2001-12-30 alex {
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 );
642 03d971d9 2002-01-02 alex else
643 03d971d9 2002-01-02 alex {
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 );
646 03d971d9 2002-01-02 alex }
647 03d971d9 2002-01-02 alex ptr = strtok( NULL, "," );
648 9856253d 2001-12-30 alex }
649 03d971d9 2002-01-02 alex return;
650 03d971d9 2002-01-02 alex }
651 03d971d9 2002-01-02 alex if( strcasecmp( Var, "MotdFile" ) == 0 )
652 03d971d9 2002-01-02 alex {
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 );
656 a6d7fb87 2005-01-20 alex
657 7281b8dd 2004-05-07 alex return;
658 7281b8dd 2004-05-07 alex }
659 7281b8dd 2004-05-07 alex if( strcasecmp( Var, "MotdPhrase" ) == 0 )
660 7281b8dd 2004-05-07 alex {
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 );
664 a6d7fb87 2005-01-20 alex
665 03d971d9 2002-01-02 alex return;
666 03d971d9 2002-01-02 alex }
667 7281b8dd 2004-05-07 alex if( strcasecmp( Var, "ChrootDir" ) == 0 )
668 7281b8dd 2004-05-07 alex {
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 );
672 a6d7fb87 2005-01-20 alex
673 7281b8dd 2004-05-07 alex return;
674 7281b8dd 2004-05-07 alex }
675 112102b1 2005-02-04 alex
676 112102b1 2005-02-04 alex if ( strcasecmp( Var, "PidFile" ) == 0 )
677 112102b1 2005-02-04 alex {
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 );
681 112102b1 2005-02-04 alex
682 112102b1 2005-02-04 alex return;
683 112102b1 2005-02-04 alex }
684 112102b1 2005-02-04 alex
685 1c2d0ae5 2002-03-29 alex if( strcasecmp( Var, "ServerUID" ) == 0 )
686 1c2d0ae5 2002-03-29 alex {
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;
690 2e02da29 2002-11-30 alex else
691 2e02da29 2002-11-30 alex {
692 2e02da29 2002-11-30 alex #ifdef HAVE_ISDIGIT
693 8adff592 2005-03-19 fw if( ! isdigit( (int)*Arg )) Config_Error_NaN( Line, Var );
694 2e02da29 2002-11-30 alex else
695 2e02da29 2002-11-30 alex #endif
696 8adff592 2005-03-19 fw Conf_UID = (unsigned int)atoi( Arg );
697 2e02da29 2002-11-30 alex }
698 1c2d0ae5 2002-03-29 alex return;
699 1c2d0ae5 2002-03-29 alex }
700 1c2d0ae5 2002-03-29 alex if( strcasecmp( Var, "ServerGID" ) == 0 )
701 1c2d0ae5 2002-03-29 alex {
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;
705 2e02da29 2002-11-30 alex else
706 2e02da29 2002-11-30 alex {
707 2e02da29 2002-11-30 alex #ifdef HAVE_ISDIGIT
708 8adff592 2005-03-19 fw if( ! isdigit( (int)*Arg )) Config_Error_NaN( Line, Var );
709 2e02da29 2002-11-30 alex else
710 2e02da29 2002-11-30 alex #endif
711 8adff592 2005-03-19 fw Conf_GID = (unsigned int)atoi( Arg );
712 2e02da29 2002-11-30 alex }
713 1c2d0ae5 2002-03-29 alex return;
714 1c2d0ae5 2002-03-29 alex }
715 03d971d9 2002-01-02 alex if( strcasecmp( Var, "PingTimeout" ) == 0 )
716 03d971d9 2002-01-02 alex {
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 )
720 2e02da29 2002-11-30 alex {
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;
723 2e02da29 2002-11-30 alex }
724 03d971d9 2002-01-02 alex return;
725 03d971d9 2002-01-02 alex }
726 03d971d9 2002-01-02 alex if( strcasecmp( Var, "PongTimeout" ) == 0 )
727 03d971d9 2002-01-02 alex {
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 )
731 2e02da29 2002-11-30 alex {
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;
734 2e02da29 2002-11-30 alex }
735 03d971d9 2002-01-02 alex return;
736 03d971d9 2002-01-02 alex }
737 03d971d9 2002-01-02 alex if( strcasecmp( Var, "ConnectRetry" ) == 0 )
738 03d971d9 2002-01-02 alex {
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 )
742 2e02da29 2002-11-30 alex {
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;
745 2e02da29 2002-11-30 alex }
746 7e1b3b91 2002-09-02 alex return;
747 7e1b3b91 2002-09-02 alex }
748 7e1b3b91 2002-09-02 alex if( strcasecmp( Var, "OperCanUseMode" ) == 0 )
749 7e1b3b91 2002-09-02 alex {
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 );
752 1d08d51e 2005-03-15 alex return;
753 1d08d51e 2005-03-15 alex }
754 1d08d51e 2005-03-15 alex if( strcasecmp( Var, "OperServerMode" ) == 0 )
755 1d08d51e 2005-03-15 alex {
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 );
758 03d971d9 2002-01-02 alex return;
759 03d971d9 2002-01-02 alex }
760 0d32a3b4 2002-11-02 alex if( strcasecmp( Var, "MaxConnections" ) == 0 )
761 0d32a3b4 2002-11-02 alex {
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);
765 2e02da29 2002-11-30 alex else
766 2e02da29 2002-11-30 alex #endif
767 0d32a3b4 2002-11-02 alex Conf_MaxConnections = atol( Arg );
768 0d32a3b4 2002-11-02 alex return;
769 0d32a3b4 2002-11-02 alex }
770 2981fe9e 2003-11-05 alex if( strcasecmp( Var, "MaxConnectionsIP" ) == 0 )
771 2981fe9e 2003-11-05 alex {
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 );
775 2981fe9e 2003-11-05 alex else
776 2981fe9e 2003-11-05 alex #endif
777 2981fe9e 2003-11-05 alex Conf_MaxConnectionsIP = atoi( Arg );
778 2981fe9e 2003-11-05 alex return;
779 2981fe9e 2003-11-05 alex }
780 8b7b23cf 2002-12-13 alex if( strcasecmp( Var, "MaxJoins" ) == 0 )
781 8b7b23cf 2002-12-13 alex {
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 );
785 8b7b23cf 2002-12-13 alex else
786 8b7b23cf 2002-12-13 alex #endif
787 8b7b23cf 2002-12-13 alex Conf_MaxJoins = atoi( Arg );
788 8b7b23cf 2002-12-13 alex return;
789 8b7b23cf 2002-12-13 alex }
790 e33ab903 2003-09-11 alex if( strcasecmp( Var, "Listen" ) == 0 )
791 e33ab903 2003-09-11 alex {
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 ))
794 e33ab903 2003-09-11 alex {
795 a6d7fb87 2005-01-20 alex Config_Error_TooLong( Line, Var );
796 e33ab903 2003-09-11 alex }
797 2981fe9e 2003-11-05 alex return;
798 e33ab903 2003-09-11 alex }
799 8b7b23cf 2002-12-13 alex
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 */
802 03d971d9 2002-01-02 alex
803 03d971d9 2002-01-02 alex
804 8adff592 2005-03-19 fw LOCAL void
805 8adff592 2005-03-19 fw Handle_OPERATOR( int Line, char *Var, char *Arg )
806 03d971d9 2002-01-02 alex {
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 );
811 03d971d9 2002-01-02 alex
812 03d971d9 2002-01-02 alex if( strcasecmp( Var, "Name" ) == 0 )
813 03d971d9 2002-01-02 alex {
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 );
816 03d971d9 2002-01-02 alex return;
817 9856253d 2001-12-30 alex }
818 03d971d9 2002-01-02 alex if( strcasecmp( Var, "Password" ) == 0 )
819 03d971d9 2002-01-02 alex {
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 );
822 03d971d9 2002-01-02 alex return;
823 03d971d9 2002-01-02 alex }
824 490c9d04 2005-03-02 alex if( strcasecmp( Var, "Mask" ) == 0 )
825 490c9d04 2005-03-02 alex {
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) );
830 490c9d04 2005-03-02 alex return;
831 490c9d04 2005-03-02 alex }
832 490c9d04 2005-03-02 alex
833 490c9d04 2005-03-02 alex return;
834 490c9d04 2005-03-02 alex }
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 */
837 574ae82c 2001-12-26 alex
838 574ae82c 2001-12-26 alex
839 8adff592 2005-03-19 fw LOCAL void
840 8adff592 2005-03-19 fw Handle_SERVER( int Line, char *Var, char *Arg )
841 03d971d9 2002-01-02 alex {
842 8adff592 2005-03-19 fw long port;
843 03d971d9 2002-01-02 alex
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 );
847 a2544e49 2002-12-30 alex
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;
850 03d971d9 2002-01-02 alex
851 03d971d9 2002-01-02 alex if( strcasecmp( Var, "Host" ) == 0 )
852 03d971d9 2002-01-02 alex {
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 );
856 a6d7fb87 2005-01-20 alex
857 03d971d9 2002-01-02 alex return;
858 03d971d9 2002-01-02 alex }
859 03d971d9 2002-01-02 alex if( strcasecmp( Var, "Name" ) == 0 )
860 03d971d9 2002-01-02 alex {
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 );
864 03d971d9 2002-01-02 alex return;
865 03d971d9 2002-01-02 alex }
866 b2615bcc 2002-11-19 alex if( strcasecmp( Var, "MyPassword" ) == 0 )
867 03d971d9 2002-01-02 alex {
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 );
870 03d971d9 2002-01-02 alex return;
871 03d971d9 2002-01-02 alex }
872 b2615bcc 2002-11-19 alex if( strcasecmp( Var, "PeerPassword" ) == 0 )
873 b2615bcc 2002-11-19 alex {
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 );
876 b2615bcc 2002-11-19 alex return;
877 b2615bcc 2002-11-19 alex }
878 03d971d9 2002-01-02 alex if( strcasecmp( Var, "Port" ) == 0 )
879 03d971d9 2002-01-02 alex {
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 );
884 03d971d9 2002-01-02 alex return;
885 03d971d9 2002-01-02 alex }
886 d67d94ea 2002-03-10 alex if( strcasecmp( Var, "Group" ) == 0 )
887 d67d94ea 2002-03-10 alex {
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 );
891 2e02da29 2002-11-30 alex else
892 2e02da29 2002-11-30 alex #endif
893 a2544e49 2002-12-30 alex New_Server.group = atoi( Arg );
894 d67d94ea 2002-03-10 alex return;
895 d67d94ea 2002-03-10 alex }
896 03d971d9 2002-01-02 alex
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 */
899 040f5422 2002-05-21 alex
900 040f5422 2002-05-21 alex
901 8adff592 2005-03-19 fw LOCAL void
902 8adff592 2005-03-19 fw Handle_CHANNEL( int Line, char *Var, char *Arg )
903 040f5422 2002-05-21 alex {
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 );
907 03d971d9 2002-01-02 alex
908 040f5422 2002-05-21 alex if( strcasecmp( Var, "Name" ) == 0 )
909 040f5422 2002-05-21 alex {
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 );
913 040f5422 2002-05-21 alex return;
914 040f5422 2002-05-21 alex }
915 040f5422 2002-05-21 alex if( strcasecmp( Var, "Modes" ) == 0 )
916 040f5422 2002-05-21 alex {
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 );
920 040f5422 2002-05-21 alex return;
921 040f5422 2002-05-21 alex }
922 040f5422 2002-05-21 alex if( strcasecmp( Var, "Topic" ) == 0 )
923 040f5422 2002-05-21 alex {
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 );
927 a6d7fb87 2005-01-20 alex
928 040f5422 2002-05-21 alex return;
929 040f5422 2002-05-21 alex }
930 03d971d9 2002-01-02 alex
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 */
933 040f5422 2002-05-21 alex
934 040f5422 2002-05-21 alex
935 8adff592 2005-03-19 fw LOCAL void
936 8adff592 2005-03-19 fw Validate_Config( bool Configtest )
937 9856253d 2001-12-30 alex {
938 6725d789 2002-12-12 alex /* Validate configuration settings. */
939 a2544e49 2002-12-30 alex
940 a2544e49 2002-12-30 alex #ifdef DEBUG
941 8adff592 2005-03-19 fw int i, servers, servers_once;
942 a2544e49 2002-12-30 alex #endif
943 a2544e49 2002-12-30 alex
944 9856253d 2001-12-30 alex if( ! Conf_ServerName[0] )
945 9856253d 2001-12-30 alex {
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 )
949 b7be46ed 2002-12-18 alex {
950 62796722 2003-03-31 alex Config_Error( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME );
951 b7be46ed 2002-12-18 alex exit( 1 );
952 b7be46ed 2002-12-18 alex }
953 9856253d 2001-12-30 alex }
954 e541da2a 2003-04-29 alex
955 05170bc9 2003-12-19 alex if( Conf_ServerName[0] && ! strchr( Conf_ServerName, '.' ))
956 e541da2a 2003-04-29 alex {
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 )
960 e541da2a 2003-04-29 alex {
961 e541da2a 2003-04-29 alex Config_Error( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME );
962 e541da2a 2003-04-29 alex exit( 1 );
963 e541da2a 2003-04-29 alex }
964 e541da2a 2003-04-29 alex }
965 b615d128 2002-09-16 alex
966 b615d128 2002-09-16 alex #ifdef STRICT_RFC
967 12cad28e 2002-10-21 alex if( ! Conf_ServerAdminMail[0] )
968 b615d128 2002-09-16 alex {
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 )
972 b7be46ed 2002-12-18 alex {
973 62796722 2003-03-31 alex Config_Error( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME );
974 b7be46ed 2002-12-18 alex exit( 1 );
975 b7be46ed 2002-12-18 alex }
976 b615d128 2002-09-16 alex }
977 b615d128 2002-09-16 alex #endif
978 b615d128 2002-09-16 alex
979 33bda862 2002-09-19 alex if( ! Conf_ServerAdmin1[0] && ! Conf_ServerAdmin2[0] && ! Conf_ServerAdminMail[0] )
980 b615d128 2002-09-16 alex {
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!" );
983 b615d128 2002-09-16 alex }
984 b7be46ed 2002-12-18 alex #ifdef FD_SETSIZE
985 8adff592 2005-03-19 fw if(( Conf_MaxConnections > (long)FD_SETSIZE ) || ( Conf_MaxConnections < 1 ))
986 b7be46ed 2002-12-18 alex {
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 );
989 b7be46ed 2002-12-18 alex }
990 b7be46ed 2002-12-18 alex #else
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!" );
992 b7be46ed 2002-12-18 alex #endif
993 a2544e49 2002-12-30 alex
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++ )
997 a2544e49 2002-12-30 alex {
998 a2544e49 2002-12-30 alex if( Conf_Server[i].name[0] )
999 a2544e49 2002-12-30 alex {
1000 a2544e49 2002-12-30 alex servers++;
1001 281f7583 2002-12-31 alex if( Conf_Server[i].flags & CONF_SFLAG_ONCE ) servers_once++;
1002 a2544e49 2002-12-30 alex }
1003 a2544e49 2002-12-30 alex }
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 );
1005 a2544e49 2002-12-30 alex #endif
1006 9856253d 2001-12-30 alex } /* Validate_Config */
1007 9856253d 2001-12-30 alex
1008 f86083a0 2002-03-27 alex
1009 8adff592 2005-03-19 fw LOCAL void
1010 27d93d7d 2005-03-19 fw Config_Error_TooLong ( const int Line, const char *Item )
1011 a6d7fb87 2005-01-20 alex {
1012 a6d7fb87 2005-01-20 alex Config_Error( LOG_WARNING, "%s, line %d: Value of \"%s\" too long!", NGIRCd_ConfFile, Line, Item );
1013 a6d7fb87 2005-01-20 alex }
1014 a6d7fb87 2005-01-20 alex
1015 8adff592 2005-03-19 fw LOCAL void
1016 27d93d7d 2005-03-19 fw Config_Error_NaN( const int Line, const char *Item )
1017 a6d7fb87 2005-01-20 alex {
1018 a6d7fb87 2005-01-20 alex Config_Error( LOG_WARNING, "%s, line %d: Value of \"%s\" is not a number!", NGIRCd_ConfFile, Line, Item );
1019 a6d7fb87 2005-01-20 alex }
1020 a6d7fb87 2005-01-20 alex
1021 f7327524 2002-05-30 alex #ifdef PROTOTYPES
1022 8adff592 2005-03-19 fw LOCAL void Config_Error( const int Level, const char *Format, ... )
1023 f7327524 2002-05-30 alex #else
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;
1027 f7327524 2002-05-30 alex va_dcl
1028 f7327524 2002-05-30 alex #endif
1029 f86083a0 2002-03-27 alex {
1030 6725d789 2002-12-12 alex /* Error! Write to console and/or logfile. */
1031 f86083a0 2002-03-27 alex
1032 8adff592 2005-03-19 fw char msg[MAX_LOG_MSG_LEN];
1033 f86083a0 2002-03-27 alex va_list ap;
1034 f86083a0 2002-03-27 alex
1035 f86083a0 2002-03-27 alex assert( Format != NULL );
1036 f86083a0 2002-03-27 alex
1037 f7327524 2002-05-30 alex #ifdef PROTOTYPES
1038 f86083a0 2002-03-27 alex va_start( ap, Format );
1039 f7327524 2002-05-30 alex #else
1040 f7327524 2002-05-30 alex va_start( ap );
1041 f7327524 2002-05-30 alex #endif
1042 f86083a0 2002-03-27 alex vsnprintf( msg, MAX_LOG_MSG_LEN, Format, ap );
1043 f86083a0 2002-03-27 alex va_end( ap );
1044 6725d789 2002-12-12 alex
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 */
1051 f86083a0 2002-03-27 alex
1052 f86083a0 2002-03-27 alex
1053 8adff592 2005-03-19 fw LOCAL void
1054 a2544e49 2002-12-30 alex Init_Server_Struct( CONF_SERVER *Server )
1055 a2544e49 2002-12-30 alex {
1056 a2544e49 2002-12-30 alex /* Initialize server configuration structur to default values */
1057 a2544e49 2002-12-30 alex
1058 a2544e49 2002-12-30 alex assert( Server != NULL );
1059 a2544e49 2002-12-30 alex
1060 a6d7fb87 2005-01-20 alex memset( Server, 0, sizeof (CONF_SERVER) );
1061 a6d7fb87 2005-01-20 alex
1062 a2544e49 2002-12-30 alex Server->group = NONE;
1063 a2544e49 2002-12-30 alex Server->lasttry = time( NULL ) - Conf_ConnectRetry + STARTUP_DELAY;
1064 a6d7fb87 2005-01-20 alex
1065 281f7583 2002-12-31 alex if( NGIRCd_Passive ) Server->flags = CONF_SFLAG_DISABLED;
1066 a6d7fb87 2005-01-20 alex
1067 a2544e49 2002-12-30 alex Server->conn_id = NONE;
1068 a2544e49 2002-12-30 alex } /* Init_Server_Struct */
1069 a2544e49 2002-12-30 alex
1070 a2544e49 2002-12-30 alex
1071 cbc1e59f 2001-12-12 alex /* -eof- */