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