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