]> arthur.barton.de Git - ngircd-alex.git/blob - src/ngircd/conf.c
Check for redability of SSL-related files like for MOTD file
[ngircd-alex.git] / src / ngircd / conf.c
1 /*
2  * ngIRCd -- The Next Generation IRC Daemon
3  * Copyright (c)2001-2011 Alexander Barton (alex@barton.de) and Contributors.
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
12 #include "portab.h"
13
14 /**
15  * @file
16  * Configuration management (reading, parsing & validation)
17  */
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 "channel.h"
45 #include "defines.h"
46 #include "log.h"
47 #include "match.h"
48 #include "tool.h"
49
50 #include "exp.h"
51 #include "conf.h"
52
53
54 static bool Use_Log = true, Using_MotdFile = true;
55 static CONF_SERVER New_Server;
56 static int New_Server_Idx;
57
58 static size_t Conf_Oper_Count;
59 static size_t Conf_Channel_Count;
60 static char Conf_MotdFile[FNAME_LEN];
61
62 static void Set_Defaults PARAMS(( bool InitServers ));
63 static bool Read_Config PARAMS(( bool ngircd_starting ));
64 static bool Validate_Config PARAMS(( bool TestOnly, bool Rehash ));
65
66 static void Handle_GLOBAL PARAMS(( int Line, char *Var, char *Arg ));
67 static void Handle_LIMITS PARAMS(( int Line, char *Var, char *Arg ));
68 static void Handle_OPTIONS PARAMS(( int Line, char *Var, char *Arg ));
69 static void Handle_OPERATOR PARAMS(( int Line, char *Var, char *Arg ));
70 static void Handle_SERVER PARAMS(( int Line, char *Var, char *Arg ));
71 static void Handle_CHANNEL PARAMS(( int Line, char *Var, char *Arg ));
72
73 static void Config_Error PARAMS(( const int Level, const char *Format, ... ));
74
75 static void Config_Error_NaN PARAMS(( const int LINE, const char *Value ));
76 static void Config_Error_Section PARAMS(( const int Line, const char *Item,
77                                           const char *Section ));
78 static void Config_Error_TooLong PARAMS(( const int LINE, const char *Value ));
79
80 static void Init_Server_Struct PARAMS(( CONF_SERVER *Server ));
81
82
83 #ifdef WANT_IPV6
84 #define DEFAULT_LISTEN_ADDRSTR "::,0.0.0.0"
85 #else
86 #define DEFAULT_LISTEN_ADDRSTR "0.0.0.0"
87 #endif
88
89
90 #ifdef SSL_SUPPORT
91
92 struct SSLOptions Conf_SSLOptions;
93
94 /**
95  * Initialize SSL configuration.
96  */
97 static void
98 ConfSSL_Init(void)
99 {
100         free(Conf_SSLOptions.KeyFile);
101         Conf_SSLOptions.KeyFile = NULL;
102
103         free(Conf_SSLOptions.CertFile);
104         Conf_SSLOptions.CertFile = NULL;
105
106         free(Conf_SSLOptions.DHFile);
107         Conf_SSLOptions.DHFile = NULL;
108         array_free_wipe(&Conf_SSLOptions.KeyFilePassword);
109 }
110
111 /**
112  * Make sure that a configured file is readable.
113  *
114  * Currently, this function is only used for SSL-related options ...
115  *
116  * @param Var Configuration variable
117  * @param Filename Configured filename
118  */
119 static void
120 CheckFileReadable(const char *Var, const char *Filename)
121 {
122         FILE *fp;
123
124         fp = fopen(Filename, "r");
125         if (fp)
126                 fclose(fp);
127         else
128                 Config_Error(LOG_ERR, "Can't read \"%s\" (\"%s\"): %s",
129                              Filename, Var, strerror(errno));
130 }
131
132 #endif
133
134
135 /**
136  * Duplicate string and warn on errors.
137  *
138  * @returns Pointer to string on success, NULL otherwise.
139  */
140 static char *
141 strdup_warn(const char *str)
142 {
143         char *ptr = strdup(str);
144         if (!ptr)
145                 Config_Error(LOG_ERR,
146                              "Could not allocate memory for string: %s", str);
147         return ptr;
148 }
149
150 /**
151  * Output a comma separated list of ports (integer values).
152  */
153 static void
154 ports_puts(array *a)
155 {
156         size_t len;
157         UINT16 *ports;
158         len = array_length(a, sizeof(UINT16));
159         if (len--) {
160                 ports = (UINT16*) array_start(a);
161                 printf("%u", (unsigned int) *ports);
162                 while (len--) {
163                         ports++;
164                         printf(", %u", (unsigned int) *ports);
165                 }
166         }
167         putc('\n', stdout);
168 }
169
170 /**
171  * Parse a comma separated string into an array of port numbers (integers).
172  */
173 static void
174 ports_parse(array *a, int Line, char *Arg)
175 {
176         char *ptr;
177         int port;
178         UINT16 port16;
179
180         array_trunc(a);
181
182         ptr = strtok( Arg, "," );
183         while (ptr) {
184                 ngt_TrimStr(ptr);
185                 port = atoi(ptr);
186                 if (port > 0 && port < 0xFFFF) {
187                         port16 = (UINT16) port;
188                         if (!array_catb(a, (char*)&port16, sizeof port16))
189                                 Config_Error(LOG_ERR, "%s, line %d Could not add port number %ld: %s",
190                                                         NGIRCd_ConfFile, Line, port, strerror(errno));
191                 } else {
192                         Config_Error( LOG_ERR, "%s, line %d (section \"Global\"): Illegal port number %ld!",
193                                                                         NGIRCd_ConfFile, Line, port );
194                 }
195
196                 ptr = strtok( NULL, "," );
197         }
198 }
199
200 /**
201  * Initialize configuration module.
202  */
203 GLOBAL void
204 Conf_Init( void )
205 {
206         Read_Config( true );
207         Validate_Config(false, false);
208 }
209
210 /**
211  * "Rehash" (reload) server configuration.
212  *
213  * @returns true if configuration has been re-read, false on errors.
214  */
215 GLOBAL bool
216 Conf_Rehash( void )
217 {
218         if (!Read_Config(false))
219                 return false;
220         Validate_Config(false, true);
221
222         /* Update CLIENT structure of local server */
223         Client_SetInfo(Client_ThisServer(), Conf_ServerInfo);
224         return true;
225 }
226
227 /**
228  * Output a boolean value as "yes/no" string.
229  */
230 static const char*
231 yesno_to_str(int boolean_value)
232 {
233         if (boolean_value)
234                 return "yes";
235         return "no";
236 }
237
238 /**
239  * Free all IRC operator configuration structures.
240  */
241 static void
242 opers_free(void)
243 {
244         struct Conf_Oper *op;
245         size_t len;
246
247         len = array_length(&Conf_Opers, sizeof(*op));
248         op = array_start(&Conf_Opers);
249         while (len--) {
250                 free(op->mask);
251                 op++;
252         }
253         array_free(&Conf_Opers);
254 }
255
256 /**
257  * Output all IRC operator configuration structures.
258  */
259 static void
260 opers_puts(void)
261 {
262         struct Conf_Oper *op;
263         size_t len;
264
265         len = array_length(&Conf_Opers, sizeof(*op));
266         op = array_start(&Conf_Opers);
267         while (len--) {
268                 assert(op->name[0]);
269
270                 puts("[OPERATOR]");
271                 printf("  Name = %s\n", op->name);
272                 printf("  Password = %s\n", op->pwd);
273                 printf("  Mask = %s\n\n", op->mask ? op->mask : "");
274                 op++;
275         }
276 }
277
278 /**
279  * Read configuration, validate and output it.
280  *
281  * This function waits for a keypress of the user when stdin/stdout are valid
282  * tty's ("you can read our nice message and we can read in your keypress").
283  *
284  * @return      0 on succes, 1 on failure(s); therefore the result code can
285  *              directly be used by exit() when running "ngircd --configtest".
286  */
287 GLOBAL int
288 Conf_Test( void )
289 {
290         struct passwd *pwd;
291         struct group *grp;
292         unsigned int i;
293         bool config_valid;
294         size_t predef_channel_count;
295         struct Conf_Channel *predef_chan;
296
297         Use_Log = false;
298
299         if (! Read_Config(true))
300                 return 1;
301
302         config_valid = Validate_Config(true, false);
303
304         /* Valid tty? */
305         if( isatty( fileno( stdin )) && isatty( fileno( stdout ))) {
306                 puts( "OK, press enter to see a dump of your service configuration ..." );
307                 getchar( );
308         } else {
309                 puts( "Ok, dump of your server configuration follows:\n" );
310         }
311
312         puts("[GLOBAL]");
313         printf("  Name = %s\n", Conf_ServerName);
314         printf("  AdminInfo1 = %s\n", Conf_ServerAdmin1);
315         printf("  AdminInfo2 = %s\n", Conf_ServerAdmin2);
316         printf("  AdminEMail = %s\n", Conf_ServerAdminMail);
317         printf("  Info = %s\n", Conf_ServerInfo);
318         printf("  Listen = %s\n", Conf_ListenAddress);
319         if (Using_MotdFile) {
320                 printf("  MotdFile = %s\n", Conf_MotdFile);
321                 printf("  MotdPhrase =\n");
322         } else {
323                 printf("  MotdFile = \n");
324                 printf("  MotdPhrase = %s\n", array_bytes(&Conf_Motd)
325                        ? (const char*) array_start(&Conf_Motd) : "");
326         }
327 #ifndef PAM
328         printf("  Password = %s\n", Conf_ServerPwd);
329 #endif
330         printf("  PidFile = %s\n", Conf_PidFile);
331         printf("  Ports = ");
332         ports_puts(&Conf_ListenPorts);
333         grp = getgrgid(Conf_GID);
334         if (grp)
335                 printf("  ServerGID = %s\n", grp->gr_name);
336         else
337                 printf("  ServerGID = %ld\n", (long)Conf_GID);
338         pwd = getpwuid(Conf_UID);
339         if (pwd)
340                 printf("  ServerUID = %s\n", pwd->pw_name);
341         else
342                 printf("  ServerUID = %ld\n", (long)Conf_UID);
343         puts("");
344
345         puts("[LIMITS]");
346         printf("  ConnectRetry = %d\n", Conf_ConnectRetry);
347         printf("  MaxConnections = %ld\n", Conf_MaxConnections);
348         printf("  MaxConnectionsIP = %d\n", Conf_MaxConnectionsIP);
349         printf("  MaxJoins = %d\n", Conf_MaxJoins > 0 ? Conf_MaxJoins : -1);
350         printf("  MaxNickLength = %u\n", Conf_MaxNickLength - 1);
351         printf("  PingTimeout = %d\n", Conf_PingTimeout);
352         printf("  PongTimeout = %d\n", Conf_PongTimeout);
353         puts("");
354
355         puts("[OPTIONS]");
356         printf("  AllowRemoteOper = %s\n", yesno_to_str(Conf_AllowRemoteOper));
357         printf("  ChrootDir = %s\n", Conf_Chroot);
358         printf("  CloakHost = %s\n", Conf_CloakHost);
359         printf("  CloakUserToNick = %s\n", yesno_to_str(Conf_CloakUserToNick));
360 #ifdef WANT_IPV6
361         printf("  ConnectIPv4 = %s\n", yesno_to_str(Conf_ConnectIPv6));
362         printf("  ConnectIPv6 = %s\n", yesno_to_str(Conf_ConnectIPv4));
363 #endif
364         printf("  DNS = %s\n", yesno_to_str(Conf_DNS));
365 #ifdef IDENT
366         printf("  Ident = %s\n", yesno_to_str(Conf_Ident));
367 #endif
368         printf("  NoticeAuth = %s\n", yesno_to_str(Conf_NoticeAuth));
369         printf("  OperCanUseMode = %s\n", yesno_to_str(Conf_OperCanMode));
370         printf("  OperServerMode = %s\n", yesno_to_str(Conf_OperServerMode));
371 #ifdef PAM
372         printf("  PAM = %s\n", yesno_to_str(Conf_PAM));
373 #endif
374         printf("  PredefChannelsOnly = %s\n", yesno_to_str(Conf_PredefChannelsOnly));
375 #ifndef STRICT_RFC
376         printf("  RequireAuthPing = %s\n", yesno_to_str(Conf_AuthPing));
377 #endif
378 #ifdef SSL_SUPPORT
379         printf("  SSLCertFile = %s\n", Conf_SSLOptions.CertFile);
380         printf("  SSLDHFile = %s\n", Conf_SSLOptions.DHFile);
381         printf("  SSLKeyFile = %s\n", Conf_SSLOptions.KeyFile);
382         if (array_bytes(&Conf_SSLOptions.KeyFilePassword))
383                 puts("  SSLKeyFilePassword = <secret>");
384         else
385                 puts("  SSLKeyFilePassword = ");
386         array_free_wipe(&Conf_SSLOptions.KeyFilePassword);
387         printf("  SSLPorts = ");
388         ports_puts(&Conf_SSLOptions.ListenPorts);
389 #endif
390 #ifdef SYSLOG
391         printf("  SyslogFacility = %s\n",
392                ngt_SyslogFacilityName(Conf_SyslogFacility));
393 #endif
394         printf("  WebircPassword = %s\n", Conf_WebircPwd);
395         puts("");
396
397         opers_puts();
398
399         for( i = 0; i < MAX_SERVERS; i++ ) {
400                 if( ! Conf_Server[i].name[0] ) continue;
401
402                 /* Valid "Server" section */
403                 puts( "[SERVER]" );
404                 printf( "  Name = %s\n", Conf_Server[i].name );
405                 printf( "  Host = %s\n", Conf_Server[i].host );
406                 printf( "  Port = %u\n", (unsigned int)Conf_Server[i].port );
407 #ifdef SSL_SUPPORT
408                 printf( "  SSLConnect = %s\n", Conf_Server[i].SSLConnect?"yes":"no");
409 #endif
410                 printf( "  MyPassword = %s\n", Conf_Server[i].pwd_in );
411                 printf( "  PeerPassword = %s\n", Conf_Server[i].pwd_out );
412                 printf( "  ServiceMask = %s\n", Conf_Server[i].svs_mask);
413                 printf( "  Group = %d\n", Conf_Server[i].group );
414                 printf( "  Passive = %s\n\n", Conf_Server[i].flags & CONF_SFLAG_DISABLED ? "yes" : "no");
415         }
416
417         predef_channel_count = array_length(&Conf_Channels, sizeof(*predef_chan));
418         predef_chan = array_start(&Conf_Channels);
419
420         for (i = 0; i < predef_channel_count; i++, predef_chan++) {
421                 if (!predef_chan->name[0])
422                         continue;
423
424                 /* Valid "Channel" section */
425                 puts( "[CHANNEL]" );
426                 printf("  Name = %s\n", predef_chan->name);
427                 printf("  Modes = %s\n", predef_chan->modes);
428                 printf("  Key = %s\n", predef_chan->key);
429                 printf("  MaxUsers = %lu\n", predef_chan->maxusers);
430                 printf("  Topic = %s\n", predef_chan->topic);
431                 printf("  KeyFile = %s\n\n", predef_chan->keyfile);
432         }
433
434         return (config_valid ? 0 : 1);
435 }
436
437 /**
438  * Remove connection information from configured server.
439  *
440  * If the server is set as "once", delete it from our configuration;
441  * otherwise set the time for the next connection attempt.
442  *
443  * Non-server connections will be silently ignored.
444  */
445 GLOBAL void
446 Conf_UnsetServer( CONN_ID Idx )
447 {
448         int i;
449         time_t t;
450
451         /* Check all our configured servers */
452         for( i = 0; i < MAX_SERVERS; i++ ) {
453                 if( Conf_Server[i].conn_id != Idx ) continue;
454
455                 /* Gotcha! Mark server configuration as "unused": */
456                 Conf_Server[i].conn_id = NONE;
457
458                 if( Conf_Server[i].flags & CONF_SFLAG_ONCE ) {
459                         /* Delete configuration here */
460                         Init_Server_Struct( &Conf_Server[i] );
461                 } else {
462                         /* Set time for next connect attempt */
463                         t = time(NULL);
464                         if (Conf_Server[i].lasttry < t - Conf_ConnectRetry) {
465                                 /* The connection has been "long", so we don't
466                                  * require the next attempt to be delayed. */
467                                 Conf_Server[i].lasttry =
468                                         t - Conf_ConnectRetry + RECONNECT_DELAY;
469                         } else
470                                 Conf_Server[i].lasttry = t;
471                 }
472         }
473 }
474
475 /**
476  * Set connection information for specified configured server.
477  */
478 GLOBAL void
479 Conf_SetServer( int ConfServer, CONN_ID Idx )
480 {
481         assert( ConfServer > NONE );
482         assert( Idx > NONE );
483
484         Conf_Server[ConfServer].conn_id = Idx;
485 }
486
487 /**
488  * Get index of server in configuration structure.
489  */
490 GLOBAL int
491 Conf_GetServer( CONN_ID Idx )
492 {
493         int i = 0;
494
495         assert( Idx > NONE );
496
497         for( i = 0; i < MAX_SERVERS; i++ ) {
498                 if( Conf_Server[i].conn_id == Idx ) return i;
499         }
500         return NONE;
501 }
502
503 /**
504  * Enable a server by name and adjust its port number.
505  *
506  * @returns     true if a server has been enabled and now has a valid port
507  *              number and host name for outgoing connections.
508  */
509 GLOBAL bool
510 Conf_EnableServer( const char *Name, UINT16 Port )
511 {
512         int i;
513
514         assert( Name != NULL );
515         for( i = 0; i < MAX_SERVERS; i++ ) {
516                 if( strcasecmp( Conf_Server[i].name, Name ) == 0 ) {
517                         /* Gotcha! Set port and enable server: */
518                         Conf_Server[i].port = Port;
519                         Conf_Server[i].flags &= ~CONF_SFLAG_DISABLED;
520                         return (Conf_Server[i].port && Conf_Server[i].host[0]);
521                 }
522         }
523         return false;
524 }
525
526 /**
527  * Enable a server by name.
528  *
529  * The server is only usable as outgoing server, if it has set a valid port
530  * number for outgoing connections!
531  * If not, you have to use Conf_EnableServer() function to make it available.
532  *
533  * @returns     true if a server has been enabled; false otherwise.
534  */
535 GLOBAL bool
536 Conf_EnablePassiveServer(const char *Name)
537 {
538         int i;
539
540         assert( Name != NULL );
541         for (i = 0; i < MAX_SERVERS; i++) {
542                 if ((strcasecmp( Conf_Server[i].name, Name ) == 0)
543                     && (Conf_Server[i].port > 0)) {
544                         /* BINGO! Enable server */
545                         Conf_Server[i].flags &= ~CONF_SFLAG_DISABLED;
546                         return true;
547                 }
548         }
549         return false;
550 }
551
552 /**
553  * Disable a server by name.
554  * An already established connection will be disconnected.
555  *
556  * @returns     true if a server was found and has been disabled.
557  */
558 GLOBAL bool
559 Conf_DisableServer( const char *Name )
560 {
561         int i;
562
563         assert( Name != NULL );
564         for( i = 0; i < MAX_SERVERS; i++ ) {
565                 if( strcasecmp( Conf_Server[i].name, Name ) == 0 ) {
566                         /* Gotcha! Disable and disconnect server: */
567                         Conf_Server[i].flags |= CONF_SFLAG_DISABLED;
568                         if( Conf_Server[i].conn_id > NONE )
569                                 Conn_Close(Conf_Server[i].conn_id, NULL,
570                                            "Server link terminated on operator request",
571                                            true);
572                         return true;
573                 }
574         }
575         return false;
576 }
577
578 /**
579  * Add a new remote server to our configuration.
580  *
581  * @param Name          Name of the new server.
582  * @param Port          Port number to connect to or 0 for incoming connections.
583  * @param Host          Host name to connect to.
584  * @param MyPwd         Password that will be sent to the peer.
585  * @param PeerPwd       Password that must be received from the peer.
586  * @returns             true if the new server has been added; false otherwise.
587  */
588 GLOBAL bool
589 Conf_AddServer(const char *Name, UINT16 Port, const char *Host,
590                const char *MyPwd, const char *PeerPwd)
591 {
592         int i;
593
594         assert( Name != NULL );
595         assert( Host != NULL );
596         assert( MyPwd != NULL );
597         assert( PeerPwd != NULL );
598
599         /* Search unused item in server configuration structure */
600         for( i = 0; i < MAX_SERVERS; i++ ) {
601                 /* Is this item used? */
602                 if( ! Conf_Server[i].name[0] ) break;
603         }
604         if( i >= MAX_SERVERS ) return false;
605
606         Init_Server_Struct( &Conf_Server[i] );
607         strlcpy( Conf_Server[i].name, Name, sizeof( Conf_Server[i].name ));
608         strlcpy( Conf_Server[i].host, Host, sizeof( Conf_Server[i].host ));
609         strlcpy( Conf_Server[i].pwd_out, MyPwd, sizeof( Conf_Server[i].pwd_out ));
610         strlcpy( Conf_Server[i].pwd_in, PeerPwd, sizeof( Conf_Server[i].pwd_in ));
611         Conf_Server[i].port = Port;
612         Conf_Server[i].flags = CONF_SFLAG_ONCE;
613
614         return true;
615 }
616
617 /**
618  * Check if the given nick name is an service.
619  *
620  * @returns true if the given nick name belongs to an "IRC service".
621  */
622 GLOBAL bool
623 Conf_IsService(int ConfServer, const char *Nick)
624 {
625         return MatchCaseInsensitive(Conf_Server[ConfServer].svs_mask, Nick);
626 }
627
628 /**
629  * Initialize configuration settings with their default values.
630  */
631 static void
632 Set_Defaults(bool InitServers)
633 {
634         int i;
635
636         /* Global */
637         strcpy(Conf_ServerName, "");
638         strcpy(Conf_ServerAdmin1, "");
639         strcpy(Conf_ServerAdmin2, "");
640         strcpy(Conf_ServerAdminMail, "");
641         snprintf(Conf_ServerInfo, sizeof Conf_ServerInfo, "%s %s",
642                  PACKAGE_NAME, PACKAGE_VERSION);
643         free(Conf_ListenAddress);
644         Conf_ListenAddress = NULL;
645         array_free(&Conf_Motd);
646         strlcpy(Conf_MotdFile, SYSCONFDIR, sizeof(Conf_MotdFile));
647         strlcat(Conf_MotdFile, MOTD_FILE, sizeof(Conf_MotdFile));
648         strcpy(Conf_ServerPwd, "");
649         strlcpy(Conf_PidFile, PID_FILE, sizeof(Conf_PidFile));
650         Conf_UID = Conf_GID = 0;
651
652         /* Limits */
653         Conf_ConnectRetry = 60;
654         Conf_MaxConnections = 0;
655         Conf_MaxConnectionsIP = 5;
656         Conf_MaxJoins = 10;
657         Conf_MaxNickLength = CLIENT_NICK_LEN_DEFAULT;
658         Conf_PingTimeout = 120;
659         Conf_PongTimeout = 20;
660
661         /* Options */
662         Conf_AllowRemoteOper = false;
663 #ifndef STRICT_RFC
664         Conf_AuthPing = false;
665 #endif
666         strlcpy(Conf_Chroot, CHROOT_DIR, sizeof(Conf_Chroot));
667         strcpy(Conf_CloakHost, "");
668         Conf_CloakUserToNick = false;
669         Conf_ConnectIPv4 = true;
670 #ifdef WANT_IPV6
671         Conf_ConnectIPv6 = true;
672 #else
673         Conf_ConnectIPv6 = false;
674 #endif
675         Conf_DNS = true;
676 #ifdef IDENTAUTH
677         Conf_Ident = true;
678 #else
679         Conf_Ident = false;
680 #endif
681         Conf_NoticeAuth = false;
682         Conf_OperCanMode = false;
683         Conf_OperServerMode = false;
684 #ifdef PAM
685         Conf_PAM = true;
686 #else
687         Conf_PAM = false;
688 #endif
689         Conf_PredefChannelsOnly = false;
690 #ifdef SYSLOG
691 #ifdef LOG_LOCAL5
692         Conf_SyslogFacility = LOG_LOCAL5;
693 #else
694         Conf_SyslogFacility = 0;
695 #endif
696 #endif
697
698         /* Initialize IRC operators and channels */
699         Conf_Oper_Count = 0;
700         Conf_Channel_Count = 0;
701
702         /* Initialize server configuration structures */
703         if (InitServers) {
704                 for (i = 0; i < MAX_SERVERS;
705                      Init_Server_Struct(&Conf_Server[i++]));
706         }
707 }
708
709 /**
710  * Get number of configured listening ports.
711  *
712  * @returns The number of ports (IPv4+IPv6) on which the server should listen.
713  */
714 static bool
715 no_listenports(void)
716 {
717         size_t cnt = array_bytes(&Conf_ListenPorts);
718 #ifdef SSL_SUPPORT
719         cnt += array_bytes(&Conf_SSLOptions.ListenPorts);
720 #endif
721         return cnt == 0;
722 }
723
724 /**
725  * Read MOTD ("message of the day") file.
726  *
727  * @param filename      Name of the file to read.
728  */
729 static void
730 Read_Motd(const char *filename)
731 {
732         char line[127];
733         FILE *fp;
734
735         if (*filename == '\0')
736                 return;
737
738         fp = fopen(filename, "r");
739         if (!fp) {
740                 Config_Error(LOG_WARNING, "Can't read MOTD file \"%s\": %s",
741                                         filename, strerror(errno));
742                 return;
743         }
744
745         array_free(&Conf_Motd);
746         Using_MotdFile = true;
747
748         while (fgets(line, (int)sizeof line, fp)) {
749                 ngt_TrimLastChr( line, '\n');
750
751                 /* add text including \0 */
752                 if (!array_catb(&Conf_Motd, line, strlen(line) + 1)) {
753                         Log(LOG_WARNING, "Cannot add MOTD text: %s", strerror(errno));
754                         break;
755                 }
756         }
757         fclose(fp);
758 }
759
760 /**
761  * Read ngIRCd configuration file.
762  *
763  * Please note that this function uses exit(1) on fatal errors and therefore
764  * can result in ngIRCd terminating!
765  *
766  * @param ngircd_starting       Flag indicating if ngIRCd is starting or not.
767  * @returns                     true when the configuration file has been read
768  *                              successfully; false otherwise.
769  */
770 static bool
771 Read_Config( bool ngircd_starting )
772 {
773         char section[LINE_LEN], str[LINE_LEN], *var, *arg, *ptr;
774         const UINT16 defaultport = 6667;
775         int line, i, n;
776         FILE *fd;
777
778         /* Open configuration file */
779         fd = fopen( NGIRCd_ConfFile, "r" );
780         if( ! fd ) {
781                 /* No configuration file found! */
782                 Config_Error( LOG_ALERT, "Can't read configuration \"%s\": %s",
783                                         NGIRCd_ConfFile, strerror( errno ));
784                 if (!ngircd_starting)
785                         return false;
786                 Config_Error( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME );
787                 exit( 1 );
788         }
789
790         opers_free();
791         Set_Defaults( ngircd_starting );
792
793         Config_Error( LOG_INFO, "Reading configuration from \"%s\" ...", NGIRCd_ConfFile );
794
795         /* Clean up server configuration structure: mark all already
796          * configured servers as "once" so that they are deleted
797          * after the next disconnect and delete all unused servers.
798          * And delete all servers which are "duplicates" of servers
799          * that are already marked as "once" (such servers have been
800          * created by the last rehash but are now useless). */
801         for( i = 0; i < MAX_SERVERS; i++ ) {
802                 if( Conf_Server[i].conn_id == NONE ) Init_Server_Struct( &Conf_Server[i] );
803                 else {
804                         /* This structure is in use ... */
805                         if( Conf_Server[i].flags & CONF_SFLAG_ONCE ) {
806                                 /* Check for duplicates */
807                                 for( n = 0; n < MAX_SERVERS; n++ ) {
808                                         if( n == i ) continue;
809
810                                         if( Conf_Server[i].conn_id == Conf_Server[n].conn_id ) {
811                                                 Init_Server_Struct( &Conf_Server[n] );
812 #ifdef DEBUG
813                                                 Log(LOG_DEBUG,"Deleted unused duplicate server %d (kept %d).",
814                                                                                                 n, i );
815 #endif
816                                         }
817                                 }
818                         } else {
819                                 /* Mark server as "once" */
820                                 Conf_Server[i].flags |= CONF_SFLAG_ONCE;
821                                 Log( LOG_DEBUG, "Marked server %d as \"once\"", i );
822                         }
823                 }
824         }
825
826         /* Initialize variables */
827         line = 0;
828         strcpy( section, "" );
829         Init_Server_Struct( &New_Server );
830         New_Server_Idx = NONE;
831 #ifdef SSL_SUPPORT
832         ConfSSL_Init();
833 #endif
834         /* Read configuration file */
835         while( true ) {
836                 if( ! fgets( str, LINE_LEN, fd )) break;
837                 ngt_TrimStr( str );
838                 line++;
839
840                 /* Skip comments and empty lines */
841                 if( str[0] == ';' || str[0] == '#' || str[0] == '\0' ) continue;
842
843                 /* Is this the beginning of a new section? */
844                 if(( str[0] == '[' ) && ( str[strlen( str ) - 1] == ']' )) {
845                         strlcpy( section, str, sizeof( section ));
846                         if (strcasecmp(section, "[GLOBAL]") == 0 ||
847                             strcasecmp(section, "[LIMITS]") == 0 ||
848                             strcasecmp(section, "[OPTIONS]") == 0)
849                                 continue;
850
851                         if( strcasecmp( section, "[SERVER]" ) == 0 ) {
852                                 /* Check if there is already a server to add */
853                                 if( New_Server.name[0] ) {
854                                         /* Copy data to "real" server structure */
855                                         assert( New_Server_Idx > NONE );
856                                         Conf_Server[New_Server_Idx] = New_Server;
857                                 }
858
859                                 /* Re-init structure for new server */
860                                 Init_Server_Struct( &New_Server );
861
862                                 /* Search unused item in server configuration structure */
863                                 for( i = 0; i < MAX_SERVERS; i++ ) {
864                                         /* Is this item used? */
865                                         if( ! Conf_Server[i].name[0] ) break;
866                                 }
867                                 if( i >= MAX_SERVERS ) {
868                                         /* Oops, no free item found! */
869                                         Config_Error( LOG_ERR, "Too many servers configured." );
870                                         New_Server_Idx = NONE;
871                                 }
872                                 else New_Server_Idx = i;
873                                 continue;
874                         }
875                         if (strcasecmp(section, "[CHANNEL]") == 0) {
876                                 Conf_Channel_Count++;
877                                 continue;
878                         }
879                         if (strcasecmp(section, "[OPERATOR]") == 0) {
880                                 Conf_Oper_Count++;
881                                 continue;
882                         }
883
884                         Config_Error( LOG_ERR, "%s, line %d: Unknown section \"%s\"!", NGIRCd_ConfFile, line, section );
885                         section[0] = 0x1;
886                 }
887                 if( section[0] == 0x1 ) continue;
888
889                 /* Split line into variable name and parameters */
890                 ptr = strchr( str, '=' );
891                 if( ! ptr ) {
892                         Config_Error( LOG_ERR, "%s, line %d: Syntax error!", NGIRCd_ConfFile, line );
893                         continue;
894                 }
895                 *ptr = '\0';
896                 var = str; ngt_TrimStr( var );
897                 arg = ptr + 1; ngt_TrimStr( arg );
898
899                 if(strcasecmp(section, "[GLOBAL]") == 0)
900                         Handle_GLOBAL(line, var, arg);
901                 else if(strcasecmp(section, "[LIMITS]") == 0)
902                         Handle_LIMITS(line, var, arg);
903                 else if(strcasecmp(section, "[OPTIONS]") == 0)
904                         Handle_OPTIONS(line, var, arg);
905                 else if(strcasecmp(section, "[OPERATOR]") == 0)
906                         Handle_OPERATOR(line, var, arg);
907                 else if(strcasecmp(section, "[SERVER]") == 0)
908                         Handle_SERVER(line, var, arg);
909                 else if(strcasecmp(section, "[CHANNEL]") == 0)
910                         Handle_CHANNEL(line, var, arg);
911                 else
912                         Config_Error(LOG_ERR,
913                                      "%s, line %d: Variable \"%s\" outside section!",
914                                      NGIRCd_ConfFile, line, var);
915         }
916
917         /* Close configuration file */
918         fclose( fd );
919
920         /* Check if there is still a server to add */
921         if( New_Server.name[0] ) {
922                 /* Copy data to "real" server structure */
923                 assert( New_Server_Idx > NONE );
924                 Conf_Server[New_Server_Idx] = New_Server;
925         }
926
927         /* not a single listening port? Add default. */
928         if (no_listenports() &&
929                 !array_copyb(&Conf_ListenPorts, (char*) &defaultport, sizeof defaultport))
930         {
931                 Config_Error(LOG_ALERT, "Could not add default listening Port %u: %s",
932                                         (unsigned int) defaultport, strerror(errno));
933
934                 exit(1);
935         }
936
937         if (!Conf_ListenAddress)
938                 Conf_ListenAddress = strdup_warn(DEFAULT_LISTEN_ADDRSTR);
939
940         if (!Conf_ListenAddress) {
941                 Config_Error(LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME);
942                 exit(1);
943         }
944
945         /* No MOTD phrase configured? (re)try motd file. */
946         if (array_bytes(&Conf_Motd) == 0)
947                 Read_Motd(Conf_MotdFile);
948
949 #ifdef SSL_SUPPORT
950         /* Make sure that all SSL-related files are readable */
951         CheckFileReadable("SSLCertFile", Conf_SSLOptions.CertFile);
952         CheckFileReadable("SSLDHFile", Conf_SSLOptions.DHFile);
953         CheckFileReadable("SSLKeyFile", Conf_SSLOptions.KeyFile);
954 #endif
955
956         return true;
957 }
958
959 /**
960  * Check whether an string argument is true or false.
961  *
962  * @param Arg   Input string.
963  * @returns     true if string has been parsed as "yes"/"true"/"on".
964  */
965 static bool
966 Check_ArgIsTrue( const char *Arg )
967 {
968         if( strcasecmp( Arg, "yes" ) == 0 ) return true;
969         if( strcasecmp( Arg, "true" ) == 0 ) return true;
970         if( atoi( Arg ) != 0 ) return true;
971
972         return false;
973 }
974
975 /**
976  * Handle setting of "MaxNickLength".
977  *
978  * @param Line  Line number in configuration file.
979  * @raram Arg   Input string.
980  * @returns     New configured maximum nick name length.
981  */
982 static unsigned int
983 Handle_MaxNickLength(int Line, const char *Arg)
984 {
985         unsigned new;
986
987         new = (unsigned) atoi(Arg) + 1;
988         if (new > CLIENT_NICK_LEN) {
989                 Config_Error(LOG_WARNING,
990                              "%s, line %d: Value of \"MaxNickLength\" exceeds %u!",
991                              NGIRCd_ConfFile, Line, CLIENT_NICK_LEN - 1);
992                 return CLIENT_NICK_LEN;
993         }
994         if (new < 2) {
995                 Config_Error(LOG_WARNING,
996                              "%s, line %d: Value of \"MaxNickLength\" must be at least 1!",
997                              NGIRCd_ConfFile, Line);
998                 return 2;
999         }
1000         return new;
1001 }
1002
1003 /**
1004  * Output a warning messages if IDENT is configured but not compiled in.
1005  */
1006 static void
1007 WarnIdent(int UNUSED Line)
1008 {
1009 #ifndef IDENTAUTH
1010         if (Conf_Ident) {
1011                 /* user has enabled ident lookups explicitly, but ... */
1012                 Config_Error(LOG_WARNING,
1013                         "%s: line %d: \"Ident = yes\", but ngircd was built without IDENT support!",
1014                         NGIRCd_ConfFile, Line);
1015         }
1016 #endif
1017 }
1018
1019 /**
1020  * Output a warning messages if IPv6 is configured but not compiled in.
1021  */
1022 static void
1023 WarnIPv6(int UNUSED Line)
1024 {
1025 #ifndef WANT_IPV6
1026         if (Conf_ConnectIPv6) {
1027                 /* user has enabled IPv6 explicitly, but ... */
1028                 Config_Error(LOG_WARNING,
1029                         "%s: line %d: \"ConnectIPv6 = yes\", but ngircd was built without IPv6 support!",
1030                         NGIRCd_ConfFile, Line);
1031         }
1032 #endif
1033 }
1034
1035 /**
1036  * Output a warning messages if PAM is configured but not compiled in.
1037  */
1038 static void
1039 WarnPAM(int UNUSED Line)
1040 {
1041 #ifndef PAM
1042         if (Conf_PAM) {
1043                 Config_Error(LOG_WARNING,
1044                         "%s: line %d: \"PAM = yes\", but ngircd was built without PAM support!",
1045                         NGIRCd_ConfFile, Line);
1046         }
1047 #endif
1048 }
1049
1050 /**
1051  * Handle legacy "NoXXX" options in [GLOBAL] section.
1052  *
1053  * TODO: This function and support for "NoXXX" should be removed starting
1054  * with ngIRCd release 19! (One release after marking it "deprecated").
1055  *
1056  * @param Var   Variable name.
1057  * @param Arg   Argument string.
1058  * @returns     true if a NoXXX option has been processed; false otherwise.
1059  */
1060 static bool
1061 CheckLegacyNoOption(const char *Var, const char *Arg)
1062 {
1063         if( strcasecmp( Var, "NoDNS" ) == 0 ) {
1064                 Conf_DNS = !Check_ArgIsTrue( Arg );
1065                 return true;
1066         }
1067         if (strcasecmp(Var, "NoIdent") == 0) {
1068                 Conf_Ident = !Check_ArgIsTrue(Arg);
1069                 return true;
1070         }
1071         if(strcasecmp(Var, "NoPAM") == 0) {
1072                 Conf_PAM = !Check_ArgIsTrue(Arg);
1073                 return true;
1074         }
1075         return false;
1076 }
1077
1078 /**
1079  * Handle deprecated legacy options in [GLOBAL] section.
1080  *
1081  * TODO: This function and support for these options in the [Global] section
1082  * could be removed starting with ngIRCd release 19 (one release after
1083  * marking it "deprecated").
1084  *
1085  * @param Var   Variable name.
1086  * @param Arg   Argument string.
1087  * @returns     true if a legacy option has been processed; false otherwise.
1088  */
1089 static const char*
1090 CheckLegacyGlobalOption(int Line, char *Var, char *Arg)
1091 {
1092         if (strcasecmp(Var, "AllowRemoteOper") == 0
1093             || strcasecmp(Var, "ChrootDir") == 0
1094             || strcasecmp(Var, "ConnectIPv4") == 0
1095             || strcasecmp(Var, "ConnectIPv6") == 0
1096             || strcasecmp(Var, "OperCanUseMode") == 0
1097             || strcasecmp(Var, "OperServerMode") == 0
1098             || strcasecmp(Var, "PredefChannelsOnly") == 0
1099 #ifdef SSL_SUPPORT
1100             || strcasecmp(Var, "SSLCertFile") == 0
1101             || strcasecmp(Var, "SSLDHFile") == 0
1102             || strcasecmp(Var, "SSLKeyFile") == 0
1103             || strcasecmp(Var, "SSLKeyFilePassword") == 0
1104             || strcasecmp(Var, "SSLPorts") == 0
1105 #endif
1106             || strcasecmp(Var, "SyslogFacility") == 0
1107             || strcasecmp(Var, "WebircPassword") == 0) {
1108                 Handle_OPTIONS(Line, Var, Arg);
1109                 return "[Options]";
1110         }
1111         if (strcasecmp(Var, "ConnectRetry") == 0
1112             || strcasecmp(Var, "MaxConnections") == 0
1113             || strcasecmp(Var, "MaxConnectionsIP") == 0
1114             || strcasecmp(Var, "MaxJoins") == 0
1115             || strcasecmp(Var, "MaxNickLength") == 0
1116             || strcasecmp(Var, "PingTimeout") == 0
1117             || strcasecmp(Var, "PongTimeout") == 0) {
1118                 Handle_LIMITS(Line, Var, Arg);
1119                 return "[Limits]";
1120         }
1121
1122         return NULL;
1123 }
1124
1125 /**
1126  * Strip "no" prefix of a string.
1127  *
1128  * TODO: This function and support for "NoXXX" should be removed starting
1129  * with ngIRCd release 19! (One release after marking it "deprecated").
1130  *
1131  * @param str   Pointer to input string starting with "no".
1132  * @returns     New pointer to string without "no" prefix.
1133  */
1134 static const char *
1135 NoNo(const char *str)
1136 {
1137         assert(strncasecmp("no", str, 2) == 0 && str[2]);
1138         return str + 2;
1139 }
1140
1141 /**
1142  * Invert "boolean" string.
1143  *
1144  * TODO: This function and support for "NoXXX" should be removed starting
1145  * with ngIRCd release 19! (One release after marking it "deprecated").
1146  *
1147  * @param arg   "Boolean" input string.
1148  * @returns     Pointer to inverted "boolean string".
1149  */
1150 static const char *
1151 InvertArg(const char *arg)
1152 {
1153         return yesno_to_str(!Check_ArgIsTrue(arg));
1154 }
1155
1156 /**
1157  * Handle variable in [Global] configuration section.
1158  *
1159  * @param Line  Line numer in configuration file.
1160  * @param Var   Variable name.
1161  * @param Arg   Variable argument.
1162  */
1163 static void
1164 Handle_GLOBAL( int Line, char *Var, char *Arg )
1165 {
1166         struct passwd *pwd;
1167         struct group *grp;
1168         size_t len;
1169         const char *section;
1170
1171         assert( Line > 0 );
1172         assert( Var != NULL );
1173         assert( Arg != NULL );
1174
1175         if (strcasecmp(Var, "Name") == 0) {
1176                 len = strlcpy(Conf_ServerName, Arg, sizeof(Conf_ServerName));
1177                 if (len >= sizeof(Conf_ServerName))
1178                         Config_Error_TooLong(Line, Var);
1179                 return;
1180         }
1181         if (strcasecmp(Var, "AdminInfo1") == 0) {
1182                 len = strlcpy(Conf_ServerAdmin1, Arg, sizeof(Conf_ServerAdmin1));
1183                 if (len >= sizeof(Conf_ServerAdmin1))
1184                         Config_Error_TooLong(Line, Var);
1185                 return;
1186         }
1187         if (strcasecmp(Var, "AdminInfo2") == 0) {
1188                 len = strlcpy(Conf_ServerAdmin2, Arg, sizeof(Conf_ServerAdmin2));
1189                 if (len >= sizeof(Conf_ServerAdmin2))
1190                         Config_Error_TooLong(Line, Var);
1191                 return;
1192         }
1193         if (strcasecmp(Var, "AdminEMail") == 0) {
1194                 len = strlcpy(Conf_ServerAdminMail, Arg,
1195                         sizeof(Conf_ServerAdminMail));
1196                 if (len >= sizeof(Conf_ServerAdminMail))
1197                         Config_Error_TooLong(Line, Var);
1198                 return;
1199         }
1200         if (strcasecmp(Var, "Info") == 0) {
1201                 len = strlcpy(Conf_ServerInfo, Arg, sizeof(Conf_ServerInfo));
1202                 if (len >= sizeof(Conf_ServerInfo))
1203                         Config_Error_TooLong(Line, Var);
1204                 return;
1205         }
1206         if (strcasecmp(Var, "Listen") == 0) {
1207                 if (Conf_ListenAddress) {
1208                         Config_Error(LOG_ERR,
1209                                      "Multiple Listen= options, ignoring: %s",
1210                                      Arg);
1211                         return;
1212                 }
1213                 Conf_ListenAddress = strdup_warn(Arg);
1214                 /* If allocation fails, we're in trouble: we cannot ignore the
1215                  * error -- otherwise ngircd would listen on all interfaces. */
1216                 if (!Conf_ListenAddress) {
1217                         Config_Error(LOG_ALERT,
1218                                      "%s exiting due to fatal errors!",
1219                                      PACKAGE_NAME);
1220                         exit(1);
1221                 }
1222                 return;
1223         }
1224         if (strcasecmp(Var, "MotdFile") == 0) {
1225                 len = strlcpy(Conf_MotdFile, Arg, sizeof(Conf_MotdFile));
1226                 if (len >= sizeof(Conf_MotdFile))
1227                         Config_Error_TooLong(Line, Var);
1228                 return;
1229         }
1230         if (strcasecmp(Var, "MotdPhrase") == 0) {
1231                 len = strlen(Arg);
1232                 if (len == 0)
1233                         return;
1234                 if (len >= LINE_LEN) {
1235                         Config_Error_TooLong( Line, Var );
1236                         return;
1237                 }
1238                 if (!array_copyb(&Conf_Motd, Arg, len + 1))
1239                         Config_Error(LOG_WARNING, "%s, line %d: Could not append MotdPhrase: %s",
1240                                                         NGIRCd_ConfFile, Line, strerror(errno));
1241                 Using_MotdFile = false;
1242                 return;
1243         }
1244         if(strcasecmp(Var, "Password") == 0) {
1245                 len = strlcpy(Conf_ServerPwd, Arg, sizeof(Conf_ServerPwd));
1246                 if (len >= sizeof(Conf_ServerPwd))
1247                         Config_Error_TooLong(Line, Var);
1248                 return;
1249         }
1250         if (strcasecmp(Var, "PidFile") == 0) {
1251                 len = strlcpy(Conf_PidFile, Arg, sizeof(Conf_PidFile));
1252                 if (len >= sizeof(Conf_PidFile))
1253                         Config_Error_TooLong(Line, Var);
1254                 return;
1255         }
1256         if (strcasecmp(Var, "Ports") == 0) {
1257                 ports_parse(&Conf_ListenPorts, Line, Arg);
1258                 return;
1259         }
1260         if (strcasecmp(Var, "ServerGID") == 0) {
1261                 grp = getgrnam(Arg);
1262                 if (grp)
1263                         Conf_GID = grp->gr_gid;
1264                 else {
1265                         Conf_GID = (unsigned int)atoi(Arg);
1266                         if (!Conf_GID && strcmp(Arg, "0"))
1267                                 Config_Error_NaN(Line, Var);
1268                 }
1269                 return;
1270         }
1271         if (strcasecmp(Var, "ServerUID") == 0) {
1272                 pwd = getpwnam(Arg);
1273                 if (pwd)
1274                         Conf_UID = pwd->pw_uid;
1275                 else {
1276                         Conf_UID = (unsigned int)atoi(Arg);
1277                         if (!Conf_UID && strcmp(Arg, "0"))
1278                                 Config_Error_NaN(Line, Var);
1279                 }
1280                 return;
1281         }
1282
1283         if (CheckLegacyNoOption(Var, Arg)) {
1284                 Config_Error(LOG_WARNING, "%s, line %d: \"No\"-Prefix has been removed, use \"%s = %s\" in [FEATURES] section instead",
1285                                         NGIRCd_ConfFile, Line, NoNo(Var), InvertArg(Arg));
1286                 if (strcasecmp(Var, "NoIdent") == 0)
1287                         WarnIdent(Line);
1288                 else if (strcasecmp(Var, "NoPam") == 0)
1289                         WarnPAM(Line);
1290                 return;
1291         }
1292         if ((section = CheckLegacyGlobalOption(Line, Var, Arg))) {
1293                 /** TODO: This function and support for these options in the
1294                  * [Global] section could be removed starting with ngIRCd
1295                  * release 19 (one release after marking it "deprecated"). */
1296                 Config_Error(LOG_WARNING,
1297                              "%s, line %d (section \"Global\"): \"%s\" is deprecated here, move it to %s!",
1298                              NGIRCd_ConfFile, Line, Var, section);
1299                 return;
1300         }
1301
1302         Config_Error_Section(Line, Var, "Global");
1303 }
1304
1305 /**
1306  * Handle variable in [Limits] configuration section.
1307  *
1308  * @param Line  Line numer in configuration file.
1309  * @param Var   Variable name.
1310  * @param Arg   Variable argument.
1311  */
1312 static void
1313 Handle_LIMITS(int Line, char *Var, char *Arg)
1314 {
1315         assert(Line > 0);
1316         assert(Var != NULL);
1317         assert(Arg != NULL);
1318
1319         if (strcasecmp(Var, "ConnectRetry") == 0) {
1320                 Conf_ConnectRetry = atoi(Arg);
1321                 if (Conf_ConnectRetry < 5) {
1322                         Config_Error(LOG_WARNING,
1323                                      "%s, line %d: Value of \"ConnectRetry\" too low!",
1324                                      NGIRCd_ConfFile, Line);
1325                         Conf_ConnectRetry = 5;
1326                 }
1327                 return;
1328         }
1329         if (strcasecmp(Var, "MaxConnections") == 0) {
1330                 Conf_MaxConnections = atol(Arg);
1331                 if (!Conf_MaxConnections && strcmp(Arg, "0"))
1332                         Config_Error_NaN(Line, Var);
1333                 return;
1334         }
1335         if (strcasecmp(Var, "MaxConnectionsIP") == 0) {
1336                 Conf_MaxConnectionsIP = atoi(Arg);
1337                 if (!Conf_MaxConnectionsIP && strcmp(Arg, "0"))
1338                         Config_Error_NaN(Line, Var);
1339                 return;
1340         }
1341         if (strcasecmp(Var, "MaxJoins") == 0) {
1342                 Conf_MaxJoins = atoi(Arg);
1343                 if (!Conf_MaxJoins && strcmp(Arg, "0"))
1344                         Config_Error_NaN(Line, Var);
1345                 return;
1346         }
1347         if (strcasecmp(Var, "MaxNickLength") == 0) {
1348                 Conf_MaxNickLength = Handle_MaxNickLength(Line, Arg);
1349                 return;
1350         }
1351         if (strcasecmp(Var, "PingTimeout") == 0) {
1352                 Conf_PingTimeout = atoi(Arg);
1353                 if (Conf_PingTimeout < 5) {
1354                         Config_Error(LOG_WARNING,
1355                                      "%s, line %d: Value of \"PingTimeout\" too low!",
1356                                      NGIRCd_ConfFile, Line);
1357                         Conf_PingTimeout = 5;
1358                 }
1359                 return;
1360         }
1361         if (strcasecmp(Var, "PongTimeout") == 0) {
1362                 Conf_PongTimeout = atoi(Arg);
1363                 if (Conf_PongTimeout < 5) {
1364                         Config_Error(LOG_WARNING,
1365                                      "%s, line %d: Value of \"PongTimeout\" too low!",
1366                                      NGIRCd_ConfFile, Line);
1367                         Conf_PongTimeout = 5;
1368                 }
1369                 return;
1370         }
1371
1372         Config_Error_Section(Line, Var, "Limits");
1373 }
1374
1375 /**
1376  * Handle variable in [Options] configuration section.
1377  *
1378  * @param Line  Line numer in configuration file.
1379  * @param Var   Variable name.
1380  * @param Arg   Variable argument.
1381  */
1382 static void
1383 Handle_OPTIONS(int Line, char *Var, char *Arg)
1384 {
1385         size_t len;
1386
1387         assert(Line > 0);
1388         assert(Var != NULL);
1389         assert(Arg != NULL);
1390
1391         if (strcasecmp(Var, "AllowRemoteOper") == 0) {
1392                 Conf_AllowRemoteOper = Check_ArgIsTrue(Arg);
1393                 return;
1394         }
1395         if (strcasecmp(Var, "ChrootDir") == 0) {
1396                 len = strlcpy(Conf_Chroot, Arg, sizeof(Conf_Chroot));
1397                 if (len >= sizeof(Conf_Chroot))
1398                         Config_Error_TooLong(Line, Var);
1399                 return;
1400         }
1401         if (strcasecmp(Var, "CloakHost") == 0) {
1402                 len = strlcpy(Conf_CloakHost, Arg, sizeof(Conf_CloakHost));
1403                 if (len >= sizeof(Conf_CloakHost))
1404                         Config_Error_TooLong(Line, Var);
1405                 return;
1406         }
1407         if (strcasecmp(Var, "CloakUserToNick") == 0) {
1408                 Conf_CloakUserToNick = Check_ArgIsTrue(Arg);
1409                 return;
1410         }
1411         if (strcasecmp(Var, "ConnectIPv6") == 0) {
1412                 Conf_ConnectIPv6 = Check_ArgIsTrue(Arg);
1413                 WarnIPv6(Line);
1414                 return;
1415         }
1416         if (strcasecmp(Var, "ConnectIPv4") == 0) {
1417                 Conf_ConnectIPv4 = Check_ArgIsTrue(Arg);
1418                 return;
1419         }
1420         if (strcasecmp(Var, "DNS") == 0) {
1421                 Conf_DNS = Check_ArgIsTrue(Arg);
1422                 return;
1423         }
1424         if (strcasecmp(Var, "Ident") == 0) {
1425                 Conf_Ident = Check_ArgIsTrue(Arg);
1426                 WarnIdent(Line);
1427                 return;
1428         }
1429         if (strcasecmp(Var, "NoticeAuth") == 0) {
1430                 Conf_NoticeAuth = Check_ArgIsTrue(Arg);
1431                 return;
1432         }
1433         if (strcasecmp(Var, "OperCanUseMode") == 0) {
1434                 Conf_OperCanMode = Check_ArgIsTrue(Arg);
1435                 return;
1436         }
1437         if (strcasecmp(Var, "OperServerMode") == 0) {
1438                 Conf_OperServerMode = Check_ArgIsTrue(Arg);
1439                 return;
1440         }
1441         if (strcasecmp(Var, "PAM") == 0) {
1442                 Conf_PAM = Check_ArgIsTrue(Arg);
1443                 WarnPAM(Line);
1444                 return;
1445         }
1446         if (strcasecmp(Var, "PredefChannelsOnly") == 0) {
1447                 Conf_PredefChannelsOnly = Check_ArgIsTrue(Arg);
1448                 return;
1449         }
1450 #ifndef STRICT_RFC
1451         if (strcasecmp(Var, "RequireAuthPing") == 0) {
1452                 Conf_AuthPing = Check_ArgIsTrue(Arg);
1453                 return;
1454         }
1455 #endif
1456 #ifdef SSL_SUPPORT
1457         if (strcasecmp(Var, "SSLCertFile") == 0) {
1458                 assert(Conf_SSLOptions.CertFile == NULL);
1459                 Conf_SSLOptions.CertFile = strdup_warn(Arg);
1460                 return;
1461         }
1462         if (strcasecmp(Var, "SSLDHFile") == 0) {
1463                 assert(Conf_SSLOptions.DHFile == NULL);
1464                 Conf_SSLOptions.DHFile = strdup_warn(Arg);
1465                 return;
1466         }
1467         if (strcasecmp(Var, "SSLKeyFile") == 0) {
1468                 assert(Conf_SSLOptions.KeyFile == NULL);
1469                 Conf_SSLOptions.KeyFile = strdup_warn(Arg);
1470                 return;
1471         }
1472         if (strcasecmp(Var, "SSLKeyFilePassword") == 0) {
1473                 assert(array_bytes(&Conf_SSLOptions.KeyFilePassword) == 0);
1474                 if (!array_copys(&Conf_SSLOptions.KeyFilePassword, Arg))
1475                         Config_Error(LOG_ERR,
1476                                      "%s, line %d (section \"Global\"): Could not copy %s: %s!",
1477                                      NGIRCd_ConfFile, Line, Var,
1478                                      strerror(errno));
1479                 return;
1480         }
1481         if (strcasecmp(Var, "SSLPorts") == 0) {
1482                 ports_parse(&Conf_SSLOptions.ListenPorts, Line, Arg);
1483                 return;
1484         }
1485 #endif
1486 #ifdef SYSLOG
1487         if (strcasecmp(Var, "SyslogFacility") == 0) {
1488                 Conf_SyslogFacility = ngt_SyslogFacilityID(Arg,
1489                                                            Conf_SyslogFacility);
1490                 return;
1491         }
1492 #endif
1493         if (strcasecmp(Var, "WebircPassword") == 0) {
1494                 len = strlcpy(Conf_WebircPwd, Arg, sizeof(Conf_WebircPwd));
1495                 if (len >= sizeof(Conf_WebircPwd))
1496                         Config_Error_TooLong(Line, Var);
1497                 return;
1498         }
1499
1500         Config_Error_Section(Line, Var, "Options");
1501 }
1502
1503 /**
1504  * Handle variable in [Operator] configuration section.
1505  *
1506  * @param Line  Line numer in configuration file.
1507  * @param Var   Variable name.
1508  * @param Arg   Variable argument.
1509  */
1510 static void
1511 Handle_OPERATOR( int Line, char *Var, char *Arg )
1512 {
1513         size_t len;
1514         struct Conf_Oper *op;
1515
1516         assert( Line > 0 );
1517         assert( Var != NULL );
1518         assert( Arg != NULL );
1519         assert( Conf_Oper_Count > 0 );
1520
1521         op = array_alloc(&Conf_Opers, sizeof(*op), Conf_Oper_Count - 1);
1522         if (!op) {
1523                 Config_Error(LOG_ERR, "Could not allocate memory for operator (%d:%s = %s)", Line, Var, Arg);
1524                 return;
1525         }
1526
1527         if (strcasecmp(Var, "Name") == 0) {
1528                 /* Name of IRC operator */
1529                 len = strlcpy(op->name, Arg, sizeof(op->name));
1530                 if (len >= sizeof(op->name))
1531                                 Config_Error_TooLong(Line, Var);
1532                 return;
1533         }
1534         if (strcasecmp(Var, "Password") == 0) {
1535                 /* Password of IRC operator */
1536                 len = strlcpy(op->pwd, Arg, sizeof(op->pwd));
1537                 if (len >= sizeof(op->pwd))
1538                                 Config_Error_TooLong(Line, Var);
1539                 return;
1540         }
1541         if (strcasecmp(Var, "Mask") == 0) {
1542                 if (op->mask)
1543                         return; /* Hostname already configured */
1544                 op->mask = strdup_warn( Arg );
1545                 return;
1546         }
1547
1548         Config_Error_Section(Line, Var, "Operator");
1549 }
1550
1551 /**
1552  * Handle variable in [Server] configuration section.
1553  *
1554  * @param Line  Line numer in configuration file.
1555  * @param Var   Variable name.
1556  * @param Arg   Variable argument.
1557  */
1558 static void
1559 Handle_SERVER( int Line, char *Var, char *Arg )
1560 {
1561         long port;
1562         size_t len;
1563
1564         assert( Line > 0 );
1565         assert( Var != NULL );
1566         assert( Arg != NULL );
1567
1568         /* Ignore server block if no space is left in server configuration structure */
1569         if( New_Server_Idx <= NONE ) return;
1570
1571         if( strcasecmp( Var, "Host" ) == 0 ) {
1572                 /* Hostname of the server */
1573                 len = strlcpy( New_Server.host, Arg, sizeof( New_Server.host ));
1574                 if (len >= sizeof( New_Server.host ))
1575                         Config_Error_TooLong ( Line, Var );
1576                 return;
1577         }
1578         if( strcasecmp( Var, "Name" ) == 0 ) {
1579                 /* Name of the server ("Nick"/"ID") */
1580                 len = strlcpy( New_Server.name, Arg, sizeof( New_Server.name ));
1581                 if (len >= sizeof( New_Server.name ))
1582                         Config_Error_TooLong( Line, Var );
1583                 return;
1584         }
1585         if (strcasecmp(Var, "Bind") == 0) {
1586                 if (ng_ipaddr_init(&New_Server.bind_addr, Arg, 0))
1587                         return;
1588
1589                 Config_Error(LOG_ERR, "%s, line %d (section \"Server\"): Can't parse IP address \"%s\"",
1590                                 NGIRCd_ConfFile, Line, Arg);
1591                 return;
1592         }
1593         if( strcasecmp( Var, "MyPassword" ) == 0 ) {
1594                 /* Password of this server which is sent to the peer */
1595                 if (*Arg == ':') {
1596                         Config_Error(LOG_ERR,
1597                                 "%s, line %d (section \"Server\"): MyPassword must not start with ':'!",
1598                                                                                 NGIRCd_ConfFile, Line);
1599                 }
1600                 len = strlcpy( New_Server.pwd_in, Arg, sizeof( New_Server.pwd_in ));
1601                 if (len >= sizeof( New_Server.pwd_in ))
1602                         Config_Error_TooLong( Line, Var );
1603                 return;
1604         }
1605         if( strcasecmp( Var, "PeerPassword" ) == 0 ) {
1606                 /* Passwort of the peer which must be received */
1607                 len = strlcpy( New_Server.pwd_out, Arg, sizeof( New_Server.pwd_out ));
1608                 if (len >= sizeof( New_Server.pwd_out ))
1609                         Config_Error_TooLong( Line, Var );
1610                 return;
1611         }
1612         if( strcasecmp( Var, "Port" ) == 0 ) {
1613                 /* Port to which this server should connect */
1614                 port = atol( Arg );
1615                 if (port >= 0 && port < 0xFFFF)
1616                         New_Server.port = (UINT16)port;
1617                 else
1618                         Config_Error(LOG_ERR,
1619                                 "%s, line %d (section \"Server\"): Illegal port number %ld!",
1620                                 NGIRCd_ConfFile, Line, port );
1621                 return;
1622         }
1623 #ifdef SSL_SUPPORT
1624         if( strcasecmp( Var, "SSLConnect" ) == 0 ) {
1625                 New_Server.SSLConnect = Check_ArgIsTrue(Arg);
1626                 return;
1627         }
1628 #endif
1629         if( strcasecmp( Var, "Group" ) == 0 ) {
1630                 /* Server group */
1631                 New_Server.group = atoi( Arg );
1632                 if (!New_Server.group && strcmp(Arg, "0"))
1633                         Config_Error_NaN(Line, Var);
1634                 return;
1635         }
1636         if( strcasecmp( Var, "Passive" ) == 0 ) {
1637                 if (Check_ArgIsTrue(Arg))
1638                         New_Server.flags |= CONF_SFLAG_DISABLED;
1639                 return;
1640         }
1641         if (strcasecmp(Var, "ServiceMask") == 0) {
1642                 len = strlcpy(New_Server.svs_mask, ngt_LowerStr(Arg),
1643                               sizeof(New_Server.svs_mask));
1644                 if (len >= sizeof(New_Server.svs_mask))
1645                         Config_Error_TooLong(Line, Var);
1646                 return;
1647         }
1648
1649         Config_Error_Section(Line, Var, "Server");
1650 }
1651
1652 /**
1653  * Copy channel name into channel structure.
1654  *
1655  * If the channel name is not valid because of a missing prefix ('#', '&'),
1656  * a default prefix of '#' will be added.
1657  *
1658  * @param new_chan      New already allocated channel structure.
1659  * @param name          Name of the new channel.
1660  * @returns             true on success, false otherwise.
1661  */
1662 static bool
1663 Handle_Channelname(struct Conf_Channel *new_chan, const char *name)
1664 {
1665         size_t size = sizeof(new_chan->name);
1666         char *dest = new_chan->name;
1667
1668         if (!Channel_IsValidName(name)) {
1669                 /*
1670                  * maybe user forgot to add a '#'.
1671                  * This is only here for user convenience.
1672                  */
1673                 *dest = '#';
1674                 --size;
1675                 ++dest;
1676         }
1677         return size > strlcpy(dest, name, size);
1678 }
1679
1680 /**
1681  * Handle variable in [Channel] configuration section.
1682  *
1683  * @param Line  Line numer in configuration file.
1684  * @param Var   Variable name.
1685  * @param Arg   Variable argument.
1686  */
1687 static void
1688 Handle_CHANNEL(int Line, char *Var, char *Arg)
1689 {
1690         size_t len;
1691         size_t chancount;
1692         struct Conf_Channel *chan;
1693
1694         assert( Line > 0 );
1695         assert( Var != NULL );
1696         assert( Arg != NULL );
1697         assert(Conf_Channel_Count > 0);
1698
1699         chancount = Conf_Channel_Count - 1;
1700
1701         chan = array_alloc(&Conf_Channels, sizeof(*chan), chancount);
1702         if (!chan) {
1703                 Config_Error(LOG_ERR, "Could not allocate memory for predefined channel (%d:%s = %s)", Line, Var, Arg);
1704                 return;
1705         }
1706         if (strcasecmp(Var, "Name") == 0) {
1707                 if (!Handle_Channelname(chan, Arg))
1708                         Config_Error_TooLong(Line, Var);
1709                 return;
1710         }
1711         if (strcasecmp(Var, "Modes") == 0) {
1712                 /* Initial modes */
1713                 len = strlcpy(chan->modes, Arg, sizeof(chan->modes));
1714                 if (len >= sizeof(chan->modes))
1715                         Config_Error_TooLong( Line, Var );
1716                 return;
1717         }
1718         if( strcasecmp( Var, "Topic" ) == 0 ) {
1719                 /* Initial topic */
1720                 len = strlcpy(chan->topic, Arg, sizeof(chan->topic));
1721                 if (len >= sizeof(chan->topic))
1722                         Config_Error_TooLong( Line, Var );
1723                 return;
1724         }
1725         if( strcasecmp( Var, "Key" ) == 0 ) {
1726                 /* Initial Channel Key (mode k) */
1727                 len = strlcpy(chan->key, Arg, sizeof(chan->key));
1728                 if (len >= sizeof(chan->key))
1729                         Config_Error_TooLong(Line, Var);
1730                 return;
1731         }
1732         if( strcasecmp( Var, "MaxUsers" ) == 0 ) {
1733                 /* maximum user limit, mode l */
1734                 chan->maxusers = (unsigned long) atol(Arg);
1735                 if (!chan->maxusers && strcmp(Arg, "0"))
1736                         Config_Error_NaN(Line, Var);
1737                 return;
1738         }
1739         if (strcasecmp(Var, "KeyFile") == 0) {
1740                 /* channel keys */
1741                 len = strlcpy(chan->keyfile, Arg, sizeof(chan->keyfile));
1742                 if (len >= sizeof(chan->keyfile))
1743                         Config_Error_TooLong(Line, Var);
1744                 return;
1745         }
1746
1747         Config_Error_Section(Line, Var, "Channel");
1748 }
1749
1750 /**
1751  * Validate server configuration.
1752  *
1753  * Please note that this function uses exit(1) on fatal errors and therefore
1754  * can result in ngIRCd terminating!
1755  *
1756  * @param Configtest    true if the daemon has been called with "--configtest".
1757  * @param Rehash        true if re-reading configuration on runtime.
1758  * @returns             true if configuration is valid.
1759  */
1760 static bool
1761 Validate_Config(bool Configtest, bool Rehash)
1762 {
1763         /* Validate configuration settings. */
1764
1765 #ifdef DEBUG
1766         int i, servers, servers_once;
1767 #endif
1768         bool config_valid = true;
1769         char *ptr;
1770
1771         /* Validate configured server name, see RFC 2812 section 2.3.1 */
1772         ptr = Conf_ServerName;
1773         do {
1774                 if (*ptr >= 'a' && *ptr <= 'z') continue;
1775                 if (*ptr >= 'A' && *ptr <= 'Z') continue;
1776                 if (*ptr >= '0' && *ptr <= '9') continue;
1777                 if (ptr > Conf_ServerName) {
1778                         if (*ptr == '.' || *ptr == '-')
1779                                 continue;
1780                 }
1781                 Conf_ServerName[0] = '\0';
1782                 break;
1783         } while (*(++ptr));
1784
1785         if (!Conf_ServerName[0]) {
1786                 /* No server name configured! */
1787                 config_valid = false;
1788                 Config_Error(LOG_ALERT,
1789                              "No (valid) server name configured in \"%s\" (section 'Global': 'Name')!",
1790                              NGIRCd_ConfFile);
1791                 if (!Configtest && !Rehash) {
1792                         Config_Error(LOG_ALERT,
1793                                      "%s exiting due to fatal errors!",
1794                                      PACKAGE_NAME);
1795                         exit(1);
1796                 }
1797         }
1798
1799         if (Conf_ServerName[0] && !strchr(Conf_ServerName, '.')) {
1800                 /* No dot in server name! */
1801                 config_valid = false;
1802                 Config_Error(LOG_ALERT,
1803                              "Invalid server name configured in \"%s\" (section 'Global': 'Name'): Dot missing!",
1804                              NGIRCd_ConfFile);
1805                 if (!Configtest) {
1806                         Config_Error(LOG_ALERT,
1807                                      "%s exiting due to fatal errors!",
1808                                      PACKAGE_NAME);
1809                         exit(1);
1810                 }
1811         }
1812
1813 #ifdef STRICT_RFC
1814         if (!Conf_ServerAdminMail[0]) {
1815                 /* No administrative contact configured! */
1816                 config_valid = false;
1817                 Config_Error(LOG_ALERT,
1818                              "No administrator email address configured in \"%s\" ('AdminEMail')!",
1819                              NGIRCd_ConfFile);
1820                 if (!Configtest) {
1821                         Config_Error(LOG_ALERT,
1822                                      "%s exiting due to fatal errors!",
1823                                      PACKAGE_NAME);
1824                         exit(1);
1825                 }
1826         }
1827 #endif
1828
1829         if (!Conf_ServerAdmin1[0] && !Conf_ServerAdmin2[0]
1830             && !Conf_ServerAdminMail[0]) {
1831                 /* No administrative information configured! */
1832                 Config_Error(LOG_WARNING,
1833                              "No administrative information configured but required by RFC!");
1834         }
1835
1836 #ifdef PAM
1837         if (Conf_ServerPwd[0])
1838                 Config_Error(LOG_ERR,
1839                              "This server uses PAM, \"Password\" will be ignored!");
1840 #endif
1841
1842 #ifdef DEBUG
1843         servers = servers_once = 0;
1844         for (i = 0; i < MAX_SERVERS; i++) {
1845                 if (Conf_Server[i].name[0]) {
1846                         servers++;
1847                         if (Conf_Server[i].flags & CONF_SFLAG_ONCE)
1848                                 servers_once++;
1849                 }
1850         }
1851         Log(LOG_DEBUG,
1852             "Configuration: Operators=%d, Servers=%d[%d], Channels=%d",
1853             Conf_Oper_Count, servers, servers_once, Conf_Channel_Count);
1854 #endif
1855
1856         return config_valid;
1857 }
1858
1859 /**
1860  * Output "line too long" warning.
1861  *
1862  * @param Line  Line number in configuration file.
1863  * @param Item  Affected variable name.
1864  */
1865 static void
1866 Config_Error_TooLong ( const int Line, const char *Item )
1867 {
1868         Config_Error( LOG_WARNING, "%s, line %d: Value of \"%s\" too long!", NGIRCd_ConfFile, Line, Item );
1869 }
1870
1871 /**
1872  * Output "unknown variable" warning.
1873  *
1874  * @param Line          Line number in configuration file.
1875  * @param Item          Affected variable name.
1876  * @param Section       Section name.
1877  */
1878 static void
1879 Config_Error_Section(const int Line, const char *Item, const char *Section)
1880 {
1881         Config_Error(LOG_ERR, "%s, line %d (section \"%s\"): Unknown variable \"%s\"!",
1882                      NGIRCd_ConfFile, Line, Section, Item);
1883 }
1884
1885 /**
1886  * Output "not a number" warning.
1887  *
1888  * @param Line  Line number in configuration file.
1889  * @param Item  Affected variable name.
1890  */
1891 static void
1892 Config_Error_NaN( const int Line, const char *Item )
1893 {
1894         Config_Error( LOG_WARNING, "%s, line %d: Value of \"%s\" is not a number!",
1895                                                 NGIRCd_ConfFile, Line, Item );
1896 }
1897
1898 /**
1899  * Output configuration error to console and/or logfile.
1900  *
1901  * On runtime, the normal log functions of the daemon are used. But when
1902  * testing the configuration ("--configtest"), all messages go directly
1903  * to the console.
1904  *
1905  * @param Level         Severity level of the message.
1906  * @param Format        Format string; see printf() function.
1907  */
1908 #ifdef PROTOTYPES
1909 static void Config_Error( const int Level, const char *Format, ... )
1910 #else
1911 static void Config_Error( Level, Format, va_alist )
1912 const int Level;
1913 const char *Format;
1914 va_dcl
1915 #endif
1916 {
1917         char msg[MAX_LOG_MSG_LEN];
1918         va_list ap;
1919
1920         assert( Format != NULL );
1921
1922 #ifdef PROTOTYPES
1923         va_start( ap, Format );
1924 #else
1925         va_start( ap );
1926 #endif
1927         vsnprintf( msg, MAX_LOG_MSG_LEN, Format, ap );
1928         va_end( ap );
1929
1930         if (Use_Log) Log( Level, "%s", msg );
1931         else puts( msg );
1932 }
1933
1934 #ifdef DEBUG
1935
1936 /**
1937  * Dump internal state of the "configuration module".
1938  */
1939 GLOBAL void
1940 Conf_DebugDump(void)
1941 {
1942         int i;
1943
1944         Log(LOG_DEBUG, "Configured servers:");
1945         for (i = 0; i < MAX_SERVERS; i++) {
1946                 if (! Conf_Server[i].name[0])
1947                         continue;
1948                 Log(LOG_DEBUG,
1949                     " - %s: %s:%d, last=%ld, group=%d, flags=%d, conn=%d",
1950                     Conf_Server[i].name, Conf_Server[i].host,
1951                     Conf_Server[i].port, Conf_Server[i].lasttry,
1952                     Conf_Server[i].group, Conf_Server[i].flags,
1953                     Conf_Server[i].conn_id);
1954         }
1955 }
1956
1957 #endif
1958
1959 /**
1960  * Initialize server configuration structur to default values.
1961  *
1962  * @param Server        Pointer to server structure to initialize.
1963  */
1964 static void
1965 Init_Server_Struct( CONF_SERVER *Server )
1966 {
1967         assert( Server != NULL );
1968
1969         memset( Server, 0, sizeof (CONF_SERVER) );
1970
1971         Server->group = NONE;
1972         Server->lasttry = time( NULL ) - Conf_ConnectRetry + STARTUP_DELAY;
1973
1974         if( NGIRCd_Passive ) Server->flags = CONF_SFLAG_DISABLED;
1975
1976         Proc_InitStruct(&Server->res_stat);
1977         Server->conn_id = NONE;
1978         memset(&Server->bind_addr, 0, sizeof(&Server->bind_addr));
1979 }
1980
1981 /* -eof- */