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 f86083a0 2002-03-27 alex * $Id: conf.c,v 1.21 2002/03/27 16:39:22 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 9856253d 2001-12-30 alex #include "client.h"
31 ca33cbda 2002-03-12 alex #include "defines.h"
32 9856253d 2001-12-30 alex #include "log.h"
33 9856253d 2001-12-30 alex #include "tool.h"
34 9856253d 2001-12-30 alex
35 ca33cbda 2002-03-12 alex #include "exp.h"
36 cbc1e59f 2001-12-12 alex #include "conf.h"
37 cbc1e59f 2001-12-12 alex
38 cbc1e59f 2001-12-12 alex
39 f86083a0 2002-03-27 alex LOCAL BOOLEAN Use_Log = TRUE;
40 f86083a0 2002-03-27 alex
41 f86083a0 2002-03-27 alex
42 f86083a0 2002-03-27 alex LOCAL VOID Set_Defaults( VOID );
43 574ae82c 2001-12-26 alex LOCAL VOID Read_Config( VOID );
44 f86083a0 2002-03-27 alex LOCAL VOID Validate_Config( VOID );
45 03d971d9 2002-01-02 alex
46 03d971d9 2002-01-02 alex GLOBAL VOID Handle_GLOBAL( INT Line, CHAR *Var, CHAR *Arg );
47 03d971d9 2002-01-02 alex GLOBAL VOID Handle_OPERATOR( INT Line, CHAR *Var, CHAR *Arg );
48 03d971d9 2002-01-02 alex GLOBAL VOID Handle_SERVER( INT Line, CHAR *Var, CHAR *Arg );
49 03d971d9 2002-01-02 alex
50 f86083a0 2002-03-27 alex LOCAL VOID Config_Error( CONST INT Level, CONST CHAR *Format, ... );
51 574ae82c 2001-12-26 alex
52 574ae82c 2001-12-26 alex
53 cbc1e59f 2001-12-12 alex GLOBAL VOID Conf_Init( VOID )
54 cbc1e59f 2001-12-12 alex {
55 f86083a0 2002-03-27 alex Set_Defaults( );
56 f86083a0 2002-03-27 alex Read_Config( );
57 f86083a0 2002-03-27 alex Validate_Config( );
58 f86083a0 2002-03-27 alex } /* Config_Init */
59 9856253d 2001-12-30 alex
60 9856253d 2001-12-30 alex
61 f86083a0 2002-03-27 alex GLOBAL INT Conf_Test( VOID )
62 f86083a0 2002-03-27 alex {
63 f86083a0 2002-03-27 alex /* Konfiguration einlesen, ueberpruefen und ausgeben. */
64 f86083a0 2002-03-27 alex
65 f86083a0 2002-03-27 alex INT i;
66 f86083a0 2002-03-27 alex
67 f86083a0 2002-03-27 alex Use_Log = FALSE;
68 f86083a0 2002-03-27 alex Set_Defaults( );
69 f86083a0 2002-03-27 alex
70 f86083a0 2002-03-27 alex printf( "Using \"%s\" as configuration file ...\n", NGIRCd_ConfFile );
71 f86083a0 2002-03-27 alex Read_Config( );
72 f86083a0 2002-03-27 alex
73 f86083a0 2002-03-27 alex /* Wenn stdin ein ein TTY ist: auf Taste warten */
74 f86083a0 2002-03-27 alex if( isatty( fileno( stdout )))
75 f86083a0 2002-03-27 alex {
76 f86083a0 2002-03-27 alex puts( "OK, press enter to see a dump of your service configuration ..." );
77 f86083a0 2002-03-27 alex getchar( );
78 f86083a0 2002-03-27 alex }
79 f86083a0 2002-03-27 alex else puts( "Ok, dump of your server configuration follows:\n" );
80 f86083a0 2002-03-27 alex
81 f86083a0 2002-03-27 alex puts( "[GLOBAL]" );
82 f86083a0 2002-03-27 alex printf( " ServerName = %s\n", Conf_ServerName );
83 f86083a0 2002-03-27 alex printf( " ServerInfo = %s\n", Conf_ServerInfo );
84 f86083a0 2002-03-27 alex printf( " ServerPwd = %s\n", Conf_ServerPwd );
85 f86083a0 2002-03-27 alex printf( " MotdFile = %s\n", Conf_MotdFile );
86 f86083a0 2002-03-27 alex printf( " ListenPorts = " );
87 f86083a0 2002-03-27 alex for( i = 0; i < Conf_ListenPorts_Count; i++ )
88 f86083a0 2002-03-27 alex {
89 f86083a0 2002-03-27 alex if( i != 0 ) printf( ", " );
90 f86083a0 2002-03-27 alex printf( "%d", Conf_ListenPorts[i] );
91 f86083a0 2002-03-27 alex }
92 f86083a0 2002-03-27 alex if( Conf_ListenPorts_Count < 1 ) puts( "<none>");
93 f86083a0 2002-03-27 alex else puts( "" );
94 f86083a0 2002-03-27 alex printf( " PingTimeout = %d\n", Conf_PingTimeout );
95 f86083a0 2002-03-27 alex printf( " PongTimeout = %d\n", Conf_PongTimeout );
96 f86083a0 2002-03-27 alex printf( " ConnectRetry = %d\n", Conf_ConnectRetry );
97 f86083a0 2002-03-27 alex puts( "" );
98 f86083a0 2002-03-27 alex
99 f86083a0 2002-03-27 alex for( i = 0; i < Conf_Oper_Count; i++ )
100 f86083a0 2002-03-27 alex {
101 f86083a0 2002-03-27 alex puts( "[OPERATOR]" );
102 f86083a0 2002-03-27 alex printf( " Name = %s\n", Conf_Oper[i].name );
103 f86083a0 2002-03-27 alex printf( " Password = %s\n", Conf_Oper[i].pwd );
104 f86083a0 2002-03-27 alex puts( "" );
105 f86083a0 2002-03-27 alex }
106 f86083a0 2002-03-27 alex
107 f86083a0 2002-03-27 alex for( i = 0; i < Conf_Server_Count; i++ )
108 f86083a0 2002-03-27 alex {
109 f86083a0 2002-03-27 alex puts( "[SERVER]" );
110 f86083a0 2002-03-27 alex printf( " Name = %s\n", Conf_Server[i].name );
111 f86083a0 2002-03-27 alex printf( " Host = %s\n", Conf_Server[i].host );
112 f86083a0 2002-03-27 alex printf( " Port = %d\n", Conf_Server[i].port );
113 f86083a0 2002-03-27 alex printf( " Password = %s\n", Conf_Server[i].pwd );
114 f86083a0 2002-03-27 alex printf( " Group = %d\n", Conf_Server[i].group );
115 f86083a0 2002-03-27 alex puts( "" );
116 f86083a0 2002-03-27 alex }
117 f86083a0 2002-03-27 alex
118 f86083a0 2002-03-27 alex return 0;
119 f86083a0 2002-03-27 alex } /* Conf_Test */
120 f86083a0 2002-03-27 alex
121 f86083a0 2002-03-27 alex
122 f86083a0 2002-03-27 alex GLOBAL VOID Conf_Exit( VOID )
123 f86083a0 2002-03-27 alex {
124 f86083a0 2002-03-27 alex /* ... */
125 f86083a0 2002-03-27 alex } /* Config_Exit */
126 f86083a0 2002-03-27 alex
127 f86083a0 2002-03-27 alex
128 f86083a0 2002-03-27 alex LOCAL VOID Set_Defaults( VOID )
129 f86083a0 2002-03-27 alex {
130 f86083a0 2002-03-27 alex /* Konfigurationsvariablen initialisieren, d.h. auf Default-Werte setzen. */
131 f86083a0 2002-03-27 alex
132 9856253d 2001-12-30 alex strcpy( Conf_ServerName, "" );
133 804b1ec4 2001-12-31 alex strcpy( Conf_ServerInfo, PACKAGE" "VERSION );
134 ed406b4a 2002-01-03 alex strcpy( Conf_ServerPwd, "" );
135 9856253d 2001-12-30 alex
136 10aa35cc 2002-03-06 alex strcpy( Conf_MotdFile, MOTD_FILE );
137 9856253d 2001-12-30 alex
138 9856253d 2001-12-30 alex Conf_ListenPorts_Count = 0;
139 574ae82c 2001-12-26 alex
140 08cf5607 2001-12-26 alex Conf_PingTimeout = 120;
141 281d8e45 2002-03-25 alex Conf_PongTimeout = 20;
142 574ae82c 2001-12-26 alex
143 03d971d9 2002-01-02 alex Conf_ConnectRetry = 60;
144 03d971d9 2002-01-02 alex
145 03d971d9 2002-01-02 alex Conf_Oper_Count = 0;
146 03d971d9 2002-01-02 alex
147 03d971d9 2002-01-02 alex Conf_Server_Count = 0;
148 f86083a0 2002-03-27 alex } /* Set_Defaults */
149 03d971d9 2002-01-02 alex
150 cbc1e59f 2001-12-12 alex
151 574ae82c 2001-12-26 alex LOCAL VOID Read_Config( VOID )
152 574ae82c 2001-12-26 alex {
153 574ae82c 2001-12-26 alex /* Konfigurationsdatei einlesen. */
154 9856253d 2001-12-30 alex
155 03d971d9 2002-01-02 alex CHAR section[LINE_LEN], str[LINE_LEN], *var, *arg, *ptr;
156 9856253d 2001-12-30 alex INT line;
157 9856253d 2001-12-30 alex FILE *fd;
158 9856253d 2001-12-30 alex
159 f86083a0 2002-03-27 alex fd = fopen( NGIRCd_ConfFile, "r" );
160 9856253d 2001-12-30 alex if( ! fd )
161 9856253d 2001-12-30 alex {
162 9856253d 2001-12-30 alex /* Keine Konfigurationsdatei gefunden */
163 f86083a0 2002-03-27 alex Config_Error( LOG_ALERT, "Can't read configuration \"%s\": %s", NGIRCd_ConfFile, strerror( errno ));
164 f86083a0 2002-03-27 alex Config_Error( LOG_ALERT, PACKAGE" exiting due to fatal errors!" );
165 9856253d 2001-12-30 alex exit( 1 );
166 9856253d 2001-12-30 alex }
167 9856253d 2001-12-30 alex
168 9856253d 2001-12-30 alex line = 0;
169 03d971d9 2002-01-02 alex strcpy( section, "" );
170 9856253d 2001-12-30 alex while( TRUE )
171 9856253d 2001-12-30 alex {
172 804b1ec4 2001-12-31 alex if( ! fgets( str, LINE_LEN, fd )) break;
173 9856253d 2001-12-30 alex ngt_TrimStr( str );
174 9856253d 2001-12-30 alex line++;
175 9856253d 2001-12-30 alex
176 9856253d 2001-12-30 alex /* Kommentarzeilen und leere Zeilen ueberspringen */
177 9856253d 2001-12-30 alex if( str[0] == ';' || str[0] == '#' || str[0] == '\0' ) continue;
178 9856253d 2001-12-30 alex
179 03d971d9 2002-01-02 alex /* Anfang eines Abschnittes? */
180 03d971d9 2002-01-02 alex if(( str[0] == '[' ) && ( str[strlen( str ) - 1] == ']' ))
181 03d971d9 2002-01-02 alex {
182 03d971d9 2002-01-02 alex strcpy( section, str );
183 03d971d9 2002-01-02 alex if( strcasecmp( section, "[GLOBAL]" ) == 0 ) continue;
184 03d971d9 2002-01-02 alex if( strcasecmp( section, "[OPERATOR]" ) == 0 )
185 03d971d9 2002-01-02 alex {
186 f86083a0 2002-03-27 alex if( Conf_Oper_Count + 1 > MAX_OPERATORS ) Config_Error( LOG_ERR, "Too many operators configured." );
187 03d971d9 2002-01-02 alex else
188 03d971d9 2002-01-02 alex {
189 03d971d9 2002-01-02 alex /* neuen Operator initialisieren */
190 03d971d9 2002-01-02 alex strcpy( Conf_Oper[Conf_Oper_Count].name, "" );
191 03d971d9 2002-01-02 alex strcpy( Conf_Oper[Conf_Oper_Count].pwd, "" );
192 03d971d9 2002-01-02 alex Conf_Oper_Count++;
193 03d971d9 2002-01-02 alex }
194 03d971d9 2002-01-02 alex continue;
195 03d971d9 2002-01-02 alex }
196 03d971d9 2002-01-02 alex if( strcasecmp( section, "[SERVER]" ) == 0 )
197 03d971d9 2002-01-02 alex {
198 f86083a0 2002-03-27 alex if( Conf_Server_Count + 1 > MAX_SERVERS ) Config_Error( LOG_ERR, "Too many servers configured." );
199 03d971d9 2002-01-02 alex else
200 03d971d9 2002-01-02 alex {
201 03d971d9 2002-01-02 alex /* neuen Server ("Peer") initialisieren */
202 03d971d9 2002-01-02 alex strcpy( Conf_Server[Conf_Server_Count].host, "" );
203 03d971d9 2002-01-02 alex strcpy( Conf_Server[Conf_Server_Count].ip, "" );
204 03d971d9 2002-01-02 alex strcpy( Conf_Server[Conf_Server_Count].name, "" );
205 03d971d9 2002-01-02 alex strcpy( Conf_Server[Conf_Server_Count].pwd, "" );
206 03d971d9 2002-01-02 alex Conf_Server[Conf_Server_Count].port = 0;
207 d67d94ea 2002-03-10 alex Conf_Server[Conf_Server_Count].group = -1;
208 6debfc31 2002-01-18 alex Conf_Server[Conf_Server_Count].lasttry = time( NULL ) - Conf_ConnectRetry + STARTUP_DELAY;
209 03d971d9 2002-01-02 alex Conf_Server[Conf_Server_Count].res_stat = NULL;
210 03d971d9 2002-01-02 alex Conf_Server_Count++;
211 03d971d9 2002-01-02 alex }
212 03d971d9 2002-01-02 alex continue;
213 03d971d9 2002-01-02 alex }
214 f86083a0 2002-03-27 alex Config_Error( LOG_ERR, "%s, line %d: Unknown section \"%s\"!", NGIRCd_ConfFile, line, section );
215 03d971d9 2002-01-02 alex section[0] = 0x1;
216 03d971d9 2002-01-02 alex }
217 03d971d9 2002-01-02 alex if( section[0] == 0x1 ) continue;
218 03d971d9 2002-01-02 alex
219 03d971d9 2002-01-02 alex /* In Variable und Argument zerlegen */
220 9856253d 2001-12-30 alex ptr = strchr( str, '=' );
221 9856253d 2001-12-30 alex if( ! ptr )
222 9856253d 2001-12-30 alex {
223 f86083a0 2002-03-27 alex Config_Error( LOG_ERR, "%s, line %d: Syntax error!", NGIRCd_ConfFile, line );
224 9856253d 2001-12-30 alex continue;
225 9856253d 2001-12-30 alex }
226 9856253d 2001-12-30 alex *ptr = '\0';
227 9856253d 2001-12-30 alex var = str; ngt_TrimStr( var );
228 9856253d 2001-12-30 alex arg = ptr + 1; ngt_TrimStr( arg );
229 03d971d9 2002-01-02 alex
230 03d971d9 2002-01-02 alex if( strcasecmp( section, "[GLOBAL]" ) == 0 ) Handle_GLOBAL( line, var, arg );
231 03d971d9 2002-01-02 alex else if( strcasecmp( section, "[OPERATOR]" ) == 0 ) Handle_OPERATOR( line, var, arg );
232 03d971d9 2002-01-02 alex else if( strcasecmp( section, "[SERVER]" ) == 0 ) Handle_SERVER( line, var, arg );
233 f86083a0 2002-03-27 alex else Config_Error( LOG_ERR, "%s, line %d: Variable \"%s\" outside section!", NGIRCd_ConfFile, line, var );
234 03d971d9 2002-01-02 alex }
235 03d971d9 2002-01-02 alex
236 03d971d9 2002-01-02 alex fclose( fd );
237 03d971d9 2002-01-02 alex } /* Read_Config */
238 03d971d9 2002-01-02 alex
239 03d971d9 2002-01-02 alex
240 03d971d9 2002-01-02 alex GLOBAL VOID Handle_GLOBAL( INT Line, CHAR *Var, CHAR *Arg )
241 03d971d9 2002-01-02 alex {
242 03d971d9 2002-01-02 alex CHAR *ptr;
243 95a4b1b1 2002-03-25 alex INT32 port;
244 03d971d9 2002-01-02 alex
245 03d971d9 2002-01-02 alex assert( Line > 0 );
246 03d971d9 2002-01-02 alex assert( Var != NULL );
247 03d971d9 2002-01-02 alex assert( Arg != NULL );
248 03d971d9 2002-01-02 alex
249 03d971d9 2002-01-02 alex if( strcasecmp( Var, "Name" ) == 0 )
250 03d971d9 2002-01-02 alex {
251 03d971d9 2002-01-02 alex /* Der Server-Name */
252 10363b39 2002-03-03 alex strncpy( Conf_ServerName, Arg, CLIENT_ID_LEN - 1 );
253 03d971d9 2002-01-02 alex Conf_ServerName[CLIENT_ID_LEN - 1] = '\0';
254 03d971d9 2002-01-02 alex return;
255 03d971d9 2002-01-02 alex }
256 03d971d9 2002-01-02 alex if( strcasecmp( Var, "Info" ) == 0 )
257 03d971d9 2002-01-02 alex {
258 03d971d9 2002-01-02 alex /* Server-Info-Text */
259 10363b39 2002-03-03 alex strncpy( Conf_ServerInfo, Arg, CLIENT_INFO_LEN - 1 );
260 03d971d9 2002-01-02 alex Conf_ServerInfo[CLIENT_INFO_LEN - 1] = '\0';
261 03d971d9 2002-01-02 alex return;
262 03d971d9 2002-01-02 alex }
263 ed406b4a 2002-01-03 alex if( strcasecmp( Var, "Password" ) == 0 )
264 ed406b4a 2002-01-03 alex {
265 10363b39 2002-03-03 alex /* Server-Passwort */
266 10363b39 2002-03-03 alex strncpy( Conf_ServerPwd, Arg, CLIENT_PASS_LEN - 1 );
267 ed406b4a 2002-01-03 alex Conf_ServerPwd[CLIENT_PASS_LEN - 1] = '\0';
268 ed406b4a 2002-01-03 alex return;
269 ed406b4a 2002-01-03 alex }
270 03d971d9 2002-01-02 alex if( strcasecmp( Var, "Ports" ) == 0 )
271 03d971d9 2002-01-02 alex {
272 03d971d9 2002-01-02 alex /* Ports, durch "," getrennt, auf denen der Server
273 03d971d9 2002-01-02 alex * Verbindungen annehmen soll */
274 03d971d9 2002-01-02 alex ptr = strtok( Arg, "," );
275 03d971d9 2002-01-02 alex while( ptr )
276 9856253d 2001-12-30 alex {
277 03d971d9 2002-01-02 alex ngt_TrimStr( ptr );
278 03d971d9 2002-01-02 alex port = atol( ptr );
279 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 );
280 03d971d9 2002-01-02 alex else
281 03d971d9 2002-01-02 alex {
282 95a4b1b1 2002-03-25 alex if( port > 0 && port < 0xFFFF ) Conf_ListenPorts[Conf_ListenPorts_Count++] = (INT)port;
283 f86083a0 2002-03-27 alex else Config_Error( LOG_ERR, "%s, line %d (section \"Global\"): Illegal port number %ld!", NGIRCd_ConfFile, Line, port );
284 03d971d9 2002-01-02 alex }
285 03d971d9 2002-01-02 alex ptr = strtok( NULL, "," );
286 9856253d 2001-12-30 alex }
287 03d971d9 2002-01-02 alex return;
288 03d971d9 2002-01-02 alex }
289 03d971d9 2002-01-02 alex if( strcasecmp( Var, "MotdFile" ) == 0 )
290 03d971d9 2002-01-02 alex {
291 03d971d9 2002-01-02 alex /* Datei mit der "message of the day" (MOTD) */
292 10363b39 2002-03-03 alex strncpy( Conf_MotdFile, Arg, FNAME_LEN - 1 );
293 03d971d9 2002-01-02 alex Conf_MotdFile[FNAME_LEN - 1] = '\0';
294 03d971d9 2002-01-02 alex return;
295 03d971d9 2002-01-02 alex }
296 03d971d9 2002-01-02 alex if( strcasecmp( Var, "PingTimeout" ) == 0 )
297 03d971d9 2002-01-02 alex {
298 03d971d9 2002-01-02 alex /* PING-Timeout */
299 03d971d9 2002-01-02 alex Conf_PingTimeout = atoi( Arg );
300 03d971d9 2002-01-02 alex if(( Conf_PingTimeout ) < 5 ) Conf_PingTimeout = 5;
301 03d971d9 2002-01-02 alex return;
302 03d971d9 2002-01-02 alex }
303 03d971d9 2002-01-02 alex if( strcasecmp( Var, "PongTimeout" ) == 0 )
304 03d971d9 2002-01-02 alex {
305 03d971d9 2002-01-02 alex /* PONG-Timeout */
306 03d971d9 2002-01-02 alex Conf_PongTimeout = atoi( Arg );
307 03d971d9 2002-01-02 alex if(( Conf_PongTimeout ) < 5 ) Conf_PongTimeout = 5;
308 03d971d9 2002-01-02 alex return;
309 03d971d9 2002-01-02 alex }
310 03d971d9 2002-01-02 alex if( strcasecmp( Var, "ConnectRetry" ) == 0 )
311 03d971d9 2002-01-02 alex {
312 03d971d9 2002-01-02 alex /* Sekunden zwischen Verbindungsversuchen zu anderen Servern */
313 03d971d9 2002-01-02 alex Conf_ConnectRetry = atoi( Arg );
314 03d971d9 2002-01-02 alex if(( Conf_ConnectRetry ) < 5 ) Conf_ConnectRetry = 5;
315 03d971d9 2002-01-02 alex return;
316 03d971d9 2002-01-02 alex }
317 9856253d 2001-12-30 alex
318 f86083a0 2002-03-27 alex Config_Error( LOG_ERR, "%s, line %d (section \"Global\"): Unknown variable \"%s\"!", NGIRCd_ConfFile, Line, Var );
319 03d971d9 2002-01-02 alex } /* Handle_GLOBAL */
320 03d971d9 2002-01-02 alex
321 03d971d9 2002-01-02 alex
322 03d971d9 2002-01-02 alex GLOBAL VOID Handle_OPERATOR( INT Line, CHAR *Var, CHAR *Arg )
323 03d971d9 2002-01-02 alex {
324 03d971d9 2002-01-02 alex assert( Line > 0 );
325 03d971d9 2002-01-02 alex assert( Var != NULL );
326 03d971d9 2002-01-02 alex assert( Arg != NULL );
327 03d971d9 2002-01-02 alex assert( Conf_Oper_Count > 0 );
328 03d971d9 2002-01-02 alex
329 03d971d9 2002-01-02 alex if( strcasecmp( Var, "Name" ) == 0 )
330 03d971d9 2002-01-02 alex {
331 03d971d9 2002-01-02 alex /* Name des IRC Operator */
332 10363b39 2002-03-03 alex strncpy( Conf_Oper[Conf_Oper_Count - 1].name, Arg, CLIENT_ID_LEN - 1 );
333 03d971d9 2002-01-02 alex Conf_Oper[Conf_Oper_Count - 1].name[CLIENT_ID_LEN - 1] = '\0';
334 03d971d9 2002-01-02 alex return;
335 9856253d 2001-12-30 alex }
336 03d971d9 2002-01-02 alex if( strcasecmp( Var, "Password" ) == 0 )
337 03d971d9 2002-01-02 alex {
338 03d971d9 2002-01-02 alex /* Passwort des IRC Operator */
339 10363b39 2002-03-03 alex strncpy( Conf_Oper[Conf_Oper_Count - 1].pwd, Arg, CLIENT_PASS_LEN - 1 );
340 03d971d9 2002-01-02 alex Conf_Oper[Conf_Oper_Count - 1].pwd[CLIENT_PASS_LEN - 1] = '\0';
341 03d971d9 2002-01-02 alex return;
342 03d971d9 2002-01-02 alex }
343 574ae82c 2001-12-26 alex
344 f86083a0 2002-03-27 alex Config_Error( LOG_ERR, "%s, line %d (section \"Operator\"): Unknown variable \"%s\"!", NGIRCd_ConfFile, Line, Var );
345 03d971d9 2002-01-02 alex } /* Handle_OPERATOR */
346 574ae82c 2001-12-26 alex
347 574ae82c 2001-12-26 alex
348 03d971d9 2002-01-02 alex GLOBAL VOID Handle_SERVER( INT Line, CHAR *Var, CHAR *Arg )
349 03d971d9 2002-01-02 alex {
350 d67d94ea 2002-03-10 alex INT32 port;
351 03d971d9 2002-01-02 alex
352 03d971d9 2002-01-02 alex assert( Line > 0 );
353 03d971d9 2002-01-02 alex assert( Var != NULL );
354 03d971d9 2002-01-02 alex assert( Arg != NULL );
355 03d971d9 2002-01-02 alex
356 03d971d9 2002-01-02 alex if( strcasecmp( Var, "Host" ) == 0 )
357 03d971d9 2002-01-02 alex {
358 03d971d9 2002-01-02 alex /* Hostname des Servers */
359 10363b39 2002-03-03 alex strncpy( Conf_Server[Conf_Server_Count - 1].host, Arg, HOST_LEN - 1 );
360 03d971d9 2002-01-02 alex Conf_Server[Conf_Server_Count - 1].host[HOST_LEN - 1] = '\0';
361 03d971d9 2002-01-02 alex return;
362 03d971d9 2002-01-02 alex }
363 03d971d9 2002-01-02 alex if( strcasecmp( Var, "Name" ) == 0 )
364 03d971d9 2002-01-02 alex {
365 03d971d9 2002-01-02 alex /* Name des Servers ("Nick") */
366 10363b39 2002-03-03 alex strncpy( Conf_Server[Conf_Server_Count - 1].name, Arg, CLIENT_ID_LEN - 1 );
367 2e289b50 2002-01-05 alex Conf_Server[Conf_Server_Count - 1].name[CLIENT_ID_LEN - 1] = '\0';
368 03d971d9 2002-01-02 alex return;
369 03d971d9 2002-01-02 alex }
370 03d971d9 2002-01-02 alex if( strcasecmp( Var, "Password" ) == 0 )
371 03d971d9 2002-01-02 alex {
372 03d971d9 2002-01-02 alex /* Passwort des Servers */
373 10363b39 2002-03-03 alex strncpy( Conf_Server[Conf_Server_Count - 1].pwd, Arg, CLIENT_PASS_LEN - 1 );
374 03d971d9 2002-01-02 alex Conf_Server[Conf_Server_Count - 1].pwd[CLIENT_PASS_LEN - 1] = '\0';
375 03d971d9 2002-01-02 alex return;
376 03d971d9 2002-01-02 alex }
377 03d971d9 2002-01-02 alex if( strcasecmp( Var, "Port" ) == 0 )
378 03d971d9 2002-01-02 alex {
379 03d971d9 2002-01-02 alex /* Port, zu dem Verbunden werden soll */
380 03d971d9 2002-01-02 alex port = atol( Arg );
381 d67d94ea 2002-03-10 alex if( port > 0 && port < 0xFFFF ) Conf_Server[Conf_Server_Count - 1].port = (INT)port;
382 f86083a0 2002-03-27 alex else Config_Error( LOG_ERR, "%s, line %d (section \"Server\"): Illegal port number %ld!", NGIRCd_ConfFile, Line, port );
383 03d971d9 2002-01-02 alex return;
384 03d971d9 2002-01-02 alex }
385 d67d94ea 2002-03-10 alex if( strcasecmp( Var, "Group" ) == 0 )
386 d67d94ea 2002-03-10 alex {
387 d67d94ea 2002-03-10 alex /* Server-Gruppe */
388 d67d94ea 2002-03-10 alex Conf_Server[Conf_Server_Count - 1].group = atoi( Arg );
389 d67d94ea 2002-03-10 alex return;
390 d67d94ea 2002-03-10 alex }
391 03d971d9 2002-01-02 alex
392 f86083a0 2002-03-27 alex Config_Error( LOG_ERR, "%s, line %d (section \"Server\"): Unknown variable \"%s\"!", NGIRCd_ConfFile, Line, Var );
393 03d971d9 2002-01-02 alex } /* Handle_SERVER */
394 03d971d9 2002-01-02 alex
395 03d971d9 2002-01-02 alex
396 9856253d 2001-12-30 alex LOCAL VOID Validate_Config( VOID )
397 9856253d 2001-12-30 alex {
398 9856253d 2001-12-30 alex /* Konfiguration ueberpruefen */
399 9856253d 2001-12-30 alex
400 9856253d 2001-12-30 alex if( ! Conf_ServerName[0] )
401 9856253d 2001-12-30 alex {
402 9856253d 2001-12-30 alex /* Kein Servername konfiguriert */
403 f86083a0 2002-03-27 alex Config_Error( LOG_ALERT, "No server name configured in \"%s\"!", NGIRCd_ConfFile );
404 f86083a0 2002-03-27 alex Config_Error( LOG_ALERT, PACKAGE" exiting due to fatal errors!" );
405 9856253d 2001-12-30 alex exit( 1 );
406 9856253d 2001-12-30 alex }
407 9856253d 2001-12-30 alex } /* Validate_Config */
408 9856253d 2001-12-30 alex
409 f86083a0 2002-03-27 alex
410 f86083a0 2002-03-27 alex LOCAL VOID Config_Error( CONST INT Level, CONST CHAR *Format, ... )
411 f86083a0 2002-03-27 alex {
412 f86083a0 2002-03-27 alex /* Fehler! Auf Console und/oder ins Log schreiben */
413 f86083a0 2002-03-27 alex
414 f86083a0 2002-03-27 alex CHAR msg[MAX_LOG_MSG_LEN];
415 f86083a0 2002-03-27 alex va_list ap;
416 f86083a0 2002-03-27 alex
417 f86083a0 2002-03-27 alex assert( Format != NULL );
418 f86083a0 2002-03-27 alex
419 f86083a0 2002-03-27 alex /* String mit variablen Argumenten zusammenbauen ... */
420 f86083a0 2002-03-27 alex va_start( ap, Format );
421 f86083a0 2002-03-27 alex vsnprintf( msg, MAX_LOG_MSG_LEN, Format, ap );
422 f86083a0 2002-03-27 alex va_end( ap );
423 f86083a0 2002-03-27 alex
424 f86083a0 2002-03-27 alex /* Im "normalen Betrieb" soll der Log-Mechanismus des ngIRCd verwendet
425 f86083a0 2002-03-27 alex * werden, beim Testen der Konfiguration jedoch nicht, hier sollen alle
426 f86083a0 2002-03-27 alex * Meldungen direkt auf die Konsole ausgegeben werden: */
427 f86083a0 2002-03-27 alex if( Use_Log ) Log( Level, msg );
428 f86083a0 2002-03-27 alex else puts( msg );
429 f86083a0 2002-03-27 alex } /* Config_Error */
430 f86083a0 2002-03-27 alex
431 f86083a0 2002-03-27 alex
432 cbc1e59f 2001-12-12 alex /* -eof- */