Blame


1 cbc1e59f 2001-12-12 alex /*
2 cbc1e59f 2001-12-12 alex * ngIRCd -- The Next Generation IRC Daemon
3 03d971d9 2002-01-02 alex * Copyright (c)2001,2002 by Alexander Barton (alex@barton.de)
4 cbc1e59f 2001-12-12 alex *
5 cbc1e59f 2001-12-12 alex * Dieses Programm ist freie Software. Sie koennen es unter den Bedingungen
6 cbc1e59f 2001-12-12 alex * der GNU General Public License (GPL), wie von der Free Software Foundation
7 cbc1e59f 2001-12-12 alex * herausgegeben, weitergeben und/oder modifizieren, entweder unter Version 2
8 cbc1e59f 2001-12-12 alex * der Lizenz oder (wenn Sie es wuenschen) jeder spaeteren Version.
9 cbc1e59f 2001-12-12 alex * Naehere Informationen entnehmen Sie bitter der Datei COPYING. Eine Liste
10 804b1ec4 2001-12-31 alex * der an ngIRCd beteiligten Autoren finden Sie in der Datei AUTHORS.
11 cbc1e59f 2001-12-12 alex *
12 33bda862 2002-09-19 alex * $Id: conf.c,v 1.30 2002/09/19 10:19:12 alex Exp $
13 cbc1e59f 2001-12-12 alex *
14 cbc1e59f 2001-12-12 alex * conf.h: Konfiguration des ngircd
15 cbc1e59f 2001-12-12 alex */
16 cbc1e59f 2001-12-12 alex
17 cbc1e59f 2001-12-12 alex
18 ca33cbda 2002-03-12 alex #include "portab.h"
19 cbc1e59f 2001-12-12 alex
20 ca33cbda 2002-03-12 alex #include "imp.h"
21 cbc1e59f 2001-12-12 alex #include <assert.h>
22 9856253d 2001-12-30 alex #include <errno.h>
23 f86083a0 2002-03-27 alex #include <stdarg.h>
24 9856253d 2001-12-30 alex #include <stdio.h>
25 b20fa7c6 2002-01-01 alex #include <stdlib.h>
26 9856253d 2001-12-30 alex #include <string.h>
27 f86083a0 2002-03-27 alex #include <unistd.h>
28 cbc1e59f 2001-12-12 alex
29 f86083a0 2002-03-27 alex #include "ngircd.h"
30 c2f60abe 2002-05-27 alex #include "conn.h"
31 9856253d 2001-12-30 alex #include "client.h"
32 ca33cbda 2002-03-12 alex #include "defines.h"
33 9856253d 2001-12-30 alex #include "log.h"
34 c2f60abe 2002-05-27 alex #include "resolve.h"
35 9856253d 2001-12-30 alex #include "tool.h"
36 9856253d 2001-12-30 alex
37 ca33cbda 2002-03-12 alex #include "exp.h"
38 cbc1e59f 2001-12-12 alex #include "conf.h"
39 cbc1e59f 2001-12-12 alex
40 cbc1e59f 2001-12-12 alex
41 f86083a0 2002-03-27 alex LOCAL BOOLEAN Use_Log = TRUE;
42 f86083a0 2002-03-27 alex
43 f86083a0 2002-03-27 alex
44 c2f60abe 2002-05-27 alex LOCAL VOID Set_Defaults PARAMS(( VOID ));
45 c2f60abe 2002-05-27 alex LOCAL VOID Read_Config PARAMS(( VOID ));
46 c2f60abe 2002-05-27 alex LOCAL VOID Validate_Config PARAMS(( VOID ));
47 03d971d9 2002-01-02 alex
48 c2f60abe 2002-05-27 alex LOCAL VOID Handle_GLOBAL PARAMS(( INT Line, CHAR *Var, CHAR *Arg ));
49 c2f60abe 2002-05-27 alex LOCAL VOID Handle_OPERATOR PARAMS(( INT Line, CHAR *Var, CHAR *Arg ));
50 c2f60abe 2002-05-27 alex LOCAL VOID Handle_SERVER PARAMS(( INT Line, CHAR *Var, CHAR *Arg ));
51 c2f60abe 2002-05-27 alex LOCAL VOID Handle_CHANNEL PARAMS(( INT Line, CHAR *Var, CHAR *Arg ));
52 03d971d9 2002-01-02 alex
53 c2f60abe 2002-05-27 alex LOCAL VOID Config_Error PARAMS(( CONST INT Level, CONST CHAR *Format, ... ));
54 574ae82c 2001-12-26 alex
55 574ae82c 2001-12-26 alex
56 c2f60abe 2002-05-27 alex GLOBAL VOID
57 c2f60abe 2002-05-27 alex Conf_Init( VOID )
58 cbc1e59f 2001-12-12 alex {
59 f86083a0 2002-03-27 alex Set_Defaults( );
60 f86083a0 2002-03-27 alex Read_Config( );
61 f86083a0 2002-03-27 alex Validate_Config( );
62 f86083a0 2002-03-27 alex } /* Config_Init */
63 9856253d 2001-12-30 alex
64 9856253d 2001-12-30 alex
65 c2f60abe 2002-05-27 alex GLOBAL INT
66 c2f60abe 2002-05-27 alex Conf_Test( VOID )
67 f86083a0 2002-03-27 alex {
68 f86083a0 2002-03-27 alex /* Konfiguration einlesen, ueberpruefen und ausgeben. */
69 f86083a0 2002-03-27 alex
70 1c2d0ae5 2002-03-29 alex UINT i;
71 f86083a0 2002-03-27 alex
72 f86083a0 2002-03-27 alex Use_Log = FALSE;
73 f86083a0 2002-03-27 alex Set_Defaults( );
74 f86083a0 2002-03-27 alex
75 f86083a0 2002-03-27 alex printf( "Using \"%s\" as configuration file ...\n", NGIRCd_ConfFile );
76 f86083a0 2002-03-27 alex Read_Config( );
77 f86083a0 2002-03-27 alex
78 f86083a0 2002-03-27 alex /* Wenn stdin ein ein TTY ist: auf Taste warten */
79 f86083a0 2002-03-27 alex if( isatty( fileno( stdout )))
80 f86083a0 2002-03-27 alex {
81 f86083a0 2002-03-27 alex puts( "OK, press enter to see a dump of your service configuration ..." );
82 f86083a0 2002-03-27 alex getchar( );
83 f86083a0 2002-03-27 alex }
84 f86083a0 2002-03-27 alex else puts( "Ok, dump of your server configuration follows:\n" );
85 f86083a0 2002-03-27 alex
86 f86083a0 2002-03-27 alex puts( "[GLOBAL]" );
87 f86083a0 2002-03-27 alex printf( " ServerName = %s\n", Conf_ServerName );
88 f86083a0 2002-03-27 alex printf( " ServerInfo = %s\n", Conf_ServerInfo );
89 f86083a0 2002-03-27 alex printf( " ServerPwd = %s\n", Conf_ServerPwd );
90 b615d128 2002-09-16 alex printf( " AdminInfo1 = %s\n", Conf_ServerAdmin1 );
91 b615d128 2002-09-16 alex printf( " AdminInfo2 = %s\n", Conf_ServerAdmin2 );
92 b615d128 2002-09-16 alex printf( " AdminEMail = %s\n", Conf_ServerAdminMail );
93 f86083a0 2002-03-27 alex printf( " MotdFile = %s\n", Conf_MotdFile );
94 f86083a0 2002-03-27 alex printf( " ListenPorts = " );
95 f86083a0 2002-03-27 alex for( i = 0; i < Conf_ListenPorts_Count; i++ )
96 f86083a0 2002-03-27 alex {
97 f86083a0 2002-03-27 alex if( i != 0 ) printf( ", " );
98 1c2d0ae5 2002-03-29 alex printf( "%u", Conf_ListenPorts[i] );
99 f86083a0 2002-03-27 alex }
100 1c2d0ae5 2002-03-29 alex puts( "" );
101 1c2d0ae5 2002-03-29 alex printf( " ServerUID = %ld\n", (INT32)Conf_UID );
102 1c2d0ae5 2002-03-29 alex printf( " ServerGID = %ld\n", (INT32)Conf_GID );
103 f86083a0 2002-03-27 alex printf( " PingTimeout = %d\n", Conf_PingTimeout );
104 f86083a0 2002-03-27 alex printf( " PongTimeout = %d\n", Conf_PongTimeout );
105 f86083a0 2002-03-27 alex printf( " ConnectRetry = %d\n", Conf_ConnectRetry );
106 7e1b3b91 2002-09-02 alex printf( " OperCanUseMode = %s\n", Conf_OperCanMode == TRUE ? "yes" : "no" );
107 f86083a0 2002-03-27 alex puts( "" );
108 f86083a0 2002-03-27 alex
109 f86083a0 2002-03-27 alex for( i = 0; i < Conf_Oper_Count; i++ )
110 f86083a0 2002-03-27 alex {
111 c23535bc 2002-05-22 alex if( ! Conf_Oper[i].name[0] ) continue;
112 c23535bc 2002-05-22 alex
113 c23535bc 2002-05-22 alex /* gueltiger Operator-Block: ausgeben */
114 f86083a0 2002-03-27 alex puts( "[OPERATOR]" );
115 f86083a0 2002-03-27 alex printf( " Name = %s\n", Conf_Oper[i].name );
116 f86083a0 2002-03-27 alex printf( " Password = %s\n", Conf_Oper[i].pwd );
117 f86083a0 2002-03-27 alex puts( "" );
118 f86083a0 2002-03-27 alex }
119 f86083a0 2002-03-27 alex
120 f86083a0 2002-03-27 alex for( i = 0; i < Conf_Server_Count; i++ )
121 f86083a0 2002-03-27 alex {
122 c23535bc 2002-05-22 alex if( ! Conf_Server[i].name[0] ) continue;
123 c23535bc 2002-05-22 alex if( ! Conf_Server[i].host[0] ) continue;
124 c23535bc 2002-05-22 alex
125 c23535bc 2002-05-22 alex /* gueltiger Server-Block: ausgeben */
126 f86083a0 2002-03-27 alex puts( "[SERVER]" );
127 f86083a0 2002-03-27 alex printf( " Name = %s\n", Conf_Server[i].name );
128 f86083a0 2002-03-27 alex printf( " Host = %s\n", Conf_Server[i].host );
129 f86083a0 2002-03-27 alex printf( " Port = %d\n", Conf_Server[i].port );
130 f86083a0 2002-03-27 alex printf( " Password = %s\n", Conf_Server[i].pwd );
131 f86083a0 2002-03-27 alex printf( " Group = %d\n", Conf_Server[i].group );
132 f86083a0 2002-03-27 alex puts( "" );
133 f86083a0 2002-03-27 alex }
134 040f5422 2002-05-21 alex
135 040f5422 2002-05-21 alex for( i = 0; i < Conf_Channel_Count; i++ )
136 040f5422 2002-05-21 alex {
137 c23535bc 2002-05-22 alex if( ! Conf_Channel[i].name[0] ) continue;
138 c23535bc 2002-05-22 alex
139 c23535bc 2002-05-22 alex /* gueltiger Channel-Block: ausgeben */
140 040f5422 2002-05-21 alex puts( "[CHANNEL]" );
141 040f5422 2002-05-21 alex printf( " Name = %s\n", Conf_Channel[i].name );
142 040f5422 2002-05-21 alex printf( " Modes = %s\n", Conf_Channel[i].modes );
143 040f5422 2002-05-21 alex printf( " Topic = %s\n", Conf_Channel[i].topic );
144 040f5422 2002-05-21 alex puts( "" );
145 040f5422 2002-05-21 alex }
146 f86083a0 2002-03-27 alex
147 f86083a0 2002-03-27 alex return 0;
148 f86083a0 2002-03-27 alex } /* Conf_Test */
149 f86083a0 2002-03-27 alex
150 f86083a0 2002-03-27 alex
151 c2f60abe 2002-05-27 alex LOCAL VOID
152 c2f60abe 2002-05-27 alex Set_Defaults( VOID )
153 f86083a0 2002-03-27 alex {
154 f86083a0 2002-03-27 alex /* Konfigurationsvariablen initialisieren, d.h. auf Default-Werte setzen. */
155 f86083a0 2002-03-27 alex
156 9856253d 2001-12-30 alex strcpy( Conf_ServerName, "" );
157 f7327524 2002-05-30 alex sprintf( Conf_ServerInfo, "%s %s", PACKAGE, VERSION );
158 ed406b4a 2002-01-03 alex strcpy( Conf_ServerPwd, "" );
159 9856253d 2001-12-30 alex
160 b615d128 2002-09-16 alex strcpy( Conf_ServerAdmin1, "" );
161 b615d128 2002-09-16 alex strcpy( Conf_ServerAdmin2, "" );
162 b615d128 2002-09-16 alex strcpy( Conf_ServerAdminMail, "" );
163 b615d128 2002-09-16 alex
164 10aa35cc 2002-03-06 alex strcpy( Conf_MotdFile, MOTD_FILE );
165 9856253d 2001-12-30 alex
166 9856253d 2001-12-30 alex Conf_ListenPorts_Count = 0;
167 1c2d0ae5 2002-03-29 alex
168 1c2d0ae5 2002-03-29 alex Conf_UID = Conf_GID = 0;
169 574ae82c 2001-12-26 alex
170 08cf5607 2001-12-26 alex Conf_PingTimeout = 120;
171 281d8e45 2002-03-25 alex Conf_PongTimeout = 20;
172 574ae82c 2001-12-26 alex
173 03d971d9 2002-01-02 alex Conf_ConnectRetry = 60;
174 03d971d9 2002-01-02 alex
175 03d971d9 2002-01-02 alex Conf_Oper_Count = 0;
176 03d971d9 2002-01-02 alex Conf_Server_Count = 0;
177 040f5422 2002-05-21 alex Conf_Channel_Count = 0;
178 7e1b3b91 2002-09-02 alex
179 7e1b3b91 2002-09-02 alex Conf_OperCanMode = FALSE;
180 f86083a0 2002-03-27 alex } /* Set_Defaults */
181 03d971d9 2002-01-02 alex
182 cbc1e59f 2001-12-12 alex
183 c2f60abe 2002-05-27 alex LOCAL VOID
184 c2f60abe 2002-05-27 alex Read_Config( VOID )
185 574ae82c 2001-12-26 alex {
186 574ae82c 2001-12-26 alex /* Konfigurationsdatei einlesen. */
187 9856253d 2001-12-30 alex
188 03d971d9 2002-01-02 alex CHAR section[LINE_LEN], str[LINE_LEN], *var, *arg, *ptr;
189 9856253d 2001-12-30 alex INT line;
190 9856253d 2001-12-30 alex FILE *fd;
191 9856253d 2001-12-30 alex
192 f86083a0 2002-03-27 alex fd = fopen( NGIRCd_ConfFile, "r" );
193 9856253d 2001-12-30 alex if( ! fd )
194 9856253d 2001-12-30 alex {
195 9856253d 2001-12-30 alex /* Keine Konfigurationsdatei gefunden */
196 f86083a0 2002-03-27 alex Config_Error( LOG_ALERT, "Can't read configuration \"%s\": %s", NGIRCd_ConfFile, strerror( errno ));
197 f7327524 2002-05-30 alex Config_Error( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE );
198 9856253d 2001-12-30 alex exit( 1 );
199 9856253d 2001-12-30 alex }
200 9856253d 2001-12-30 alex
201 9856253d 2001-12-30 alex line = 0;
202 03d971d9 2002-01-02 alex strcpy( section, "" );
203 9856253d 2001-12-30 alex while( TRUE )
204 9856253d 2001-12-30 alex {
205 804b1ec4 2001-12-31 alex if( ! fgets( str, LINE_LEN, fd )) break;
206 9856253d 2001-12-30 alex ngt_TrimStr( str );
207 9856253d 2001-12-30 alex line++;
208 9856253d 2001-12-30 alex
209 9856253d 2001-12-30 alex /* Kommentarzeilen und leere Zeilen ueberspringen */
210 9856253d 2001-12-30 alex if( str[0] == ';' || str[0] == '#' || str[0] == '\0' ) continue;
211 9856253d 2001-12-30 alex
212 03d971d9 2002-01-02 alex /* Anfang eines Abschnittes? */
213 03d971d9 2002-01-02 alex if(( str[0] == '[' ) && ( str[strlen( str ) - 1] == ']' ))
214 03d971d9 2002-01-02 alex {
215 03d971d9 2002-01-02 alex strcpy( section, str );
216 03d971d9 2002-01-02 alex if( strcasecmp( section, "[GLOBAL]" ) == 0 ) continue;
217 03d971d9 2002-01-02 alex if( strcasecmp( section, "[OPERATOR]" ) == 0 )
218 03d971d9 2002-01-02 alex {
219 f86083a0 2002-03-27 alex if( Conf_Oper_Count + 1 > MAX_OPERATORS ) Config_Error( LOG_ERR, "Too many operators configured." );
220 03d971d9 2002-01-02 alex else
221 03d971d9 2002-01-02 alex {
222 03d971d9 2002-01-02 alex /* neuen Operator initialisieren */
223 03d971d9 2002-01-02 alex strcpy( Conf_Oper[Conf_Oper_Count].name, "" );
224 03d971d9 2002-01-02 alex strcpy( Conf_Oper[Conf_Oper_Count].pwd, "" );
225 03d971d9 2002-01-02 alex Conf_Oper_Count++;
226 03d971d9 2002-01-02 alex }
227 03d971d9 2002-01-02 alex continue;
228 03d971d9 2002-01-02 alex }
229 03d971d9 2002-01-02 alex if( strcasecmp( section, "[SERVER]" ) == 0 )
230 03d971d9 2002-01-02 alex {
231 f86083a0 2002-03-27 alex if( Conf_Server_Count + 1 > MAX_SERVERS ) Config_Error( LOG_ERR, "Too many servers configured." );
232 03d971d9 2002-01-02 alex else
233 03d971d9 2002-01-02 alex {
234 03d971d9 2002-01-02 alex /* neuen Server ("Peer") initialisieren */
235 03d971d9 2002-01-02 alex strcpy( Conf_Server[Conf_Server_Count].host, "" );
236 03d971d9 2002-01-02 alex strcpy( Conf_Server[Conf_Server_Count].ip, "" );
237 03d971d9 2002-01-02 alex strcpy( Conf_Server[Conf_Server_Count].name, "" );
238 03d971d9 2002-01-02 alex strcpy( Conf_Server[Conf_Server_Count].pwd, "" );
239 03d971d9 2002-01-02 alex Conf_Server[Conf_Server_Count].port = 0;
240 d67d94ea 2002-03-10 alex Conf_Server[Conf_Server_Count].group = -1;
241 6debfc31 2002-01-18 alex Conf_Server[Conf_Server_Count].lasttry = time( NULL ) - Conf_ConnectRetry + STARTUP_DELAY;
242 03d971d9 2002-01-02 alex Conf_Server[Conf_Server_Count].res_stat = NULL;
243 03d971d9 2002-01-02 alex Conf_Server_Count++;
244 040f5422 2002-05-21 alex }
245 040f5422 2002-05-21 alex continue;
246 040f5422 2002-05-21 alex }
247 040f5422 2002-05-21 alex if( strcasecmp( section, "[CHANNEL]" ) == 0 )
248 040f5422 2002-05-21 alex {
249 040f5422 2002-05-21 alex if( Conf_Channel_Count + 1 > MAX_DEFCHANNELS ) Config_Error( LOG_ERR, "Too many pre-defined channels configured." );
250 040f5422 2002-05-21 alex else
251 040f5422 2002-05-21 alex {
252 040f5422 2002-05-21 alex /* neuen vordefinierten Channel initialisieren */
253 040f5422 2002-05-21 alex strcpy( Conf_Channel[Conf_Channel_Count].name, "" );
254 040f5422 2002-05-21 alex strcpy( Conf_Channel[Conf_Channel_Count].modes, "" );
255 040f5422 2002-05-21 alex strcpy( Conf_Channel[Conf_Channel_Count].topic, "" );
256 040f5422 2002-05-21 alex Conf_Channel_Count++;
257 03d971d9 2002-01-02 alex }
258 03d971d9 2002-01-02 alex continue;
259 03d971d9 2002-01-02 alex }
260 f86083a0 2002-03-27 alex Config_Error( LOG_ERR, "%s, line %d: Unknown section \"%s\"!", NGIRCd_ConfFile, line, section );
261 03d971d9 2002-01-02 alex section[0] = 0x1;
262 03d971d9 2002-01-02 alex }
263 03d971d9 2002-01-02 alex if( section[0] == 0x1 ) continue;
264 03d971d9 2002-01-02 alex
265 03d971d9 2002-01-02 alex /* In Variable und Argument zerlegen */
266 9856253d 2001-12-30 alex ptr = strchr( str, '=' );
267 9856253d 2001-12-30 alex if( ! ptr )
268 9856253d 2001-12-30 alex {
269 f86083a0 2002-03-27 alex Config_Error( LOG_ERR, "%s, line %d: Syntax error!", NGIRCd_ConfFile, line );
270 9856253d 2001-12-30 alex continue;
271 9856253d 2001-12-30 alex }
272 9856253d 2001-12-30 alex *ptr = '\0';
273 9856253d 2001-12-30 alex var = str; ngt_TrimStr( var );
274 9856253d 2001-12-30 alex arg = ptr + 1; ngt_TrimStr( arg );
275 03d971d9 2002-01-02 alex
276 03d971d9 2002-01-02 alex if( strcasecmp( section, "[GLOBAL]" ) == 0 ) Handle_GLOBAL( line, var, arg );
277 03d971d9 2002-01-02 alex else if( strcasecmp( section, "[OPERATOR]" ) == 0 ) Handle_OPERATOR( line, var, arg );
278 03d971d9 2002-01-02 alex else if( strcasecmp( section, "[SERVER]" ) == 0 ) Handle_SERVER( line, var, arg );
279 040f5422 2002-05-21 alex else if( strcasecmp( section, "[CHANNEL]" ) == 0 ) Handle_CHANNEL( line, var, arg );
280 f86083a0 2002-03-27 alex else Config_Error( LOG_ERR, "%s, line %d: Variable \"%s\" outside section!", NGIRCd_ConfFile, line, var );
281 03d971d9 2002-01-02 alex }
282 03d971d9 2002-01-02 alex
283 03d971d9 2002-01-02 alex fclose( fd );
284 1c99b837 2002-03-30 alex
285 1c99b837 2002-03-30 alex /* Wenn kein Port definiert wurde, Port 6667 als Default benutzen */
286 1c99b837 2002-03-30 alex if( Conf_ListenPorts_Count < 1 )
287 1c99b837 2002-03-30 alex {
288 1c99b837 2002-03-30 alex Conf_ListenPorts_Count = 1;
289 1c99b837 2002-03-30 alex Conf_ListenPorts[0] = 6667;
290 1c99b837 2002-03-30 alex }
291 03d971d9 2002-01-02 alex } /* Read_Config */
292 03d971d9 2002-01-02 alex
293 03d971d9 2002-01-02 alex
294 c2f60abe 2002-05-27 alex LOCAL VOID
295 c2f60abe 2002-05-27 alex Handle_GLOBAL( INT Line, CHAR *Var, CHAR *Arg )
296 03d971d9 2002-01-02 alex {
297 03d971d9 2002-01-02 alex CHAR *ptr;
298 95a4b1b1 2002-03-25 alex INT32 port;
299 03d971d9 2002-01-02 alex
300 03d971d9 2002-01-02 alex assert( Line > 0 );
301 03d971d9 2002-01-02 alex assert( Var != NULL );
302 03d971d9 2002-01-02 alex assert( Arg != NULL );
303 03d971d9 2002-01-02 alex
304 03d971d9 2002-01-02 alex if( strcasecmp( Var, "Name" ) == 0 )
305 03d971d9 2002-01-02 alex {
306 03d971d9 2002-01-02 alex /* Der Server-Name */
307 10363b39 2002-03-03 alex strncpy( Conf_ServerName, Arg, CLIENT_ID_LEN - 1 );
308 03d971d9 2002-01-02 alex Conf_ServerName[CLIENT_ID_LEN - 1] = '\0';
309 03d971d9 2002-01-02 alex return;
310 03d971d9 2002-01-02 alex }
311 03d971d9 2002-01-02 alex if( strcasecmp( Var, "Info" ) == 0 )
312 03d971d9 2002-01-02 alex {
313 03d971d9 2002-01-02 alex /* Server-Info-Text */
314 10363b39 2002-03-03 alex strncpy( Conf_ServerInfo, Arg, CLIENT_INFO_LEN - 1 );
315 03d971d9 2002-01-02 alex Conf_ServerInfo[CLIENT_INFO_LEN - 1] = '\0';
316 03d971d9 2002-01-02 alex return;
317 03d971d9 2002-01-02 alex }
318 ed406b4a 2002-01-03 alex if( strcasecmp( Var, "Password" ) == 0 )
319 ed406b4a 2002-01-03 alex {
320 10363b39 2002-03-03 alex /* Server-Passwort */
321 10363b39 2002-03-03 alex strncpy( Conf_ServerPwd, Arg, CLIENT_PASS_LEN - 1 );
322 ed406b4a 2002-01-03 alex Conf_ServerPwd[CLIENT_PASS_LEN - 1] = '\0';
323 b615d128 2002-09-16 alex return;
324 b615d128 2002-09-16 alex }
325 b615d128 2002-09-16 alex if( strcasecmp( Var, "AdminInfo1" ) == 0 )
326 b615d128 2002-09-16 alex {
327 b615d128 2002-09-16 alex /* Server-Info-Text */
328 b615d128 2002-09-16 alex strncpy( Conf_ServerAdmin1, Arg, CLIENT_INFO_LEN - 1 );
329 b615d128 2002-09-16 alex Conf_ServerAdmin1[CLIENT_INFO_LEN - 1] = '\0';
330 b615d128 2002-09-16 alex return;
331 b615d128 2002-09-16 alex }
332 b615d128 2002-09-16 alex if( strcasecmp( Var, "AdminInfo2" ) == 0 )
333 b615d128 2002-09-16 alex {
334 b615d128 2002-09-16 alex /* Server-Info-Text */
335 b615d128 2002-09-16 alex strncpy( Conf_ServerAdmin2, Arg, CLIENT_INFO_LEN - 1 );
336 b615d128 2002-09-16 alex Conf_ServerAdmin2[CLIENT_INFO_LEN - 1] = '\0';
337 b615d128 2002-09-16 alex return;
338 b615d128 2002-09-16 alex }
339 b615d128 2002-09-16 alex if( strcasecmp( Var, "AdminEMail" ) == 0 )
340 b615d128 2002-09-16 alex {
341 b615d128 2002-09-16 alex /* Server-Info-Text */
342 b615d128 2002-09-16 alex strncpy( Conf_ServerAdminMail, Arg, CLIENT_INFO_LEN - 1 );
343 b615d128 2002-09-16 alex Conf_ServerAdminMail[CLIENT_INFO_LEN - 1] = '\0';
344 ed406b4a 2002-01-03 alex return;
345 ed406b4a 2002-01-03 alex }
346 03d971d9 2002-01-02 alex if( strcasecmp( Var, "Ports" ) == 0 )
347 03d971d9 2002-01-02 alex {
348 03d971d9 2002-01-02 alex /* Ports, durch "," getrennt, auf denen der Server
349 03d971d9 2002-01-02 alex * Verbindungen annehmen soll */
350 03d971d9 2002-01-02 alex ptr = strtok( Arg, "," );
351 03d971d9 2002-01-02 alex while( ptr )
352 9856253d 2001-12-30 alex {
353 03d971d9 2002-01-02 alex ngt_TrimStr( ptr );
354 03d971d9 2002-01-02 alex port = atol( ptr );
355 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 );
356 03d971d9 2002-01-02 alex else
357 03d971d9 2002-01-02 alex {
358 1c2d0ae5 2002-03-29 alex if( port > 0 && port < 0xFFFF ) Conf_ListenPorts[Conf_ListenPorts_Count++] = (UINT)port;
359 f86083a0 2002-03-27 alex else Config_Error( LOG_ERR, "%s, line %d (section \"Global\"): Illegal port number %ld!", NGIRCd_ConfFile, Line, port );
360 03d971d9 2002-01-02 alex }
361 03d971d9 2002-01-02 alex ptr = strtok( NULL, "," );
362 9856253d 2001-12-30 alex }
363 03d971d9 2002-01-02 alex return;
364 03d971d9 2002-01-02 alex }
365 03d971d9 2002-01-02 alex if( strcasecmp( Var, "MotdFile" ) == 0 )
366 03d971d9 2002-01-02 alex {
367 03d971d9 2002-01-02 alex /* Datei mit der "message of the day" (MOTD) */
368 10363b39 2002-03-03 alex strncpy( Conf_MotdFile, Arg, FNAME_LEN - 1 );
369 03d971d9 2002-01-02 alex Conf_MotdFile[FNAME_LEN - 1] = '\0';
370 03d971d9 2002-01-02 alex return;
371 03d971d9 2002-01-02 alex }
372 1c2d0ae5 2002-03-29 alex if( strcasecmp( Var, "ServerUID" ) == 0 )
373 1c2d0ae5 2002-03-29 alex {
374 1c2d0ae5 2002-03-29 alex /* UID, mit der der Daemon laufen soll */
375 1c2d0ae5 2002-03-29 alex Conf_UID = (UINT)atoi( Arg );
376 1c2d0ae5 2002-03-29 alex return;
377 1c2d0ae5 2002-03-29 alex }
378 1c2d0ae5 2002-03-29 alex if( strcasecmp( Var, "ServerGID" ) == 0 )
379 1c2d0ae5 2002-03-29 alex {
380 1c2d0ae5 2002-03-29 alex /* GID, mit der der Daemon laufen soll */
381 1c2d0ae5 2002-03-29 alex Conf_GID = (UINT)atoi( Arg );
382 1c2d0ae5 2002-03-29 alex return;
383 1c2d0ae5 2002-03-29 alex }
384 03d971d9 2002-01-02 alex if( strcasecmp( Var, "PingTimeout" ) == 0 )
385 03d971d9 2002-01-02 alex {
386 03d971d9 2002-01-02 alex /* PING-Timeout */
387 03d971d9 2002-01-02 alex Conf_PingTimeout = atoi( Arg );
388 03d971d9 2002-01-02 alex if(( Conf_PingTimeout ) < 5 ) Conf_PingTimeout = 5;
389 03d971d9 2002-01-02 alex return;
390 03d971d9 2002-01-02 alex }
391 03d971d9 2002-01-02 alex if( strcasecmp( Var, "PongTimeout" ) == 0 )
392 03d971d9 2002-01-02 alex {
393 03d971d9 2002-01-02 alex /* PONG-Timeout */
394 03d971d9 2002-01-02 alex Conf_PongTimeout = atoi( Arg );
395 03d971d9 2002-01-02 alex if(( Conf_PongTimeout ) < 5 ) Conf_PongTimeout = 5;
396 03d971d9 2002-01-02 alex return;
397 03d971d9 2002-01-02 alex }
398 03d971d9 2002-01-02 alex if( strcasecmp( Var, "ConnectRetry" ) == 0 )
399 03d971d9 2002-01-02 alex {
400 03d971d9 2002-01-02 alex /* Sekunden zwischen Verbindungsversuchen zu anderen Servern */
401 03d971d9 2002-01-02 alex Conf_ConnectRetry = atoi( Arg );
402 03d971d9 2002-01-02 alex if(( Conf_ConnectRetry ) < 5 ) Conf_ConnectRetry = 5;
403 7e1b3b91 2002-09-02 alex return;
404 7e1b3b91 2002-09-02 alex }
405 7e1b3b91 2002-09-02 alex if( strcasecmp( Var, "OperCanUseMode" ) == 0 )
406 7e1b3b91 2002-09-02 alex {
407 7e1b3b91 2002-09-02 alex /* Koennen IRC-Operatoren immer MODE benutzen? */
408 7e1b3b91 2002-09-02 alex if( strcasecmp( Arg, "yes" ) == 0 ) Conf_OperCanMode = TRUE;
409 7e1b3b91 2002-09-02 alex else if( strcasecmp( Arg, "true" ) == 0 ) Conf_OperCanMode = TRUE;
410 7e1b3b91 2002-09-02 alex else if( atoi( Arg ) != 0 ) Conf_OperCanMode = TRUE;
411 7e1b3b91 2002-09-02 alex else Conf_OperCanMode = FALSE;
412 03d971d9 2002-01-02 alex return;
413 03d971d9 2002-01-02 alex }
414 9856253d 2001-12-30 alex
415 f86083a0 2002-03-27 alex Config_Error( LOG_ERR, "%s, line %d (section \"Global\"): Unknown variable \"%s\"!", NGIRCd_ConfFile, Line, Var );
416 03d971d9 2002-01-02 alex } /* Handle_GLOBAL */
417 03d971d9 2002-01-02 alex
418 03d971d9 2002-01-02 alex
419 c2f60abe 2002-05-27 alex LOCAL VOID
420 c2f60abe 2002-05-27 alex Handle_OPERATOR( INT Line, CHAR *Var, CHAR *Arg )
421 03d971d9 2002-01-02 alex {
422 03d971d9 2002-01-02 alex assert( Line > 0 );
423 03d971d9 2002-01-02 alex assert( Var != NULL );
424 03d971d9 2002-01-02 alex assert( Arg != NULL );
425 03d971d9 2002-01-02 alex assert( Conf_Oper_Count > 0 );
426 03d971d9 2002-01-02 alex
427 03d971d9 2002-01-02 alex if( strcasecmp( Var, "Name" ) == 0 )
428 03d971d9 2002-01-02 alex {
429 03d971d9 2002-01-02 alex /* Name des IRC Operator */
430 b615d128 2002-09-16 alex strncpy( Conf_Oper[Conf_Oper_Count - 1].name, Arg, CLIENT_PASS_LEN - 1 );
431 b615d128 2002-09-16 alex Conf_Oper[Conf_Oper_Count - 1].name[CLIENT_PASS_LEN - 1] = '\0';
432 03d971d9 2002-01-02 alex return;
433 9856253d 2001-12-30 alex }
434 03d971d9 2002-01-02 alex if( strcasecmp( Var, "Password" ) == 0 )
435 03d971d9 2002-01-02 alex {
436 03d971d9 2002-01-02 alex /* Passwort des IRC Operator */
437 10363b39 2002-03-03 alex strncpy( Conf_Oper[Conf_Oper_Count - 1].pwd, Arg, CLIENT_PASS_LEN - 1 );
438 03d971d9 2002-01-02 alex Conf_Oper[Conf_Oper_Count - 1].pwd[CLIENT_PASS_LEN - 1] = '\0';
439 03d971d9 2002-01-02 alex return;
440 03d971d9 2002-01-02 alex }
441 574ae82c 2001-12-26 alex
442 f86083a0 2002-03-27 alex Config_Error( LOG_ERR, "%s, line %d (section \"Operator\"): Unknown variable \"%s\"!", NGIRCd_ConfFile, Line, Var );
443 03d971d9 2002-01-02 alex } /* Handle_OPERATOR */
444 574ae82c 2001-12-26 alex
445 574ae82c 2001-12-26 alex
446 c2f60abe 2002-05-27 alex LOCAL VOID
447 c2f60abe 2002-05-27 alex Handle_SERVER( INT Line, CHAR *Var, CHAR *Arg )
448 03d971d9 2002-01-02 alex {
449 d67d94ea 2002-03-10 alex INT32 port;
450 03d971d9 2002-01-02 alex
451 03d971d9 2002-01-02 alex assert( Line > 0 );
452 03d971d9 2002-01-02 alex assert( Var != NULL );
453 03d971d9 2002-01-02 alex assert( Arg != NULL );
454 03d971d9 2002-01-02 alex
455 03d971d9 2002-01-02 alex if( strcasecmp( Var, "Host" ) == 0 )
456 03d971d9 2002-01-02 alex {
457 03d971d9 2002-01-02 alex /* Hostname des Servers */
458 10363b39 2002-03-03 alex strncpy( Conf_Server[Conf_Server_Count - 1].host, Arg, HOST_LEN - 1 );
459 03d971d9 2002-01-02 alex Conf_Server[Conf_Server_Count - 1].host[HOST_LEN - 1] = '\0';
460 03d971d9 2002-01-02 alex return;
461 03d971d9 2002-01-02 alex }
462 03d971d9 2002-01-02 alex if( strcasecmp( Var, "Name" ) == 0 )
463 03d971d9 2002-01-02 alex {
464 03d971d9 2002-01-02 alex /* Name des Servers ("Nick") */
465 10363b39 2002-03-03 alex strncpy( Conf_Server[Conf_Server_Count - 1].name, Arg, CLIENT_ID_LEN - 1 );
466 2e289b50 2002-01-05 alex Conf_Server[Conf_Server_Count - 1].name[CLIENT_ID_LEN - 1] = '\0';
467 03d971d9 2002-01-02 alex return;
468 03d971d9 2002-01-02 alex }
469 03d971d9 2002-01-02 alex if( strcasecmp( Var, "Password" ) == 0 )
470 03d971d9 2002-01-02 alex {
471 03d971d9 2002-01-02 alex /* Passwort des Servers */
472 10363b39 2002-03-03 alex strncpy( Conf_Server[Conf_Server_Count - 1].pwd, Arg, CLIENT_PASS_LEN - 1 );
473 03d971d9 2002-01-02 alex Conf_Server[Conf_Server_Count - 1].pwd[CLIENT_PASS_LEN - 1] = '\0';
474 03d971d9 2002-01-02 alex return;
475 03d971d9 2002-01-02 alex }
476 03d971d9 2002-01-02 alex if( strcasecmp( Var, "Port" ) == 0 )
477 03d971d9 2002-01-02 alex {
478 03d971d9 2002-01-02 alex /* Port, zu dem Verbunden werden soll */
479 03d971d9 2002-01-02 alex port = atol( Arg );
480 d67d94ea 2002-03-10 alex if( port > 0 && port < 0xFFFF ) Conf_Server[Conf_Server_Count - 1].port = (INT)port;
481 f86083a0 2002-03-27 alex else Config_Error( LOG_ERR, "%s, line %d (section \"Server\"): Illegal port number %ld!", NGIRCd_ConfFile, Line, port );
482 03d971d9 2002-01-02 alex return;
483 03d971d9 2002-01-02 alex }
484 d67d94ea 2002-03-10 alex if( strcasecmp( Var, "Group" ) == 0 )
485 d67d94ea 2002-03-10 alex {
486 d67d94ea 2002-03-10 alex /* Server-Gruppe */
487 d67d94ea 2002-03-10 alex Conf_Server[Conf_Server_Count - 1].group = atoi( Arg );
488 d67d94ea 2002-03-10 alex return;
489 d67d94ea 2002-03-10 alex }
490 03d971d9 2002-01-02 alex
491 f86083a0 2002-03-27 alex Config_Error( LOG_ERR, "%s, line %d (section \"Server\"): Unknown variable \"%s\"!", NGIRCd_ConfFile, Line, Var );
492 03d971d9 2002-01-02 alex } /* Handle_SERVER */
493 040f5422 2002-05-21 alex
494 040f5422 2002-05-21 alex
495 c2f60abe 2002-05-27 alex LOCAL VOID
496 c2f60abe 2002-05-27 alex Handle_CHANNEL( INT Line, CHAR *Var, CHAR *Arg )
497 040f5422 2002-05-21 alex {
498 040f5422 2002-05-21 alex assert( Line > 0 );
499 040f5422 2002-05-21 alex assert( Var != NULL );
500 040f5422 2002-05-21 alex assert( Arg != NULL );
501 03d971d9 2002-01-02 alex
502 040f5422 2002-05-21 alex if( strcasecmp( Var, "Name" ) == 0 )
503 040f5422 2002-05-21 alex {
504 040f5422 2002-05-21 alex /* Hostname des Servers */
505 040f5422 2002-05-21 alex strncpy( Conf_Channel[Conf_Channel_Count - 1].name, Arg, CHANNEL_NAME_LEN - 1 );
506 040f5422 2002-05-21 alex Conf_Channel[Conf_Channel_Count - 1].name[CHANNEL_NAME_LEN - 1] = '\0';
507 040f5422 2002-05-21 alex return;
508 040f5422 2002-05-21 alex }
509 040f5422 2002-05-21 alex if( strcasecmp( Var, "Modes" ) == 0 )
510 040f5422 2002-05-21 alex {
511 040f5422 2002-05-21 alex /* Name des Servers ("Nick") */
512 040f5422 2002-05-21 alex strncpy( Conf_Channel[Conf_Channel_Count - 1].modes, Arg, CHANNEL_MODE_LEN - 1 );
513 040f5422 2002-05-21 alex Conf_Channel[Conf_Channel_Count - 1].modes[CHANNEL_MODE_LEN - 1] = '\0';
514 040f5422 2002-05-21 alex return;
515 040f5422 2002-05-21 alex }
516 040f5422 2002-05-21 alex if( strcasecmp( Var, "Topic" ) == 0 )
517 040f5422 2002-05-21 alex {
518 040f5422 2002-05-21 alex /* Passwort des Servers */
519 040f5422 2002-05-21 alex strncpy( Conf_Channel[Conf_Channel_Count - 1].topic, Arg, CHANNEL_TOPIC_LEN - 1 );
520 040f5422 2002-05-21 alex Conf_Channel[Conf_Channel_Count - 1].topic[CHANNEL_TOPIC_LEN - 1] = '\0';
521 040f5422 2002-05-21 alex return;
522 040f5422 2002-05-21 alex }
523 03d971d9 2002-01-02 alex
524 040f5422 2002-05-21 alex Config_Error( LOG_ERR, "%s, line %d (section \"Channel\"): Unknown variable \"%s\"!", NGIRCd_ConfFile, Line, Var );
525 040f5422 2002-05-21 alex } /* Handle_CHANNEL */
526 040f5422 2002-05-21 alex
527 040f5422 2002-05-21 alex
528 c2f60abe 2002-05-27 alex LOCAL VOID
529 c2f60abe 2002-05-27 alex Validate_Config( VOID )
530 9856253d 2001-12-30 alex {
531 9856253d 2001-12-30 alex /* Konfiguration ueberpruefen */
532 9856253d 2001-12-30 alex
533 9856253d 2001-12-30 alex if( ! Conf_ServerName[0] )
534 9856253d 2001-12-30 alex {
535 9856253d 2001-12-30 alex /* Kein Servername konfiguriert */
536 b615d128 2002-09-16 alex Config_Error( LOG_ALERT, "No server name configured in \"%s\" ('ServerName')!", NGIRCd_ConfFile );
537 f7327524 2002-05-30 alex Config_Error( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE );
538 9856253d 2001-12-30 alex exit( 1 );
539 9856253d 2001-12-30 alex }
540 b615d128 2002-09-16 alex
541 b615d128 2002-09-16 alex #ifdef STRICT_RFC
542 b615d128 2002-09-16 alex if( ! ConfAdminMail[0] )
543 b615d128 2002-09-16 alex {
544 b615d128 2002-09-16 alex /* Keine Server-Information konfiguriert */
545 b615d128 2002-09-16 alex Config_Error( LOG_ALERT, "No administrator email address configured in \"%s\" ('AdminEMail')!", NGIRCd_ConfFile );
546 b615d128 2002-09-16 alex Config_Error( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE );
547 b615d128 2002-09-16 alex exit( 1 );
548 b615d128 2002-09-16 alex }
549 b615d128 2002-09-16 alex #endif
550 b615d128 2002-09-16 alex
551 33bda862 2002-09-19 alex if( ! Conf_ServerAdmin1[0] && ! Conf_ServerAdmin2[0] && ! Conf_ServerAdminMail[0] )
552 b615d128 2002-09-16 alex {
553 b615d128 2002-09-16 alex /* Keine Server-Information konfiguriert */
554 b615d128 2002-09-16 alex Log( LOG_WARNING, "No server information configured but required by RFC!" );
555 b615d128 2002-09-16 alex }
556 9856253d 2001-12-30 alex } /* Validate_Config */
557 9856253d 2001-12-30 alex
558 f86083a0 2002-03-27 alex
559 f7327524 2002-05-30 alex #ifdef PROTOTYPES
560 f7327524 2002-05-30 alex LOCAL VOID Config_Error( CONST INT Level, CONST CHAR *Format, ... )
561 f7327524 2002-05-30 alex #else
562 f7327524 2002-05-30 alex LOCAL VOID Config_Error( Level, Format, va_alist )
563 f7327524 2002-05-30 alex CONST INT Level;
564 f7327524 2002-05-30 alex CONST CHAR *Format;
565 f7327524 2002-05-30 alex va_dcl
566 f7327524 2002-05-30 alex #endif
567 f86083a0 2002-03-27 alex {
568 f86083a0 2002-03-27 alex /* Fehler! Auf Console und/oder ins Log schreiben */
569 f86083a0 2002-03-27 alex
570 f86083a0 2002-03-27 alex CHAR msg[MAX_LOG_MSG_LEN];
571 f86083a0 2002-03-27 alex va_list ap;
572 f86083a0 2002-03-27 alex
573 f86083a0 2002-03-27 alex assert( Format != NULL );
574 f86083a0 2002-03-27 alex
575 f86083a0 2002-03-27 alex /* String mit variablen Argumenten zusammenbauen ... */
576 f7327524 2002-05-30 alex #ifdef PROTOTYPES
577 f86083a0 2002-03-27 alex va_start( ap, Format );
578 f7327524 2002-05-30 alex #else
579 f7327524 2002-05-30 alex va_start( ap );
580 f7327524 2002-05-30 alex #endif
581 f86083a0 2002-03-27 alex vsnprintf( msg, MAX_LOG_MSG_LEN, Format, ap );
582 f86083a0 2002-03-27 alex va_end( ap );
583 f86083a0 2002-03-27 alex
584 f86083a0 2002-03-27 alex /* Im "normalen Betrieb" soll der Log-Mechanismus des ngIRCd verwendet
585 f86083a0 2002-03-27 alex * werden, beim Testen der Konfiguration jedoch nicht, hier sollen alle
586 f86083a0 2002-03-27 alex * Meldungen direkt auf die Konsole ausgegeben werden: */
587 f86083a0 2002-03-27 alex if( Use_Log ) Log( Level, msg );
588 f86083a0 2002-03-27 alex else puts( msg );
589 f86083a0 2002-03-27 alex } /* Config_Error */
590 f86083a0 2002-03-27 alex
591 f86083a0 2002-03-27 alex
592 cbc1e59f 2001-12-12 alex /* -eof- */