]> arthur.barton.de Git - ngircd-alex.git/blob - src/ngircd/conf.c
c5a621fee65d9a7f8f484c592f45ab58a4599f78
[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.105 2008/03/18 20:12:47 fw Exp $";
18
19 #include "imp.h"
20 #include <assert.h>
21 #include <errno.h>
22 #ifdef PROTOTYPES
23 #       include <stdarg.h>
24 #else
25 #       include <varargs.h>
26 #endif
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <string.h>
30 #include <strings.h>
31 #include <unistd.h>
32 #include <pwd.h>
33 #include <grp.h>
34 #include <sys/types.h>
35 #include <unistd.h>
36
37 #ifdef HAVE_CTYPE_H
38 # include <ctype.h>
39 #endif
40
41 #include "array.h"
42 #include "ngircd.h"
43 #include "conn.h"
44 #include "client.h"
45 #include "defines.h"
46 #include "log.h"
47 #include "resolve.h"
48 #include "tool.h"
49
50 #include "exp.h"
51 #include "conf.h"
52
53
54 static bool Use_Log = true;
55 static CONF_SERVER New_Server;
56 static int New_Server_Idx;
57
58
59 static void Set_Defaults PARAMS(( bool InitServers ));
60 static bool Read_Config PARAMS(( bool ngircd_starting ));
61 static void Validate_Config PARAMS(( bool TestOnly, bool Rehash ));
62
63 static void Handle_GLOBAL PARAMS(( int Line, char *Var, char *Arg ));
64 static void Handle_OPERATOR PARAMS(( int Line, char *Var, char *Arg ));
65 static void Handle_SERVER PARAMS(( int Line, char *Var, char *Arg ));
66 static void Handle_CHANNEL PARAMS(( int Line, char *Var, char *Arg ));
67
68 static void Config_Error PARAMS(( const int Level, const char *Format, ... ));
69
70 static void Config_Error_NaN PARAMS(( const int LINE, const char *Value ));
71 static void Config_Error_TooLong PARAMS(( const int LINE, const char *Value ));
72
73 static void Init_Server_Struct PARAMS(( CONF_SERVER *Server ));
74
75
76 static char *
77 strdup_warn(const char *str)
78 {
79         char *ptr = strdup(str);
80         if (!ptr)
81                 Config_Error(LOG_ERR, "Could not allocate mem for string: %s", str);
82         return ptr;
83 }
84
85
86 static void
87 ports_puts(array *a)
88 {
89         size_t len;
90         UINT16 *ports;
91         len = array_length(a, sizeof(UINT16));
92         if (len--) {
93                 ports = (UINT16*) array_start(a);
94                 printf("%u", (unsigned int) *ports);
95                 while (len--) {
96                         ports++;
97                         printf(", %u", (unsigned int) *ports);
98                 }
99         }
100         putc('\n', stdout);
101 }
102
103
104 static void
105 ports_parse(array *a, int Line, char *Arg)
106 {
107         char *ptr;
108         int port;
109         UINT16 port16;
110
111         array_trunc(a);
112
113         /* Ports on that the server should listen. More port numbers
114          * must be separated by "," */
115         ptr = strtok( Arg, "," );
116         while (ptr) {
117                 ngt_TrimStr( ptr );
118                 port = atol( ptr );
119                 if (port > 0 && port < 0xFFFF) {
120                         port16 = (UINT16) port;
121                         if (!array_catb(a, (char*)&port16, sizeof port16))
122                                 Config_Error(LOG_ERR, "%s, line %d Could not add port number %ld: %s",
123                                                         NGIRCd_ConfFile, Line, port, strerror(errno));
124                 } else {
125                         Config_Error( LOG_ERR, "%s, line %d (section \"Global\"): Illegal port number %ld!",
126                                                                         NGIRCd_ConfFile, Line, port );
127                 }
128
129                 ptr = strtok( NULL, "," );
130         }
131 }
132
133
134 GLOBAL void
135 Conf_Init( void )
136 {
137         Read_Config( true );
138         Validate_Config(false, false);
139 } /* Config_Init */
140
141
142 GLOBAL bool
143 Conf_Rehash( void )
144 {
145         if (!Read_Config(false))
146                 return false;
147         Validate_Config(false, true);
148
149         /* Update CLIENT structure of local server */
150         Client_SetInfo(Client_ThisServer(), Conf_ServerInfo);
151         return true;
152 } /* Config_Rehash */
153
154
155 static const char*
156 yesno_to_str(int boolean_value)
157 {
158         if (boolean_value)
159                 return "yes";
160         return "no";
161 }
162
163
164 GLOBAL int
165 Conf_Test( void )
166 {
167         /* Read configuration, validate and output it. */
168
169         struct passwd *pwd;
170         struct group *grp;
171         unsigned int i;
172         char *topic;
173
174         Use_Log = false;
175
176         Read_Config( true );
177         Validate_Config(true, false);
178
179         /* If stdin and stdout ("you can read our nice message and we can
180          * read in your keypress") are valid tty's, wait for a key: */
181         if( isatty( fileno( stdin )) && isatty( fileno( stdout ))) {
182                 puts( "OK, press enter to see a dump of your service configuration ..." );
183                 getchar( );
184         } else {
185                 puts( "Ok, dump of your server configuration follows:\n" );
186         }
187
188         puts( "[GLOBAL]" );
189         printf( "  Name = %s\n", Conf_ServerName );
190         printf( "  Info = %s\n", Conf_ServerInfo );
191         printf( "  Password = %s\n", Conf_ServerPwd );
192         printf( "  AdminInfo1 = %s\n", Conf_ServerAdmin1 );
193         printf( "  AdminInfo2 = %s\n", Conf_ServerAdmin2 );
194         printf( "  AdminEMail = %s\n", Conf_ServerAdminMail );
195         printf( "  MotdFile = %s\n", Conf_MotdFile );
196         printf( "  MotdPhrase = %s\n", Conf_MotdPhrase );
197         printf( "  ChrootDir = %s\n", Conf_Chroot );
198         printf( "  PidFile = %s\n", Conf_PidFile);
199         fputs("  Ports = ", stdout);
200
201         ports_puts(&Conf_ListenPorts);
202
203         printf( "  Listen = %s\n", Conf_ListenAddress );
204         pwd = getpwuid( Conf_UID );
205         if( pwd ) printf( "  ServerUID = %s\n", pwd->pw_name );
206         else printf( "  ServerUID = %ld\n", (long)Conf_UID );
207         grp = getgrgid( Conf_GID );
208         if( grp ) printf( "  ServerGID = %s\n", grp->gr_name );
209         else printf( "  ServerGID = %ld\n", (long)Conf_GID );
210         printf( "  PingTimeout = %d\n", Conf_PingTimeout );
211         printf( "  PongTimeout = %d\n", Conf_PongTimeout );
212         printf( "  ConnectRetry = %d\n", Conf_ConnectRetry );
213         printf( "  OperCanUseMode = %s\n", yesno_to_str(Conf_OperCanMode));
214         printf( "  OperServerMode = %s\n", yesno_to_str(Conf_OperServerMode));
215         printf( "  PredefChannelsOnly = %s\n", yesno_to_str(Conf_PredefChannelsOnly));
216         printf( "  NoDNS = %s\n", yesno_to_str(Conf_NoDNS));
217
218 #ifdef WANT_IPV6
219         printf("  ListenIPv6 = %s\n", yesno_to_str(Conf_ListenIPv6));
220         printf("  ListenIPv4 = %s\n", yesno_to_str(Conf_ListenIPv4));
221         printf("  ConnectIPv4 = %s\n", yesno_to_str(Conf_ConnectIPv6));
222         printf("  ConnectIPv6 = %s\n", yesno_to_str(Conf_ConnectIPv4));
223 #endif
224         printf( "  MaxConnections = %ld\n", Conf_MaxConnections);
225         printf( "  MaxConnectionsIP = %d\n", Conf_MaxConnectionsIP);
226         printf( "  MaxJoins = %d\n", Conf_MaxJoins>0 ? Conf_MaxJoins : -1);
227         printf( "  MaxNickLength = %u\n\n", Conf_MaxNickLength - 1);
228
229         for( i = 0; i < Conf_Oper_Count; i++ ) {
230                 if( ! Conf_Oper[i].name[0] ) continue;
231
232                 /* Valid "Operator" section */
233                 puts( "[OPERATOR]" );
234                 printf( "  Name = %s\n", Conf_Oper[i].name );
235                 printf( "  Password = %s\n", Conf_Oper[i].pwd );
236                 if ( Conf_Oper[i].mask ) printf( "  Mask = %s\n", Conf_Oper[i].mask );
237                 puts( "" );
238         }
239
240         for( i = 0; i < MAX_SERVERS; i++ ) {
241                 if( ! Conf_Server[i].name[0] ) continue;
242
243                 /* Valid "Server" section */
244                 puts( "[SERVER]" );
245                 printf( "  Name = %s\n", Conf_Server[i].name );
246                 printf( "  Host = %s\n", Conf_Server[i].host );
247                 printf( "  Port = %u\n", (unsigned int)Conf_Server[i].port );
248                 printf( "  MyPassword = %s\n", Conf_Server[i].pwd_in );
249                 printf( "  PeerPassword = %s\n", Conf_Server[i].pwd_out );
250                 printf( "  Group = %d\n", Conf_Server[i].group );
251                 printf( "  Passive = %s\n\n", Conf_Server[i].flags & CONF_SFLAG_DISABLED ? "yes" : "no");
252         }
253
254         for( i = 0; i < Conf_Channel_Count; i++ ) {
255                 if( ! Conf_Channel[i].name[0] ) continue;
256
257                 /* Valid "Channel" section */
258                 puts( "[CHANNEL]" );
259                 printf( "  Name = %s\n", Conf_Channel[i].name );
260                 printf( "  Modes = %s\n", Conf_Channel[i].modes );
261                 printf( "  Key = %s\n", Conf_Channel[i].key );
262                 printf( "  MaxUsers = %lu\n", Conf_Channel[i].maxusers );
263
264                 topic = (char*)array_start(&Conf_Channel[i].topic);
265                 printf( "  Topic = %s\n\n", topic ? topic : "");
266         }
267
268         return 0;
269 } /* Conf_Test */
270
271
272 GLOBAL void
273 Conf_UnsetServer( CONN_ID Idx )
274 {
275         /* Set next time for next connection attempt, if this is a server
276          * link that is (still) configured here. If the server is set as
277          * "once", delete it from our configuration.
278          * Non-Server-Connections will be silently ignored. */
279
280         int i;
281         time_t t;
282
283         /* Check all our configured servers */
284         for( i = 0; i < MAX_SERVERS; i++ ) {
285                 if( Conf_Server[i].conn_id != Idx ) continue;
286
287                 /* Gotcha! Mark server configuration as "unused": */
288                 Conf_Server[i].conn_id = NONE;
289
290                 if( Conf_Server[i].flags & CONF_SFLAG_ONCE ) {
291                         /* Delete configuration here */
292                         Init_Server_Struct( &Conf_Server[i] );
293                 } else {
294                         /* Set time for next connect attempt */
295                         t = time(NULL);
296                         if (Conf_Server[i].lasttry < t - Conf_ConnectRetry) {
297                                 /* The connection has been "long", so we don't
298                                  * require the next attempt to be delayed. */
299                                 Conf_Server[i].lasttry =
300                                         t - Conf_ConnectRetry + RECONNECT_DELAY;
301                         } else
302                                 Conf_Server[i].lasttry = t;
303                 }
304         }
305 } /* Conf_UnsetServer */
306
307
308 GLOBAL void
309 Conf_SetServer( int ConfServer, CONN_ID Idx )
310 {
311         /* Set connection for specified configured server */
312
313         assert( ConfServer > NONE );
314         assert( Idx > NONE );
315
316         Conf_Server[ConfServer].conn_id = Idx;
317 } /* Conf_SetServer */
318
319
320 GLOBAL int
321 Conf_GetServer( CONN_ID Idx )
322 {
323         /* Get index of server in configuration structure */
324
325         int i = 0;
326
327         assert( Idx > NONE );
328
329         for( i = 0; i < MAX_SERVERS; i++ ) {
330                 if( Conf_Server[i].conn_id == Idx ) return i;
331         }
332         return NONE;
333 } /* Conf_GetServer */
334
335
336 GLOBAL bool
337 Conf_EnableServer( char *Name, UINT16 Port )
338 {
339         /* Enable specified server and adjust port */
340
341         int i;
342
343         assert( Name != NULL );
344
345         for( i = 0; i < MAX_SERVERS; i++ ) {
346                 if( strcasecmp( Conf_Server[i].name, Name ) == 0 ) {
347                         /* Gotcha! Set port and enable server: */
348                         Conf_Server[i].port = Port;
349                         Conf_Server[i].flags &= ~CONF_SFLAG_DISABLED;
350                         return true;
351                 }
352         }
353         return false;
354 } /* Conf_EnableServer */
355
356
357 GLOBAL bool
358 Conf_EnablePassiveServer(const char *Name)
359 {
360         /* Enable specified server */
361         int i;
362
363         assert( Name != NULL );
364         for (i = 0; i < MAX_SERVERS; i++) {
365                 if ((strcasecmp( Conf_Server[i].name, Name ) == 0) && (Conf_Server[i].port > 0)) {
366                         /* BINGO! Enable server */
367                         Conf_Server[i].flags &= ~CONF_SFLAG_DISABLED;
368                         return true;
369                 }
370         }
371         return false;
372 } /* Conf_EnablePassiveServer */
373
374
375 GLOBAL bool
376 Conf_DisableServer( char *Name )
377 {
378         /* Enable specified server and adjust port */
379
380         int i;
381
382         assert( Name != NULL );
383
384         for( i = 0; i < MAX_SERVERS; i++ ) {
385                 if( strcasecmp( Conf_Server[i].name, Name ) == 0 ) {
386                         /* Gotcha! Disable and disconnect server: */
387                         Conf_Server[i].flags |= CONF_SFLAG_DISABLED;
388                         if( Conf_Server[i].conn_id > NONE ) Conn_Close( Conf_Server[i].conn_id, NULL, "Server link terminated on operator request", true);
389                         return true;
390                 }
391         }
392         return false;
393 } /* Conf_DisableServer */
394
395
396 GLOBAL bool
397 Conf_AddServer( char *Name, UINT16 Port, char *Host, char *MyPwd, char *PeerPwd )
398 {
399         /* Add new server to configuration */
400
401         int i;
402
403         assert( Name != NULL );
404         assert( Host != NULL );
405         assert( MyPwd != NULL );
406         assert( PeerPwd != NULL );
407
408         /* Search unused item in server configuration structure */
409         for( i = 0; i < MAX_SERVERS; i++ ) {
410                 /* Is this item used? */
411                 if( ! Conf_Server[i].name[0] ) break;
412         }
413         if( i >= MAX_SERVERS ) return false;
414
415         Init_Server_Struct( &Conf_Server[i] );
416         strlcpy( Conf_Server[i].name, Name, sizeof( Conf_Server[i].name ));
417         strlcpy( Conf_Server[i].host, Host, sizeof( Conf_Server[i].host ));
418         strlcpy( Conf_Server[i].pwd_out, MyPwd, sizeof( Conf_Server[i].pwd_out ));
419         strlcpy( Conf_Server[i].pwd_in, PeerPwd, sizeof( Conf_Server[i].pwd_in ));
420         Conf_Server[i].port = Port;
421         Conf_Server[i].flags = CONF_SFLAG_ONCE;
422
423         return true;
424 } /* Conf_AddServer */
425
426
427 static void
428 Set_Defaults( bool InitServers )
429 {
430         /* Initialize configuration variables with default values. */
431
432         int i;
433
434         strcpy( Conf_ServerName, "" );
435         snprintf( Conf_ServerInfo, sizeof Conf_ServerInfo, "%s %s", PACKAGE_NAME, PACKAGE_VERSION );
436         strcpy( Conf_ServerPwd, "" );
437
438         strcpy( Conf_ServerAdmin1, "" );
439         strcpy( Conf_ServerAdmin2, "" );
440         strcpy( Conf_ServerAdminMail, "" );
441
442         strlcpy( Conf_MotdFile, SYSCONFDIR, sizeof( Conf_MotdFile ));
443         strlcat( Conf_MotdFile, MOTD_FILE, sizeof( Conf_MotdFile ));
444
445         strlcpy( Conf_MotdPhrase, MOTD_PHRASE, sizeof( Conf_MotdPhrase ));
446
447         strlcpy( Conf_Chroot, CHROOT_DIR, sizeof( Conf_Chroot ));
448
449         strlcpy( Conf_PidFile, PID_FILE, sizeof( Conf_PidFile ));
450
451         strcpy( Conf_ListenAddress, "" );
452
453         Conf_UID = Conf_GID = 0;
454
455         Conf_PingTimeout = 120;
456         Conf_PongTimeout = 20;
457
458         Conf_ConnectRetry = 60;
459
460         Conf_Oper_Count = 0;
461         Conf_Channel_Count = 0;
462
463         Conf_OperCanMode = false;
464         Conf_NoDNS = false;
465         Conf_PredefChannelsOnly = false;
466         Conf_OperServerMode = false;
467
468         Conf_ConnectIPv4 = true;
469         Conf_ListenIPv4 = true;
470         Conf_ConnectIPv6 = true;
471         Conf_ListenIPv6 = true;
472
473         Conf_MaxConnections = 0;
474         Conf_MaxConnectionsIP = 5;
475         Conf_MaxJoins = 10;
476         Conf_MaxNickLength = CLIENT_NICK_LEN_DEFAULT;
477
478         /* Initialize server configuration structures */
479         if( InitServers ) for( i = 0; i < MAX_SERVERS; Init_Server_Struct( &Conf_Server[i++] ));
480 } /* Set_Defaults */
481
482
483 static bool
484 Read_Config( bool ngircd_starting )
485 {
486         /* Read configuration file. */
487
488         char section[LINE_LEN], str[LINE_LEN], *var, *arg, *ptr;
489         const UINT16 defaultport = 6667;
490         int line, i, n;
491         FILE *fd;
492
493         /* Open configuration file */
494         fd = fopen( NGIRCd_ConfFile, "r" );
495         if( ! fd ) {
496                 /* No configuration file found! */
497                 Config_Error( LOG_ALERT, "Can't read configuration \"%s\": %s",
498                                         NGIRCd_ConfFile, strerror( errno ));
499                 if (!ngircd_starting)
500                         return false;
501                 Config_Error( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME );
502                 exit( 1 );
503         }
504
505         Set_Defaults( ngircd_starting );
506
507         Config_Error( LOG_INFO, "Reading configuration from \"%s\" ...", NGIRCd_ConfFile );
508
509         /* Clean up server configuration structure: mark all already
510          * configured servers as "once" so that they are deleted
511          * after the next disconnect and delete all unused servers.
512          * And delete all servers which are "duplicates" of servers
513          * that are already marked as "once" (such servers have been
514          * created by the last rehash but are now useless). */
515         for( i = 0; i < MAX_SERVERS; i++ ) {
516                 if( Conf_Server[i].conn_id == NONE ) Init_Server_Struct( &Conf_Server[i] );
517                 else {
518                         /* This structure is in use ... */
519                         if( Conf_Server[i].flags & CONF_SFLAG_ONCE ) {
520                                 /* Check for duplicates */
521                                 for( n = 0; n < MAX_SERVERS; n++ ) {
522                                         if( n == i ) continue;
523
524                                         if( Conf_Server[i].conn_id == Conf_Server[n].conn_id ) {
525                                                 Init_Server_Struct( &Conf_Server[n] );
526 #ifdef DEBUG
527                                                 Log(LOG_DEBUG,"Deleted unused duplicate server %d (kept %d).",
528                                                                                                 n, i );
529 #endif
530                                         }
531                                 }
532                         } else {
533                                 /* Mark server as "once" */
534                                 Conf_Server[i].flags |= CONF_SFLAG_ONCE;
535                                 Log( LOG_DEBUG, "Marked server %d as \"once\"", i );
536                         }
537                 }
538         }
539
540         /* Initialize variables */
541         line = 0;
542         strcpy( section, "" );
543         Init_Server_Struct( &New_Server );
544         New_Server_Idx = NONE;
545
546         /* Read configuration file */
547         while( true ) {
548                 if( ! fgets( str, LINE_LEN, fd )) break;
549                 ngt_TrimStr( str );
550                 line++;
551
552                 /* Skip comments and empty lines */
553                 if( str[0] == ';' || str[0] == '#' || str[0] == '\0' ) continue;
554
555                 /* Is this the beginning of a new section? */
556                 if(( str[0] == '[' ) && ( str[strlen( str ) - 1] == ']' )) {
557                         strlcpy( section, str, sizeof( section ));
558                         if( strcasecmp( section, "[GLOBAL]" ) == 0 )
559                                 continue;
560
561                         if( strcasecmp( section, "[OPERATOR]" ) == 0 ) {
562                                 if( Conf_Oper_Count + 1 > MAX_OPERATORS )
563                                         Config_Error( LOG_ERR, "Too many operators configured.");
564                                 else {
565                                         /* Initialize new operator structure */
566                                         Conf_Oper[Conf_Oper_Count].name[0] = '\0';
567                                         Conf_Oper[Conf_Oper_Count].pwd[0] = '\0';
568                                         if (Conf_Oper[Conf_Oper_Count].mask) {
569                                                 free(Conf_Oper[Conf_Oper_Count].mask );
570                                                 Conf_Oper[Conf_Oper_Count].mask = NULL;
571                                         }
572                                         Conf_Oper_Count++;
573                                 }
574                                 continue;
575                         }
576                         if( strcasecmp( section, "[SERVER]" ) == 0 ) {
577                                 /* Check if there is already a server to add */
578                                 if( New_Server.name[0] ) {
579                                         /* Copy data to "real" server structure */
580                                         assert( New_Server_Idx > NONE );
581                                         Conf_Server[New_Server_Idx] = New_Server;
582                                 }
583
584                                 /* Re-init structure for new server */
585                                 Init_Server_Struct( &New_Server );
586
587                                 /* Search unused item in server configuration structure */
588                                 for( i = 0; i < MAX_SERVERS; i++ ) {
589                                         /* Is this item used? */
590                                         if( ! Conf_Server[i].name[0] ) break;
591                                 }
592                                 if( i >= MAX_SERVERS ) {
593                                         /* Oops, no free item found! */
594                                         Config_Error( LOG_ERR, "Too many servers configured." );
595                                         New_Server_Idx = NONE;
596                                 }
597                                 else New_Server_Idx = i;
598                                 continue;
599                         }
600                         if( strcasecmp( section, "[CHANNEL]" ) == 0 ) {
601                                 if( Conf_Channel_Count + 1 > MAX_DEFCHANNELS ) {
602                                         Config_Error( LOG_ERR, "Too many pre-defined channels configured." );
603                                 } else {
604                                         /* Initialize new channel structure */
605                                         strcpy( Conf_Channel[Conf_Channel_Count].name, "" );
606                                         strcpy( Conf_Channel[Conf_Channel_Count].modes, "" );
607                                         strcpy( Conf_Channel[Conf_Channel_Count].key, "" );
608                                         Conf_Channel[Conf_Channel_Count].maxusers = 0;
609                                         array_free(&Conf_Channel[Conf_Channel_Count].topic);
610                                         Conf_Channel_Count++;
611                                 }
612                                 continue;
613                         }
614                         Config_Error( LOG_ERR, "%s, line %d: Unknown section \"%s\"!", NGIRCd_ConfFile, line, section );
615                         section[0] = 0x1;
616                 }
617                 if( section[0] == 0x1 ) continue;
618
619                 /* Split line into variable name and parameters */
620                 ptr = strchr( str, '=' );
621                 if( ! ptr ) {
622                         Config_Error( LOG_ERR, "%s, line %d: Syntax error!", NGIRCd_ConfFile, line );
623                         continue;
624                 }
625                 *ptr = '\0';
626                 var = str; ngt_TrimStr( var );
627                 arg = ptr + 1; ngt_TrimStr( arg );
628
629                 if( strcasecmp( section, "[GLOBAL]" ) == 0 ) Handle_GLOBAL( line, var, arg );
630                 else if( strcasecmp( section, "[OPERATOR]" ) == 0 ) Handle_OPERATOR( line, var, arg );
631                 else if( strcasecmp( section, "[SERVER]" ) == 0 ) Handle_SERVER( line, var, arg );
632                 else if( strcasecmp( section, "[CHANNEL]" ) == 0 ) Handle_CHANNEL( line, var, arg );
633                 else Config_Error( LOG_ERR, "%s, line %d: Variable \"%s\" outside section!", NGIRCd_ConfFile, line, var );
634         }
635
636         /* Close configuration file */
637         fclose( fd );
638
639         /* Check if there is still a server to add */
640         if( New_Server.name[0] ) {
641                 /* Copy data to "real" server structure */
642                 assert( New_Server_Idx > NONE );
643                 Conf_Server[New_Server_Idx] = New_Server;
644         }
645
646         if (0 == array_length(&Conf_ListenPorts, sizeof(UINT16))) {
647                 if (!array_copyb(&Conf_ListenPorts, (char*) &defaultport, sizeof defaultport)) {
648                         Config_Error( LOG_ALERT, "Could not add default listening Port %u: %s",
649                                                         (unsigned int) defaultport, strerror(errno));
650                         exit( 1 );
651                 }
652         }
653         return true;
654 } /* Read_Config */
655
656
657 static bool
658 Check_ArgIsTrue( const char *Arg )
659 {
660         if( strcasecmp( Arg, "yes" ) == 0 ) return true;
661         if( strcasecmp( Arg, "true" ) == 0 ) return true;
662         if( atoi( Arg ) != 0 ) return true;
663
664         return false;
665 } /* Check_ArgIsTrue */
666
667
668 static unsigned int Handle_MaxNickLength(int Line, const char *Arg)
669 {
670         unsigned new;
671
672         new = (unsigned) atoi(Arg) + 1;
673         if (new > CLIENT_NICK_LEN) {
674                 Config_Error(LOG_WARNING,
675                              "%s, line %d: Value of \"MaxNickLength\" exceeds %u!",
676                              NGIRCd_ConfFile, Line, CLIENT_NICK_LEN - 1);
677                 return CLIENT_NICK_LEN;
678         }
679         if (new < 2) {
680                 Config_Error(LOG_WARNING,
681                              "%s, line %d: Value of \"MaxNickLength\" must be at least 1!",
682                              NGIRCd_ConfFile, Line);
683                 return 2;
684         }
685         return new;
686 } /* Handle_MaxNickLength */
687
688
689 static void
690 Handle_GLOBAL( int Line, char *Var, char *Arg )
691 {
692         struct passwd *pwd;
693         struct group *grp;
694         size_t len;
695         
696         assert( Line > 0 );
697         assert( Var != NULL );
698         assert( Arg != NULL );
699         
700         if( strcasecmp( Var, "Name" ) == 0 ) {
701                 /* Server name */
702                 len = strlcpy( Conf_ServerName, Arg, sizeof( Conf_ServerName ));
703                 if (len >= sizeof( Conf_ServerName ))
704                         Config_Error_TooLong( Line, Var );
705                 return;
706         }
707         if( strcasecmp( Var, "Info" ) == 0 ) {
708                 /* Info text of server */
709                 len = strlcpy( Conf_ServerInfo, Arg, sizeof( Conf_ServerInfo ));
710                 if (len >= sizeof( Conf_ServerInfo ))
711                         Config_Error_TooLong ( Line, Var );
712                 return;
713         }
714         if( strcasecmp( Var, "Password" ) == 0 ) {
715                 /* Global server password */
716                 len = strlcpy( Conf_ServerPwd, Arg, sizeof( Conf_ServerPwd ));
717                 if (len >= sizeof( Conf_ServerPwd ))
718                         Config_Error_TooLong( Line, Var );
719                 return;
720         }
721         if( strcasecmp( Var, "AdminInfo1" ) == 0 ) {
722                 /* Administrative info #1 */
723                 len = strlcpy( Conf_ServerAdmin1, Arg, sizeof( Conf_ServerAdmin1 ));
724                 if (len >= sizeof( Conf_ServerAdmin1 ))
725                         Config_Error_TooLong ( Line, Var );
726                 return;
727         }
728         if( strcasecmp( Var, "AdminInfo2" ) == 0 ) {
729                 /* Administrative info #2 */
730                 len = strlcpy( Conf_ServerAdmin2, Arg, sizeof( Conf_ServerAdmin2 ));
731                 if (len >= sizeof( Conf_ServerAdmin2 ))
732                         Config_Error_TooLong ( Line, Var );
733                 return;
734         }
735         if( strcasecmp( Var, "AdminEMail" ) == 0 ) {
736                 /* Administrative email contact */
737                 len = strlcpy( Conf_ServerAdminMail, Arg, sizeof( Conf_ServerAdminMail ));
738                 if (len >= sizeof( Conf_ServerAdminMail ))
739                         Config_Error_TooLong( Line, Var );
740                 return;
741         }
742
743         if( strcasecmp( Var, "Ports" ) == 0 ) {
744                 ports_parse(&Conf_ListenPorts, Line, Arg);
745                 return;
746         }
747         if( strcasecmp( Var, "MotdFile" ) == 0 ) {
748                 /* "Message of the day" (MOTD) file */
749                 len = strlcpy( Conf_MotdFile, Arg, sizeof( Conf_MotdFile ));
750                 if (len >= sizeof( Conf_MotdFile ))
751                         Config_Error_TooLong( Line, Var );
752                 return;
753         }
754         if( strcasecmp( Var, "MotdPhrase" ) == 0 ) {
755                 /* "Message of the day" phrase (instead of file) */
756                 len = strlcpy( Conf_MotdPhrase, Arg, sizeof( Conf_MotdPhrase ));
757                 if (len >= sizeof( Conf_MotdPhrase ))
758                         Config_Error_TooLong( Line, Var );
759                 return;
760         }
761         if( strcasecmp( Var, "ChrootDir" ) == 0 ) {
762                 /* directory for chroot() */
763                 len = strlcpy( Conf_Chroot, Arg, sizeof( Conf_Chroot ));
764                 if (len >= sizeof( Conf_Chroot ))
765                         Config_Error_TooLong( Line, Var );
766                 return;
767         }
768         if ( strcasecmp( Var, "PidFile" ) == 0 ) {
769                 /* name of pidfile */
770                 len = strlcpy( Conf_PidFile, Arg, sizeof( Conf_PidFile ));
771                 if (len >= sizeof( Conf_PidFile ))
772                         Config_Error_TooLong( Line, Var );
773                 return;
774         }
775         if( strcasecmp( Var, "ServerUID" ) == 0 ) {
776                 /* UID the daemon should switch to */
777                 pwd = getpwnam( Arg );
778                 if( pwd ) Conf_UID = pwd->pw_uid;
779                 else {
780 #ifdef HAVE_ISDIGIT
781                         if( ! isdigit( (int)*Arg )) Config_Error_NaN( Line, Var );
782                         else
783 #endif
784                         Conf_UID = (unsigned int)atoi( Arg );
785                 }
786                 return;
787         }
788         if( strcasecmp( Var, "ServerGID" ) == 0 ) {
789                 /* GID the daemon should use */
790                 grp = getgrnam( Arg );
791                 if( grp ) Conf_GID = grp->gr_gid;
792                 else {
793 #ifdef HAVE_ISDIGIT
794                         if( ! isdigit( (int)*Arg )) Config_Error_NaN( Line, Var );
795                         else
796 #endif
797                         Conf_GID = (unsigned int)atoi( Arg );
798                 }
799                 return;
800         }
801         if( strcasecmp( Var, "PingTimeout" ) == 0 ) {
802                 /* PING timeout */
803                 Conf_PingTimeout = atoi( Arg );
804                 if( Conf_PingTimeout < 5 ) {
805                         Config_Error( LOG_WARNING, "%s, line %d: Value of \"PingTimeout\" too low!",
806                                                                         NGIRCd_ConfFile, Line );
807                         Conf_PingTimeout = 5;
808                 }
809                 return;
810         }
811         if( strcasecmp( Var, "PongTimeout" ) == 0 ) {
812                 /* PONG timeout */
813                 Conf_PongTimeout = atoi( Arg );
814                 if( Conf_PongTimeout < 5 ) {
815                         Config_Error( LOG_WARNING, "%s, line %d: Value of \"PongTimeout\" too low!",
816                                                                         NGIRCd_ConfFile, Line );
817                         Conf_PongTimeout = 5;
818                 }
819                 return;
820         }
821         if( strcasecmp( Var, "ConnectRetry" ) == 0 ) {
822                 /* Seconds between connection attempts to other servers */
823                 Conf_ConnectRetry = atoi( Arg );
824                 if( Conf_ConnectRetry < 5 ) {
825                         Config_Error( LOG_WARNING, "%s, line %d: Value of \"ConnectRetry\" too low!",
826                                                                         NGIRCd_ConfFile, Line );
827                         Conf_ConnectRetry = 5;
828                 }
829                 return;
830         }
831         if( strcasecmp( Var, "PredefChannelsOnly" ) == 0 ) {
832                 /* Should we only allow pre-defined-channels? (i.e. users cannot create their own channels) */
833                 Conf_PredefChannelsOnly = Check_ArgIsTrue( Arg );
834                 return;
835         }
836         if( strcasecmp( Var, "NoDNS" ) == 0 ) {
837                 /* don't do reverse dns lookups when clients connect? */
838                 Conf_NoDNS = Check_ArgIsTrue( Arg );
839                 return;
840         }
841 #ifdef WANT_IPV6
842         /* the default setting for all the WANT_IPV6 special options is 'true' */
843         if( strcasecmp( Var, "ListenIPv6" ) == 0 ) {
844                 /* listen on ipv6 sockets, if available? */
845                 Conf_ListenIPv6 = Check_ArgIsTrue( Arg );
846                 return;
847         }
848         if( strcasecmp( Var, "ListenIPv4" ) == 0 ) {
849                 /*
850                  * listen on ipv4 sockets, if available?
851                  * this allows "ipv6-only" setups.
852                  */
853                 Conf_ListenIPv4 = Check_ArgIsTrue( Arg );
854                 return;
855         }
856         if( strcasecmp( Var, "ConnectIPv6" ) == 0 ) {
857                 /* connect to other hosts using ipv6, if they have an AAAA record? */
858                 Conf_ConnectIPv6 = Check_ArgIsTrue( Arg );
859                 return;
860         }
861         if( strcasecmp( Var, "ConnectIPv4" ) == 0 ) {
862                 /* connect to other hosts using ipv4.
863                  * again, this can be used for ipv6-only setups */
864                 Conf_ConnectIPv4 = Check_ArgIsTrue( Arg );
865                 return;
866         }
867 #endif
868         if( strcasecmp( Var, "OperCanUseMode" ) == 0 ) {
869                 /* Are IRC operators allowed to use MODE in channels they aren't Op in? */
870                 Conf_OperCanMode = Check_ArgIsTrue( Arg );
871                 return;
872         }
873         if( strcasecmp( Var, "OperServerMode" ) == 0 ) {
874                 /* Mask IRC operator as if coming from the server? (ircd-irc2 compat hack) */
875                 Conf_OperServerMode = Check_ArgIsTrue( Arg );
876                 return;
877         }
878         if( strcasecmp( Var, "MaxConnections" ) == 0 ) {
879                 /* Maximum number of connections. 0 -> "no limit". */
880 #ifdef HAVE_ISDIGIT
881                 if( ! isdigit( (int)*Arg )) Config_Error_NaN( Line, Var);
882                 else
883 #endif
884                 Conf_MaxConnections = atol( Arg );
885                 return;
886         }
887         if( strcasecmp( Var, "MaxConnectionsIP" ) == 0 ) {
888                 /* Maximum number of simultaneous connections from one IP. 0 -> "no limit" */
889 #ifdef HAVE_ISDIGIT
890                 if( ! isdigit( (int)*Arg )) Config_Error_NaN( Line, Var );
891                 else
892 #endif
893                 Conf_MaxConnectionsIP = atoi( Arg );
894                 return;
895         }
896         if( strcasecmp( Var, "MaxJoins" ) == 0 ) {
897                 /* Maximum number of channels a user can join. 0 -> "no limit". */
898 #ifdef HAVE_ISDIGIT
899                 if( ! isdigit( (int)*Arg )) Config_Error_NaN( Line, Var );
900                 else
901 #endif
902                 Conf_MaxJoins = atoi( Arg );
903                 return;
904         }
905         if( strcasecmp( Var, "MaxNickLength" ) == 0 ) {
906                 /* Maximum length of a nick name; must be same on all servers
907                  * within the IRC network! */
908                 Conf_MaxNickLength = Handle_MaxNickLength(Line, Arg);
909                 return;
910         }
911
912         if( strcasecmp( Var, "Listen" ) == 0 ) {
913                 /* IP-Address to bind sockets */
914                 len = strlcpy( Conf_ListenAddress, Arg, sizeof( Conf_ListenAddress ));
915                 if (len >= sizeof( Conf_ListenAddress ))
916                         Config_Error_TooLong( Line, Var );
917                 return;
918         }
919
920         Config_Error( LOG_ERR, "%s, line %d (section \"Global\"): Unknown variable \"%s\"!",
921                                                                 NGIRCd_ConfFile, Line, Var );
922 } /* Handle_GLOBAL */
923
924
925 static void
926 Handle_OPERATOR( int Line, char *Var, char *Arg )
927 {
928         unsigned int opercount;
929         size_t len;
930         assert( Line > 0 );
931         assert( Var != NULL );
932         assert( Arg != NULL );
933         assert( Conf_Oper_Count > 0 );
934
935         if ( Conf_Oper_Count == 0 )
936                 return;
937
938         opercount = Conf_Oper_Count - 1;
939
940         if( strcasecmp( Var, "Name" ) == 0 ) {
941                 /* Name of IRC operator */
942                 len = strlcpy( Conf_Oper[opercount].name, Arg, sizeof( Conf_Oper[opercount].name ));
943                 if (len >= sizeof( Conf_Oper[opercount].name ))
944                                 Config_Error_TooLong( Line, Var );
945                 return;
946         }
947         if( strcasecmp( Var, "Password" ) == 0 ) {
948                 /* Password of IRC operator */
949                 len = strlcpy( Conf_Oper[opercount].pwd, Arg, sizeof( Conf_Oper[opercount].pwd ));
950                 if (len >= sizeof( Conf_Oper[opercount].pwd ))
951                                 Config_Error_TooLong( Line, Var );
952                 return;
953         }
954         if( strcasecmp( Var, "Mask" ) == 0 ) {
955                 if (Conf_Oper[opercount].mask) return; /* Hostname already configured */
956
957                 Conf_Oper[opercount].mask = strdup_warn( Arg );
958                 return;
959         }
960         Config_Error( LOG_ERR, "%s, line %d (section \"Operator\"): Unknown variable \"%s\"!",
961                                                                 NGIRCd_ConfFile, Line, Var );
962 } /* Handle_OPERATOR */
963
964
965 static void
966 Handle_SERVER( int Line, char *Var, char *Arg )
967 {
968         long port;
969         size_t len;
970         
971         assert( Line > 0 );
972         assert( Var != NULL );
973         assert( Arg != NULL );
974
975         /* Ignore server block if no space is left in server configuration structure */
976         if( New_Server_Idx <= NONE ) return;
977
978         if( strcasecmp( Var, "Host" ) == 0 ) {
979                 /* Hostname of the server */
980                 len = strlcpy( New_Server.host, Arg, sizeof( New_Server.host ));
981                 if (len >= sizeof( New_Server.host ))
982                         Config_Error_TooLong ( Line, Var );
983                 return;
984         }
985         if( strcasecmp( Var, "Name" ) == 0 ) {
986                 /* Name of the server ("Nick"/"ID") */
987                 len = strlcpy( New_Server.name, Arg, sizeof( New_Server.name ));
988                 if (len >= sizeof( New_Server.name ))
989                         Config_Error_TooLong( Line, Var );
990                 return;
991         }
992         if (strcasecmp(Var, "Bind") == 0) {
993                 if (ng_ipaddr_init(&New_Server.bind_addr, Arg, 0))
994                         return;
995
996                 Config_Error(LOG_ERR, "%s, line %d (section \"Server\"): Can't parse IP address \"%s\"",
997                                 NGIRCd_ConfFile, Line, Arg);
998                 return;
999         }
1000         if( strcasecmp( Var, "MyPassword" ) == 0 ) {
1001                 /* Password of this server which is sent to the peer */
1002                 if (*Arg == ':') {
1003                         Config_Error(LOG_ERR,
1004                                 "%s, line %d (section \"Server\"): MyPassword must not start with ':'!",
1005                                                                                 NGIRCd_ConfFile, Line);
1006                 }
1007                 len = strlcpy( New_Server.pwd_in, Arg, sizeof( New_Server.pwd_in ));
1008                 if (len >= sizeof( New_Server.pwd_in ))
1009                         Config_Error_TooLong( Line, Var );
1010                 return;
1011         }
1012         if( strcasecmp( Var, "PeerPassword" ) == 0 ) {
1013                 /* Passwort of the peer which must be received */
1014                 len = strlcpy( New_Server.pwd_out, Arg, sizeof( New_Server.pwd_out ));
1015                 if (len >= sizeof( New_Server.pwd_out ))
1016                         Config_Error_TooLong( Line, Var );
1017                 return;
1018         }
1019         if( strcasecmp( Var, "Port" ) == 0 ) {
1020                 /* Port to which this server should connect */
1021                 port = atol( Arg );
1022                 if( port > 0 && port < 0xFFFF )
1023                         New_Server.port = (UINT16)port;
1024                 else
1025                         Config_Error( LOG_ERR, "%s, line %d (section \"Server\"): Illegal port number %ld!",
1026                                                                                 NGIRCd_ConfFile, Line, port );
1027                 return;
1028         }
1029         if( strcasecmp( Var, "Group" ) == 0 ) {
1030                 /* Server group */
1031 #ifdef HAVE_ISDIGIT
1032                 if( ! isdigit( (int)*Arg ))
1033                         Config_Error_NaN( Line, Var );
1034                 else
1035 #endif
1036                 New_Server.group = atoi( Arg );
1037                 return;
1038         }
1039         if( strcasecmp( Var, "Passive" ) == 0 ) {
1040                 if (Check_ArgIsTrue(Arg))
1041                         New_Server.flags |= CONF_SFLAG_DISABLED;
1042                 return;
1043         }
1044         
1045         Config_Error( LOG_ERR, "%s, line %d (section \"Server\"): Unknown variable \"%s\"!",
1046                                                                 NGIRCd_ConfFile, Line, Var );
1047 } /* Handle_SERVER */
1048
1049
1050 static bool
1051 Handle_Channelname(size_t chancount, const char *name)
1052 {
1053         size_t size = sizeof( Conf_Channel[chancount].name );
1054         char *dest = Conf_Channel[chancount].name;
1055
1056         if (*name && *name != '#') {
1057                 *dest = '#';
1058                 --size;
1059                 ++dest;
1060         }
1061         return size > strlcpy(dest, name, size);
1062 }
1063
1064
1065 static void
1066 Handle_CHANNEL( int Line, char *Var, char *Arg )
1067 {
1068         size_t len;
1069         size_t chancount = 0;
1070
1071         assert( Line > 0 );
1072         assert( Var != NULL );
1073         assert( Arg != NULL );
1074         if (Conf_Channel_Count > 0)
1075                 chancount = Conf_Channel_Count - 1;
1076
1077         if( strcasecmp( Var, "Name" ) == 0 ) {
1078                 if (!Handle_Channelname(chancount, Arg))
1079                         Config_Error_TooLong( Line, Var );
1080                 return;
1081         }
1082         if( strcasecmp( Var, "Modes" ) == 0 ) {
1083                 /* Initial modes */
1084                 len = strlcpy( Conf_Channel[chancount].modes, Arg, sizeof( Conf_Channel[chancount].modes ));
1085                 if (len >= sizeof( Conf_Channel[chancount].modes ))
1086                         Config_Error_TooLong( Line, Var );
1087                 return;
1088         }
1089         if( strcasecmp( Var, "Topic" ) == 0 ) {
1090                 /* Initial topic */
1091                 if (!array_copys( &Conf_Channel[chancount].topic, Arg))
1092                         Config_Error_TooLong( Line, Var );
1093                 return;
1094         }
1095
1096         if( strcasecmp( Var, "Key" ) == 0 ) {
1097                 /* Initial Channel Key (mode k) */
1098                 len = strlcpy(Conf_Channel[chancount].key, Arg, sizeof(Conf_Channel[chancount].key));
1099                 if (len >= sizeof( Conf_Channel[chancount].key ))
1100                         Config_Error_TooLong(Line, Var);
1101                 return;
1102         }
1103
1104         if( strcasecmp( Var, "MaxUsers" ) == 0 ) {
1105                 /* maximum user limit, mode l */
1106                 Conf_Channel[chancount].maxusers = (unsigned long) atol(Arg);
1107                 if (Conf_Channel[chancount].maxusers == 0)
1108                         Config_Error_NaN(Line, Var);
1109                 return;
1110         }
1111
1112         Config_Error( LOG_ERR, "%s, line %d (section \"Channel\"): Unknown variable \"%s\"!",
1113                                                                 NGIRCd_ConfFile, Line, Var );
1114 } /* Handle_CHANNEL */
1115
1116
1117 static void
1118 Validate_Config(bool Configtest, bool Rehash)
1119 {
1120         /* Validate configuration settings. */
1121
1122 #ifdef DEBUG
1123         int i, servers, servers_once;
1124 #endif
1125         char *ptr;
1126
1127         /* Validate configured server name, see RFC 2812 section 2.3.1 */
1128         ptr = Conf_ServerName;
1129         do {
1130                 if (*ptr >= 'a' && *ptr <= 'z') continue;
1131                 if (*ptr >= 'A' && *ptr <= 'Z') continue;
1132                 if (*ptr >= '0' && *ptr <= '9') continue;
1133                 if (ptr > Conf_ServerName) {
1134                         if (*ptr == '.' || *ptr == '-')
1135                                 continue;
1136                 }
1137                 Conf_ServerName[0] = '\0';
1138                 break;
1139         } while (*(++ptr));
1140
1141         if (!Conf_ServerName[0]) {
1142                 /* No server name configured! */
1143                 Config_Error(LOG_ALERT,
1144                              "No (valid) server name configured in \"%s\" (section 'Global': 'Name')!",
1145                              NGIRCd_ConfFile);
1146                 if (!Configtest && !Rehash) {
1147                         Config_Error(LOG_ALERT,
1148                                      "%s exiting due to fatal errors!",
1149                                      PACKAGE_NAME);
1150                         exit(1);
1151                 }
1152         }
1153
1154         if (Conf_ServerName[0] && !strchr(Conf_ServerName, '.')) {
1155                 /* No dot in server name! */
1156                 Config_Error(LOG_ALERT,
1157                              "Invalid server name configured in \"%s\" (section 'Global': 'Name'): Dot missing!",
1158                              NGIRCd_ConfFile);
1159                 if (!Configtest) {
1160                         Config_Error(LOG_ALERT,
1161                                      "%s exiting due to fatal errors!",
1162                                      PACKAGE_NAME);
1163                         exit(1);
1164                 }
1165         }
1166
1167 #ifdef STRICT_RFC
1168         if (!Conf_ServerAdminMail[0]) {
1169                 /* No administrative contact configured! */
1170                 Config_Error(LOG_ALERT,
1171                              "No administrator email address configured in \"%s\" ('AdminEMail')!",
1172                              NGIRCd_ConfFile);
1173                 if (!Configtest) {
1174                         Config_Error(LOG_ALERT,
1175                                      "%s exiting due to fatal errors!",
1176                                      PACKAGE_NAME);
1177                         exit(1);
1178                 }
1179         }
1180 #endif
1181
1182         if (!Conf_ServerAdmin1[0] && !Conf_ServerAdmin2[0]
1183             && !Conf_ServerAdminMail[0]) {
1184                 /* No administrative information configured! */
1185                 Config_Error(LOG_WARNING,
1186                              "No administrative information configured but required by RFC!");
1187         }
1188
1189 #ifdef WANT_IPV6
1190         if (!Conf_ListenIPv4 && !Conf_ListenIPv6)
1191                 Config_Error(LOG_ALERT,
1192                         "Both \"ListenIPv4\" and \"ListenIPv6\" are set to 'no'; no network protocol available!");
1193
1194         if (!Conf_ConnectIPv4 && !Conf_ConnectIPv6)
1195                 Config_Error(LOG_ALERT,
1196                         "Both \"ConnectIPv4\" and \"ConnectIPv6\" are set to 'no'; ngircd will fail to connect to other irc servers");
1197 #endif
1198
1199 #ifdef DEBUG
1200         servers = servers_once = 0;
1201         for (i = 0; i < MAX_SERVERS; i++) {
1202                 if (Conf_Server[i].name[0]) {
1203                         servers++;
1204                         if (Conf_Server[i].flags & CONF_SFLAG_ONCE)
1205                                 servers_once++;
1206                 }
1207         }
1208         Log(LOG_DEBUG,
1209             "Configuration: Operators=%d, Servers=%d[%d], Channels=%d",
1210             Conf_Oper_Count, servers, servers_once, Conf_Channel_Count);
1211 #endif
1212 } /* Validate_Config */
1213
1214
1215 static void
1216 Config_Error_TooLong ( const int Line, const char *Item )
1217 {
1218         Config_Error( LOG_WARNING, "%s, line %d: Value of \"%s\" too long!", NGIRCd_ConfFile, Line, Item );
1219 }
1220
1221
1222 static void
1223 Config_Error_NaN( const int Line, const char *Item )
1224 {
1225         Config_Error( LOG_WARNING, "%s, line %d: Value of \"%s\" is not a number!",
1226                                                 NGIRCd_ConfFile, Line, Item );
1227 }
1228
1229
1230 #ifdef PROTOTYPES
1231 static void Config_Error( const int Level, const char *Format, ... )
1232 #else
1233 static void Config_Error( Level, Format, va_alist )
1234 const int Level;
1235 const char *Format;
1236 va_dcl
1237 #endif
1238 {
1239         /* Error! Write to console and/or logfile. */
1240
1241         char msg[MAX_LOG_MSG_LEN];
1242         va_list ap;
1243
1244         assert( Format != NULL );
1245
1246 #ifdef PROTOTYPES
1247         va_start( ap, Format );
1248 #else
1249         va_start( ap );
1250 #endif
1251         vsnprintf( msg, MAX_LOG_MSG_LEN, Format, ap );
1252         va_end( ap );
1253         
1254         /* During "normal operations" the log functions of the daemon should
1255          * be used, but during testing of the configuration file, all messages
1256          * should go directly to the console: */
1257         if (Use_Log) Log( Level, "%s", msg );
1258         else puts( msg );
1259 } /* Config_Error */
1260
1261
1262 static void
1263 Init_Server_Struct( CONF_SERVER *Server )
1264 {
1265         /* Initialize server configuration structur to default values */
1266
1267         assert( Server != NULL );
1268
1269         memset( Server, 0, sizeof (CONF_SERVER) );
1270
1271         Server->group = NONE;
1272         Server->lasttry = time( NULL ) - Conf_ConnectRetry + STARTUP_DELAY;
1273
1274         if( NGIRCd_Passive ) Server->flags = CONF_SFLAG_DISABLED;
1275
1276         Resolve_Init(&Server->res_stat);
1277         Server->conn_id = NONE;
1278         memset(&Server->bind_addr, 0, sizeof(&Server->bind_addr));
1279 } /* Init_Server_Struct */
1280
1281
1282 /* -eof- */