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