]> arthur.barton.de Git - ngircd.git/blob - src/ngircd/conf.c
Fix 'no-ipv6' compile error.
[ngircd.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_ConnectIPv6 = true;
484 #ifdef WANT_IPV6
485         Conf_ListenIPv4 = true;
486         Conf_ListenIPv6 = true;
487 #endif
488         Conf_MaxConnections = 0;
489         Conf_MaxConnectionsIP = 5;
490         Conf_MaxJoins = 10;
491         Conf_MaxNickLength = CLIENT_NICK_LEN_DEFAULT;
492
493         /* Initialize server configuration structures */
494         if( InitServers ) for( i = 0; i < MAX_SERVERS; Init_Server_Struct( &Conf_Server[i++] ));
495 } /* Set_Defaults */
496
497
498 static bool
499 Read_Config( bool ngircd_starting )
500 {
501         /* Read configuration file. */
502
503         char section[LINE_LEN], str[LINE_LEN], *var, *arg, *ptr;
504         const UINT16 defaultport = 6667;
505         int line, i, n;
506         FILE *fd;
507
508         /* Open configuration file */
509         fd = fopen( NGIRCd_ConfFile, "r" );
510         if( ! fd ) {
511                 /* No configuration file found! */
512                 Config_Error( LOG_ALERT, "Can't read configuration \"%s\": %s",
513                                         NGIRCd_ConfFile, strerror( errno ));
514                 if (!ngircd_starting)
515                         return false;
516                 Config_Error( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME );
517                 exit( 1 );
518         }
519
520         Set_Defaults( ngircd_starting );
521
522         Config_Error( LOG_INFO, "Reading configuration from \"%s\" ...", NGIRCd_ConfFile );
523
524         /* Clean up server configuration structure: mark all already
525          * configured servers as "once" so that they are deleted
526          * after the next disconnect and delete all unused servers.
527          * And delete all servers which are "duplicates" of servers
528          * that are already marked as "once" (such servers have been
529          * created by the last rehash but are now useless). */
530         for( i = 0; i < MAX_SERVERS; i++ ) {
531                 if( Conf_Server[i].conn_id == NONE ) Init_Server_Struct( &Conf_Server[i] );
532                 else {
533                         /* This structure is in use ... */
534                         if( Conf_Server[i].flags & CONF_SFLAG_ONCE ) {
535                                 /* Check for duplicates */
536                                 for( n = 0; n < MAX_SERVERS; n++ ) {
537                                         if( n == i ) continue;
538
539                                         if( Conf_Server[i].conn_id == Conf_Server[n].conn_id ) {
540                                                 Init_Server_Struct( &Conf_Server[n] );
541 #ifdef DEBUG
542                                                 Log(LOG_DEBUG,"Deleted unused duplicate server %d (kept %d).",
543                                                                                                 n, i );
544 #endif
545                                         }
546                                 }
547                         } else {
548                                 /* Mark server as "once" */
549                                 Conf_Server[i].flags |= CONF_SFLAG_ONCE;
550                                 Log( LOG_DEBUG, "Marked server %d as \"once\"", i );
551                         }
552                 }
553         }
554
555         /* Initialize variables */
556         line = 0;
557         strcpy( section, "" );
558         Init_Server_Struct( &New_Server );
559         New_Server_Idx = NONE;
560
561         /* Read configuration file */
562         while( true ) {
563                 if( ! fgets( str, LINE_LEN, fd )) break;
564                 ngt_TrimStr( str );
565                 line++;
566
567                 /* Skip comments and empty lines */
568                 if( str[0] == ';' || str[0] == '#' || str[0] == '\0' ) continue;
569
570                 /* Is this the beginning of a new section? */
571                 if(( str[0] == '[' ) && ( str[strlen( str ) - 1] == ']' )) {
572                         strlcpy( section, str, sizeof( section ));
573                         if( strcasecmp( section, "[GLOBAL]" ) == 0 )
574                                 continue;
575
576                         if( strcasecmp( section, "[OPERATOR]" ) == 0 ) {
577                                 if( Conf_Oper_Count + 1 > MAX_OPERATORS )
578                                         Config_Error( LOG_ERR, "Too many operators configured.");
579                                 else {
580                                         /* Initialize new operator structure */
581                                         Conf_Oper[Conf_Oper_Count].name[0] = '\0';
582                                         Conf_Oper[Conf_Oper_Count].pwd[0] = '\0';
583                                         if (Conf_Oper[Conf_Oper_Count].mask) {
584                                                 free(Conf_Oper[Conf_Oper_Count].mask );
585                                                 Conf_Oper[Conf_Oper_Count].mask = NULL;
586                                         }
587                                         Conf_Oper_Count++;
588                                 }
589                                 continue;
590                         }
591                         if( strcasecmp( section, "[SERVER]" ) == 0 ) {
592                                 /* Check if there is already a server to add */
593                                 if( New_Server.name[0] ) {
594                                         /* Copy data to "real" server structure */
595                                         assert( New_Server_Idx > NONE );
596                                         Conf_Server[New_Server_Idx] = New_Server;
597                                 }
598
599                                 /* Re-init structure for new server */
600                                 Init_Server_Struct( &New_Server );
601
602                                 /* Search unused item in server configuration structure */
603                                 for( i = 0; i < MAX_SERVERS; i++ ) {
604                                         /* Is this item used? */
605                                         if( ! Conf_Server[i].name[0] ) break;
606                                 }
607                                 if( i >= MAX_SERVERS ) {
608                                         /* Oops, no free item found! */
609                                         Config_Error( LOG_ERR, "Too many servers configured." );
610                                         New_Server_Idx = NONE;
611                                 }
612                                 else New_Server_Idx = i;
613                                 continue;
614                         }
615                         if( strcasecmp( section, "[CHANNEL]" ) == 0 ) {
616                                 if( Conf_Channel_Count + 1 > MAX_DEFCHANNELS ) {
617                                         Config_Error( LOG_ERR, "Too many pre-defined channels configured." );
618                                 } else {
619                                         /* Initialize new channel structure */
620                                         strcpy( Conf_Channel[Conf_Channel_Count].name, "" );
621                                         strcpy( Conf_Channel[Conf_Channel_Count].modes, "" );
622                                         strcpy( Conf_Channel[Conf_Channel_Count].key, "" );
623                                         Conf_Channel[Conf_Channel_Count].maxusers = 0;
624                                         array_free(&Conf_Channel[Conf_Channel_Count].topic);
625                                         Conf_Channel_Count++;
626                                 }
627                                 continue;
628                         }
629                         Config_Error( LOG_ERR, "%s, line %d: Unknown section \"%s\"!", NGIRCd_ConfFile, line, section );
630                         section[0] = 0x1;
631                 }
632                 if( section[0] == 0x1 ) continue;
633
634                 /* Split line into variable name and parameters */
635                 ptr = strchr( str, '=' );
636                 if( ! ptr ) {
637                         Config_Error( LOG_ERR, "%s, line %d: Syntax error!", NGIRCd_ConfFile, line );
638                         continue;
639                 }
640                 *ptr = '\0';
641                 var = str; ngt_TrimStr( var );
642                 arg = ptr + 1; ngt_TrimStr( arg );
643
644                 if( strcasecmp( section, "[GLOBAL]" ) == 0 ) Handle_GLOBAL( line, var, arg );
645                 else if( strcasecmp( section, "[OPERATOR]" ) == 0 ) Handle_OPERATOR( line, var, arg );
646                 else if( strcasecmp( section, "[SERVER]" ) == 0 ) Handle_SERVER( line, var, arg );
647                 else if( strcasecmp( section, "[CHANNEL]" ) == 0 ) Handle_CHANNEL( line, var, arg );
648                 else Config_Error( LOG_ERR, "%s, line %d: Variable \"%s\" outside section!", NGIRCd_ConfFile, line, var );
649         }
650
651         /* Close configuration file */
652         fclose( fd );
653
654         /* Check if there is still a server to add */
655         if( New_Server.name[0] ) {
656                 /* Copy data to "real" server structure */
657                 assert( New_Server_Idx > NONE );
658                 Conf_Server[New_Server_Idx] = New_Server;
659         }
660
661         if (0 == array_length(&Conf_ListenPorts, sizeof(UINT16))) {
662                 if (!array_copyb(&Conf_ListenPorts, (char*) &defaultport, sizeof defaultport)) {
663                         Config_Error( LOG_ALERT, "Could not add default listening Port %u: %s",
664                                                         (unsigned int) defaultport, strerror(errno));
665                         exit( 1 );
666                 }
667         }
668
669         if (!Conf_ListenAddress) {
670                 /* no Listen addresses configured, use default */
671 #ifdef WANT_IPV6
672                 /* Conf_ListenIPv6/4 should no longer be used */
673                 if (Conf_ListenIPv6 && Conf_ListenIPv4)
674                         Conf_ListenAddress = strdup_warn("::,0.0.0.0");
675                 else if (Conf_ListenIPv6)
676                         Conf_ListenAddress = strdup_warn("::");
677                 else
678 #endif
679                 Conf_ListenAddress = strdup_warn("0.0.0.0");
680         }
681         if (!Conf_ListenAddress) {
682                 Config_Error(LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME);
683                 exit(1);
684         }
685         return true;
686 } /* Read_Config */
687
688
689 static bool
690 Check_ArgIsTrue( const char *Arg )
691 {
692         if( strcasecmp( Arg, "yes" ) == 0 ) return true;
693         if( strcasecmp( Arg, "true" ) == 0 ) return true;
694         if( atoi( Arg ) != 0 ) return true;
695
696         return false;
697 } /* Check_ArgIsTrue */
698
699
700 static unsigned int Handle_MaxNickLength(int Line, const char *Arg)
701 {
702         unsigned new;
703
704         new = (unsigned) atoi(Arg) + 1;
705         if (new > CLIENT_NICK_LEN) {
706                 Config_Error(LOG_WARNING,
707                              "%s, line %d: Value of \"MaxNickLength\" exceeds %u!",
708                              NGIRCd_ConfFile, Line, CLIENT_NICK_LEN - 1);
709                 return CLIENT_NICK_LEN;
710         }
711         if (new < 2) {
712                 Config_Error(LOG_WARNING,
713                              "%s, line %d: Value of \"MaxNickLength\" must be at least 1!",
714                              NGIRCd_ConfFile, Line);
715                 return 2;
716         }
717         return new;
718 } /* Handle_MaxNickLength */
719
720
721 static void
722 Handle_GLOBAL( int Line, char *Var, char *Arg )
723 {
724         struct passwd *pwd;
725         struct group *grp;
726         size_t len;
727         
728         assert( Line > 0 );
729         assert( Var != NULL );
730         assert( Arg != NULL );
731         
732         if( strcasecmp( Var, "Name" ) == 0 ) {
733                 /* Server name */
734                 len = strlcpy( Conf_ServerName, Arg, sizeof( Conf_ServerName ));
735                 if (len >= sizeof( Conf_ServerName ))
736                         Config_Error_TooLong( Line, Var );
737                 return;
738         }
739         if( strcasecmp( Var, "Info" ) == 0 ) {
740                 /* Info text of server */
741                 len = strlcpy( Conf_ServerInfo, Arg, sizeof( Conf_ServerInfo ));
742                 if (len >= sizeof( Conf_ServerInfo ))
743                         Config_Error_TooLong ( Line, Var );
744                 return;
745         }
746         if( strcasecmp( Var, "Password" ) == 0 ) {
747                 /* Global server password */
748                 len = strlcpy( Conf_ServerPwd, Arg, sizeof( Conf_ServerPwd ));
749                 if (len >= sizeof( Conf_ServerPwd ))
750                         Config_Error_TooLong( Line, Var );
751                 return;
752         }
753         if( strcasecmp( Var, "AdminInfo1" ) == 0 ) {
754                 /* Administrative info #1 */
755                 len = strlcpy( Conf_ServerAdmin1, Arg, sizeof( Conf_ServerAdmin1 ));
756                 if (len >= sizeof( Conf_ServerAdmin1 ))
757                         Config_Error_TooLong ( Line, Var );
758                 return;
759         }
760         if( strcasecmp( Var, "AdminInfo2" ) == 0 ) {
761                 /* Administrative info #2 */
762                 len = strlcpy( Conf_ServerAdmin2, Arg, sizeof( Conf_ServerAdmin2 ));
763                 if (len >= sizeof( Conf_ServerAdmin2 ))
764                         Config_Error_TooLong ( Line, Var );
765                 return;
766         }
767         if( strcasecmp( Var, "AdminEMail" ) == 0 ) {
768                 /* Administrative email contact */
769                 len = strlcpy( Conf_ServerAdminMail, Arg, sizeof( Conf_ServerAdminMail ));
770                 if (len >= sizeof( Conf_ServerAdminMail ))
771                         Config_Error_TooLong( Line, Var );
772                 return;
773         }
774
775         if( strcasecmp( Var, "Ports" ) == 0 ) {
776                 ports_parse(&Conf_ListenPorts, Line, Arg);
777                 return;
778         }
779         if( strcasecmp( Var, "MotdFile" ) == 0 ) {
780                 /* "Message of the day" (MOTD) file */
781                 len = strlcpy( Conf_MotdFile, Arg, sizeof( Conf_MotdFile ));
782                 if (len >= sizeof( Conf_MotdFile ))
783                         Config_Error_TooLong( Line, Var );
784                 return;
785         }
786         if( strcasecmp( Var, "MotdPhrase" ) == 0 ) {
787                 /* "Message of the day" phrase (instead of file) */
788                 len = strlcpy( Conf_MotdPhrase, Arg, sizeof( Conf_MotdPhrase ));
789                 if (len >= sizeof( Conf_MotdPhrase ))
790                         Config_Error_TooLong( Line, Var );
791                 return;
792         }
793         if( strcasecmp( Var, "ChrootDir" ) == 0 ) {
794                 /* directory for chroot() */
795                 len = strlcpy( Conf_Chroot, Arg, sizeof( Conf_Chroot ));
796                 if (len >= sizeof( Conf_Chroot ))
797                         Config_Error_TooLong( Line, Var );
798                 return;
799         }
800         if ( strcasecmp( Var, "PidFile" ) == 0 ) {
801                 /* name of pidfile */
802                 len = strlcpy( Conf_PidFile, Arg, sizeof( Conf_PidFile ));
803                 if (len >= sizeof( Conf_PidFile ))
804                         Config_Error_TooLong( Line, Var );
805                 return;
806         }
807         if( strcasecmp( Var, "ServerUID" ) == 0 ) {
808                 /* UID the daemon should switch to */
809                 pwd = getpwnam( Arg );
810                 if( pwd ) Conf_UID = pwd->pw_uid;
811                 else {
812 #ifdef HAVE_ISDIGIT
813                         if( ! isdigit( (int)*Arg )) Config_Error_NaN( Line, Var );
814                         else
815 #endif
816                         Conf_UID = (unsigned int)atoi( Arg );
817                 }
818                 return;
819         }
820         if( strcasecmp( Var, "ServerGID" ) == 0 ) {
821                 /* GID the daemon should use */
822                 grp = getgrnam( Arg );
823                 if( grp ) Conf_GID = grp->gr_gid;
824                 else {
825 #ifdef HAVE_ISDIGIT
826                         if( ! isdigit( (int)*Arg )) Config_Error_NaN( Line, Var );
827                         else
828 #endif
829                         Conf_GID = (unsigned int)atoi( Arg );
830                 }
831                 return;
832         }
833         if( strcasecmp( Var, "PingTimeout" ) == 0 ) {
834                 /* PING timeout */
835                 Conf_PingTimeout = atoi( Arg );
836                 if( Conf_PingTimeout < 5 ) {
837                         Config_Error( LOG_WARNING, "%s, line %d: Value of \"PingTimeout\" too low!",
838                                                                         NGIRCd_ConfFile, Line );
839                         Conf_PingTimeout = 5;
840                 }
841                 return;
842         }
843         if( strcasecmp( Var, "PongTimeout" ) == 0 ) {
844                 /* PONG timeout */
845                 Conf_PongTimeout = atoi( Arg );
846                 if( Conf_PongTimeout < 5 ) {
847                         Config_Error( LOG_WARNING, "%s, line %d: Value of \"PongTimeout\" too low!",
848                                                                         NGIRCd_ConfFile, Line );
849                         Conf_PongTimeout = 5;
850                 }
851                 return;
852         }
853         if( strcasecmp( Var, "ConnectRetry" ) == 0 ) {
854                 /* Seconds between connection attempts to other servers */
855                 Conf_ConnectRetry = atoi( Arg );
856                 if( Conf_ConnectRetry < 5 ) {
857                         Config_Error( LOG_WARNING, "%s, line %d: Value of \"ConnectRetry\" too low!",
858                                                                         NGIRCd_ConfFile, Line );
859                         Conf_ConnectRetry = 5;
860                 }
861                 return;
862         }
863         if( strcasecmp( Var, "PredefChannelsOnly" ) == 0 ) {
864                 /* Should we only allow pre-defined-channels? (i.e. users cannot create their own channels) */
865                 Conf_PredefChannelsOnly = Check_ArgIsTrue( Arg );
866                 return;
867         }
868         if( strcasecmp( Var, "NoDNS" ) == 0 ) {
869                 /* don't do reverse dns lookups when clients connect? */
870                 Conf_NoDNS = Check_ArgIsTrue( Arg );
871                 return;
872         }
873 #ifdef WANT_IPV6
874         /* the default setting for all the WANT_IPV6 special options is 'true' */
875         if (strcasecmp(Var, "ListenIPv6") == 0) { /* DEPRECATED, option appeared in 0.12.0 */
876                 /*
877                  * listen on ipv6 sockets, if available?
878                  * Deprecated use "Listen = 0.0.0.0" (or, rather, do not list "::")
879                  */
880                 Conf_ListenIPv6 = Check_ArgIsTrue( Arg );
881                 Config_Error(LOG_WARNING, "%s, line %d: %s=%s is deprecated, %sinclude '::' in \"Listen =\" option instead",
882                                 NGIRCd_ConfFile, Line, Var, yesno_to_str(Conf_ListenIPv6), Conf_ListenIPv6 ? " ":"do not ");
883                 return;
884         }
885         if (strcasecmp(Var, "ListenIPv4") == 0) { /* DEPRECATED, option appeared in 0.12.0 */
886                 /*
887                  * listen on ipv4 sockets, if available?
888                  * this allows "ipv6-only" setups
889                  * Deprecated use "Listen = ::" (or, rather, do not list "0.0.0.0")
890                  */
891                 Conf_ListenIPv4 = Check_ArgIsTrue( Arg );
892                 Config_Error(LOG_WARNING, "%s, line %d: %s=%s is deprecated, %sinclude '0.0.0.0' in \"Listen =\" option instead",
893                                 NGIRCd_ConfFile, Line, Var, yesno_to_str(Conf_ListenIPv4), Conf_ListenIPv4 ? " ":"do not ");
894                 return;
895         }
896         if( strcasecmp( Var, "ConnectIPv6" ) == 0 ) {
897                 /* connect to other hosts using ipv6, if they have an AAAA record? */
898                 Conf_ConnectIPv6 = Check_ArgIsTrue( Arg );
899                 return;
900         }
901         if( strcasecmp( Var, "ConnectIPv4" ) == 0 ) {
902                 /* connect to other hosts using ipv4.
903                  * again, this can be used for ipv6-only setups */
904                 Conf_ConnectIPv4 = Check_ArgIsTrue( Arg );
905                 return;
906         }
907 #endif
908         if( strcasecmp( Var, "OperCanUseMode" ) == 0 ) {
909                 /* Are IRC operators allowed to use MODE in channels they aren't Op in? */
910                 Conf_OperCanMode = Check_ArgIsTrue( Arg );
911                 return;
912         }
913         if( strcasecmp( Var, "OperServerMode" ) == 0 ) {
914                 /* Mask IRC operator as if coming from the server? (ircd-irc2 compat hack) */
915                 Conf_OperServerMode = Check_ArgIsTrue( Arg );
916                 return;
917         }
918         if( strcasecmp( Var, "MaxConnections" ) == 0 ) {
919                 /* Maximum number of connections. 0 -> "no limit". */
920 #ifdef HAVE_ISDIGIT
921                 if( ! isdigit( (int)*Arg )) Config_Error_NaN( Line, Var);
922                 else
923 #endif
924                 Conf_MaxConnections = atol( Arg );
925                 return;
926         }
927         if( strcasecmp( Var, "MaxConnectionsIP" ) == 0 ) {
928                 /* Maximum number of simultaneous connections from one IP. 0 -> "no limit" */
929 #ifdef HAVE_ISDIGIT
930                 if( ! isdigit( (int)*Arg )) Config_Error_NaN( Line, Var );
931                 else
932 #endif
933                 Conf_MaxConnectionsIP = atoi( Arg );
934                 return;
935         }
936         if( strcasecmp( Var, "MaxJoins" ) == 0 ) {
937                 /* Maximum number of channels a user can join. 0 -> "no limit". */
938 #ifdef HAVE_ISDIGIT
939                 if( ! isdigit( (int)*Arg )) Config_Error_NaN( Line, Var );
940                 else
941 #endif
942                 Conf_MaxJoins = atoi( Arg );
943                 return;
944         }
945         if( strcasecmp( Var, "MaxNickLength" ) == 0 ) {
946                 /* Maximum length of a nick name; must be same on all servers
947                  * within the IRC network! */
948                 Conf_MaxNickLength = Handle_MaxNickLength(Line, Arg);
949                 return;
950         }
951
952         if( strcasecmp( Var, "Listen" ) == 0 ) {
953                 /* IP-Address to bind sockets */
954                 if (Conf_ListenAddress) {
955                         Config_Error(LOG_ERR, "Multiple Listen= options, ignoring: %s", Arg);
956                         return;
957                 }
958                 Conf_ListenAddress = strdup_warn(Arg);
959                 /*
960                  * if allocation fails, we're in trouble:
961                  * we cannot ignore the error -- otherwise ngircd
962                  * would listen on all interfaces.
963                  */
964                 if (!Conf_ListenAddress) {
965                         Config_Error(LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME);
966                         exit(1);
967                 }
968                 return;
969         }
970         Config_Error(LOG_ERR, "%s, line %d (section \"Global\"): Unknown variable \"%s\"!",
971                                                                 NGIRCd_ConfFile, Line, Var);
972 } /* Handle_GLOBAL */
973
974
975 static void
976 Handle_OPERATOR( int Line, char *Var, char *Arg )
977 {
978         unsigned int opercount;
979         size_t len;
980         assert( Line > 0 );
981         assert( Var != NULL );
982         assert( Arg != NULL );
983         assert( Conf_Oper_Count > 0 );
984
985         if ( Conf_Oper_Count == 0 )
986                 return;
987
988         opercount = Conf_Oper_Count - 1;
989
990         if( strcasecmp( Var, "Name" ) == 0 ) {
991                 /* Name of IRC operator */
992                 len = strlcpy( Conf_Oper[opercount].name, Arg, sizeof( Conf_Oper[opercount].name ));
993                 if (len >= sizeof( Conf_Oper[opercount].name ))
994                                 Config_Error_TooLong( Line, Var );
995                 return;
996         }
997         if( strcasecmp( Var, "Password" ) == 0 ) {
998                 /* Password of IRC operator */
999                 len = strlcpy( Conf_Oper[opercount].pwd, Arg, sizeof( Conf_Oper[opercount].pwd ));
1000                 if (len >= sizeof( Conf_Oper[opercount].pwd ))
1001                                 Config_Error_TooLong( Line, Var );
1002                 return;
1003         }
1004         if( strcasecmp( Var, "Mask" ) == 0 ) {
1005                 if (Conf_Oper[opercount].mask) return; /* Hostname already configured */
1006
1007                 Conf_Oper[opercount].mask = strdup_warn( Arg );
1008                 return;
1009         }
1010         Config_Error( LOG_ERR, "%s, line %d (section \"Operator\"): Unknown variable \"%s\"!",
1011                                                                 NGIRCd_ConfFile, Line, Var );
1012 } /* Handle_OPERATOR */
1013
1014
1015 static void
1016 Handle_SERVER( int Line, char *Var, char *Arg )
1017 {
1018         long port;
1019         size_t len;
1020         
1021         assert( Line > 0 );
1022         assert( Var != NULL );
1023         assert( Arg != NULL );
1024
1025         /* Ignore server block if no space is left in server configuration structure */
1026         if( New_Server_Idx <= NONE ) return;
1027
1028         if( strcasecmp( Var, "Host" ) == 0 ) {
1029                 /* Hostname of the server */
1030                 len = strlcpy( New_Server.host, Arg, sizeof( New_Server.host ));
1031                 if (len >= sizeof( New_Server.host ))
1032                         Config_Error_TooLong ( Line, Var );
1033                 return;
1034         }
1035         if( strcasecmp( Var, "Name" ) == 0 ) {
1036                 /* Name of the server ("Nick"/"ID") */
1037                 len = strlcpy( New_Server.name, Arg, sizeof( New_Server.name ));
1038                 if (len >= sizeof( New_Server.name ))
1039                         Config_Error_TooLong( Line, Var );
1040                 return;
1041         }
1042         if (strcasecmp(Var, "Bind") == 0) {
1043                 if (ng_ipaddr_init(&New_Server.bind_addr, Arg, 0))
1044                         return;
1045
1046                 Config_Error(LOG_ERR, "%s, line %d (section \"Server\"): Can't parse IP address \"%s\"",
1047                                 NGIRCd_ConfFile, Line, Arg);
1048                 return;
1049         }
1050         if( strcasecmp( Var, "MyPassword" ) == 0 ) {
1051                 /* Password of this server which is sent to the peer */
1052                 if (*Arg == ':') {
1053                         Config_Error(LOG_ERR,
1054                                 "%s, line %d (section \"Server\"): MyPassword must not start with ':'!",
1055                                                                                 NGIRCd_ConfFile, Line);
1056                 }
1057                 len = strlcpy( New_Server.pwd_in, Arg, sizeof( New_Server.pwd_in ));
1058                 if (len >= sizeof( New_Server.pwd_in ))
1059                         Config_Error_TooLong( Line, Var );
1060                 return;
1061         }
1062         if( strcasecmp( Var, "PeerPassword" ) == 0 ) {
1063                 /* Passwort of the peer which must be received */
1064                 len = strlcpy( New_Server.pwd_out, Arg, sizeof( New_Server.pwd_out ));
1065                 if (len >= sizeof( New_Server.pwd_out ))
1066                         Config_Error_TooLong( Line, Var );
1067                 return;
1068         }
1069         if( strcasecmp( Var, "Port" ) == 0 ) {
1070                 /* Port to which this server should connect */
1071                 port = atol( Arg );
1072                 if( port > 0 && port < 0xFFFF )
1073                         New_Server.port = (UINT16)port;
1074                 else
1075                         Config_Error( LOG_ERR, "%s, line %d (section \"Server\"): Illegal port number %ld!",
1076                                                                                 NGIRCd_ConfFile, Line, port );
1077                 return;
1078         }
1079         if( strcasecmp( Var, "Group" ) == 0 ) {
1080                 /* Server group */
1081 #ifdef HAVE_ISDIGIT
1082                 if( ! isdigit( (int)*Arg ))
1083                         Config_Error_NaN( Line, Var );
1084                 else
1085 #endif
1086                 New_Server.group = atoi( Arg );
1087                 return;
1088         }
1089         if( strcasecmp( Var, "Passive" ) == 0 ) {
1090                 if (Check_ArgIsTrue(Arg))
1091                         New_Server.flags |= CONF_SFLAG_DISABLED;
1092                 return;
1093         }
1094         
1095         Config_Error( LOG_ERR, "%s, line %d (section \"Server\"): Unknown variable \"%s\"!",
1096                                                                 NGIRCd_ConfFile, Line, Var );
1097 } /* Handle_SERVER */
1098
1099
1100 static bool
1101 Handle_Channelname(size_t chancount, const char *name)
1102 {
1103         size_t size = sizeof( Conf_Channel[chancount].name );
1104         char *dest = Conf_Channel[chancount].name;
1105
1106         if (*name && *name != '#') {
1107                 *dest = '#';
1108                 --size;
1109                 ++dest;
1110         }
1111         return size > strlcpy(dest, name, size);
1112 }
1113
1114
1115 static void
1116 Handle_CHANNEL( int Line, char *Var, char *Arg )
1117 {
1118         size_t len;
1119         size_t chancount = 0;
1120
1121         assert( Line > 0 );
1122         assert( Var != NULL );
1123         assert( Arg != NULL );
1124         if (Conf_Channel_Count > 0)
1125                 chancount = Conf_Channel_Count - 1;
1126
1127         if( strcasecmp( Var, "Name" ) == 0 ) {
1128                 if (!Handle_Channelname(chancount, Arg))
1129                         Config_Error_TooLong( Line, Var );
1130                 return;
1131         }
1132         if( strcasecmp( Var, "Modes" ) == 0 ) {
1133                 /* Initial modes */
1134                 len = strlcpy( Conf_Channel[chancount].modes, Arg, sizeof( Conf_Channel[chancount].modes ));
1135                 if (len >= sizeof( Conf_Channel[chancount].modes ))
1136                         Config_Error_TooLong( Line, Var );
1137                 return;
1138         }
1139         if( strcasecmp( Var, "Topic" ) == 0 ) {
1140                 /* Initial topic */
1141                 if (!array_copys( &Conf_Channel[chancount].topic, Arg))
1142                         Config_Error_TooLong( Line, Var );
1143                 return;
1144         }
1145
1146         if( strcasecmp( Var, "Key" ) == 0 ) {
1147                 /* Initial Channel Key (mode k) */
1148                 len = strlcpy(Conf_Channel[chancount].key, Arg, sizeof(Conf_Channel[chancount].key));
1149                 if (len >= sizeof( Conf_Channel[chancount].key ))
1150                         Config_Error_TooLong(Line, Var);
1151                 return;
1152         }
1153
1154         if( strcasecmp( Var, "MaxUsers" ) == 0 ) {
1155                 /* maximum user limit, mode l */
1156                 Conf_Channel[chancount].maxusers = (unsigned long) atol(Arg);
1157                 if (Conf_Channel[chancount].maxusers == 0)
1158                         Config_Error_NaN(Line, Var);
1159                 return;
1160         }
1161
1162         Config_Error( LOG_ERR, "%s, line %d (section \"Channel\"): Unknown variable \"%s\"!",
1163                                                                 NGIRCd_ConfFile, Line, Var );
1164 } /* Handle_CHANNEL */
1165
1166
1167 static void
1168 Validate_Config(bool Configtest, bool Rehash)
1169 {
1170         /* Validate configuration settings. */
1171
1172 #ifdef DEBUG
1173         int i, servers, servers_once;
1174 #endif
1175         char *ptr;
1176
1177         /* Validate configured server name, see RFC 2812 section 2.3.1 */
1178         ptr = Conf_ServerName;
1179         do {
1180                 if (*ptr >= 'a' && *ptr <= 'z') continue;
1181                 if (*ptr >= 'A' && *ptr <= 'Z') continue;
1182                 if (*ptr >= '0' && *ptr <= '9') continue;
1183                 if (ptr > Conf_ServerName) {
1184                         if (*ptr == '.' || *ptr == '-')
1185                                 continue;
1186                 }
1187                 Conf_ServerName[0] = '\0';
1188                 break;
1189         } while (*(++ptr));
1190
1191         if (!Conf_ServerName[0]) {
1192                 /* No server name configured! */
1193                 Config_Error(LOG_ALERT,
1194                              "No (valid) server name configured in \"%s\" (section 'Global': 'Name')!",
1195                              NGIRCd_ConfFile);
1196                 if (!Configtest && !Rehash) {
1197                         Config_Error(LOG_ALERT,
1198                                      "%s exiting due to fatal errors!",
1199                                      PACKAGE_NAME);
1200                         exit(1);
1201                 }
1202         }
1203
1204         if (Conf_ServerName[0] && !strchr(Conf_ServerName, '.')) {
1205                 /* No dot in server name! */
1206                 Config_Error(LOG_ALERT,
1207                              "Invalid server name configured in \"%s\" (section 'Global': 'Name'): Dot missing!",
1208                              NGIRCd_ConfFile);
1209                 if (!Configtest) {
1210                         Config_Error(LOG_ALERT,
1211                                      "%s exiting due to fatal errors!",
1212                                      PACKAGE_NAME);
1213                         exit(1);
1214                 }
1215         }
1216
1217 #ifdef STRICT_RFC
1218         if (!Conf_ServerAdminMail[0]) {
1219                 /* No administrative contact configured! */
1220                 Config_Error(LOG_ALERT,
1221                              "No administrator email address configured in \"%s\" ('AdminEMail')!",
1222                              NGIRCd_ConfFile);
1223                 if (!Configtest) {
1224                         Config_Error(LOG_ALERT,
1225                                      "%s exiting due to fatal errors!",
1226                                      PACKAGE_NAME);
1227                         exit(1);
1228                 }
1229         }
1230 #endif
1231
1232         if (!Conf_ServerAdmin1[0] && !Conf_ServerAdmin2[0]
1233             && !Conf_ServerAdminMail[0]) {
1234                 /* No administrative information configured! */
1235                 Config_Error(LOG_WARNING,
1236                              "No administrative information configured but required by RFC!");
1237         }
1238
1239 #ifdef DEBUG
1240         servers = servers_once = 0;
1241         for (i = 0; i < MAX_SERVERS; i++) {
1242                 if (Conf_Server[i].name[0]) {
1243                         servers++;
1244                         if (Conf_Server[i].flags & CONF_SFLAG_ONCE)
1245                                 servers_once++;
1246                 }
1247         }
1248         Log(LOG_DEBUG,
1249             "Configuration: Operators=%d, Servers=%d[%d], Channels=%d",
1250             Conf_Oper_Count, servers, servers_once, Conf_Channel_Count);
1251 #endif
1252 } /* Validate_Config */
1253
1254
1255 static void
1256 Config_Error_TooLong ( const int Line, const char *Item )
1257 {
1258         Config_Error( LOG_WARNING, "%s, line %d: Value of \"%s\" too long!", NGIRCd_ConfFile, Line, Item );
1259 }
1260
1261
1262 static void
1263 Config_Error_NaN( const int Line, const char *Item )
1264 {
1265         Config_Error( LOG_WARNING, "%s, line %d: Value of \"%s\" is not a number!",
1266                                                 NGIRCd_ConfFile, Line, Item );
1267 }
1268
1269
1270 #ifdef PROTOTYPES
1271 static void Config_Error( const int Level, const char *Format, ... )
1272 #else
1273 static void Config_Error( Level, Format, va_alist )
1274 const int Level;
1275 const char *Format;
1276 va_dcl
1277 #endif
1278 {
1279         /* Error! Write to console and/or logfile. */
1280
1281         char msg[MAX_LOG_MSG_LEN];
1282         va_list ap;
1283
1284         assert( Format != NULL );
1285
1286 #ifdef PROTOTYPES
1287         va_start( ap, Format );
1288 #else
1289         va_start( ap );
1290 #endif
1291         vsnprintf( msg, MAX_LOG_MSG_LEN, Format, ap );
1292         va_end( ap );
1293         
1294         /* During "normal operations" the log functions of the daemon should
1295          * be used, but during testing of the configuration file, all messages
1296          * should go directly to the console: */
1297         if (Use_Log) Log( Level, "%s", msg );
1298         else puts( msg );
1299 } /* Config_Error */
1300
1301
1302 static void
1303 Init_Server_Struct( CONF_SERVER *Server )
1304 {
1305         /* Initialize server configuration structur to default values */
1306
1307         assert( Server != NULL );
1308
1309         memset( Server, 0, sizeof (CONF_SERVER) );
1310
1311         Server->group = NONE;
1312         Server->lasttry = time( NULL ) - Conf_ConnectRetry + STARTUP_DELAY;
1313
1314         if( NGIRCd_Passive ) Server->flags = CONF_SFLAG_DISABLED;
1315
1316         Resolve_Init(&Server->res_stat);
1317         Server->conn_id = NONE;
1318         memset(&Server->bind_addr, 0, sizeof(&Server->bind_addr));
1319 } /* Init_Server_Struct */
1320
1321
1322 /* -eof- */