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