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