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