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 c1f32e82 2004-10-20 alex static char UNUSED id[] = "$Id: conf.c,v 1.66 2004/10/20 13:47:32 alex 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 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;
56 f86083a0 2002-03-27 alex
57 f86083a0 2002-03-27 alex
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 ));
61 03d971d9 2002-01-02 alex
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 ));
66 03d971d9 2002-01-02 alex
67 c2f60abe 2002-05-27 alex LOCAL VOID Config_Error PARAMS(( CONST INT Level, CONST CHAR *Format, ... ));
68 574ae82c 2001-12-26 alex
69 a2544e49 2002-12-30 alex LOCAL VOID Init_Server_Struct PARAMS(( CONF_SERVER *Server ));
70 574ae82c 2001-12-26 alex
71 a2544e49 2002-12-30 alex
72 c2f60abe 2002-05-27 alex GLOBAL VOID
73 c2f60abe 2002-05-27 alex Conf_Init( VOID )
74 cbc1e59f 2001-12-12 alex {
75 a2544e49 2002-12-30 alex Set_Defaults( TRUE );
76 f86083a0 2002-03-27 alex Read_Config( );
77 b7be46ed 2002-12-18 alex Validate_Config( FALSE );
78 f86083a0 2002-03-27 alex } /* Config_Init */
79 9856253d 2001-12-30 alex
80 9856253d 2001-12-30 alex
81 a2544e49 2002-12-30 alex GLOBAL VOID
82 a2544e49 2002-12-30 alex Conf_Rehash( VOID )
83 a2544e49 2002-12-30 alex {
84 a2544e49 2002-12-30 alex Set_Defaults( FALSE );
85 a2544e49 2002-12-30 alex Read_Config( );
86 a2544e49 2002-12-30 alex Validate_Config( FALSE );
87 a2544e49 2002-12-30 alex } /* Config_Rehash */
88 a2544e49 2002-12-30 alex
89 a2544e49 2002-12-30 alex
90 c2f60abe 2002-05-27 alex GLOBAL INT
91 c2f60abe 2002-05-27 alex Conf_Test( VOID )
92 f86083a0 2002-03-27 alex {
93 6725d789 2002-12-12 alex /* Read configuration, validate and output it. */
94 f86083a0 2002-03-27 alex
95 ae39724a 2002-11-08 alex struct passwd *pwd;
96 ae39724a 2002-11-08 alex struct group *grp;
97 74ff9828 2002-10-03 alex INT i;
98 f86083a0 2002-03-27 alex
99 f86083a0 2002-03-27 alex Use_Log = FALSE;
100 a2544e49 2002-12-30 alex Set_Defaults( TRUE );
101 f86083a0 2002-03-27 alex
102 f86083a0 2002-03-27 alex Read_Config( );
103 b7be46ed 2002-12-18 alex Validate_Config( TRUE );
104 f86083a0 2002-03-27 alex
105 6725d789 2002-12-12 alex /* If stdin is a valid tty wait for a key: */
106 f86083a0 2002-03-27 alex if( isatty( fileno( stdout )))
107 f86083a0 2002-03-27 alex {
108 f86083a0 2002-03-27 alex puts( "OK, press enter to see a dump of your service configuration ..." );
109 f86083a0 2002-03-27 alex getchar( );
110 f86083a0 2002-03-27 alex }
111 f86083a0 2002-03-27 alex else puts( "Ok, dump of your server configuration follows:\n" );
112 f86083a0 2002-03-27 alex
113 f86083a0 2002-03-27 alex puts( "[GLOBAL]" );
114 1e692e58 2004-09-24 alex printf( " Name = %s\n", Conf_ServerName );
115 1e692e58 2004-09-24 alex printf( " Info = %s\n", Conf_ServerInfo );
116 0e01a37a 2003-04-27 alex printf( " Password = %s\n", Conf_ServerPwd );
117 b615d128 2002-09-16 alex printf( " AdminInfo1 = %s\n", Conf_ServerAdmin1 );
118 b615d128 2002-09-16 alex printf( " AdminInfo2 = %s\n", Conf_ServerAdmin2 );
119 b615d128 2002-09-16 alex printf( " AdminEMail = %s\n", Conf_ServerAdminMail );
120 f86083a0 2002-03-27 alex printf( " MotdFile = %s\n", Conf_MotdFile );
121 7281b8dd 2004-05-07 alex printf( " MotdPhrase = %s\n", Conf_MotdPhrase );
122 7281b8dd 2004-05-07 alex printf( " ChrootDir= %s\n", Conf_Chroot );
123 7bbdfb3d 2002-11-18 alex printf( " Ports = " );
124 f86083a0 2002-03-27 alex for( i = 0; i < Conf_ListenPorts_Count; i++ )
125 f86083a0 2002-03-27 alex {
126 f86083a0 2002-03-27 alex if( i != 0 ) printf( ", " );
127 1c2d0ae5 2002-03-29 alex printf( "%u", Conf_ListenPorts[i] );
128 f86083a0 2002-03-27 alex }
129 1c2d0ae5 2002-03-29 alex puts( "" );
130 e33ab903 2003-09-11 alex printf( " Listen = %s\n", Conf_ListenAddress );
131 ae39724a 2002-11-08 alex pwd = getpwuid( Conf_UID );
132 ae39724a 2002-11-08 alex if( pwd ) printf( " ServerUID = %s\n", pwd->pw_name );
133 ae39724a 2002-11-08 alex else printf( " ServerUID = %ld\n", (LONG)Conf_UID );
134 ae39724a 2002-11-08 alex grp = getgrgid( Conf_GID );
135 ae39724a 2002-11-08 alex if( grp ) printf( " ServerGID = %s\n", grp->gr_name );
136 ae39724a 2002-11-08 alex else printf( " ServerGID = %ld\n", (LONG)Conf_GID );
137 f86083a0 2002-03-27 alex printf( " PingTimeout = %d\n", Conf_PingTimeout );
138 f86083a0 2002-03-27 alex printf( " PongTimeout = %d\n", Conf_PongTimeout );
139 f86083a0 2002-03-27 alex printf( " ConnectRetry = %d\n", Conf_ConnectRetry );
140 7e1b3b91 2002-09-02 alex printf( " OperCanUseMode = %s\n", Conf_OperCanMode == TRUE ? "yes" : "no" );
141 0d32a3b4 2002-11-02 alex if( Conf_MaxConnections > 0 ) printf( " MaxConnections = %ld\n", Conf_MaxConnections );
142 0d32a3b4 2002-11-02 alex else printf( " MaxConnections = -1\n" );
143 2981fe9e 2003-11-05 alex if( Conf_MaxConnectionsIP > 0 ) printf( " MaxConnectionsIP = %d\n", Conf_MaxConnectionsIP );
144 2981fe9e 2003-11-05 alex else printf( " MaxConnectionsIP = -1\n" );
145 8b7b23cf 2002-12-13 alex if( Conf_MaxJoins > 0 ) printf( " MaxJoins = %d\n", Conf_MaxJoins );
146 8b7b23cf 2002-12-13 alex else printf( " MaxJoins = -1\n" );
147 f86083a0 2002-03-27 alex puts( "" );
148 f86083a0 2002-03-27 alex
149 f86083a0 2002-03-27 alex for( i = 0; i < Conf_Oper_Count; i++ )
150 f86083a0 2002-03-27 alex {
151 c23535bc 2002-05-22 alex if( ! Conf_Oper[i].name[0] ) continue;
152 c23535bc 2002-05-22 alex
153 6725d789 2002-12-12 alex /* Valid "Operator" section */
154 f86083a0 2002-03-27 alex puts( "[OPERATOR]" );
155 f86083a0 2002-03-27 alex printf( " Name = %s\n", Conf_Oper[i].name );
156 f86083a0 2002-03-27 alex printf( " Password = %s\n", Conf_Oper[i].pwd );
157 f86083a0 2002-03-27 alex puts( "" );
158 f86083a0 2002-03-27 alex }
159 f86083a0 2002-03-27 alex
160 a2544e49 2002-12-30 alex for( i = 0; i < MAX_SERVERS; i++ )
161 f86083a0 2002-03-27 alex {
162 c23535bc 2002-05-22 alex if( ! Conf_Server[i].name[0] ) continue;
163 c23535bc 2002-05-22 alex
164 6725d789 2002-12-12 alex /* Valid "Server" section */
165 f86083a0 2002-03-27 alex puts( "[SERVER]" );
166 f86083a0 2002-03-27 alex printf( " Name = %s\n", Conf_Server[i].name );
167 f86083a0 2002-03-27 alex printf( " Host = %s\n", Conf_Server[i].host );
168 f86083a0 2002-03-27 alex printf( " Port = %d\n", Conf_Server[i].port );
169 b2615bcc 2002-11-19 alex printf( " MyPassword = %s\n", Conf_Server[i].pwd_in );
170 b2615bcc 2002-11-19 alex printf( " PeerPassword = %s\n", Conf_Server[i].pwd_out );
171 f86083a0 2002-03-27 alex printf( " Group = %d\n", Conf_Server[i].group );
172 f86083a0 2002-03-27 alex puts( "" );
173 f86083a0 2002-03-27 alex }
174 040f5422 2002-05-21 alex
175 040f5422 2002-05-21 alex for( i = 0; i < Conf_Channel_Count; i++ )
176 040f5422 2002-05-21 alex {
177 c23535bc 2002-05-22 alex if( ! Conf_Channel[i].name[0] ) continue;
178 c23535bc 2002-05-22 alex
179 6725d789 2002-12-12 alex /* Valid "Channel" section */
180 040f5422 2002-05-21 alex puts( "[CHANNEL]" );
181 040f5422 2002-05-21 alex printf( " Name = %s\n", Conf_Channel[i].name );
182 040f5422 2002-05-21 alex printf( " Modes = %s\n", Conf_Channel[i].modes );
183 040f5422 2002-05-21 alex printf( " Topic = %s\n", Conf_Channel[i].topic );
184 040f5422 2002-05-21 alex puts( "" );
185 040f5422 2002-05-21 alex }
186 f86083a0 2002-03-27 alex
187 f86083a0 2002-03-27 alex return 0;
188 f86083a0 2002-03-27 alex } /* Conf_Test */
189 a2544e49 2002-12-30 alex
190 a2544e49 2002-12-30 alex
191 a2544e49 2002-12-30 alex GLOBAL VOID
192 a2544e49 2002-12-30 alex Conf_UnsetServer( CONN_ID Idx )
193 a2544e49 2002-12-30 alex {
194 a2544e49 2002-12-30 alex /* Set next time for next connection attempt, if this is a server
195 a2544e49 2002-12-30 alex * link that is (still) configured here. If the server is set as
196 a2544e49 2002-12-30 alex * "once", delete it from our configuration.
197 a2544e49 2002-12-30 alex * Non-Server-Connections will be silently ignored. */
198 a2544e49 2002-12-30 alex
199 a2544e49 2002-12-30 alex INT i;
200 a2544e49 2002-12-30 alex
201 a2544e49 2002-12-30 alex /* Check all our configured servers */
202 a2544e49 2002-12-30 alex for( i = 0; i < MAX_SERVERS; i++ )
203 a2544e49 2002-12-30 alex {
204 a2544e49 2002-12-30 alex if( Conf_Server[i].conn_id != Idx ) continue;
205 a2544e49 2002-12-30 alex
206 a2544e49 2002-12-30 alex /* Gotcha! Mark server configuration as "unused": */
207 a2544e49 2002-12-30 alex Conf_Server[i].conn_id = NONE;
208 a2544e49 2002-12-30 alex
209 281f7583 2002-12-31 alex if( Conf_Server[i].flags & CONF_SFLAG_ONCE )
210 a2544e49 2002-12-30 alex {
211 a2544e49 2002-12-30 alex /* Delete configuration here */
212 a2544e49 2002-12-30 alex Init_Server_Struct( &Conf_Server[i] );
213 a2544e49 2002-12-30 alex }
214 a2544e49 2002-12-30 alex else
215 a2544e49 2002-12-30 alex {
216 a2544e49 2002-12-30 alex /* Set time for next connect attempt */
217 a2544e49 2002-12-30 alex if( Conf_Server[i].lasttry < time( NULL ) - Conf_ConnectRetry )
218 a2544e49 2002-12-30 alex {
219 a2544e49 2002-12-30 alex /* Okay, the connection was established "long enough": */
220 a2544e49 2002-12-30 alex Conf_Server[i].lasttry = time( NULL ) - Conf_ConnectRetry + RECONNECT_DELAY;
221 a2544e49 2002-12-30 alex }
222 a2544e49 2002-12-30 alex }
223 a2544e49 2002-12-30 alex }
224 a2544e49 2002-12-30 alex } /* Conf_UnsetServer */
225 f86083a0 2002-03-27 alex
226 f86083a0 2002-03-27 alex
227 a2544e49 2002-12-30 alex GLOBAL VOID
228 a2544e49 2002-12-30 alex Conf_SetServer( INT ConfServer, CONN_ID Idx )
229 a2544e49 2002-12-30 alex {
230 a2544e49 2002-12-30 alex /* Set connection for specified configured server */
231 a2544e49 2002-12-30 alex
232 a2544e49 2002-12-30 alex assert( ConfServer > NONE );
233 a2544e49 2002-12-30 alex assert( Idx > NONE );
234 a2544e49 2002-12-30 alex
235 a2544e49 2002-12-30 alex Conf_Server[ConfServer].conn_id = Idx;
236 a2544e49 2002-12-30 alex } /* Conf_SetServer */
237 a2544e49 2002-12-30 alex
238 a2544e49 2002-12-30 alex
239 a2544e49 2002-12-30 alex GLOBAL INT
240 a2544e49 2002-12-30 alex Conf_GetServer( CONN_ID Idx )
241 a2544e49 2002-12-30 alex {
242 a2544e49 2002-12-30 alex /* Get index of server in configuration structure */
243 a061668b 2003-04-21 alex
244 a061668b 2003-04-21 alex INT i = 0;
245 a061668b 2003-04-21 alex
246 a2544e49 2002-12-30 alex assert( Idx > NONE );
247 a2544e49 2002-12-30 alex
248 a2544e49 2002-12-30 alex for( i = 0; i < MAX_SERVERS; i++ )
249 a2544e49 2002-12-30 alex {
250 a2544e49 2002-12-30 alex if( Conf_Server[i].conn_id == Idx ) return i;
251 a2544e49 2002-12-30 alex }
252 a2544e49 2002-12-30 alex return NONE;
253 a2544e49 2002-12-30 alex } /* Conf_GetServer */
254 281f7583 2002-12-31 alex
255 281f7583 2002-12-31 alex
256 281f7583 2002-12-31 alex GLOBAL BOOLEAN
257 281f7583 2002-12-31 alex Conf_EnableServer( CHAR *Name, INT Port )
258 281f7583 2002-12-31 alex {
259 281f7583 2002-12-31 alex /* Enable specified server and adjust port */
260 281f7583 2002-12-31 alex
261 281f7583 2002-12-31 alex INT i;
262 281f7583 2002-12-31 alex
263 281f7583 2002-12-31 alex assert( Name != NULL );
264 281f7583 2002-12-31 alex
265 281f7583 2002-12-31 alex for( i = 0; i < MAX_SERVERS; i++ )
266 281f7583 2002-12-31 alex {
267 281f7583 2002-12-31 alex if( strcasecmp( Conf_Server[i].name, Name ) == 0 )
268 281f7583 2002-12-31 alex {
269 281f7583 2002-12-31 alex /* Gotcha! Set port and enable server: */
270 281f7583 2002-12-31 alex Conf_Server[i].port = Port;
271 281f7583 2002-12-31 alex Conf_Server[i].flags &= ~CONF_SFLAG_DISABLED;
272 281f7583 2002-12-31 alex return TRUE;
273 281f7583 2002-12-31 alex }
274 281f7583 2002-12-31 alex }
275 281f7583 2002-12-31 alex return FALSE;
276 281f7583 2002-12-31 alex } /* Conf_EnableServer */
277 a2544e49 2002-12-30 alex
278 a2544e49 2002-12-30 alex
279 281f7583 2002-12-31 alex GLOBAL BOOLEAN
280 281f7583 2002-12-31 alex Conf_DisableServer( CHAR *Name )
281 281f7583 2002-12-31 alex {
282 281f7583 2002-12-31 alex /* Enable specified server and adjust port */
283 281f7583 2002-12-31 alex
284 281f7583 2002-12-31 alex INT i;
285 281f7583 2002-12-31 alex
286 281f7583 2002-12-31 alex assert( Name != NULL );
287 281f7583 2002-12-31 alex
288 281f7583 2002-12-31 alex for( i = 0; i < MAX_SERVERS; i++ )
289 281f7583 2002-12-31 alex {
290 281f7583 2002-12-31 alex if( strcasecmp( Conf_Server[i].name, Name ) == 0 )
291 281f7583 2002-12-31 alex {
292 281f7583 2002-12-31 alex /* Gotcha! Disable and disconnect server: */
293 281f7583 2002-12-31 alex Conf_Server[i].flags |= CONF_SFLAG_DISABLED;
294 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 );
295 281f7583 2002-12-31 alex return TRUE;
296 281f7583 2002-12-31 alex }
297 281f7583 2002-12-31 alex }
298 281f7583 2002-12-31 alex return FALSE;
299 281f7583 2002-12-31 alex } /* Conf_DisableServer */
300 281f7583 2002-12-31 alex
301 281f7583 2002-12-31 alex
302 281f7583 2002-12-31 alex GLOBAL BOOLEAN
303 281f7583 2002-12-31 alex Conf_AddServer( CHAR *Name, INT Port, CHAR *Host, CHAR *MyPwd, CHAR *PeerPwd )
304 281f7583 2002-12-31 alex {
305 281f7583 2002-12-31 alex /* Add new server to configuration */
306 281f7583 2002-12-31 alex
307 281f7583 2002-12-31 alex INT i;
308 281f7583 2002-12-31 alex
309 281f7583 2002-12-31 alex assert( Name != NULL );
310 281f7583 2002-12-31 alex assert( Host != NULL );
311 281f7583 2002-12-31 alex assert( MyPwd != NULL );
312 281f7583 2002-12-31 alex assert( PeerPwd != NULL );
313 281f7583 2002-12-31 alex
314 281f7583 2002-12-31 alex /* Search unused item in server configuration structure */
315 281f7583 2002-12-31 alex for( i = 0; i < MAX_SERVERS; i++ )
316 281f7583 2002-12-31 alex {
317 281f7583 2002-12-31 alex /* Is this item used? */
318 281f7583 2002-12-31 alex if( ! Conf_Server[i].name[0] ) break;
319 281f7583 2002-12-31 alex }
320 281f7583 2002-12-31 alex if( i >= MAX_SERVERS ) return FALSE;
321 281f7583 2002-12-31 alex
322 281f7583 2002-12-31 alex Init_Server_Struct( &Conf_Server[i] );
323 281f7583 2002-12-31 alex strlcpy( Conf_Server[i].name, Name, sizeof( Conf_Server[i].name ));
324 281f7583 2002-12-31 alex strlcpy( Conf_Server[i].host, Host, sizeof( Conf_Server[i].host ));
325 281f7583 2002-12-31 alex strlcpy( Conf_Server[i].pwd_out, MyPwd, sizeof( Conf_Server[i].pwd_out ));
326 281f7583 2002-12-31 alex strlcpy( Conf_Server[i].pwd_in, PeerPwd, sizeof( Conf_Server[i].pwd_in ));
327 281f7583 2002-12-31 alex Conf_Server[i].port = Port;
328 281f7583 2002-12-31 alex Conf_Server[i].flags = CONF_SFLAG_ONCE;
329 281f7583 2002-12-31 alex
330 281f7583 2002-12-31 alex return TRUE;
331 281f7583 2002-12-31 alex } /* Conf_AddServer */
332 281f7583 2002-12-31 alex
333 281f7583 2002-12-31 alex
334 c2f60abe 2002-05-27 alex LOCAL VOID
335 a2544e49 2002-12-30 alex Set_Defaults( BOOLEAN InitServers )
336 f86083a0 2002-03-27 alex {
337 6725d789 2002-12-12 alex /* Initialize configuration variables with default values. */
338 f86083a0 2002-03-27 alex
339 a2544e49 2002-12-30 alex INT i;
340 a2544e49 2002-12-30 alex
341 9856253d 2001-12-30 alex strcpy( Conf_ServerName, "" );
342 62796722 2003-03-31 alex sprintf( Conf_ServerInfo, "%s %s", PACKAGE_NAME, PACKAGE_VERSION );
343 ed406b4a 2002-01-03 alex strcpy( Conf_ServerPwd, "" );
344 9856253d 2001-12-30 alex
345 b615d128 2002-09-16 alex strcpy( Conf_ServerAdmin1, "" );
346 b615d128 2002-09-16 alex strcpy( Conf_ServerAdmin2, "" );
347 b615d128 2002-09-16 alex strcpy( Conf_ServerAdminMail, "" );
348 b615d128 2002-09-16 alex
349 6626395c 2002-12-26 alex strlcpy( Conf_MotdFile, SYSCONFDIR, sizeof( Conf_MotdFile ));
350 6626395c 2002-12-26 alex strlcat( Conf_MotdFile, MOTD_FILE, sizeof( Conf_MotdFile ));
351 7281b8dd 2004-05-07 alex
352 7281b8dd 2004-05-07 alex strlcpy( Conf_MotdPhrase, MOTD_PHRASE, sizeof( Conf_MotdPhrase ));
353 7281b8dd 2004-05-07 alex
354 7281b8dd 2004-05-07 alex strlcpy( Conf_Chroot, CHROOT_DIR, sizeof( Conf_Chroot ));
355 9856253d 2001-12-30 alex
356 9856253d 2001-12-30 alex Conf_ListenPorts_Count = 0;
357 e33ab903 2003-09-11 alex strcpy( Conf_ListenAddress, "" );
358 1c2d0ae5 2002-03-29 alex
359 1c2d0ae5 2002-03-29 alex Conf_UID = Conf_GID = 0;
360 574ae82c 2001-12-26 alex
361 08cf5607 2001-12-26 alex Conf_PingTimeout = 120;
362 281d8e45 2002-03-25 alex Conf_PongTimeout = 20;
363 574ae82c 2001-12-26 alex
364 03d971d9 2002-01-02 alex Conf_ConnectRetry = 60;
365 03d971d9 2002-01-02 alex
366 03d971d9 2002-01-02 alex Conf_Oper_Count = 0;
367 040f5422 2002-05-21 alex Conf_Channel_Count = 0;
368 7e1b3b91 2002-09-02 alex
369 7e1b3b91 2002-09-02 alex Conf_OperCanMode = FALSE;
370 0d32a3b4 2002-11-02 alex
371 8b7b23cf 2002-12-13 alex Conf_MaxConnections = -1;
372 2981fe9e 2003-11-05 alex Conf_MaxConnectionsIP = 5;
373 8b7b23cf 2002-12-13 alex Conf_MaxJoins = 10;
374 a2544e49 2002-12-30 alex
375 a2544e49 2002-12-30 alex /* Initialize server configuration structures */
376 a2544e49 2002-12-30 alex if( InitServers ) for( i = 0; i < MAX_SERVERS; Init_Server_Struct( &Conf_Server[i++] ));
377 f86083a0 2002-03-27 alex } /* Set_Defaults */
378 03d971d9 2002-01-02 alex
379 cbc1e59f 2001-12-12 alex
380 c2f60abe 2002-05-27 alex LOCAL VOID
381 c2f60abe 2002-05-27 alex Read_Config( VOID )
382 574ae82c 2001-12-26 alex {
383 6725d789 2002-12-12 alex /* Read configuration file. */
384 9856253d 2001-12-30 alex
385 03d971d9 2002-01-02 alex CHAR section[LINE_LEN], str[LINE_LEN], *var, *arg, *ptr;
386 02a22611 2003-03-27 alex INT line, i, n;
387 9856253d 2001-12-30 alex FILE *fd;
388 9856253d 2001-12-30 alex
389 a2544e49 2002-12-30 alex /* Open configuration file */
390 f86083a0 2002-03-27 alex fd = fopen( NGIRCd_ConfFile, "r" );
391 9856253d 2001-12-30 alex if( ! fd )
392 9856253d 2001-12-30 alex {
393 6725d789 2002-12-12 alex /* No configuration file found! */
394 f86083a0 2002-03-27 alex Config_Error( LOG_ALERT, "Can't read configuration \"%s\": %s", NGIRCd_ConfFile, strerror( errno ));
395 62796722 2003-03-31 alex Config_Error( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME );
396 9856253d 2001-12-30 alex exit( 1 );
397 9856253d 2001-12-30 alex }
398 03ec91f9 2002-11-22 alex
399 03ec91f9 2002-11-22 alex Config_Error( LOG_INFO, "Reading configuration from \"%s\" ...", NGIRCd_ConfFile );
400 9856253d 2001-12-30 alex
401 a2544e49 2002-12-30 alex /* Clean up server configuration structure: mark all already
402 a2544e49 2002-12-30 alex * configured servers as "once" so that they are deleted
403 02a22611 2003-03-27 alex * after the next disconnect and delete all unused servers.
404 02a22611 2003-03-27 alex * And delete all servers which are "duplicates" of servers
405 02a22611 2003-03-27 alex * that are already marked as "once" (such servers have been
406 02a22611 2003-03-27 alex * created by the last rehash but are now useless). */
407 a2544e49 2002-12-30 alex for( i = 0; i < MAX_SERVERS; i++ )
408 a2544e49 2002-12-30 alex {
409 a2544e49 2002-12-30 alex if( Conf_Server[i].conn_id == NONE ) Init_Server_Struct( &Conf_Server[i] );
410 02a22611 2003-03-27 alex else
411 02a22611 2003-03-27 alex {
412 02a22611 2003-03-27 alex /* This structure is in use ... */
413 02a22611 2003-03-27 alex if( Conf_Server[i].flags & CONF_SFLAG_ONCE )
414 02a22611 2003-03-27 alex {
415 02a22611 2003-03-27 alex /* Check for duplicates */
416 02a22611 2003-03-27 alex for( n = 0; n < MAX_SERVERS; n++ )
417 02a22611 2003-03-27 alex {
418 02a22611 2003-03-27 alex if( n == i ) continue;
419 02a22611 2003-03-27 alex
420 02a22611 2003-03-27 alex if( Conf_Server[i].conn_id == Conf_Server[n].conn_id )
421 02a22611 2003-03-27 alex {
422 02a22611 2003-03-27 alex Init_Server_Struct( &Conf_Server[n] );
423 02a22611 2003-03-27 alex Log( LOG_DEBUG, "Deleted unused duplicate server %d (kept %d).", n, i );
424 02a22611 2003-03-27 alex }
425 02a22611 2003-03-27 alex }
426 02a22611 2003-03-27 alex }
427 02a22611 2003-03-27 alex else
428 02a22611 2003-03-27 alex {
429 02a22611 2003-03-27 alex /* Mark server as "once" */
430 02a22611 2003-03-27 alex Conf_Server[i].flags |= CONF_SFLAG_ONCE;
431 0b91df05 2003-04-20 alex Log( LOG_DEBUG, "Marked server %d as \"once\"", i );
432 02a22611 2003-03-27 alex }
433 02a22611 2003-03-27 alex }
434 a2544e49 2002-12-30 alex }
435 a2544e49 2002-12-30 alex
436 a2544e49 2002-12-30 alex /* Initialize variables */
437 9856253d 2001-12-30 alex line = 0;
438 03d971d9 2002-01-02 alex strcpy( section, "" );
439 a2544e49 2002-12-30 alex Init_Server_Struct( &New_Server );
440 a2544e49 2002-12-30 alex New_Server_Idx = NONE;
441 a2544e49 2002-12-30 alex
442 a2544e49 2002-12-30 alex /* Read configuration file */
443 9856253d 2001-12-30 alex while( TRUE )
444 9856253d 2001-12-30 alex {
445 804b1ec4 2001-12-31 alex if( ! fgets( str, LINE_LEN, fd )) break;
446 9856253d 2001-12-30 alex ngt_TrimStr( str );
447 9856253d 2001-12-30 alex line++;
448 9856253d 2001-12-30 alex
449 6725d789 2002-12-12 alex /* Skip comments and empty lines */
450 9856253d 2001-12-30 alex if( str[0] == ';' || str[0] == '#' || str[0] == '\0' ) continue;
451 9856253d 2001-12-30 alex
452 6725d789 2002-12-12 alex /* Is this the beginning of a new section? */
453 03d971d9 2002-01-02 alex if(( str[0] == '[' ) && ( str[strlen( str ) - 1] == ']' ))
454 03d971d9 2002-01-02 alex {
455 695631b2 2002-12-26 alex strlcpy( section, str, sizeof( section ));
456 03d971d9 2002-01-02 alex if( strcasecmp( section, "[GLOBAL]" ) == 0 ) continue;
457 03d971d9 2002-01-02 alex if( strcasecmp( section, "[OPERATOR]" ) == 0 )
458 03d971d9 2002-01-02 alex {
459 f86083a0 2002-03-27 alex if( Conf_Oper_Count + 1 > MAX_OPERATORS ) Config_Error( LOG_ERR, "Too many operators configured." );
460 03d971d9 2002-01-02 alex else
461 03d971d9 2002-01-02 alex {
462 6725d789 2002-12-12 alex /* Initialize new operator structure */
463 03d971d9 2002-01-02 alex strcpy( Conf_Oper[Conf_Oper_Count].name, "" );
464 03d971d9 2002-01-02 alex strcpy( Conf_Oper[Conf_Oper_Count].pwd, "" );
465 03d971d9 2002-01-02 alex Conf_Oper_Count++;
466 03d971d9 2002-01-02 alex }
467 03d971d9 2002-01-02 alex continue;
468 03d971d9 2002-01-02 alex }
469 03d971d9 2002-01-02 alex if( strcasecmp( section, "[SERVER]" ) == 0 )
470 03d971d9 2002-01-02 alex {
471 a2544e49 2002-12-30 alex /* Check if there is already a server to add */
472 a2544e49 2002-12-30 alex if( New_Server.name[0] )
473 03d971d9 2002-01-02 alex {
474 a2544e49 2002-12-30 alex /* Copy data to "real" server structure */
475 a2544e49 2002-12-30 alex assert( New_Server_Idx > NONE );
476 a2544e49 2002-12-30 alex Conf_Server[New_Server_Idx] = New_Server;
477 a2544e49 2002-12-30 alex }
478 a2544e49 2002-12-30 alex
479 a2544e49 2002-12-30 alex /* Re-init structure for new server */
480 a2544e49 2002-12-30 alex Init_Server_Struct( &New_Server );
481 a2544e49 2002-12-30 alex
482 a2544e49 2002-12-30 alex /* Search unused item in server configuration structure */
483 a2544e49 2002-12-30 alex for( i = 0; i < MAX_SERVERS; i++ )
484 a2544e49 2002-12-30 alex {
485 a2544e49 2002-12-30 alex /* Is this item used? */
486 a2544e49 2002-12-30 alex if( ! Conf_Server[i].name[0] ) break;
487 040f5422 2002-05-21 alex }
488 a2544e49 2002-12-30 alex if( i >= MAX_SERVERS )
489 a2544e49 2002-12-30 alex {
490 a2544e49 2002-12-30 alex /* Oops, no free item found! */
491 a2544e49 2002-12-30 alex Config_Error( LOG_ERR, "Too many servers configured." );
492 a2544e49 2002-12-30 alex New_Server_Idx = NONE;
493 a2544e49 2002-12-30 alex }
494 a2544e49 2002-12-30 alex else New_Server_Idx = i;
495 040f5422 2002-05-21 alex continue;
496 040f5422 2002-05-21 alex }
497 040f5422 2002-05-21 alex if( strcasecmp( section, "[CHANNEL]" ) == 0 )
498 040f5422 2002-05-21 alex {
499 040f5422 2002-05-21 alex if( Conf_Channel_Count + 1 > MAX_DEFCHANNELS ) Config_Error( LOG_ERR, "Too many pre-defined channels configured." );
500 040f5422 2002-05-21 alex else
501 040f5422 2002-05-21 alex {
502 6725d789 2002-12-12 alex /* Initialize new channel structure */
503 040f5422 2002-05-21 alex strcpy( Conf_Channel[Conf_Channel_Count].name, "" );
504 040f5422 2002-05-21 alex strcpy( Conf_Channel[Conf_Channel_Count].modes, "" );
505 040f5422 2002-05-21 alex strcpy( Conf_Channel[Conf_Channel_Count].topic, "" );
506 040f5422 2002-05-21 alex Conf_Channel_Count++;
507 03d971d9 2002-01-02 alex }
508 03d971d9 2002-01-02 alex continue;
509 03d971d9 2002-01-02 alex }
510 f86083a0 2002-03-27 alex Config_Error( LOG_ERR, "%s, line %d: Unknown section \"%s\"!", NGIRCd_ConfFile, line, section );
511 03d971d9 2002-01-02 alex section[0] = 0x1;
512 03d971d9 2002-01-02 alex }
513 03d971d9 2002-01-02 alex if( section[0] == 0x1 ) continue;
514 03d971d9 2002-01-02 alex
515 6725d789 2002-12-12 alex /* Split line into variable name and parameters */
516 9856253d 2001-12-30 alex ptr = strchr( str, '=' );
517 9856253d 2001-12-30 alex if( ! ptr )
518 9856253d 2001-12-30 alex {
519 f86083a0 2002-03-27 alex Config_Error( LOG_ERR, "%s, line %d: Syntax error!", NGIRCd_ConfFile, line );
520 9856253d 2001-12-30 alex continue;
521 9856253d 2001-12-30 alex }
522 9856253d 2001-12-30 alex *ptr = '\0';
523 9856253d 2001-12-30 alex var = str; ngt_TrimStr( var );
524 9856253d 2001-12-30 alex arg = ptr + 1; ngt_TrimStr( arg );
525 03d971d9 2002-01-02 alex
526 03d971d9 2002-01-02 alex if( strcasecmp( section, "[GLOBAL]" ) == 0 ) Handle_GLOBAL( line, var, arg );
527 03d971d9 2002-01-02 alex else if( strcasecmp( section, "[OPERATOR]" ) == 0 ) Handle_OPERATOR( line, var, arg );
528 03d971d9 2002-01-02 alex else if( strcasecmp( section, "[SERVER]" ) == 0 ) Handle_SERVER( line, var, arg );
529 040f5422 2002-05-21 alex else if( strcasecmp( section, "[CHANNEL]" ) == 0 ) Handle_CHANNEL( line, var, arg );
530 f86083a0 2002-03-27 alex else Config_Error( LOG_ERR, "%s, line %d: Variable \"%s\" outside section!", NGIRCd_ConfFile, line, var );
531 03d971d9 2002-01-02 alex }
532 a2544e49 2002-12-30 alex
533 a2544e49 2002-12-30 alex /* Close configuration file */
534 03d971d9 2002-01-02 alex fclose( fd );
535 a2544e49 2002-12-30 alex
536 a2544e49 2002-12-30 alex /* Check if there is still a server to add */
537 a2544e49 2002-12-30 alex if( New_Server.name[0] )
538 a2544e49 2002-12-30 alex {
539 a2544e49 2002-12-30 alex /* Copy data to "real" server structure */
540 a2544e49 2002-12-30 alex assert( New_Server_Idx > NONE );
541 a2544e49 2002-12-30 alex Conf_Server[New_Server_Idx] = New_Server;
542 a2544e49 2002-12-30 alex }
543 1c99b837 2002-03-30 alex
544 6725d789 2002-12-12 alex /* If there are no ports configured use the default: 6667 */
545 1c99b837 2002-03-30 alex if( Conf_ListenPorts_Count < 1 )
546 1c99b837 2002-03-30 alex {
547 1c99b837 2002-03-30 alex Conf_ListenPorts_Count = 1;
548 1c99b837 2002-03-30 alex Conf_ListenPorts[0] = 6667;
549 1c99b837 2002-03-30 alex }
550 03d971d9 2002-01-02 alex } /* Read_Config */
551 03d971d9 2002-01-02 alex
552 03d971d9 2002-01-02 alex
553 c2f60abe 2002-05-27 alex LOCAL VOID
554 c2f60abe 2002-05-27 alex Handle_GLOBAL( INT Line, CHAR *Var, CHAR *Arg )
555 03d971d9 2002-01-02 alex {
556 ae39724a 2002-11-08 alex struct passwd *pwd;
557 ae39724a 2002-11-08 alex struct group *grp;
558 03d971d9 2002-01-02 alex CHAR *ptr;
559 c7b55aa6 2002-10-09 alex LONG port;
560 03d971d9 2002-01-02 alex
561 03d971d9 2002-01-02 alex assert( Line > 0 );
562 03d971d9 2002-01-02 alex assert( Var != NULL );
563 03d971d9 2002-01-02 alex assert( Arg != NULL );
564 03d971d9 2002-01-02 alex
565 03d971d9 2002-01-02 alex if( strcasecmp( Var, "Name" ) == 0 )
566 03d971d9 2002-01-02 alex {
567 6725d789 2002-12-12 alex /* Server name */
568 0ced4181 2002-12-26 alex if( strlcpy( Conf_ServerName, Arg, sizeof( Conf_ServerName )) >= sizeof( Conf_ServerName )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"Name\" too long!", NGIRCd_ConfFile, Line );
569 03d971d9 2002-01-02 alex return;
570 03d971d9 2002-01-02 alex }
571 03d971d9 2002-01-02 alex if( strcasecmp( Var, "Info" ) == 0 )
572 03d971d9 2002-01-02 alex {
573 6725d789 2002-12-12 alex /* Info text of server */
574 0ced4181 2002-12-26 alex if( strlcpy( Conf_ServerInfo, Arg, sizeof( Conf_ServerInfo )) >= sizeof( Conf_ServerInfo )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"Info\" too long!", NGIRCd_ConfFile, Line );
575 03d971d9 2002-01-02 alex return;
576 03d971d9 2002-01-02 alex }
577 ed406b4a 2002-01-03 alex if( strcasecmp( Var, "Password" ) == 0 )
578 ed406b4a 2002-01-03 alex {
579 6725d789 2002-12-12 alex /* Global server password */
580 0ced4181 2002-12-26 alex if( strlcpy( Conf_ServerPwd, Arg, sizeof( Conf_ServerPwd )) >= sizeof( Conf_ServerPwd )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"Password\" too long!", NGIRCd_ConfFile, Line );
581 b615d128 2002-09-16 alex return;
582 b615d128 2002-09-16 alex }
583 b615d128 2002-09-16 alex if( strcasecmp( Var, "AdminInfo1" ) == 0 )
584 b615d128 2002-09-16 alex {
585 6725d789 2002-12-12 alex /* Administrative info #1 */
586 0ced4181 2002-12-26 alex if( strlcpy( Conf_ServerAdmin1, Arg, sizeof( Conf_ServerAdmin1 )) >= sizeof( Conf_ServerAdmin1 )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"AdminInfo1\" too long!", NGIRCd_ConfFile, Line );
587 b615d128 2002-09-16 alex return;
588 b615d128 2002-09-16 alex }
589 b615d128 2002-09-16 alex if( strcasecmp( Var, "AdminInfo2" ) == 0 )
590 b615d128 2002-09-16 alex {
591 6725d789 2002-12-12 alex /* Administrative info #2 */
592 0ced4181 2002-12-26 alex if( strlcpy( Conf_ServerAdmin2, Arg, sizeof( Conf_ServerAdmin2 )) >= sizeof( Conf_ServerAdmin2 )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"AdminInfo2\" too long!", NGIRCd_ConfFile, Line );
593 b615d128 2002-09-16 alex return;
594 b615d128 2002-09-16 alex }
595 b615d128 2002-09-16 alex if( strcasecmp( Var, "AdminEMail" ) == 0 )
596 b615d128 2002-09-16 alex {
597 6725d789 2002-12-12 alex /* Administrative email contact */
598 0ced4181 2002-12-26 alex if( strlcpy( Conf_ServerAdminMail, Arg, sizeof( Conf_ServerAdminMail )) >= sizeof( Conf_ServerAdminMail )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"AdminEMail\" too long!", NGIRCd_ConfFile, Line );
599 ed406b4a 2002-01-03 alex return;
600 ed406b4a 2002-01-03 alex }
601 03d971d9 2002-01-02 alex if( strcasecmp( Var, "Ports" ) == 0 )
602 03d971d9 2002-01-02 alex {
603 6725d789 2002-12-12 alex /* Ports on that the server should listen. More port numbers
604 6725d789 2002-12-12 alex * must be separated by "," */
605 03d971d9 2002-01-02 alex ptr = strtok( Arg, "," );
606 03d971d9 2002-01-02 alex while( ptr )
607 9856253d 2001-12-30 alex {
608 03d971d9 2002-01-02 alex ngt_TrimStr( ptr );
609 03d971d9 2002-01-02 alex port = atol( ptr );
610 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 );
611 03d971d9 2002-01-02 alex else
612 03d971d9 2002-01-02 alex {
613 1c2d0ae5 2002-03-29 alex if( port > 0 && port < 0xFFFF ) Conf_ListenPorts[Conf_ListenPorts_Count++] = (UINT)port;
614 f86083a0 2002-03-27 alex else Config_Error( LOG_ERR, "%s, line %d (section \"Global\"): Illegal port number %ld!", NGIRCd_ConfFile, Line, port );
615 03d971d9 2002-01-02 alex }
616 03d971d9 2002-01-02 alex ptr = strtok( NULL, "," );
617 9856253d 2001-12-30 alex }
618 03d971d9 2002-01-02 alex return;
619 03d971d9 2002-01-02 alex }
620 03d971d9 2002-01-02 alex if( strcasecmp( Var, "MotdFile" ) == 0 )
621 03d971d9 2002-01-02 alex {
622 6725d789 2002-12-12 alex /* "Message of the day" (MOTD) file */
623 0ced4181 2002-12-26 alex if( strlcpy( Conf_MotdFile, Arg, sizeof( Conf_MotdFile )) >= sizeof( Conf_MotdFile )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"MotdFile\" too long!", NGIRCd_ConfFile, Line );
624 7281b8dd 2004-05-07 alex return;
625 7281b8dd 2004-05-07 alex }
626 7281b8dd 2004-05-07 alex if( strcasecmp( Var, "MotdPhrase" ) == 0 )
627 7281b8dd 2004-05-07 alex {
628 7281b8dd 2004-05-07 alex /* "Message of the day" phrase (instead of file) */
629 7281b8dd 2004-05-07 alex if( strlcpy( Conf_MotdPhrase, Arg, sizeof( Conf_MotdPhrase )) >= sizeof( Conf_MotdPhrase )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"MotdPhrase\" too long!", NGIRCd_ConfFile, Line );
630 03d971d9 2002-01-02 alex return;
631 03d971d9 2002-01-02 alex }
632 7281b8dd 2004-05-07 alex if( strcasecmp( Var, "ChrootDir" ) == 0 )
633 7281b8dd 2004-05-07 alex {
634 7281b8dd 2004-05-07 alex /* directory for chroot() */
635 7281b8dd 2004-05-07 alex if( strlcpy( Conf_Chroot, Arg, sizeof( Conf_Chroot )) >= sizeof( Conf_Chroot )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"ChrootDir\" too long!", NGIRCd_ConfFile, Line );
636 7281b8dd 2004-05-07 alex return;
637 7281b8dd 2004-05-07 alex }
638 1c2d0ae5 2002-03-29 alex if( strcasecmp( Var, "ServerUID" ) == 0 )
639 1c2d0ae5 2002-03-29 alex {
640 6725d789 2002-12-12 alex /* UID the daemon should switch to */
641 ae39724a 2002-11-08 alex pwd = getpwnam( Arg );
642 ae39724a 2002-11-08 alex if( pwd ) Conf_UID = pwd->pw_uid;
643 2e02da29 2002-11-30 alex else
644 2e02da29 2002-11-30 alex {
645 2e02da29 2002-11-30 alex #ifdef HAVE_ISDIGIT
646 cdb694ae 2004-01-17 alex if( ! isdigit( (INT)*Arg )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"ServerUID\" is not a number!", NGIRCd_ConfFile, Line );
647 2e02da29 2002-11-30 alex else
648 2e02da29 2002-11-30 alex #endif
649 2e02da29 2002-11-30 alex Conf_UID = (UINT)atoi( Arg );
650 2e02da29 2002-11-30 alex }
651 1c2d0ae5 2002-03-29 alex return;
652 1c2d0ae5 2002-03-29 alex }
653 1c2d0ae5 2002-03-29 alex if( strcasecmp( Var, "ServerGID" ) == 0 )
654 1c2d0ae5 2002-03-29 alex {
655 6725d789 2002-12-12 alex /* GID the daemon should use */
656 ae39724a 2002-11-08 alex grp = getgrnam( Arg );
657 ae39724a 2002-11-08 alex if( grp ) Conf_GID = grp->gr_gid;
658 2e02da29 2002-11-30 alex else
659 2e02da29 2002-11-30 alex {
660 2e02da29 2002-11-30 alex #ifdef HAVE_ISDIGIT
661 cdb694ae 2004-01-17 alex if( ! isdigit( (INT)*Arg )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"ServerGID\" is not a number!", NGIRCd_ConfFile, Line );
662 2e02da29 2002-11-30 alex else
663 2e02da29 2002-11-30 alex #endif
664 2e02da29 2002-11-30 alex Conf_GID = (UINT)atoi( Arg );
665 2e02da29 2002-11-30 alex }
666 1c2d0ae5 2002-03-29 alex return;
667 1c2d0ae5 2002-03-29 alex }
668 03d971d9 2002-01-02 alex if( strcasecmp( Var, "PingTimeout" ) == 0 )
669 03d971d9 2002-01-02 alex {
670 6725d789 2002-12-12 alex /* PING timeout */
671 03d971d9 2002-01-02 alex Conf_PingTimeout = atoi( Arg );
672 2e02da29 2002-11-30 alex if( Conf_PingTimeout < 5 )
673 2e02da29 2002-11-30 alex {
674 2e02da29 2002-11-30 alex Config_Error( LOG_WARNING, "%s, line %d: Value of \"PingTimeout\" too low!", NGIRCd_ConfFile, Line );
675 2e02da29 2002-11-30 alex Conf_PingTimeout = 5;
676 2e02da29 2002-11-30 alex }
677 03d971d9 2002-01-02 alex return;
678 03d971d9 2002-01-02 alex }
679 03d971d9 2002-01-02 alex if( strcasecmp( Var, "PongTimeout" ) == 0 )
680 03d971d9 2002-01-02 alex {
681 6725d789 2002-12-12 alex /* PONG timeout */
682 03d971d9 2002-01-02 alex Conf_PongTimeout = atoi( Arg );
683 2e02da29 2002-11-30 alex if( Conf_PongTimeout < 5 )
684 2e02da29 2002-11-30 alex {
685 2e02da29 2002-11-30 alex Config_Error( LOG_WARNING, "%s, line %d: Value of \"PongTimeout\" too low!", NGIRCd_ConfFile, Line );
686 2e02da29 2002-11-30 alex Conf_PongTimeout = 5;
687 2e02da29 2002-11-30 alex }
688 03d971d9 2002-01-02 alex return;
689 03d971d9 2002-01-02 alex }
690 03d971d9 2002-01-02 alex if( strcasecmp( Var, "ConnectRetry" ) == 0 )
691 03d971d9 2002-01-02 alex {
692 6725d789 2002-12-12 alex /* Seconds between connection attempts to other servers */
693 03d971d9 2002-01-02 alex Conf_ConnectRetry = atoi( Arg );
694 2e02da29 2002-11-30 alex if( Conf_ConnectRetry < 5 )
695 2e02da29 2002-11-30 alex {
696 2e02da29 2002-11-30 alex Config_Error( LOG_WARNING, "%s, line %d: Value of \"ConnectRetry\" too low!", NGIRCd_ConfFile, Line );
697 2e02da29 2002-11-30 alex Conf_ConnectRetry = 5;
698 2e02da29 2002-11-30 alex }
699 7e1b3b91 2002-09-02 alex return;
700 7e1b3b91 2002-09-02 alex }
701 7e1b3b91 2002-09-02 alex if( strcasecmp( Var, "OperCanUseMode" ) == 0 )
702 7e1b3b91 2002-09-02 alex {
703 6725d789 2002-12-12 alex /* Are IRC operators allowed to use MODE in channels they aren't Op in? */
704 7e1b3b91 2002-09-02 alex if( strcasecmp( Arg, "yes" ) == 0 ) Conf_OperCanMode = TRUE;
705 7e1b3b91 2002-09-02 alex else if( strcasecmp( Arg, "true" ) == 0 ) Conf_OperCanMode = TRUE;
706 7e1b3b91 2002-09-02 alex else if( atoi( Arg ) != 0 ) Conf_OperCanMode = TRUE;
707 7e1b3b91 2002-09-02 alex else Conf_OperCanMode = FALSE;
708 03d971d9 2002-01-02 alex return;
709 03d971d9 2002-01-02 alex }
710 0d32a3b4 2002-11-02 alex if( strcasecmp( Var, "MaxConnections" ) == 0 )
711 0d32a3b4 2002-11-02 alex {
712 6725d789 2002-12-12 alex /* Maximum number of connections. Values <= 0 are equal to "no limit". */
713 2e02da29 2002-11-30 alex #ifdef HAVE_ISDIGIT
714 cdb694ae 2004-01-17 alex if( ! isdigit( (INT)*Arg )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"MaxConnections\" is not a number!", NGIRCd_ConfFile, Line );
715 2e02da29 2002-11-30 alex else
716 2e02da29 2002-11-30 alex #endif
717 0d32a3b4 2002-11-02 alex Conf_MaxConnections = atol( Arg );
718 0d32a3b4 2002-11-02 alex return;
719 0d32a3b4 2002-11-02 alex }
720 2981fe9e 2003-11-05 alex if( strcasecmp( Var, "MaxConnectionsIP" ) == 0 )
721 2981fe9e 2003-11-05 alex {
722 2981fe9e 2003-11-05 alex /* Maximum number of simoultanous connections from one IP. Values <= 0 are equal to "no limit". */
723 2981fe9e 2003-11-05 alex #ifdef HAVE_ISDIGIT
724 cdb694ae 2004-01-17 alex if( ! isdigit( (INT)*Arg )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"MaxConnectionsIP\" is not a number!", NGIRCd_ConfFile, Line );
725 2981fe9e 2003-11-05 alex else
726 2981fe9e 2003-11-05 alex #endif
727 2981fe9e 2003-11-05 alex Conf_MaxConnectionsIP = atoi( Arg );
728 2981fe9e 2003-11-05 alex return;
729 2981fe9e 2003-11-05 alex }
730 8b7b23cf 2002-12-13 alex if( strcasecmp( Var, "MaxJoins" ) == 0 )
731 8b7b23cf 2002-12-13 alex {
732 8b7b23cf 2002-12-13 alex /* Maximum number of channels a user can join. Values <= 0 are equal to "no limit". */
733 8b7b23cf 2002-12-13 alex #ifdef HAVE_ISDIGIT
734 cdb694ae 2004-01-17 alex if( ! isdigit( (INT)*Arg )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"MaxJoins\" is not a number!", NGIRCd_ConfFile, Line );
735 8b7b23cf 2002-12-13 alex else
736 8b7b23cf 2002-12-13 alex #endif
737 8b7b23cf 2002-12-13 alex Conf_MaxJoins = atoi( Arg );
738 8b7b23cf 2002-12-13 alex return;
739 8b7b23cf 2002-12-13 alex }
740 e33ab903 2003-09-11 alex if( strcasecmp( Var, "Listen" ) == 0 )
741 e33ab903 2003-09-11 alex {
742 e33ab903 2003-09-11 alex /* IP-Address to bind sockets */
743 e33ab903 2003-09-11 alex if( strlcpy( Conf_ListenAddress, Arg, sizeof( Conf_ListenAddress )) >= sizeof( Conf_ListenAddress ))
744 e33ab903 2003-09-11 alex {
745 e33ab903 2003-09-11 alex Config_Error( LOG_WARNING, "%s, line %d: Value of \"Listen\" too long!", NGIRCd_ConfFile, Line );
746 e33ab903 2003-09-11 alex }
747 2981fe9e 2003-11-05 alex return;
748 e33ab903 2003-09-11 alex }
749 8b7b23cf 2002-12-13 alex
750 f86083a0 2002-03-27 alex Config_Error( LOG_ERR, "%s, line %d (section \"Global\"): Unknown variable \"%s\"!", NGIRCd_ConfFile, Line, Var );
751 03d971d9 2002-01-02 alex } /* Handle_GLOBAL */
752 03d971d9 2002-01-02 alex
753 03d971d9 2002-01-02 alex
754 c2f60abe 2002-05-27 alex LOCAL VOID
755 c2f60abe 2002-05-27 alex Handle_OPERATOR( INT Line, CHAR *Var, CHAR *Arg )
756 03d971d9 2002-01-02 alex {
757 03d971d9 2002-01-02 alex assert( Line > 0 );
758 03d971d9 2002-01-02 alex assert( Var != NULL );
759 03d971d9 2002-01-02 alex assert( Arg != NULL );
760 03d971d9 2002-01-02 alex assert( Conf_Oper_Count > 0 );
761 03d971d9 2002-01-02 alex
762 03d971d9 2002-01-02 alex if( strcasecmp( Var, "Name" ) == 0 )
763 03d971d9 2002-01-02 alex {
764 6725d789 2002-12-12 alex /* Name of IRC operator */
765 0ced4181 2002-12-26 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( LOG_WARNING, "%s, line %d: Value of \"Name\" too long!", NGIRCd_ConfFile, Line );
766 03d971d9 2002-01-02 alex return;
767 9856253d 2001-12-30 alex }
768 03d971d9 2002-01-02 alex if( strcasecmp( Var, "Password" ) == 0 )
769 03d971d9 2002-01-02 alex {
770 6725d789 2002-12-12 alex /* Password of IRC operator */
771 0ced4181 2002-12-26 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( LOG_WARNING, "%s, line %d: Value of \"Password\" too long!", NGIRCd_ConfFile, Line );
772 03d971d9 2002-01-02 alex return;
773 03d971d9 2002-01-02 alex }
774 574ae82c 2001-12-26 alex
775 f86083a0 2002-03-27 alex Config_Error( LOG_ERR, "%s, line %d (section \"Operator\"): Unknown variable \"%s\"!", NGIRCd_ConfFile, Line, Var );
776 03d971d9 2002-01-02 alex } /* Handle_OPERATOR */
777 574ae82c 2001-12-26 alex
778 574ae82c 2001-12-26 alex
779 c2f60abe 2002-05-27 alex LOCAL VOID
780 c2f60abe 2002-05-27 alex Handle_SERVER( INT Line, CHAR *Var, CHAR *Arg )
781 03d971d9 2002-01-02 alex {
782 c7b55aa6 2002-10-09 alex LONG port;
783 03d971d9 2002-01-02 alex
784 03d971d9 2002-01-02 alex assert( Line > 0 );
785 03d971d9 2002-01-02 alex assert( Var != NULL );
786 03d971d9 2002-01-02 alex assert( Arg != NULL );
787 a2544e49 2002-12-30 alex
788 a2544e49 2002-12-30 alex /* Ignore server block if no space is left in server configuration structure */
789 a2544e49 2002-12-30 alex if( New_Server_Idx <= NONE ) return;
790 03d971d9 2002-01-02 alex
791 03d971d9 2002-01-02 alex if( strcasecmp( Var, "Host" ) == 0 )
792 03d971d9 2002-01-02 alex {
793 6725d789 2002-12-12 alex /* Hostname of the server */
794 a2544e49 2002-12-30 alex if( strlcpy( New_Server.host, Arg, sizeof( New_Server.host )) >= sizeof( New_Server.host )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"Host\" too long!", NGIRCd_ConfFile, Line );
795 03d971d9 2002-01-02 alex return;
796 03d971d9 2002-01-02 alex }
797 03d971d9 2002-01-02 alex if( strcasecmp( Var, "Name" ) == 0 )
798 03d971d9 2002-01-02 alex {
799 6725d789 2002-12-12 alex /* Name of the server ("Nick"/"ID") */
800 a2544e49 2002-12-30 alex if( strlcpy( New_Server.name, Arg, sizeof( New_Server.name )) >= sizeof( New_Server.name )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"Name\" too long!", NGIRCd_ConfFile, Line );
801 03d971d9 2002-01-02 alex return;
802 03d971d9 2002-01-02 alex }
803 b2615bcc 2002-11-19 alex if( strcasecmp( Var, "MyPassword" ) == 0 )
804 03d971d9 2002-01-02 alex {
805 6725d789 2002-12-12 alex /* Password of this server which is sent to the peer */
806 a2544e49 2002-12-30 alex if( strlcpy( New_Server.pwd_in, Arg, sizeof( New_Server.pwd_in )) >= sizeof( New_Server.pwd_in )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"MyPassword\" too long!", NGIRCd_ConfFile, Line );
807 03d971d9 2002-01-02 alex return;
808 03d971d9 2002-01-02 alex }
809 b2615bcc 2002-11-19 alex if( strcasecmp( Var, "PeerPassword" ) == 0 )
810 b2615bcc 2002-11-19 alex {
811 6725d789 2002-12-12 alex /* Passwort of the peer which must be received */
812 a2544e49 2002-12-30 alex if( strlcpy( New_Server.pwd_out, Arg, sizeof( New_Server.pwd_out )) >= sizeof( New_Server.pwd_out )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"PeerPassword\" too long!", NGIRCd_ConfFile, Line );
813 b2615bcc 2002-11-19 alex return;
814 b2615bcc 2002-11-19 alex }
815 03d971d9 2002-01-02 alex if( strcasecmp( Var, "Port" ) == 0 )
816 03d971d9 2002-01-02 alex {
817 6725d789 2002-12-12 alex /* Port to which this server should connect */
818 03d971d9 2002-01-02 alex port = atol( Arg );
819 a2544e49 2002-12-30 alex if( port > 0 && port < 0xFFFF ) New_Server.port = (INT)port;
820 f86083a0 2002-03-27 alex else Config_Error( LOG_ERR, "%s, line %d (section \"Server\"): Illegal port number %ld!", NGIRCd_ConfFile, Line, port );
821 03d971d9 2002-01-02 alex return;
822 03d971d9 2002-01-02 alex }
823 d67d94ea 2002-03-10 alex if( strcasecmp( Var, "Group" ) == 0 )
824 d67d94ea 2002-03-10 alex {
825 6725d789 2002-12-12 alex /* Server group */
826 2e02da29 2002-11-30 alex #ifdef HAVE_ISDIGIT
827 cdb694ae 2004-01-17 alex if( ! isdigit( (INT)*Arg )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"Group\" is not a number!", NGIRCd_ConfFile, Line );
828 2e02da29 2002-11-30 alex else
829 2e02da29 2002-11-30 alex #endif
830 a2544e49 2002-12-30 alex New_Server.group = atoi( Arg );
831 d67d94ea 2002-03-10 alex return;
832 d67d94ea 2002-03-10 alex }
833 03d971d9 2002-01-02 alex
834 f86083a0 2002-03-27 alex Config_Error( LOG_ERR, "%s, line %d (section \"Server\"): Unknown variable \"%s\"!", NGIRCd_ConfFile, Line, Var );
835 03d971d9 2002-01-02 alex } /* Handle_SERVER */
836 040f5422 2002-05-21 alex
837 040f5422 2002-05-21 alex
838 c2f60abe 2002-05-27 alex LOCAL VOID
839 c2f60abe 2002-05-27 alex Handle_CHANNEL( INT Line, CHAR *Var, CHAR *Arg )
840 040f5422 2002-05-21 alex {
841 040f5422 2002-05-21 alex assert( Line > 0 );
842 040f5422 2002-05-21 alex assert( Var != NULL );
843 040f5422 2002-05-21 alex assert( Arg != NULL );
844 03d971d9 2002-01-02 alex
845 040f5422 2002-05-21 alex if( strcasecmp( Var, "Name" ) == 0 )
846 040f5422 2002-05-21 alex {
847 6725d789 2002-12-12 alex /* Name of the channel */
848 0ced4181 2002-12-26 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 )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"Name\" too long!", NGIRCd_ConfFile, Line );
849 040f5422 2002-05-21 alex return;
850 040f5422 2002-05-21 alex }
851 040f5422 2002-05-21 alex if( strcasecmp( Var, "Modes" ) == 0 )
852 040f5422 2002-05-21 alex {
853 6725d789 2002-12-12 alex /* Initial modes */
854 0ced4181 2002-12-26 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 )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"Modes\" too long!", NGIRCd_ConfFile, Line );
855 040f5422 2002-05-21 alex return;
856 040f5422 2002-05-21 alex }
857 040f5422 2002-05-21 alex if( strcasecmp( Var, "Topic" ) == 0 )
858 040f5422 2002-05-21 alex {
859 6725d789 2002-12-12 alex /* Initial topic */
860 0ced4181 2002-12-26 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 )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"Topic\" too long!", NGIRCd_ConfFile, Line );
861 040f5422 2002-05-21 alex return;
862 040f5422 2002-05-21 alex }
863 03d971d9 2002-01-02 alex
864 040f5422 2002-05-21 alex Config_Error( LOG_ERR, "%s, line %d (section \"Channel\"): Unknown variable \"%s\"!", NGIRCd_ConfFile, Line, Var );
865 040f5422 2002-05-21 alex } /* Handle_CHANNEL */
866 040f5422 2002-05-21 alex
867 040f5422 2002-05-21 alex
868 c2f60abe 2002-05-27 alex LOCAL VOID
869 b7be46ed 2002-12-18 alex Validate_Config( BOOLEAN Configtest )
870 9856253d 2001-12-30 alex {
871 6725d789 2002-12-12 alex /* Validate configuration settings. */
872 a2544e49 2002-12-30 alex
873 a2544e49 2002-12-30 alex #ifdef DEBUG
874 a2544e49 2002-12-30 alex INT i, servers, servers_once;
875 a2544e49 2002-12-30 alex #endif
876 a2544e49 2002-12-30 alex
877 9856253d 2001-12-30 alex if( ! Conf_ServerName[0] )
878 9856253d 2001-12-30 alex {
879 6725d789 2002-12-12 alex /* No server name configured! */
880 05170bc9 2003-12-19 alex Config_Error( LOG_ALERT, "No server name configured in \"%s\" (section 'Global': 'Name')!", NGIRCd_ConfFile );
881 b7be46ed 2002-12-18 alex if( ! Configtest )
882 b7be46ed 2002-12-18 alex {
883 62796722 2003-03-31 alex Config_Error( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME );
884 b7be46ed 2002-12-18 alex exit( 1 );
885 b7be46ed 2002-12-18 alex }
886 9856253d 2001-12-30 alex }
887 e541da2a 2003-04-29 alex
888 05170bc9 2003-12-19 alex if( Conf_ServerName[0] && ! strchr( Conf_ServerName, '.' ))
889 e541da2a 2003-04-29 alex {
890 e541da2a 2003-04-29 alex /* No dot in server name! */
891 05170bc9 2003-12-19 alex Config_Error( LOG_ALERT, "Invalid server name configured in \"%s\" (section 'Global': 'Name'): Dot missing!", NGIRCd_ConfFile );
892 e541da2a 2003-04-29 alex if( ! Configtest )
893 e541da2a 2003-04-29 alex {
894 e541da2a 2003-04-29 alex Config_Error( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME );
895 e541da2a 2003-04-29 alex exit( 1 );
896 e541da2a 2003-04-29 alex }
897 e541da2a 2003-04-29 alex }
898 b615d128 2002-09-16 alex
899 b615d128 2002-09-16 alex #ifdef STRICT_RFC
900 12cad28e 2002-10-21 alex if( ! Conf_ServerAdminMail[0] )
901 b615d128 2002-09-16 alex {
902 6725d789 2002-12-12 alex /* No administrative contact configured! */
903 b615d128 2002-09-16 alex Config_Error( LOG_ALERT, "No administrator email address configured in \"%s\" ('AdminEMail')!", NGIRCd_ConfFile );
904 b7be46ed 2002-12-18 alex if( ! Configtest )
905 b7be46ed 2002-12-18 alex {
906 62796722 2003-03-31 alex Config_Error( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME );
907 b7be46ed 2002-12-18 alex exit( 1 );
908 b7be46ed 2002-12-18 alex }
909 b615d128 2002-09-16 alex }
910 b615d128 2002-09-16 alex #endif
911 b615d128 2002-09-16 alex
912 33bda862 2002-09-19 alex if( ! Conf_ServerAdmin1[0] && ! Conf_ServerAdmin2[0] && ! Conf_ServerAdminMail[0] )
913 b615d128 2002-09-16 alex {
914 6725d789 2002-12-12 alex /* No administrative information configured! */
915 b7be46ed 2002-12-18 alex Config_Error( LOG_WARNING, "No administrative information configured but required by RFC!" );
916 b615d128 2002-09-16 alex }
917 b7be46ed 2002-12-18 alex #ifdef FD_SETSIZE
918 3e4f58e4 2002-12-18 alex if(( Conf_MaxConnections > (LONG)FD_SETSIZE ) || ( Conf_MaxConnections < 1 ))
919 b7be46ed 2002-12-18 alex {
920 b7be46ed 2002-12-18 alex Conf_MaxConnections = (LONG)FD_SETSIZE;
921 b7be46ed 2002-12-18 alex Config_Error( LOG_ERR, "Setting MaxConnections to %ld, select() can't handle more file descriptors!", Conf_MaxConnections );
922 b7be46ed 2002-12-18 alex }
923 b7be46ed 2002-12-18 alex #else
924 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!" );
925 b7be46ed 2002-12-18 alex #endif
926 a2544e49 2002-12-30 alex
927 a2544e49 2002-12-30 alex #ifdef DEBUG
928 a2544e49 2002-12-30 alex servers = servers_once = 0;
929 a2544e49 2002-12-30 alex for( i = 0; i < MAX_SERVERS; i++ )
930 a2544e49 2002-12-30 alex {
931 a2544e49 2002-12-30 alex if( Conf_Server[i].name[0] )
932 a2544e49 2002-12-30 alex {
933 a2544e49 2002-12-30 alex servers++;
934 281f7583 2002-12-31 alex if( Conf_Server[i].flags & CONF_SFLAG_ONCE ) servers_once++;
935 a2544e49 2002-12-30 alex }
936 a2544e49 2002-12-30 alex }
937 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 );
938 a2544e49 2002-12-30 alex #endif
939 9856253d 2001-12-30 alex } /* Validate_Config */
940 9856253d 2001-12-30 alex
941 f86083a0 2002-03-27 alex
942 f7327524 2002-05-30 alex #ifdef PROTOTYPES
943 f7327524 2002-05-30 alex LOCAL VOID Config_Error( CONST INT Level, CONST CHAR *Format, ... )
944 f7327524 2002-05-30 alex #else
945 f7327524 2002-05-30 alex LOCAL VOID Config_Error( Level, Format, va_alist )
946 f7327524 2002-05-30 alex CONST INT Level;
947 f7327524 2002-05-30 alex CONST CHAR *Format;
948 f7327524 2002-05-30 alex va_dcl
949 f7327524 2002-05-30 alex #endif
950 f86083a0 2002-03-27 alex {
951 6725d789 2002-12-12 alex /* Error! Write to console and/or logfile. */
952 f86083a0 2002-03-27 alex
953 f86083a0 2002-03-27 alex CHAR msg[MAX_LOG_MSG_LEN];
954 f86083a0 2002-03-27 alex va_list ap;
955 f86083a0 2002-03-27 alex
956 f86083a0 2002-03-27 alex assert( Format != NULL );
957 f86083a0 2002-03-27 alex
958 f7327524 2002-05-30 alex #ifdef PROTOTYPES
959 f86083a0 2002-03-27 alex va_start( ap, Format );
960 f7327524 2002-05-30 alex #else
961 f7327524 2002-05-30 alex va_start( ap );
962 f7327524 2002-05-30 alex #endif
963 f86083a0 2002-03-27 alex vsnprintf( msg, MAX_LOG_MSG_LEN, Format, ap );
964 f86083a0 2002-03-27 alex va_end( ap );
965 6725d789 2002-12-12 alex
966 6725d789 2002-12-12 alex /* During "normal operations" the log functions of the daemon should
967 6725d789 2002-12-12 alex * be used, but during testing of the configuration file, all messages
968 6725d789 2002-12-12 alex * should go directly to the console: */
969 ec474a4b 2002-10-04 alex if( Use_Log ) Log( Level, "%s", msg );
970 f86083a0 2002-03-27 alex else puts( msg );
971 f86083a0 2002-03-27 alex } /* Config_Error */
972 f86083a0 2002-03-27 alex
973 f86083a0 2002-03-27 alex
974 a2544e49 2002-12-30 alex LOCAL VOID
975 a2544e49 2002-12-30 alex Init_Server_Struct( CONF_SERVER *Server )
976 a2544e49 2002-12-30 alex {
977 a2544e49 2002-12-30 alex /* Initialize server configuration structur to default values */
978 a2544e49 2002-12-30 alex
979 a2544e49 2002-12-30 alex assert( Server != NULL );
980 a2544e49 2002-12-30 alex
981 a2544e49 2002-12-30 alex strcpy( Server->host, "" );
982 a2544e49 2002-12-30 alex strcpy( Server->ip, "" );
983 a2544e49 2002-12-30 alex strcpy( Server->name, "" );
984 a2544e49 2002-12-30 alex strcpy( Server->pwd_in, "" );
985 a2544e49 2002-12-30 alex strcpy( Server->pwd_out, "" );
986 a2544e49 2002-12-30 alex Server->port = 0;
987 a2544e49 2002-12-30 alex Server->group = NONE;
988 a2544e49 2002-12-30 alex Server->lasttry = time( NULL ) - Conf_ConnectRetry + STARTUP_DELAY;
989 a2544e49 2002-12-30 alex Server->res_stat = NULL;
990 281f7583 2002-12-31 alex if( NGIRCd_Passive ) Server->flags = CONF_SFLAG_DISABLED;
991 281f7583 2002-12-31 alex else Server->flags = 0;
992 a2544e49 2002-12-30 alex Server->conn_id = NONE;
993 a2544e49 2002-12-30 alex } /* Init_Server_Struct */
994 a2544e49 2002-12-30 alex
995 a2544e49 2002-12-30 alex
996 cbc1e59f 2001-12-12 alex /* -eof- */