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