]> arthur.barton.de Git - ngircd-alex.git/blob - src/ngircd/conf.c
- new allocated connection structures will be initialized correctly now.
[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.44 2002/12/14 13:36:19 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         if( Conf_MaxJoins > 0 ) printf( "  MaxJoins = %d\n", Conf_MaxJoins );
121         else printf( "  MaxJoins = -1\n" );
122         puts( "" );
123
124         for( i = 0; i < Conf_Oper_Count; i++ )
125         {
126                 if( ! Conf_Oper[i].name[0] ) continue;
127                 
128                 /* Valid "Operator" section */
129                 puts( "[OPERATOR]" );
130                 printf( "  Name = %s\n", Conf_Oper[i].name );
131                 printf( "  Password = %s\n", Conf_Oper[i].pwd );
132                 puts( "" );
133         }
134
135         for( i = 0; i < Conf_Server_Count; i++ )
136         {
137                 if( ! Conf_Server[i].name[0] ) continue;
138                 
139                 /* Valid "Server" section */
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                 /* Valid "Channel" section */
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         /* Initialize configuration variables with default values. */
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 = -1;
197         Conf_MaxJoins = 10;
198 } /* Set_Defaults */
199
200
201 LOCAL VOID
202 Read_Config( VOID )
203 {
204         /* Read configuration file. */
205
206         CHAR section[LINE_LEN], str[LINE_LEN], *var, *arg, *ptr;
207         INT line;
208         FILE *fd;
209
210         fd = fopen( NGIRCd_ConfFile, "r" );
211         if( ! fd )
212         {
213                 /* No configuration file found! */
214                 Config_Error( LOG_ALERT, "Can't read configuration \"%s\": %s", NGIRCd_ConfFile, strerror( errno ));
215                 Config_Error( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE );
216                 exit( 1 );
217         }
218
219         Config_Error( LOG_INFO, "Reading configuration from \"%s\" ...", NGIRCd_ConfFile );
220
221         line = 0;
222         strcpy( section, "" );
223         while( TRUE )
224         {
225                 if( ! fgets( str, LINE_LEN, fd )) break;
226                 ngt_TrimStr( str );
227                 line++;
228
229                 /* Skip comments and empty lines */
230                 if( str[0] == ';' || str[0] == '#' || str[0] == '\0' ) continue;
231
232                 /* Is this the beginning of a new section? */
233                 if(( str[0] == '[' ) && ( str[strlen( str ) - 1] == ']' ))
234                 {
235                         strcpy( section, str );
236                         if( strcasecmp( section, "[GLOBAL]" ) == 0 ) continue;
237                         if( strcasecmp( section, "[OPERATOR]" ) == 0 )
238                         {
239                                 if( Conf_Oper_Count + 1 > MAX_OPERATORS ) Config_Error( LOG_ERR, "Too many operators configured." );
240                                 else
241                                 {
242                                         /* Initialize new operator structure */
243                                         strcpy( Conf_Oper[Conf_Oper_Count].name, "" );
244                                         strcpy( Conf_Oper[Conf_Oper_Count].pwd, "" );
245                                         Conf_Oper_Count++;
246                                 }
247                                 continue;
248                         }
249                         if( strcasecmp( section, "[SERVER]" ) == 0 )
250                         {
251                                 if( Conf_Server_Count + 1 > MAX_SERVERS ) Config_Error( LOG_ERR, "Too many servers configured." );
252                                 else
253                                 {
254                                         /* Initialize new server structure */
255                                         strcpy( Conf_Server[Conf_Server_Count].host, "" );
256                                         strcpy( Conf_Server[Conf_Server_Count].ip, "" );
257                                         strcpy( Conf_Server[Conf_Server_Count].name, "" );
258                                         strcpy( Conf_Server[Conf_Server_Count].pwd_in, "" );
259                                         strcpy( Conf_Server[Conf_Server_Count].pwd_out, "" );
260                                         Conf_Server[Conf_Server_Count].port = 0;
261                                         Conf_Server[Conf_Server_Count].group = -1;
262                                         Conf_Server[Conf_Server_Count].lasttry = time( NULL ) - Conf_ConnectRetry + STARTUP_DELAY;
263                                         Conf_Server[Conf_Server_Count].res_stat = NULL;
264                                         Conf_Server_Count++;
265                                 }
266                                 continue;
267                         }
268                         if( strcasecmp( section, "[CHANNEL]" ) == 0 )
269                         {
270                                 if( Conf_Channel_Count + 1 > MAX_DEFCHANNELS ) Config_Error( LOG_ERR, "Too many pre-defined channels configured." );
271                                 else
272                                 {
273                                         /* Initialize new channel structure */
274                                         strcpy( Conf_Channel[Conf_Channel_Count].name, "" );
275                                         strcpy( Conf_Channel[Conf_Channel_Count].modes, "" );
276                                         strcpy( Conf_Channel[Conf_Channel_Count].topic, "" );
277                                         Conf_Channel_Count++;
278                                 }
279                                 continue;
280                         }
281                         Config_Error( LOG_ERR, "%s, line %d: Unknown section \"%s\"!", NGIRCd_ConfFile, line, section );
282                         section[0] = 0x1;
283                 }
284                 if( section[0] == 0x1 ) continue;
285
286                 /* Split line into variable name and parameters */
287                 ptr = strchr( str, '=' );
288                 if( ! ptr )
289                 {
290                         Config_Error( LOG_ERR, "%s, line %d: Syntax error!", NGIRCd_ConfFile, line );
291                         continue;
292                 }
293                 *ptr = '\0';
294                 var = str; ngt_TrimStr( var );
295                 arg = ptr + 1; ngt_TrimStr( arg );
296
297                 if( strcasecmp( section, "[GLOBAL]" ) == 0 ) Handle_GLOBAL( line, var, arg );
298                 else if( strcasecmp( section, "[OPERATOR]" ) == 0 ) Handle_OPERATOR( line, var, arg );
299                 else if( strcasecmp( section, "[SERVER]" ) == 0 ) Handle_SERVER( line, var, arg );
300                 else if( strcasecmp( section, "[CHANNEL]" ) == 0 ) Handle_CHANNEL( line, var, arg );
301                 else Config_Error( LOG_ERR, "%s, line %d: Variable \"%s\" outside section!", NGIRCd_ConfFile, line, var );
302         }
303         
304         fclose( fd );
305         
306         /* If there are no ports configured use the default: 6667 */
307         if( Conf_ListenPorts_Count < 1 )
308         {
309                 Conf_ListenPorts_Count = 1;
310                 Conf_ListenPorts[0] = 6667;
311         }
312 } /* Read_Config */
313
314
315 LOCAL VOID
316 Handle_GLOBAL( INT Line, CHAR *Var, CHAR *Arg )
317 {
318         struct passwd *pwd;
319         struct group *grp;
320         CHAR *ptr;
321         LONG port;
322         
323         assert( Line > 0 );
324         assert( Var != NULL );
325         assert( Arg != NULL );
326         
327         if( strcasecmp( Var, "Name" ) == 0 )
328         {
329                 /* Server name */
330                 strncpy( Conf_ServerName, Arg, CLIENT_ID_LEN - 1 );
331                 Conf_ServerName[CLIENT_ID_LEN - 1] = '\0';
332                 if( strlen( Arg ) > CLIENT_ID_LEN - 1 ) Config_Error( LOG_WARNING, "%s, line %d: Value of \"Name\" too long!", NGIRCd_ConfFile, Line );
333                 return;
334         }
335         if( strcasecmp( Var, "Info" ) == 0 )
336         {
337                 /* Info text of server */
338                 strncpy( Conf_ServerInfo, Arg, CLIENT_INFO_LEN - 1 );
339                 Conf_ServerInfo[CLIENT_INFO_LEN - 1] = '\0';
340                 if( strlen( Arg ) > CLIENT_INFO_LEN - 1 ) Config_Error( LOG_WARNING, "%s, line %d: Value of \"Info\" too long!", NGIRCd_ConfFile, Line );
341                 return;
342         }
343         if( strcasecmp( Var, "Password" ) == 0 )
344         {
345                 /* Global server password */
346                 strncpy( Conf_ServerPwd, Arg, CLIENT_PASS_LEN - 1 );
347                 Conf_ServerPwd[CLIENT_PASS_LEN - 1] = '\0';
348                 if( strlen( Arg ) > CLIENT_PASS_LEN - 1 ) Config_Error( LOG_WARNING, "%s, line %d: Value of \"Password\" too long!", NGIRCd_ConfFile, Line );
349                 return;
350         }
351         if( strcasecmp( Var, "AdminInfo1" ) == 0 )
352         {
353                 /* Administrative info #1 */
354                 strncpy( Conf_ServerAdmin1, Arg, CLIENT_INFO_LEN - 1 );
355                 Conf_ServerAdmin1[CLIENT_INFO_LEN - 1] = '\0';
356                 if( strlen( Arg ) > CLIENT_INFO_LEN - 1 ) Config_Error( LOG_WARNING, "%s, line %d: Value of \"AdminInfo1\" too long!", NGIRCd_ConfFile, Line );
357                 return;
358         }
359         if( strcasecmp( Var, "AdminInfo2" ) == 0 )
360         {
361                 /* Administrative info #2 */
362                 strncpy( Conf_ServerAdmin2, Arg, CLIENT_INFO_LEN - 1 );
363                 Conf_ServerAdmin2[CLIENT_INFO_LEN - 1] = '\0';
364                 if( strlen( Arg ) > CLIENT_INFO_LEN - 1 ) Config_Error( LOG_WARNING, "%s, line %d: Value of \"AdminInfo2\" too long!", NGIRCd_ConfFile, Line );
365                 return;
366         }
367         if( strcasecmp( Var, "AdminEMail" ) == 0 )
368         {
369                 /* Administrative email contact */
370                 strncpy( Conf_ServerAdminMail, Arg, CLIENT_INFO_LEN - 1 );
371                 Conf_ServerAdminMail[CLIENT_INFO_LEN - 1] = '\0';
372                 if( strlen( Arg ) > CLIENT_INFO_LEN - 1 ) Config_Error( LOG_WARNING, "%s, line %d: Value of \"AdminEMail\" too long!", NGIRCd_ConfFile, Line );
373                 return;
374         }
375         if( strcasecmp( Var, "Ports" ) == 0 )
376         {
377                 /* Ports on that the server should listen. More port numbers
378                  * must be separated by "," */
379                 ptr = strtok( Arg, "," );
380                 while( ptr )
381                 {
382                         ngt_TrimStr( ptr );
383                         port = atol( ptr );
384                         if( Conf_ListenPorts_Count + 1 > MAX_LISTEN_PORTS ) Config_Error( LOG_ERR, "Too many listen ports configured. Port %ld ignored.", port );
385                         else
386                         {
387                                 if( port > 0 && port < 0xFFFF ) Conf_ListenPorts[Conf_ListenPorts_Count++] = (UINT)port;
388                                 else Config_Error( LOG_ERR, "%s, line %d (section \"Global\"): Illegal port number %ld!", NGIRCd_ConfFile, Line, port );
389                         }
390                         ptr = strtok( NULL, "," );
391                 }
392                 return;
393         }
394         if( strcasecmp( Var, "MotdFile" ) == 0 )
395         {
396                 /* "Message of the day" (MOTD) file */
397                 strncpy( Conf_MotdFile, Arg, FNAME_LEN - 1 );
398                 Conf_MotdFile[FNAME_LEN - 1] = '\0';
399                 if( strlen( Arg ) > FNAME_LEN - 1 ) Config_Error( LOG_WARNING, "%s, line %d: Value of \"MotdFile\" too long!", NGIRCd_ConfFile, Line );
400                 return;
401         }
402         if( strcasecmp( Var, "ServerUID" ) == 0 )
403         {
404                 /* UID the daemon should switch to */
405                 pwd = getpwnam( Arg );
406                 if( pwd ) Conf_UID = pwd->pw_uid;
407                 else
408                 {
409 #ifdef HAVE_ISDIGIT
410                         if( ! isdigit( *Arg )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"ServerUID\" is not a number!", NGIRCd_ConfFile, Line );
411                         else
412 #endif
413                         Conf_UID = (UINT)atoi( Arg );
414                 }
415                 return;
416         }
417         if( strcasecmp( Var, "ServerGID" ) == 0 )
418         {
419                 /* GID the daemon should use */
420                 grp = getgrnam( Arg );
421                 if( grp ) Conf_GID = grp->gr_gid;
422                 else
423                 {
424 #ifdef HAVE_ISDIGIT
425                         if( ! isdigit( *Arg )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"ServerGID\" is not a number!", NGIRCd_ConfFile, Line );
426                         else
427 #endif
428                         Conf_GID = (UINT)atoi( Arg );
429                 }
430                 return;
431         }
432         if( strcasecmp( Var, "PingTimeout" ) == 0 )
433         {
434                 /* PING timeout */
435                 Conf_PingTimeout = atoi( Arg );
436                 if( Conf_PingTimeout < 5 )
437                 {
438                         Config_Error( LOG_WARNING, "%s, line %d: Value of \"PingTimeout\" too low!", NGIRCd_ConfFile, Line );
439                         Conf_PingTimeout = 5;
440                 }
441                 return;
442         }
443         if( strcasecmp( Var, "PongTimeout" ) == 0 )
444         {
445                 /* PONG timeout */
446                 Conf_PongTimeout = atoi( Arg );
447                 if( Conf_PongTimeout < 5 )
448                 {
449                         Config_Error( LOG_WARNING, "%s, line %d: Value of \"PongTimeout\" too low!", NGIRCd_ConfFile, Line );
450                         Conf_PongTimeout = 5;
451                 }
452                 return;
453         }
454         if( strcasecmp( Var, "ConnectRetry" ) == 0 )
455         {
456                 /* Seconds between connection attempts to other servers */
457                 Conf_ConnectRetry = atoi( Arg );
458                 if( Conf_ConnectRetry < 5 )
459                 {
460                         Config_Error( LOG_WARNING, "%s, line %d: Value of \"ConnectRetry\" too low!", NGIRCd_ConfFile, Line );
461                         Conf_ConnectRetry = 5;
462                 }
463                 return;
464         }
465         if( strcasecmp( Var, "OperCanUseMode" ) == 0 )
466         {
467                 /* Are IRC operators allowed to use MODE in channels they aren't Op in? */
468                 if( strcasecmp( Arg, "yes" ) == 0 ) Conf_OperCanMode = TRUE;
469                 else if( strcasecmp( Arg, "true" ) == 0 ) Conf_OperCanMode = TRUE;
470                 else if( atoi( Arg ) != 0 ) Conf_OperCanMode = TRUE;
471                 else Conf_OperCanMode = FALSE;
472                 return;
473         }
474         if( strcasecmp( Var, "MaxConnections" ) == 0 )
475         {
476                 /* Maximum number of connections. Values <= 0 are equal to "no 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         if( strcasecmp( Var, "MaxJoins" ) == 0 )
485         {
486                 /* Maximum number of channels a user can join. Values <= 0 are equal to "no limit". */
487 #ifdef HAVE_ISDIGIT
488                 if( ! isdigit( *Arg )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"MaxJoins\" is not a number!", NGIRCd_ConfFile, Line );
489                 else
490 #endif
491                 Conf_MaxJoins = atoi( Arg );
492                 return;
493         }
494
495         Config_Error( LOG_ERR, "%s, line %d (section \"Global\"): Unknown variable \"%s\"!", NGIRCd_ConfFile, Line, Var );
496 } /* Handle_GLOBAL */
497
498
499 LOCAL VOID
500 Handle_OPERATOR( INT Line, CHAR *Var, CHAR *Arg )
501 {
502         assert( Line > 0 );
503         assert( Var != NULL );
504         assert( Arg != NULL );
505         assert( Conf_Oper_Count > 0 );
506
507         if( strcasecmp( Var, "Name" ) == 0 )
508         {
509                 /* Name of IRC operator */
510                 strncpy( Conf_Oper[Conf_Oper_Count - 1].name, Arg, CLIENT_PASS_LEN - 1 );
511                 Conf_Oper[Conf_Oper_Count - 1].name[CLIENT_PASS_LEN - 1] = '\0';
512                 if( strlen( Arg ) > CLIENT_PASS_LEN - 1 ) Config_Error( LOG_WARNING, "%s, line %d: Value of \"Name\" too long!", NGIRCd_ConfFile, Line );
513                 return;
514         }
515         if( strcasecmp( Var, "Password" ) == 0 )
516         {
517                 /* Password of IRC operator */
518                 strncpy( Conf_Oper[Conf_Oper_Count - 1].pwd, Arg, CLIENT_PASS_LEN - 1 );
519                 Conf_Oper[Conf_Oper_Count - 1].pwd[CLIENT_PASS_LEN - 1] = '\0';
520                 if( strlen( Arg ) > CLIENT_PASS_LEN - 1 ) Config_Error( LOG_WARNING, "%s, line %d: Value of \"Password\" too long!", NGIRCd_ConfFile, Line );
521                 return;
522         }
523         
524         Config_Error( LOG_ERR, "%s, line %d (section \"Operator\"): Unknown variable \"%s\"!", NGIRCd_ConfFile, Line, Var );
525 } /* Handle_OPERATOR */
526
527
528 LOCAL VOID
529 Handle_SERVER( INT Line, CHAR *Var, CHAR *Arg )
530 {
531         LONG port;
532         
533         assert( Line > 0 );
534         assert( Var != NULL );
535         assert( Arg != NULL );
536
537         if( strcasecmp( Var, "Host" ) == 0 )
538         {
539                 /* Hostname of the server */
540                 strncpy( Conf_Server[Conf_Server_Count - 1].host, Arg, HOST_LEN - 1 );
541                 Conf_Server[Conf_Server_Count - 1].host[HOST_LEN - 1] = '\0';
542                 if( strlen( Arg ) > HOST_LEN - 1 ) Config_Error( LOG_WARNING, "%s, line %d: Value of \"Host\" too long!", NGIRCd_ConfFile, Line );
543                 return;
544         }
545         if( strcasecmp( Var, "Name" ) == 0 )
546         {
547                 /* Name of the server ("Nick"/"ID") */
548                 strncpy( Conf_Server[Conf_Server_Count - 1].name, Arg, CLIENT_ID_LEN - 1 );
549                 Conf_Server[Conf_Server_Count - 1].name[CLIENT_ID_LEN - 1] = '\0';
550                 if( strlen( Arg ) > CLIENT_ID_LEN - 1 ) Config_Error( LOG_WARNING, "%s, line %d: Value of \"Name\" too long!", NGIRCd_ConfFile, Line );
551                 return;
552         }
553         if( strcasecmp( Var, "MyPassword" ) == 0 )
554         {
555                 /* Password of this server which is sent to the peer */
556                 strncpy( Conf_Server[Conf_Server_Count - 1].pwd_in, Arg, CLIENT_PASS_LEN - 1 );
557                 Conf_Server[Conf_Server_Count - 1].pwd_in[CLIENT_PASS_LEN - 1] = '\0';
558                 if( strlen( Arg ) > CLIENT_PASS_LEN - 1 ) Config_Error( LOG_WARNING, "%s, line %d: Value of \"MyPassword\" too long!", NGIRCd_ConfFile, Line );
559                 return;
560         }
561         if( strcasecmp( Var, "PeerPassword" ) == 0 )
562         {
563                 /* Passwort of the peer which must be received */
564                 strncpy( Conf_Server[Conf_Server_Count - 1].pwd_out, Arg, CLIENT_PASS_LEN - 1 );
565                 Conf_Server[Conf_Server_Count - 1].pwd_out[CLIENT_PASS_LEN - 1] = '\0';
566                 if( strlen( Arg ) > CLIENT_PASS_LEN - 1 ) Config_Error( LOG_WARNING, "%s, line %d: Value of \"PeerPassword\" too long!", NGIRCd_ConfFile, Line );
567                 return;
568         }
569         if( strcasecmp( Var, "Port" ) == 0 )
570         {
571                 /* Port to which this server should connect */
572                 port = atol( Arg );
573                 if( port > 0 && port < 0xFFFF ) Conf_Server[Conf_Server_Count - 1].port = (INT)port;
574                 else Config_Error( LOG_ERR, "%s, line %d (section \"Server\"): Illegal port number %ld!", NGIRCd_ConfFile, Line, port );
575                 return;
576         }
577         if( strcasecmp( Var, "Group" ) == 0 )
578         {
579                 /* Server group */
580 #ifdef HAVE_ISDIGIT
581                 if( ! isdigit( *Arg )) Config_Error( LOG_WARNING, "%s, line %d: Value of \"Group\" is not a number!", NGIRCd_ConfFile, Line );
582                 else
583 #endif
584                 Conf_Server[Conf_Server_Count - 1].group = atoi( Arg );
585                 return;
586         }
587         
588         Config_Error( LOG_ERR, "%s, line %d (section \"Server\"): Unknown variable \"%s\"!", NGIRCd_ConfFile, Line, Var );
589 } /* Handle_SERVER */
590
591
592 LOCAL VOID
593 Handle_CHANNEL( INT Line, CHAR *Var, CHAR *Arg )
594 {
595         assert( Line > 0 );
596         assert( Var != NULL );
597         assert( Arg != NULL );
598
599         if( strcasecmp( Var, "Name" ) == 0 )
600         {
601                 /* Name of the channel */
602                 strncpy( Conf_Channel[Conf_Channel_Count - 1].name, Arg, CHANNEL_NAME_LEN - 1 );
603                 Conf_Channel[Conf_Channel_Count - 1].name[CHANNEL_NAME_LEN - 1] = '\0';
604                 if( strlen( Arg ) > CHANNEL_NAME_LEN - 1 ) Config_Error( LOG_WARNING, "%s, line %d: Value of \"Name\" too long!", NGIRCd_ConfFile, Line );
605                 return;
606         }
607         if( strcasecmp( Var, "Modes" ) == 0 )
608         {
609                 /* Initial modes */
610                 strncpy( Conf_Channel[Conf_Channel_Count - 1].modes, Arg, CHANNEL_MODE_LEN - 1 );
611                 Conf_Channel[Conf_Channel_Count - 1].modes[CHANNEL_MODE_LEN - 1] = '\0';
612                 if( strlen( Arg ) > CHANNEL_MODE_LEN - 1 ) Config_Error( LOG_WARNING, "%s, line %d: Value of \"Modes\" too long!", NGIRCd_ConfFile, Line );
613                 return;
614         }
615         if( strcasecmp( Var, "Topic" ) == 0 )
616         {
617                 /* Initial topic */
618                 strncpy( Conf_Channel[Conf_Channel_Count - 1].topic, Arg, CHANNEL_TOPIC_LEN - 1 );
619                 Conf_Channel[Conf_Channel_Count - 1].topic[CHANNEL_TOPIC_LEN - 1] = '\0';
620                 if( strlen( Arg ) > CHANNEL_TOPIC_LEN - 1 ) Config_Error( LOG_WARNING, "%s, line %d: Value of \"Topic\" too long!", NGIRCd_ConfFile, Line );
621                 return;
622         }
623
624         Config_Error( LOG_ERR, "%s, line %d (section \"Channel\"): Unknown variable \"%s\"!", NGIRCd_ConfFile, Line, Var );
625 } /* Handle_CHANNEL */
626
627
628 LOCAL VOID
629 Validate_Config( VOID )
630 {
631         /* Validate configuration settings. */
632         
633         if( ! Conf_ServerName[0] )
634         {
635                 /* No server name configured! */
636                 Config_Error( LOG_ALERT, "No server name configured in \"%s\" ('ServerName')!", NGIRCd_ConfFile );
637                 Config_Error( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE );
638                 exit( 1 );
639         }
640
641 #ifdef STRICT_RFC
642         if( ! Conf_ServerAdminMail[0] )
643         {
644                 /* No administrative contact configured! */
645                 Config_Error( LOG_ALERT, "No administrator email address configured in \"%s\" ('AdminEMail')!", NGIRCd_ConfFile );
646                 Config_Error( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE );
647                 exit( 1 );
648         }
649 #endif
650
651         if( ! Conf_ServerAdmin1[0] && ! Conf_ServerAdmin2[0] && ! Conf_ServerAdminMail[0] )
652         {
653                 /* No administrative information configured! */
654                 Log( LOG_WARNING, "No administrative information configured but required by RFC!" );
655         }
656 } /* Validate_Config */
657
658
659 #ifdef PROTOTYPES
660 LOCAL VOID Config_Error( CONST INT Level, CONST CHAR *Format, ... )
661 #else
662 LOCAL VOID Config_Error( Level, Format, va_alist )
663 CONST INT Level;
664 CONST CHAR *Format;
665 va_dcl
666 #endif
667 {
668         /* Error! Write to console and/or logfile. */
669
670         CHAR msg[MAX_LOG_MSG_LEN];
671         va_list ap;
672
673         assert( Format != NULL );
674
675 #ifdef PROTOTYPES
676         va_start( ap, Format );
677 #else
678         va_start( ap );
679 #endif
680         vsnprintf( msg, MAX_LOG_MSG_LEN, Format, ap );
681         va_end( ap );
682         
683         /* During "normal operations" the log functions of the daemon should
684          * be used, but during testing of the configuration file, all messages
685          * should go directly to the console: */
686         if( Use_Log ) Log( Level, "%s", msg );
687         else puts( msg );
688 } /* Config_Error */
689
690
691 /* -eof- */