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