]> arthur.barton.de Git - ngircd-alex.git/blob - src/ngircd/conf.c
- translated file header and comments to english;
[ngircd-alex.git] / src / ngircd / conf.c
1 /*
2  * ngIRCd -- The Next Generation IRC Daemon
3  * Copyright (c)2001,2002 Alexander Barton (alex@barton.de)
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  * Please read the file COPYING, README and AUTHORS for more information.
10  *
11  * Configuration management (reading, parsing & validation)
12  */
13
14
15 #include "portab.h"
16
17 static char UNUSED id[] = "$Id: conf.c,v 1.42 2002/12/12 11:26:08 alex Exp $";
18
19 #include "imp.h"
20 #include <assert.h>
21 #include <errno.h>
22 #include <stdarg.h>
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include <unistd.h>
27 #include <pwd.h>
28 #include <grp.h>
29 #include <sys/types.h>
30
31 #ifdef HAVE_CTYPE_H
32 # include <ctype.h>
33 #endif
34
35 #include "ngircd.h"
36 #include "conn.h"
37 #include "client.h"
38 #include "defines.h"
39 #include "log.h"
40 #include "resolve.h"
41 #include "tool.h"
42
43 #include "exp.h"
44 #include "conf.h"
45
46
47 LOCAL BOOLEAN Use_Log = TRUE;
48
49
50 LOCAL VOID Set_Defaults PARAMS(( VOID ));
51 LOCAL VOID Read_Config PARAMS(( VOID ));
52 LOCAL VOID Validate_Config PARAMS(( VOID ));
53
54 LOCAL VOID Handle_GLOBAL PARAMS(( INT Line, CHAR *Var, CHAR *Arg ));
55 LOCAL VOID Handle_OPERATOR PARAMS(( INT Line, CHAR *Var, CHAR *Arg ));
56 LOCAL VOID Handle_SERVER PARAMS(( INT Line, CHAR *Var, CHAR *Arg ));
57 LOCAL VOID Handle_CHANNEL PARAMS(( INT Line, CHAR *Var, CHAR *Arg ));
58
59 LOCAL VOID Config_Error PARAMS(( CONST INT Level, CONST CHAR *Format, ... ));
60
61
62 GLOBAL VOID
63 Conf_Init( VOID )
64 {
65         Set_Defaults( );
66         Read_Config( );
67         Validate_Config( );
68 } /* Config_Init */
69
70
71 GLOBAL INT
72 Conf_Test( VOID )
73 {
74         /* Read configuration, validate and output it. */
75
76         struct passwd *pwd;
77         struct group *grp;
78         INT i;
79
80         Use_Log = FALSE;
81         Set_Defaults( );
82
83         Read_Config( );
84
85         /* If stdin is a valid tty wait for a key: */
86         if( isatty( fileno( stdout )))
87         {
88                 puts( "OK, press enter to see a dump of your service configuration ..." );
89                 getchar( );
90         }
91         else puts( "Ok, dump of your server configuration follows:\n" );
92
93         puts( "[GLOBAL]" );
94         printf( "  ServerName = %s\n", Conf_ServerName );
95         printf( "  ServerInfo = %s\n", Conf_ServerInfo );
96         printf( "  ServerPwd = %s\n", Conf_ServerPwd );
97         printf( "  AdminInfo1 = %s\n", Conf_ServerAdmin1 );
98         printf( "  AdminInfo2 = %s\n", Conf_ServerAdmin2 );
99         printf( "  AdminEMail = %s\n", Conf_ServerAdminMail );
100         printf( "  MotdFile = %s\n", Conf_MotdFile );
101         printf( "  Ports = " );
102         for( i = 0; i < Conf_ListenPorts_Count; i++ )
103         {
104                 if( i != 0 ) printf( ", " );
105                 printf( "%u", Conf_ListenPorts[i] );
106         }
107         puts( "" );
108         pwd = getpwuid( Conf_UID );
109         if( pwd ) printf( "  ServerUID = %s\n", pwd->pw_name );
110         else printf( "  ServerUID = %ld\n", (LONG)Conf_UID );
111         grp = getgrgid( Conf_GID );
112         if( grp ) printf( "  ServerGID = %s\n", grp->gr_name );
113         else printf( "  ServerGID = %ld\n", (LONG)Conf_GID );
114         printf( "  PingTimeout = %d\n", Conf_PingTimeout );
115         printf( "  PongTimeout = %d\n", Conf_PongTimeout );
116         printf( "  ConnectRetry = %d\n", Conf_ConnectRetry );
117         printf( "  OperCanUseMode = %s\n", Conf_OperCanMode == TRUE ? "yes" : "no" );
118         if( Conf_MaxConnections > 0 ) printf( "  MaxConnections = %ld\n", Conf_MaxConnections );
119         else printf( "  MaxConnections = -1\n" );
120         puts( "" );
121
122         for( i = 0; i < Conf_Oper_Count; i++ )
123         {
124                 if( ! Conf_Oper[i].name[0] ) continue;
125                 
126                 /* Valid "Operator" section */
127                 puts( "[OPERATOR]" );
128                 printf( "  Name = %s\n", Conf_Oper[i].name );
129                 printf( "  Password = %s\n", Conf_Oper[i].pwd );
130                 puts( "" );
131         }
132
133         for( i = 0; i < Conf_Server_Count; i++ )
134         {
135                 if( ! Conf_Server[i].name[0] ) continue;
136                 
137                 /* Valid "Server" section */
138                 puts( "[SERVER]" );
139                 printf( "  Name = %s\n", Conf_Server[i].name );
140                 printf( "  Host = %s\n", Conf_Server[i].host );
141                 printf( "  Port = %d\n", Conf_Server[i].port );
142                 printf( "  MyPassword = %s\n", Conf_Server[i].pwd_in );
143                 printf( "  PeerPassword = %s\n", Conf_Server[i].pwd_out );
144                 printf( "  Group = %d\n", Conf_Server[i].group );
145                 puts( "" );
146         }
147
148         for( i = 0; i < Conf_Channel_Count; i++ )
149         {
150                 if( ! Conf_Channel[i].name[0] ) continue;
151                 
152                 /* Valid "Channel" section */
153                 puts( "[CHANNEL]" );
154                 printf( "  Name = %s\n", Conf_Channel[i].name );
155                 printf( "  Modes = %s\n", Conf_Channel[i].modes );
156                 printf( "  Topic = %s\n", Conf_Channel[i].topic );
157                 puts( "" );
158         }
159         
160         return 0;
161 } /* Conf_Test */
162
163
164 LOCAL VOID
165 Set_Defaults( VOID )
166 {
167         /* Initialize configuration variables with default values. */
168
169         strcpy( Conf_ServerName, "" );
170         sprintf( Conf_ServerInfo, "%s %s", PACKAGE, VERSION );
171         strcpy( Conf_ServerPwd, "" );
172
173         strcpy( Conf_ServerAdmin1, "" );
174         strcpy( Conf_ServerAdmin2, "" );
175         strcpy( Conf_ServerAdminMail, "" );
176
177         strcpy( Conf_MotdFile, MOTD_FILE );
178
179         Conf_ListenPorts_Count = 0;
180
181         Conf_UID = Conf_GID = 0;
182         
183         Conf_PingTimeout = 120;
184         Conf_PongTimeout = 20;
185
186         Conf_ConnectRetry = 60;
187
188         Conf_Oper_Count = 0;
189         Conf_Server_Count = 0;
190         Conf_Channel_Count = 0;
191
192         Conf_OperCanMode = FALSE;
193         
194         Conf_MaxConnections = 0;
195 } /* Set_Defaults */
196
197
198 LOCAL VOID
199 Read_Config( VOID )
200 {
201         /* Read configuration file. */
202
203         CHAR section[LINE_LEN], str[LINE_LEN], *var, *arg, *ptr;
204         INT line;
205         FILE *fd;
206
207         fd = fopen( NGIRCd_ConfFile, "r" );
208         if( ! fd )
209         {
210                 /* No configuration file found! */
211                 Config_Error( LOG_ALERT, "Can't read configuration \"%s\": %s", NGIRCd_ConfFile, strerror( errno ));
212                 Config_Error( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE );
213                 exit( 1 );
214         }
215
216         Config_Error( LOG_INFO, "Reading configuration from \"%s\" ...", NGIRCd_ConfFile );
217
218         line = 0;
219         strcpy( section, "" );
220         while( TRUE )
221         {
222                 if( ! fgets( str, LINE_LEN, fd )) break;
223                 ngt_TrimStr( str );
224                 line++;
225
226                 /* Skip comments and empty lines */
227                 if( str[0] == ';' || str[0] == '#' || str[0] == '\0' ) continue;
228
229                 /* Is this the beginning of a new section? */
230                 if(( str[0] == '[' ) && ( str[strlen( str ) - 1] == ']' ))
231                 {
232                         strcpy( section, str );
233                         if( strcasecmp( section, "[GLOBAL]" ) == 0 ) continue;
234                         if( strcasecmp( section, "[OPERATOR]" ) == 0 )
235                         {
236                                 if( Conf_Oper_Count + 1 > MAX_OPERATORS ) Config_Error( LOG_ERR, "Too many operators configured." );
237                                 else
238                                 {
239                                         /* Initialize new operator structure */
240                                         strcpy( Conf_Oper[Conf_Oper_Count].name, "" );
241                                         strcpy( Conf_Oper[Conf_Oper_Count].pwd, "" );
242                                         Conf_Oper_Count++;
243                                 }
244                                 continue;
245                         }
246                         if( strcasecmp( section, "[SERVER]" ) == 0 )
247                         {
248                                 if( Conf_Server_Count + 1 > MAX_SERVERS ) Config_Error( LOG_ERR, "Too many servers configured." );
249                                 else
250                                 {
251                                         /* Initialize new server structure */
252                                         strcpy( Conf_Server[Conf_Server_Count].host, "" );
253                                         strcpy( Conf_Server[Conf_Server_Count].ip, "" );
254                                         strcpy( Conf_Server[Conf_Server_Count].name, "" );
255                                         strcpy( Conf_Server[Conf_Server_Count].pwd_in, "" );
256                                         strcpy( Conf_Server[Conf_Server_Count].pwd_out, "" );
257                                         Conf_Server[Conf_Server_Count].port = 0;
258                                         Conf_Server[Conf_Server_Count].group = -1;
259                                         Conf_Server[Conf_Server_Count].lasttry = time( NULL ) - Conf_ConnectRetry + STARTUP_DELAY;
260                                         Conf_Server[Conf_Server_Count].res_stat = NULL;
261                                         Conf_Server_Count++;
262                                 }
263                                 continue;
264                         }
265                         if( strcasecmp( section, "[CHANNEL]" ) == 0 )
266                         {
267                                 if( Conf_Channel_Count + 1 > MAX_DEFCHANNELS ) Config_Error( LOG_ERR, "Too many pre-defined channels configured." );
268                                 else
269                                 {
270                                         /* Initialize new channel structure */
271                                         strcpy( Conf_Channel[Conf_Channel_Count].name, "" );
272                                         strcpy( Conf_Channel[Conf_Channel_Count].modes, "" );
273                                         strcpy( Conf_Channel[Conf_Channel_Count].topic, "" );
274                                         Conf_Channel_Count++;
275                                 }
276                                 continue;
277                         }
278                         Config_Error( LOG_ERR, "%s, line %d: Unknown section \"%s\"!", NGIRCd_ConfFile, line, section );
279                         section[0] = 0x1;
280                 }
281                 if( section[0] == 0x1 ) continue;
282
283                 /* Split line into variable name and parameters */
284                 ptr = strchr( str, '=' );
285                 if( ! ptr )
286                 {
287                         Config_Error( LOG_ERR, "%s, line %d: Syntax error!", NGIRCd_ConfFile, line );
288                         continue;
289                 }
290                 *ptr = '\0';
291                 var = str; ngt_TrimStr( var );
292                 arg = ptr + 1; ngt_TrimStr( arg );
293
294                 if( strcasecmp( section, "[GLOBAL]" ) == 0 ) Handle_GLOBAL( line, var, arg );
295                 else if( strcasecmp( section, "[OPERATOR]" ) == 0 ) Handle_OPERATOR( line, var, arg );
296                 else if( strcasecmp( section, "[SERVER]" ) == 0 ) Handle_SERVER( line, var, arg );
297                 else if( strcasecmp( section, "[CHANNEL]" ) == 0 ) Handle_CHANNEL( line, var, arg );
298                 else Config_Error( LOG_ERR, "%s, line %d: Variable \"%s\" outside section!", NGIRCd_ConfFile, line, var );
299         }
300         
301         fclose( fd );
302         
303         /* If there are no ports configured use the default: 6667 */
304         if( Conf_ListenPorts_Count < 1 )
305         {
306                 Conf_ListenPorts_Count = 1;
307                 Conf_ListenPorts[0] = 6667;
308         }
309 } /* Read_Config */
310
311
312 LOCAL VOID
313 Handle_GLOBAL( INT Line, CHAR *Var, CHAR *Arg )
314 {
315         struct passwd *pwd;
316         struct group *grp;
317         CHAR *ptr;
318         LONG port;
319         
320         assert( Line > 0 );
321         assert( Var != NULL );
322         assert( Arg != NULL );
323         
324         if( strcasecmp( Var, "Name" ) == 0 )
325         {
326                 /* Server name */
327                 strncpy( Conf_ServerName, Arg, CLIENT_ID_LEN - 1 );
328                 Conf_ServerName[CLIENT_ID_LEN - 1] = '\0';
329                 if( strlen( Arg ) > CLIENT_ID_LEN - 1 ) Config_Error( LOG_WARNING, "%s, line %d: Value of \"Name\" too long!", NGIRCd_ConfFile, Line );
330                 return;
331         }
332         if( strcasecmp( Var, "Info" ) == 0 )
333         {
334                 /* Info text of server */
335                 strncpy( Conf_ServerInfo, Arg, CLIENT_INFO_LEN - 1 );
336                 Conf_ServerInfo[CLIENT_INFO_LEN - 1] = '\0';
337                 if( strlen( Arg ) > CLIENT_INFO_LEN - 1 ) Config_Error( LOG_WARNING, "%s, line %d: Value of \"Info\" too long!", NGIRCd_ConfFile, Line );
338                 return;
339         }
340         if( strcasecmp( Var, "Password" ) == 0 )
341         {
342                 /* Global server password */
343                 strncpy( Conf_ServerPwd, Arg, CLIENT_PASS_LEN - 1 );
344                 Conf_ServerPwd[CLIENT_PASS_LEN - 1] = '\0';
345                 if( strlen( Arg ) > CLIENT_PASS_LEN - 1 ) Config_Error( LOG_WARNING, "%s, line %d: Value of \"Password\" too long!", NGIRCd_ConfFile, Line );
346                 return;
347         }
348         if( strcasecmp( Var, "AdminInfo1" ) == 0 )
349         {
350                 /* Administrative info #1 */
351                 strncpy( Conf_ServerAdmin1, Arg, CLIENT_INFO_LEN - 1 );
352                 Conf_ServerAdmin1[CLIENT_INFO_LEN - 1] = '\0';
353                 if( strlen( Arg ) > CLIENT_INFO_LEN - 1 ) Config_Error( LOG_WARNING, "%s, line %d: Value of \"AdminInfo1\" too long!", NGIRCd_ConfFile, Line );
354                 return;
355         }
356         if( strcasecmp( Var, "AdminInfo2" ) == 0 )
357         {
358                 /* Administrative info #2 */
359                 strncpy( Conf_ServerAdmin2, Arg, CLIENT_INFO_LEN - 1 );
360                 Conf_ServerAdmin2[CLIENT_INFO_LEN - 1] = '\0';
361                 if( strlen( Arg ) > CLIENT_INFO_LEN - 1 ) Config_Error( LOG_WARNING, "%s, line %d: Value of \"AdminInfo2\" too long!", NGIRCd_ConfFile, Line );
362                 return;
363         }
364         if( strcasecmp( Var, "AdminEMail" ) == 0 )
365         {
366                 /* Administrative email contact */
367                 strncpy( Conf_ServerAdminMail, Arg, CLIENT_INFO_LEN - 1 );
368                 Conf_ServerAdminMail[CLIENT_INFO_LEN - 1] = '\0';
369                 if( strlen( Arg ) > CLIENT_INFO_LEN - 1 ) Config_Error( LOG_WARNING, "%s, line %d: Value of \"AdminEMail\" too long!", NGIRCd_ConfFile, Line );
370                 return;
371         }
372         if( strcasecmp( Var, "Ports" ) == 0 )
373         {
374                 /* Ports on that the server should listen. More port numbers
375                  * must be separated by "," */
376                 ptr = strtok( Arg, "," );
377                 while( ptr )
378                 {
379                         ngt_TrimStr( ptr );
380                         port = atol( ptr );
381                         if( Conf_ListenPorts_Count + 1 > MAX_LISTEN_PORTS ) Config_Error( LOG_ERR, "Too many listen ports configured. Port %ld ignored.", port );
382                         else
383                         {
384                                 if( port > 0 && port < 0xFFFF ) Conf_ListenPorts[Conf_ListenPorts_Count++] = (UINT)port;
385                                 else Config_Error( LOG_ERR, "%s, line %d (section \"Global\"): Illegal port number %ld!", NGIRCd_ConfFile, Line, port );
386                         }
387                         ptr = strtok( NULL, "," );
388                 }
389                 return;
390         }
391         if( strcasecmp( Var, "MotdFile" ) == 0 )
392         {
393                 /* "Message of the day" (MOTD) file */
394                 strncpy( Conf_MotdFile, Arg, FNAME_LEN - 1 );
395                 Conf_MotdFile[FNAME_LEN - 1] = '\0';
396                 if( strlen( Arg ) > FNAME_LEN - 1 ) Config_Error( LOG_WARNING, "%s, line %d: Value of \"MotdFile\" too long!", NGIRCd_ConfFile, Line );
397                 return;
398         }
399         if( strcasecmp( Var, "ServerUID" ) == 0 )
400         {
401                 /* UID the daemon should switch to */
402                 pwd = getpwnam( Arg );
403                 if( pwd ) Conf_UID = pwd->pw_uid;
404                 else
405                 {
406 #ifdef HAVE_ISDIGIT
407                         if( ! isdigit( *Arg )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"ServerUID\" is not a number!", NGIRCd_ConfFile, Line );
408                         else
409 #endif
410                         Conf_UID = (UINT)atoi( Arg );
411                 }
412                 return;
413         }
414         if( strcasecmp( Var, "ServerGID" ) == 0 )
415         {
416                 /* GID the daemon should use */
417                 grp = getgrnam( Arg );
418                 if( grp ) Conf_GID = grp->gr_gid;
419                 else
420                 {
421 #ifdef HAVE_ISDIGIT
422                         if( ! isdigit( *Arg )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"ServerGID\" is not a number!", NGIRCd_ConfFile, Line );
423                         else
424 #endif
425                         Conf_GID = (UINT)atoi( Arg );
426                 }
427                 return;
428         }
429         if( strcasecmp( Var, "PingTimeout" ) == 0 )
430         {
431                 /* PING timeout */
432                 Conf_PingTimeout = atoi( Arg );
433                 if( Conf_PingTimeout < 5 )
434                 {
435                         Config_Error( LOG_WARNING, "%s, line %d: Value of \"PingTimeout\" too low!", NGIRCd_ConfFile, Line );
436                         Conf_PingTimeout = 5;
437                 }
438                 return;
439         }
440         if( strcasecmp( Var, "PongTimeout" ) == 0 )
441         {
442                 /* PONG timeout */
443                 Conf_PongTimeout = atoi( Arg );
444                 if( Conf_PongTimeout < 5 )
445                 {
446                         Config_Error( LOG_WARNING, "%s, line %d: Value of \"PongTimeout\" too low!", NGIRCd_ConfFile, Line );
447                         Conf_PongTimeout = 5;
448                 }
449                 return;
450         }
451         if( strcasecmp( Var, "ConnectRetry" ) == 0 )
452         {
453                 /* Seconds between connection attempts to other servers */
454                 Conf_ConnectRetry = atoi( Arg );
455                 if( Conf_ConnectRetry < 5 )
456                 {
457                         Config_Error( LOG_WARNING, "%s, line %d: Value of \"ConnectRetry\" too low!", NGIRCd_ConfFile, Line );
458                         Conf_ConnectRetry = 5;
459                 }
460                 return;
461         }
462         if( strcasecmp( Var, "OperCanUseMode" ) == 0 )
463         {
464                 /* Are IRC operators allowed to use MODE in channels they aren't Op in? */
465                 if( strcasecmp( Arg, "yes" ) == 0 ) Conf_OperCanMode = TRUE;
466                 else if( strcasecmp( Arg, "true" ) == 0 ) Conf_OperCanMode = TRUE;
467                 else if( atoi( Arg ) != 0 ) Conf_OperCanMode = TRUE;
468                 else Conf_OperCanMode = FALSE;
469                 return;
470         }
471         if( strcasecmp( Var, "MaxConnections" ) == 0 )
472         {
473                 /* Maximum number of connections. Values <= 0 are equal to "no limit". */
474 #ifdef HAVE_ISDIGIT
475                 if( ! isdigit( *Arg )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"MaxConnections\" is not a number!", NGIRCd_ConfFile, Line );
476                 else
477 #endif
478                 Conf_MaxConnections = atol( Arg );
479                 return;
480         }
481                 
482         Config_Error( LOG_ERR, "%s, line %d (section \"Global\"): Unknown variable \"%s\"!", NGIRCd_ConfFile, Line, Var );
483 } /* Handle_GLOBAL */
484
485
486 LOCAL VOID
487 Handle_OPERATOR( INT Line, CHAR *Var, CHAR *Arg )
488 {
489         assert( Line > 0 );
490         assert( Var != NULL );
491         assert( Arg != NULL );
492         assert( Conf_Oper_Count > 0 );
493
494         if( strcasecmp( Var, "Name" ) == 0 )
495         {
496                 /* Name of IRC operator */
497                 strncpy( Conf_Oper[Conf_Oper_Count - 1].name, Arg, CLIENT_PASS_LEN - 1 );
498                 Conf_Oper[Conf_Oper_Count - 1].name[CLIENT_PASS_LEN - 1] = '\0';
499                 if( strlen( Arg ) > CLIENT_PASS_LEN - 1 ) Config_Error( LOG_WARNING, "%s, line %d: Value of \"Name\" too long!", NGIRCd_ConfFile, Line );
500                 return;
501         }
502         if( strcasecmp( Var, "Password" ) == 0 )
503         {
504                 /* Password of IRC operator */
505                 strncpy( Conf_Oper[Conf_Oper_Count - 1].pwd, Arg, CLIENT_PASS_LEN - 1 );
506                 Conf_Oper[Conf_Oper_Count - 1].pwd[CLIENT_PASS_LEN - 1] = '\0';
507                 if( strlen( Arg ) > CLIENT_PASS_LEN - 1 ) Config_Error( LOG_WARNING, "%s, line %d: Value of \"Password\" too long!", NGIRCd_ConfFile, Line );
508                 return;
509         }
510         
511         Config_Error( LOG_ERR, "%s, line %d (section \"Operator\"): Unknown variable \"%s\"!", NGIRCd_ConfFile, Line, Var );
512 } /* Handle_OPERATOR */
513
514
515 LOCAL VOID
516 Handle_SERVER( INT Line, CHAR *Var, CHAR *Arg )
517 {
518         LONG port;
519         
520         assert( Line > 0 );
521         assert( Var != NULL );
522         assert( Arg != NULL );
523
524         if( strcasecmp( Var, "Host" ) == 0 )
525         {
526                 /* Hostname of the server */
527                 strncpy( Conf_Server[Conf_Server_Count - 1].host, Arg, HOST_LEN - 1 );
528                 Conf_Server[Conf_Server_Count - 1].host[HOST_LEN - 1] = '\0';
529                 if( strlen( Arg ) > HOST_LEN - 1 ) Config_Error( LOG_WARNING, "%s, line %d: Value of \"Host\" too long!", NGIRCd_ConfFile, Line );
530                 return;
531         }
532         if( strcasecmp( Var, "Name" ) == 0 )
533         {
534                 /* Name of the server ("Nick"/"ID") */
535                 strncpy( Conf_Server[Conf_Server_Count - 1].name, Arg, CLIENT_ID_LEN - 1 );
536                 Conf_Server[Conf_Server_Count - 1].name[CLIENT_ID_LEN - 1] = '\0';
537                 if( strlen( Arg ) > CLIENT_ID_LEN - 1 ) Config_Error( LOG_WARNING, "%s, line %d: Value of \"Name\" too long!", NGIRCd_ConfFile, Line );
538                 return;
539         }
540         if( strcasecmp( Var, "MyPassword" ) == 0 )
541         {
542                 /* Password of this server which is sent to the peer */
543                 strncpy( Conf_Server[Conf_Server_Count - 1].pwd_in, Arg, CLIENT_PASS_LEN - 1 );
544                 Conf_Server[Conf_Server_Count - 1].pwd_in[CLIENT_PASS_LEN - 1] = '\0';
545                 if( strlen( Arg ) > CLIENT_PASS_LEN - 1 ) Config_Error( LOG_WARNING, "%s, line %d: Value of \"MyPassword\" too long!", NGIRCd_ConfFile, Line );
546                 return;
547         }
548         if( strcasecmp( Var, "PeerPassword" ) == 0 )
549         {
550                 /* Passwort of the peer which must be received */
551                 strncpy( Conf_Server[Conf_Server_Count - 1].pwd_out, Arg, CLIENT_PASS_LEN - 1 );
552                 Conf_Server[Conf_Server_Count - 1].pwd_out[CLIENT_PASS_LEN - 1] = '\0';
553                 if( strlen( Arg ) > CLIENT_PASS_LEN - 1 ) Config_Error( LOG_WARNING, "%s, line %d: Value of \"PeerPassword\" too long!", NGIRCd_ConfFile, Line );
554                 return;
555         }
556         if( strcasecmp( Var, "Port" ) == 0 )
557         {
558                 /* Port to which this server should connect */
559                 port = atol( Arg );
560                 if( port > 0 && port < 0xFFFF ) Conf_Server[Conf_Server_Count - 1].port = (INT)port;
561                 else Config_Error( LOG_ERR, "%s, line %d (section \"Server\"): Illegal port number %ld!", NGIRCd_ConfFile, Line, port );
562                 return;
563         }
564         if( strcasecmp( Var, "Group" ) == 0 )
565         {
566                 /* Server group */
567 #ifdef HAVE_ISDIGIT
568                 if( ! isdigit( *Arg )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"Group\" is not a number!", NGIRCd_ConfFile, Line );
569                 else
570 #endif
571                 Conf_Server[Conf_Server_Count - 1].group = atoi( Arg );
572                 return;
573         }
574         
575         Config_Error( LOG_ERR, "%s, line %d (section \"Server\"): Unknown variable \"%s\"!", NGIRCd_ConfFile, Line, Var );
576 } /* Handle_SERVER */
577
578
579 LOCAL VOID
580 Handle_CHANNEL( INT Line, CHAR *Var, CHAR *Arg )
581 {
582         assert( Line > 0 );
583         assert( Var != NULL );
584         assert( Arg != NULL );
585
586         if( strcasecmp( Var, "Name" ) == 0 )
587         {
588                 /* Name of the channel */
589                 strncpy( Conf_Channel[Conf_Channel_Count - 1].name, Arg, CHANNEL_NAME_LEN - 1 );
590                 Conf_Channel[Conf_Channel_Count - 1].name[CHANNEL_NAME_LEN - 1] = '\0';
591                 if( strlen( Arg ) > CHANNEL_NAME_LEN - 1 ) Config_Error( LOG_WARNING, "%s, line %d: Value of \"Name\" too long!", NGIRCd_ConfFile, Line );
592                 return;
593         }
594         if( strcasecmp( Var, "Modes" ) == 0 )
595         {
596                 /* Initial modes */
597                 strncpy( Conf_Channel[Conf_Channel_Count - 1].modes, Arg, CHANNEL_MODE_LEN - 1 );
598                 Conf_Channel[Conf_Channel_Count - 1].modes[CHANNEL_MODE_LEN - 1] = '\0';
599                 if( strlen( Arg ) > CHANNEL_MODE_LEN - 1 ) Config_Error( LOG_WARNING, "%s, line %d: Value of \"Modes\" too long!", NGIRCd_ConfFile, Line );
600                 return;
601         }
602         if( strcasecmp( Var, "Topic" ) == 0 )
603         {
604                 /* Initial topic */
605                 strncpy( Conf_Channel[Conf_Channel_Count - 1].topic, Arg, CHANNEL_TOPIC_LEN - 1 );
606                 Conf_Channel[Conf_Channel_Count - 1].topic[CHANNEL_TOPIC_LEN - 1] = '\0';
607                 if( strlen( Arg ) > CHANNEL_TOPIC_LEN - 1 ) Config_Error( LOG_WARNING, "%s, line %d: Value of \"Topic\" too long!", NGIRCd_ConfFile, Line );
608                 return;
609         }
610
611         Config_Error( LOG_ERR, "%s, line %d (section \"Channel\"): Unknown variable \"%s\"!", NGIRCd_ConfFile, Line, Var );
612 } /* Handle_CHANNEL */
613
614
615 LOCAL VOID
616 Validate_Config( VOID )
617 {
618         /* Validate configuration settings. */
619         
620         if( ! Conf_ServerName[0] )
621         {
622                 /* No server name configured! */
623                 Config_Error( LOG_ALERT, "No server name configured in \"%s\" ('ServerName')!", NGIRCd_ConfFile );
624                 Config_Error( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE );
625                 exit( 1 );
626         }
627
628 #ifdef STRICT_RFC
629         if( ! Conf_ServerAdminMail[0] )
630         {
631                 /* No administrative contact configured! */
632                 Config_Error( LOG_ALERT, "No administrator email address configured in \"%s\" ('AdminEMail')!", NGIRCd_ConfFile );
633                 Config_Error( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE );
634                 exit( 1 );
635         }
636 #endif
637
638         if( ! Conf_ServerAdmin1[0] && ! Conf_ServerAdmin2[0] && ! Conf_ServerAdminMail[0] )
639         {
640                 /* No administrative information configured! */
641                 Log( LOG_WARNING, "No administrative information configured but required by RFC!" );
642         }
643 } /* Validate_Config */
644
645
646 #ifdef PROTOTYPES
647 LOCAL VOID Config_Error( CONST INT Level, CONST CHAR *Format, ... )
648 #else
649 LOCAL VOID Config_Error( Level, Format, va_alist )
650 CONST INT Level;
651 CONST CHAR *Format;
652 va_dcl
653 #endif
654 {
655         /* Error! Write to console and/or logfile. */
656
657         CHAR msg[MAX_LOG_MSG_LEN];
658         va_list ap;
659
660         assert( Format != NULL );
661
662 #ifdef PROTOTYPES
663         va_start( ap, Format );
664 #else
665         va_start( ap );
666 #endif
667         vsnprintf( msg, MAX_LOG_MSG_LEN, Format, ap );
668         va_end( ap );
669         
670         /* During "normal operations" the log functions of the daemon should
671          * be used, but during testing of the configuration file, all messages
672          * should go directly to the console: */
673         if( Use_Log ) Log( Level, "%s", msg );
674         else puts( msg );
675 } /* Config_Error */
676
677
678 /* -eof- */