2 * ngIRCd -- The Next Generation IRC Daemon
3 * Copyright (c)2001-2010 Alexander Barton (alex@barton.de)
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.
16 * Configuration management (reading, parsing & validation)
34 #include <sys/types.h>
54 static bool Use_Log = true, Using_MotdFile = true;
55 static CONF_SERVER New_Server;
56 static int New_Server_Idx;
58 static size_t Conf_Oper_Count;
59 static size_t Conf_Channel_Count;
60 static char Conf_MotdFile[FNAME_LEN];
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 ));
66 static void Handle_GLOBAL PARAMS(( int Line, char *Var, char *Arg ));
67 static void Handle_FEATURES PARAMS(( int Line, char *Var, char *Arg ));
68 static void Handle_OPERATOR PARAMS(( int Line, char *Var, char *Arg ));
69 static void Handle_SERVER PARAMS(( int Line, char *Var, char *Arg ));
70 static void Handle_CHANNEL PARAMS(( int Line, char *Var, char *Arg ));
72 static void Config_Error PARAMS(( const int Level, const char *Format, ... ));
74 static void Config_Error_NaN PARAMS(( const int LINE, const char *Value ));
75 static void Config_Error_TooLong PARAMS(( const int LINE, const char *Value ));
77 static void Init_Server_Struct PARAMS(( CONF_SERVER *Server ));
80 #define DEFAULT_LISTEN_ADDRSTR "::,0.0.0.0"
82 #define DEFAULT_LISTEN_ADDRSTR "0.0.0.0"
86 struct SSLOptions Conf_SSLOptions;
91 free(Conf_SSLOptions.KeyFile);
92 Conf_SSLOptions.KeyFile = NULL;
94 free(Conf_SSLOptions.CertFile);
95 Conf_SSLOptions.CertFile = NULL;
97 free(Conf_SSLOptions.DHFile);
98 Conf_SSLOptions.DHFile = NULL;
99 array_free_wipe(&Conf_SSLOptions.KeyFilePassword);
103 ssl_print_configvar(const char *name, const char *file)
108 printf(" %s =\n", name);
112 fp = fopen(file, "r");
116 fprintf(stderr, "ERROR: %s \"%s\": %s\n",
117 name, file, strerror(errno));
119 printf(" %s = %s\n", name, file);
128 ret = ssl_print_configvar("SSLKeyFile", Conf_SSLOptions.KeyFile);
130 if (!ssl_print_configvar("SSLCertFile", Conf_SSLOptions.CertFile))
133 if (!ssl_print_configvar("SSLDHFile", Conf_SSLOptions.DHFile))
136 if (array_bytes(&Conf_SSLOptions.KeyFilePassword))
137 puts(" SSLKeyFilePassword = <secret>");
139 array_free_wipe(&Conf_SSLOptions.KeyFilePassword);
146 strdup_warn(const char *str)
148 char *ptr = strdup(str);
150 Config_Error(LOG_ERR, "Could not allocate mem for string: %s", str);
160 len = array_length(a, sizeof(UINT16));
162 ports = (UINT16*) array_start(a);
163 printf("%u", (unsigned int) *ports);
166 printf(", %u", (unsigned int) *ports);
174 ports_parse(array *a, int Line, char *Arg)
182 /* Ports on that the server should listen. More port numbers
183 * must be separated by "," */
184 ptr = strtok( Arg, "," );
188 if (port > 0 && port < 0xFFFF) {
189 port16 = (UINT16) port;
190 if (!array_catb(a, (char*)&port16, sizeof port16))
191 Config_Error(LOG_ERR, "%s, line %d Could not add port number %ld: %s",
192 NGIRCd_ConfFile, Line, port, strerror(errno));
194 Config_Error( LOG_ERR, "%s, line %d (section \"Global\"): Illegal port number %ld!",
195 NGIRCd_ConfFile, Line, port );
198 ptr = strtok( NULL, "," );
207 Validate_Config(false, false);
214 if (!Read_Config(false))
216 Validate_Config(false, true);
218 /* Update CLIENT structure of local server */
219 Client_SetInfo(Client_ThisServer(), Conf_ServerInfo);
221 } /* Config_Rehash */
225 yesno_to_str(int boolean_value)
236 struct Conf_Oper *op;
239 len = array_length(&Conf_Opers, sizeof(*op));
240 op = array_start(&Conf_Opers);
245 array_free(&Conf_Opers);
251 struct Conf_Oper *op;
254 len = array_length(&Conf_Opers, sizeof(*op));
255 op = array_start(&Conf_Opers);
260 printf(" Name = %s\n", op->name);
261 printf(" Password = %s\n", op->pwd);
262 printf(" Mask = %s\n\n", op->mask ? op->mask : "");
271 /* Read configuration, validate and output it. */
277 size_t predef_channel_count;
278 struct Conf_Channel *predef_chan;
282 if (! Read_Config(true))
285 config_valid = Validate_Config(true, false);
287 /* If stdin and stdout ("you can read our nice message and we can
288 * read in your keypress") are valid tty's, wait for a key: */
289 if( isatty( fileno( stdin )) && isatty( fileno( stdout ))) {
290 puts( "OK, press enter to see a dump of your service configuration ..." );
293 puts( "Ok, dump of your server configuration follows:\n" );
297 printf(" Name = %s\n", Conf_ServerName);
298 printf(" Info = %s\n", Conf_ServerInfo);
300 printf(" Password = %s\n", Conf_ServerPwd);
302 printf(" WebircPassword = %s\n", Conf_WebircPwd);
303 printf(" AdminInfo1 = %s\n", Conf_ServerAdmin1);
304 printf(" AdminInfo2 = %s\n", Conf_ServerAdmin2);
305 printf(" AdminEMail = %s\n", Conf_ServerAdminMail);
306 if (Using_MotdFile) {
307 printf(" MotdFile = %s\n", Conf_MotdFile);
308 printf(" MotdPhrase =\n");
310 printf(" MotdFile = \n");
311 printf(" MotdPhrase = %s\n", array_bytes(&Conf_Motd)
312 ? (const char*) array_start(&Conf_Motd) : "");
314 printf(" ChrootDir = %s\n", Conf_Chroot);
315 printf(" PidFile = %s\n", Conf_PidFile);
316 printf(" Listen = %s\n", Conf_ListenAddress);
317 fputs(" Ports = ", stdout);
318 ports_puts(&Conf_ListenPorts);
320 fputs(" SSLPorts = ", stdout);
321 ports_puts(&Conf_SSLOptions.ListenPorts);
323 config_valid = false;
326 pwd = getpwuid(Conf_UID);
328 printf(" ServerUID = %s\n", pwd->pw_name);
330 printf(" ServerUID = %ld\n", (long)Conf_UID);
331 grp = getgrgid(Conf_GID);
333 printf(" ServerGID = %s\n", grp->gr_name);
335 printf(" ServerGID = %ld\n", (long)Conf_GID);
337 printf(" SyslogFacility = %s\n",
338 ngt_SyslogFacilityName(Conf_SyslogFacility));
340 printf(" PingTimeout = %d\n", Conf_PingTimeout);
341 printf(" PongTimeout = %d\n", Conf_PongTimeout);
342 printf(" ConnectRetry = %d\n", Conf_ConnectRetry);
343 printf(" OperCanUseMode = %s\n", yesno_to_str(Conf_OperCanMode));
344 printf(" OperServerMode = %s\n", yesno_to_str(Conf_OperServerMode));
345 printf(" AllowRemoteOper = %s\n", yesno_to_str(Conf_AllowRemoteOper));
346 printf(" PredefChannelsOnly = %s\n", yesno_to_str(Conf_PredefChannelsOnly));
348 printf(" ConnectIPv4 = %s\n", yesno_to_str(Conf_ConnectIPv6));
349 printf(" ConnectIPv6 = %s\n", yesno_to_str(Conf_ConnectIPv4));
351 printf(" MaxConnections = %ld\n", Conf_MaxConnections);
352 printf(" MaxConnectionsIP = %d\n", Conf_MaxConnectionsIP);
353 printf(" MaxJoins = %d\n", Conf_MaxJoins > 0 ? Conf_MaxJoins : -1);
354 printf(" MaxNickLength = %u\n", Conf_MaxNickLength - 1);
355 printf(" NoticeAuth = %s\n", yesno_to_str(Conf_NoticeAuth));
356 printf(" CloakHost = %s\n", Conf_CloakHost);
357 printf(" CloakUserToNick = %s\n\n", yesno_to_str(Conf_CloakUserToNick));
360 printf(" DNS = %s\n", yesno_to_str(Conf_DNS));
361 printf(" Ident = %s\n", yesno_to_str(Conf_Ident));
362 printf(" PAM = %s\n", yesno_to_str(Conf_PAM));
367 for( i = 0; i < MAX_SERVERS; i++ ) {
368 if( ! Conf_Server[i].name[0] ) continue;
370 /* Valid "Server" section */
372 printf( " Name = %s\n", Conf_Server[i].name );
373 printf( " Host = %s\n", Conf_Server[i].host );
374 printf( " Port = %u\n", (unsigned int)Conf_Server[i].port );
376 printf( " SSLConnect = %s\n", Conf_Server[i].SSLConnect?"yes":"no");
378 printf( " MyPassword = %s\n", Conf_Server[i].pwd_in );
379 printf( " PeerPassword = %s\n", Conf_Server[i].pwd_out );
380 printf( " ServiceMask = %s\n", Conf_Server[i].svs_mask);
381 printf( " Group = %d\n", Conf_Server[i].group );
382 printf( " Passive = %s\n\n", Conf_Server[i].flags & CONF_SFLAG_DISABLED ? "yes" : "no");
385 predef_channel_count = array_length(&Conf_Channels, sizeof(*predef_chan));
386 predef_chan = array_start(&Conf_Channels);
388 for (i = 0; i < predef_channel_count; i++, predef_chan++) {
389 if (!predef_chan->name[0])
392 /* Valid "Channel" section */
394 printf(" Name = %s\n", predef_chan->name);
395 printf(" Modes = %s\n", predef_chan->modes);
396 printf(" Key = %s\n", predef_chan->key);
397 printf(" MaxUsers = %lu\n", predef_chan->maxusers);
398 printf(" Topic = %s\n", predef_chan->topic);
399 printf(" KeyFile = %s\n\n", predef_chan->keyfile);
402 return (config_valid ? 0 : 1);
407 Conf_UnsetServer( CONN_ID Idx )
409 /* Set next time for next connection attempt, if this is a server
410 * link that is (still) configured here. If the server is set as
411 * "once", delete it from our configuration.
412 * Non-Server-Connections will be silently ignored. */
417 /* Check all our configured servers */
418 for( i = 0; i < MAX_SERVERS; i++ ) {
419 if( Conf_Server[i].conn_id != Idx ) continue;
421 /* Gotcha! Mark server configuration as "unused": */
422 Conf_Server[i].conn_id = NONE;
424 if( Conf_Server[i].flags & CONF_SFLAG_ONCE ) {
425 /* Delete configuration here */
426 Init_Server_Struct( &Conf_Server[i] );
428 /* Set time for next connect attempt */
430 if (Conf_Server[i].lasttry < t - Conf_ConnectRetry) {
431 /* The connection has been "long", so we don't
432 * require the next attempt to be delayed. */
433 Conf_Server[i].lasttry =
434 t - Conf_ConnectRetry + RECONNECT_DELAY;
436 Conf_Server[i].lasttry = t;
439 } /* Conf_UnsetServer */
443 Conf_SetServer( int ConfServer, CONN_ID Idx )
445 /* Set connection for specified configured server */
447 assert( ConfServer > NONE );
448 assert( Idx > NONE );
450 Conf_Server[ConfServer].conn_id = Idx;
451 } /* Conf_SetServer */
455 Conf_GetServer( CONN_ID Idx )
457 /* Get index of server in configuration structure */
461 assert( Idx > NONE );
463 for( i = 0; i < MAX_SERVERS; i++ ) {
464 if( Conf_Server[i].conn_id == Idx ) return i;
467 } /* Conf_GetServer */
471 Conf_EnableServer( const char *Name, UINT16 Port )
473 /* Enable specified server and adjust port */
477 assert( Name != NULL );
479 for( i = 0; i < MAX_SERVERS; i++ ) {
480 if( strcasecmp( Conf_Server[i].name, Name ) == 0 ) {
481 /* Gotcha! Set port and enable server: */
482 Conf_Server[i].port = Port;
483 Conf_Server[i].flags &= ~CONF_SFLAG_DISABLED;
484 return (Conf_Server[i].port && Conf_Server[i].host[0]);
488 } /* Conf_EnableServer */
492 Conf_EnablePassiveServer(const char *Name)
494 /* Enable specified server */
497 assert( Name != NULL );
498 for (i = 0; i < MAX_SERVERS; i++) {
499 if ((strcasecmp( Conf_Server[i].name, Name ) == 0) && (Conf_Server[i].port > 0)) {
500 /* BINGO! Enable server */
501 Conf_Server[i].flags &= ~CONF_SFLAG_DISABLED;
506 } /* Conf_EnablePassiveServer */
510 Conf_DisableServer( const char *Name )
512 /* Enable specified server and adjust port */
516 assert( Name != NULL );
518 for( i = 0; i < MAX_SERVERS; i++ ) {
519 if( strcasecmp( Conf_Server[i].name, Name ) == 0 ) {
520 /* Gotcha! Disable and disconnect server: */
521 Conf_Server[i].flags |= CONF_SFLAG_DISABLED;
522 if( Conf_Server[i].conn_id > NONE ) Conn_Close( Conf_Server[i].conn_id, NULL, "Server link terminated on operator request", true);
527 } /* Conf_DisableServer */
531 Conf_AddServer( const char *Name, UINT16 Port, const char *Host, const char *MyPwd, const char *PeerPwd )
533 /* Add new server to configuration */
537 assert( Name != NULL );
538 assert( Host != NULL );
539 assert( MyPwd != NULL );
540 assert( PeerPwd != NULL );
542 /* Search unused item in server configuration structure */
543 for( i = 0; i < MAX_SERVERS; i++ ) {
544 /* Is this item used? */
545 if( ! Conf_Server[i].name[0] ) break;
547 if( i >= MAX_SERVERS ) return false;
549 Init_Server_Struct( &Conf_Server[i] );
550 strlcpy( Conf_Server[i].name, Name, sizeof( Conf_Server[i].name ));
551 strlcpy( Conf_Server[i].host, Host, sizeof( Conf_Server[i].host ));
552 strlcpy( Conf_Server[i].pwd_out, MyPwd, sizeof( Conf_Server[i].pwd_out ));
553 strlcpy( Conf_Server[i].pwd_in, PeerPwd, sizeof( Conf_Server[i].pwd_in ));
554 Conf_Server[i].port = Port;
555 Conf_Server[i].flags = CONF_SFLAG_ONCE;
558 } /* Conf_AddServer */
562 * Check if the given nick name is an service
565 Conf_IsService(int ConfServer, const char *Nick)
567 return MatchCaseInsensitive(Conf_Server[ConfServer].svs_mask, Nick);
568 } /* Conf_IsService */
572 Set_Defaults_Optional(void)
588 * Initialize configuration settings with their default values.
591 Set_Defaults(bool InitServers)
595 strcpy(Conf_ServerName, "");
596 snprintf(Conf_ServerInfo, sizeof Conf_ServerInfo, "%s %s",
597 PACKAGE_NAME, PACKAGE_VERSION);
598 strcpy(Conf_ServerPwd, "");
600 strcpy(Conf_ServerAdmin1, "");
601 strcpy(Conf_ServerAdmin2, "");
602 strcpy(Conf_ServerAdminMail, "");
604 strlcpy(Conf_MotdFile, SYSCONFDIR, sizeof(Conf_MotdFile));
605 strlcat(Conf_MotdFile, MOTD_FILE, sizeof(Conf_MotdFile));
607 Conf_UID = Conf_GID = 0;
608 strlcpy(Conf_Chroot, CHROOT_DIR, sizeof(Conf_Chroot));
609 strlcpy(Conf_PidFile, PID_FILE, sizeof(Conf_PidFile));
611 free(Conf_ListenAddress);
612 Conf_ListenAddress = NULL;
614 Conf_PingTimeout = 120;
615 Conf_PongTimeout = 20;
616 Conf_ConnectRetry = 60;
618 Conf_NoticeAuth = false;
621 Conf_Channel_Count = 0;
623 Conf_OperCanMode = false;
624 Conf_OperServerMode = false;
625 Conf_AllowRemoteOper = false;
626 Conf_PredefChannelsOnly = false;
628 Conf_ConnectIPv4 = true;
629 Conf_ConnectIPv6 = true;
631 Conf_MaxConnections = 0;
632 Conf_MaxConnectionsIP = 5;
634 Conf_MaxNickLength = CLIENT_NICK_LEN_DEFAULT;
636 strcpy(Conf_CloakHost, "");
637 Conf_CloakUserToNick = false;
641 Conf_SyslogFacility = LOG_LOCAL5;
643 Conf_SyslogFacility = 0;
646 Set_Defaults_Optional();
648 /* Initialize server configuration structures */
650 for (i = 0; i < MAX_SERVERS;
651 Init_Server_Struct(&Conf_Server[i++]));
654 /* Free MOTD; this is important when reloading the configuration */
655 array_free(&Conf_Motd);
662 size_t cnt = array_bytes(&Conf_ListenPorts);
664 cnt += array_bytes(&Conf_SSLOptions.ListenPorts);
670 Read_Motd(const char *filename)
675 if (*filename == '\0')
678 fp = fopen(filename, "r");
680 Config_Error(LOG_WARNING, "Can't read MOTD file \"%s\": %s",
681 filename, strerror(errno));
685 array_free(&Conf_Motd);
686 Using_MotdFile = true;
688 while (fgets(line, (int)sizeof line, fp)) {
689 ngt_TrimLastChr( line, '\n');
691 /* add text including \0 */
692 if (!array_catb(&Conf_Motd, line, strlen(line) + 1)) {
693 Log(LOG_WARNING, "Cannot add MOTD text: %s", strerror(errno));
701 Read_Config( bool ngircd_starting )
703 /* Read configuration file. */
705 char section[LINE_LEN], str[LINE_LEN], *var, *arg, *ptr;
706 const UINT16 defaultport = 6667;
710 /* Open configuration file */
711 fd = fopen( NGIRCd_ConfFile, "r" );
713 /* No configuration file found! */
714 Config_Error( LOG_ALERT, "Can't read configuration \"%s\": %s",
715 NGIRCd_ConfFile, strerror( errno ));
716 if (!ngircd_starting)
718 Config_Error( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME );
723 Set_Defaults( ngircd_starting );
725 Config_Error( LOG_INFO, "Reading configuration from \"%s\" ...", NGIRCd_ConfFile );
727 /* Clean up server configuration structure: mark all already
728 * configured servers as "once" so that they are deleted
729 * after the next disconnect and delete all unused servers.
730 * And delete all servers which are "duplicates" of servers
731 * that are already marked as "once" (such servers have been
732 * created by the last rehash but are now useless). */
733 for( i = 0; i < MAX_SERVERS; i++ ) {
734 if( Conf_Server[i].conn_id == NONE ) Init_Server_Struct( &Conf_Server[i] );
736 /* This structure is in use ... */
737 if( Conf_Server[i].flags & CONF_SFLAG_ONCE ) {
738 /* Check for duplicates */
739 for( n = 0; n < MAX_SERVERS; n++ ) {
740 if( n == i ) continue;
742 if( Conf_Server[i].conn_id == Conf_Server[n].conn_id ) {
743 Init_Server_Struct( &Conf_Server[n] );
745 Log(LOG_DEBUG,"Deleted unused duplicate server %d (kept %d).",
751 /* Mark server as "once" */
752 Conf_Server[i].flags |= CONF_SFLAG_ONCE;
753 Log( LOG_DEBUG, "Marked server %d as \"once\"", i );
758 /* Initialize variables */
760 strcpy( section, "" );
761 Init_Server_Struct( &New_Server );
762 New_Server_Idx = NONE;
766 /* Read configuration file */
768 if( ! fgets( str, LINE_LEN, fd )) break;
772 /* Skip comments and empty lines */
773 if( str[0] == ';' || str[0] == '#' || str[0] == '\0' ) continue;
775 /* Is this the beginning of a new section? */
776 if(( str[0] == '[' ) && ( str[strlen( str ) - 1] == ']' )) {
777 strlcpy( section, str, sizeof( section ));
778 if (strcasecmp( section, "[GLOBAL]" ) == 0 ||
779 strcasecmp( section, "[FEATURES]") == 0)
782 if( strcasecmp( section, "[SERVER]" ) == 0 ) {
783 /* Check if there is already a server to add */
784 if( New_Server.name[0] ) {
785 /* Copy data to "real" server structure */
786 assert( New_Server_Idx > NONE );
787 Conf_Server[New_Server_Idx] = New_Server;
790 /* Re-init structure for new server */
791 Init_Server_Struct( &New_Server );
793 /* Search unused item in server configuration structure */
794 for( i = 0; i < MAX_SERVERS; i++ ) {
795 /* Is this item used? */
796 if( ! Conf_Server[i].name[0] ) break;
798 if( i >= MAX_SERVERS ) {
799 /* Oops, no free item found! */
800 Config_Error( LOG_ERR, "Too many servers configured." );
801 New_Server_Idx = NONE;
803 else New_Server_Idx = i;
806 if (strcasecmp(section, "[CHANNEL]") == 0) {
807 Conf_Channel_Count++;
810 if (strcasecmp(section, "[OPERATOR]") == 0) {
815 Config_Error( LOG_ERR, "%s, line %d: Unknown section \"%s\"!", NGIRCd_ConfFile, line, section );
818 if( section[0] == 0x1 ) continue;
820 /* Split line into variable name and parameters */
821 ptr = strchr( str, '=' );
823 Config_Error( LOG_ERR, "%s, line %d: Syntax error!", NGIRCd_ConfFile, line );
827 var = str; ngt_TrimStr( var );
828 arg = ptr + 1; ngt_TrimStr( arg );
830 if( strcasecmp( section, "[GLOBAL]" ) == 0 ) Handle_GLOBAL( line, var, arg );
831 else if( strcasecmp( section, "[FEATURES]" ) == 0 ) Handle_FEATURES( line, var, arg );
832 else if( strcasecmp( section, "[OPERATOR]" ) == 0 ) Handle_OPERATOR( line, var, arg );
833 else if( strcasecmp( section, "[SERVER]" ) == 0 ) Handle_SERVER( line, var, arg );
834 else if( strcasecmp( section, "[CHANNEL]" ) == 0 ) Handle_CHANNEL( line, var, arg );
835 else Config_Error( LOG_ERR, "%s, line %d: Variable \"%s\" outside section!", NGIRCd_ConfFile, line, var );
838 /* Close configuration file */
841 /* Check if there is still a server to add */
842 if( New_Server.name[0] ) {
843 /* Copy data to "real" server structure */
844 assert( New_Server_Idx > NONE );
845 Conf_Server[New_Server_Idx] = New_Server;
848 /* not a single listening port? Add default. */
849 if (no_listenports() &&
850 !array_copyb(&Conf_ListenPorts, (char*) &defaultport, sizeof defaultport))
852 Config_Error(LOG_ALERT, "Could not add default listening Port %u: %s",
853 (unsigned int) defaultport, strerror(errno));
858 if (!Conf_ListenAddress)
859 Conf_ListenAddress = strdup_warn(DEFAULT_LISTEN_ADDRSTR);
861 if (!Conf_ListenAddress) {
862 Config_Error(LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME);
866 /* No MOTD phrase configured? (re)try motd file. */
867 if (array_bytes(&Conf_Motd) == 0)
868 Read_Motd(Conf_MotdFile);
874 Check_ArgIsTrue( const char *Arg )
876 if( strcasecmp( Arg, "yes" ) == 0 ) return true;
877 if( strcasecmp( Arg, "true" ) == 0 ) return true;
878 if( atoi( Arg ) != 0 ) return true;
881 } /* Check_ArgIsTrue */
885 Handle_MaxNickLength(int Line, const char *Arg)
889 new = (unsigned) atoi(Arg) + 1;
890 if (new > CLIENT_NICK_LEN) {
891 Config_Error(LOG_WARNING,
892 "%s, line %d: Value of \"MaxNickLength\" exceeds %u!",
893 NGIRCd_ConfFile, Line, CLIENT_NICK_LEN - 1);
894 return CLIENT_NICK_LEN;
897 Config_Error(LOG_WARNING,
898 "%s, line %d: Value of \"MaxNickLength\" must be at least 1!",
899 NGIRCd_ConfFile, Line);
903 } /* Handle_MaxNickLength */
907 WarnIdent(int UNUSED Line)
911 /* user has enabled ident lookups explicitly, but ... */
912 Config_Error(LOG_WARNING,
913 "%s: line %d: %s=True, but ngircd was built without support",
914 NGIRCd_ConfFile, Line, "Ident");
920 WarnPAM(int UNUSED Line)
924 Config_Error(LOG_WARNING,
925 "%s: line %d: %s=True, but ngircd was built without support",
926 NGIRCd_ConfFile, Line, "PAM");
932 CheckLegacyNoOption(const char *Var, const char *Arg)
934 if( strcasecmp( Var, "NoDNS" ) == 0 ) {
935 Conf_DNS = !Check_ArgIsTrue( Arg );
938 if (strcasecmp(Var, "NoIdent") == 0) {
939 Conf_Ident = !Check_ArgIsTrue(Arg);
942 if(strcasecmp(Var, "NoPAM") == 0) {
943 Conf_PAM = !Check_ArgIsTrue(Arg);
950 NoNo(const char *str)
952 assert(strncasecmp("no", str, 2) == 0 && str[2]);
957 InvertArg(const char *arg)
959 return yesno_to_str(!Check_ArgIsTrue(arg));
963 Handle_GLOBAL( int Line, char *Var, char *Arg )
970 assert( Var != NULL );
971 assert( Arg != NULL );
973 if( strcasecmp( Var, "Name" ) == 0 ) {
975 len = strlcpy( Conf_ServerName, Arg, sizeof( Conf_ServerName ));
976 if (len >= sizeof( Conf_ServerName ))
977 Config_Error_TooLong( Line, Var );
980 if( strcasecmp( Var, "CloakHost" ) == 0 ) {
981 /* Client hostname */
982 len = strlcpy( Conf_CloakHost, Arg, sizeof( Conf_CloakHost ));
983 if (len >= sizeof( Conf_CloakHost ))
984 Config_Error_TooLong( Line, Var );
987 if( strcasecmp( Var, "CloakUserToNick" ) == 0 ) {
988 /* Use client nick name as user name */
989 Conf_CloakUserToNick = Check_ArgIsTrue( Arg );
992 if( strcasecmp( Var, "Info" ) == 0 ) {
993 /* Info text of server */
994 len = strlcpy( Conf_ServerInfo, Arg, sizeof( Conf_ServerInfo ));
995 if (len >= sizeof( Conf_ServerInfo ))
996 Config_Error_TooLong ( Line, Var );
999 if( strcasecmp( Var, "Password" ) == 0 ) {
1000 /* Global server password */
1001 len = strlcpy( Conf_ServerPwd, Arg, sizeof( Conf_ServerPwd ));
1002 if (len >= sizeof( Conf_ServerPwd ))
1003 Config_Error_TooLong( Line, Var );
1006 if (strcasecmp(Var, "WebircPassword") == 0) {
1007 /* Password required for WEBIRC command */
1008 len = strlcpy(Conf_WebircPwd, Arg, sizeof(Conf_WebircPwd));
1009 if (len >= sizeof(Conf_WebircPwd))
1010 Config_Error_TooLong(Line, Var);
1013 if( strcasecmp( Var, "AdminInfo1" ) == 0 ) {
1014 /* Administrative info #1 */
1015 len = strlcpy( Conf_ServerAdmin1, Arg, sizeof( Conf_ServerAdmin1 ));
1016 if (len >= sizeof( Conf_ServerAdmin1 ))
1017 Config_Error_TooLong ( Line, Var );
1020 if( strcasecmp( Var, "AdminInfo2" ) == 0 ) {
1021 /* Administrative info #2 */
1022 len = strlcpy( Conf_ServerAdmin2, Arg, sizeof( Conf_ServerAdmin2 ));
1023 if (len >= sizeof( Conf_ServerAdmin2 ))
1024 Config_Error_TooLong ( Line, Var );
1027 if( strcasecmp( Var, "AdminEMail" ) == 0 ) {
1028 /* Administrative email contact */
1029 len = strlcpy( Conf_ServerAdminMail, Arg, sizeof( Conf_ServerAdminMail ));
1030 if (len >= sizeof( Conf_ServerAdminMail ))
1031 Config_Error_TooLong( Line, Var );
1035 if( strcasecmp( Var, "Ports" ) == 0 ) {
1036 ports_parse(&Conf_ListenPorts, Line, Arg);
1039 if( strcasecmp( Var, "MotdFile" ) == 0 ) {
1040 len = strlcpy( Conf_MotdFile, Arg, sizeof( Conf_MotdFile ));
1041 if (len >= sizeof( Conf_MotdFile ))
1042 Config_Error_TooLong( Line, Var );
1045 if( strcasecmp( Var, "MotdPhrase" ) == 0 ) {
1046 /* "Message of the day" phrase (instead of file) */
1050 if (len >= LINE_LEN) {
1051 Config_Error_TooLong( Line, Var );
1054 if (!array_copyb(&Conf_Motd, Arg, len + 1))
1055 Config_Error(LOG_WARNING, "%s, line %d: Could not append MotdPhrase: %s",
1056 NGIRCd_ConfFile, Line, strerror(errno));
1057 Using_MotdFile = false;
1060 if( strcasecmp( Var, "ChrootDir" ) == 0 ) {
1061 /* directory for chroot() */
1062 len = strlcpy( Conf_Chroot, Arg, sizeof( Conf_Chroot ));
1063 if (len >= sizeof( Conf_Chroot ))
1064 Config_Error_TooLong( Line, Var );
1067 if ( strcasecmp( Var, "PidFile" ) == 0 ) {
1068 /* name of pidfile */
1069 len = strlcpy( Conf_PidFile, Arg, sizeof( Conf_PidFile ));
1070 if (len >= sizeof( Conf_PidFile ))
1071 Config_Error_TooLong( Line, Var );
1074 if( strcasecmp( Var, "ServerUID" ) == 0 ) {
1075 /* UID the daemon should switch to */
1076 pwd = getpwnam( Arg );
1077 if( pwd ) Conf_UID = pwd->pw_uid;
1079 Conf_UID = (unsigned int)atoi( Arg );
1080 if (!Conf_UID && strcmp(Arg, "0"))
1081 Config_Error_NaN(Line, Var);
1085 if( strcasecmp( Var, "ServerGID" ) == 0 ) {
1086 /* GID the daemon should use */
1087 grp = getgrnam( Arg );
1088 if( grp ) Conf_GID = grp->gr_gid;
1090 Conf_GID = (unsigned int)atoi(Arg);
1091 if (!Conf_GID && strcmp(Arg, "0"))
1092 Config_Error_NaN( Line, Var );
1096 if( strcasecmp( Var, "PingTimeout" ) == 0 ) {
1098 Conf_PingTimeout = atoi( Arg );
1099 if( Conf_PingTimeout < 5 ) {
1100 Config_Error( LOG_WARNING, "%s, line %d: Value of \"PingTimeout\" too low!",
1101 NGIRCd_ConfFile, Line );
1102 Conf_PingTimeout = 5;
1106 if( strcasecmp( Var, "PongTimeout" ) == 0 ) {
1108 Conf_PongTimeout = atoi( Arg );
1109 if( Conf_PongTimeout < 5 ) {
1110 Config_Error( LOG_WARNING, "%s, line %d: Value of \"PongTimeout\" too low!",
1111 NGIRCd_ConfFile, Line );
1112 Conf_PongTimeout = 5;
1116 if( strcasecmp( Var, "ConnectRetry" ) == 0 ) {
1117 /* Seconds between connection attempts to other servers */
1118 Conf_ConnectRetry = atoi( Arg );
1119 if( Conf_ConnectRetry < 5 ) {
1120 Config_Error( LOG_WARNING, "%s, line %d: Value of \"ConnectRetry\" too low!",
1121 NGIRCd_ConfFile, Line );
1122 Conf_ConnectRetry = 5;
1126 if( strcasecmp( Var, "PredefChannelsOnly" ) == 0 ) {
1127 /* Should we only allow pre-defined-channels? (i.e. users cannot create their own channels) */
1128 Conf_PredefChannelsOnly = Check_ArgIsTrue( Arg );
1132 if (CheckLegacyNoOption(Var, Arg)) {
1133 Config_Error(LOG_WARNING, "%s, line %d: \"No\"-Prefix has been removed, use \"%s = %s\" in [FEATURES] section instead",
1134 NGIRCd_ConfFile, Line, NoNo(Var), InvertArg(Arg));
1135 if (strcasecmp(Var, "NoIdent") == 0)
1137 else if (strcasecmp(Var, "NoPam") == 0)
1142 /* the default setting for all the WANT_IPV6 special options is 'true' */
1143 if( strcasecmp( Var, "ConnectIPv6" ) == 0 ) {
1144 /* connect to other hosts using ipv6, if they have an AAAA record? */
1145 Conf_ConnectIPv6 = Check_ArgIsTrue( Arg );
1148 if( strcasecmp( Var, "ConnectIPv4" ) == 0 ) {
1149 /* connect to other hosts using ipv4.
1150 * again, this can be used for ipv6-only setups */
1151 Conf_ConnectIPv4 = Check_ArgIsTrue( Arg );
1155 if( strcasecmp( Var, "OperCanUseMode" ) == 0 ) {
1156 /* Are IRC operators allowed to use MODE in channels they aren't Op in? */
1157 Conf_OperCanMode = Check_ArgIsTrue( Arg );
1160 if( strcasecmp( Var, "OperServerMode" ) == 0 ) {
1161 /* Mask IRC operator as if coming from the server? (ircd-irc2 compat hack) */
1162 Conf_OperServerMode = Check_ArgIsTrue( Arg );
1165 if(strcasecmp(Var, "AllowRemoteOper") == 0) {
1166 /* Are remote IRC operators allowed to control this server? */
1167 Conf_AllowRemoteOper = Check_ArgIsTrue(Arg);
1170 if( strcasecmp( Var, "MaxConnections" ) == 0 ) {
1171 /* Maximum number of connections. 0 -> "no limit". */
1172 Conf_MaxConnections = atol( Arg );
1173 if (!Conf_MaxConnections && strcmp(Arg, "0"))
1174 Config_Error_NaN(Line, Var);
1177 if( strcasecmp( Var, "MaxConnectionsIP" ) == 0 ) {
1178 /* Maximum number of simultaneous connections from one IP. 0 -> "no limit" */
1179 Conf_MaxConnectionsIP = atoi( Arg );
1180 if (!Conf_MaxConnectionsIP && strcmp(Arg, "0"))
1181 Config_Error_NaN(Line, Var);
1184 if( strcasecmp( Var, "MaxJoins" ) == 0 ) {
1185 /* Maximum number of channels a user can join. 0 -> "no limit". */
1186 Conf_MaxJoins = atoi( Arg );
1187 if (!Conf_MaxJoins && strcmp(Arg, "0"))
1188 Config_Error_NaN(Line, Var);
1191 if( strcasecmp( Var, "MaxNickLength" ) == 0 ) {
1192 /* Maximum length of a nick name; must be same on all servers
1193 * within the IRC network! */
1194 Conf_MaxNickLength = Handle_MaxNickLength(Line, Arg);
1197 if(strcasecmp(Var, "NoticeAuth") == 0) {
1198 /* send NOTICE AUTH messages to clients on connect */
1199 Conf_NoticeAuth = Check_ArgIsTrue(Arg);
1203 if( strcasecmp( Var, "Listen" ) == 0 ) {
1204 /* IP-Address to bind sockets */
1205 if (Conf_ListenAddress) {
1206 Config_Error(LOG_ERR, "Multiple Listen= options, ignoring: %s", Arg);
1209 Conf_ListenAddress = strdup_warn(Arg);
1211 * if allocation fails, we're in trouble:
1212 * we cannot ignore the error -- otherwise ngircd
1213 * would listen on all interfaces.
1215 if (!Conf_ListenAddress) {
1216 Config_Error(LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME);
1223 if( strcasecmp( Var, "SSLPorts" ) == 0 ) {
1224 ports_parse(&Conf_SSLOptions.ListenPorts, Line, Arg);
1228 if( strcasecmp( Var, "SSLKeyFile" ) == 0 ) {
1229 assert(Conf_SSLOptions.KeyFile == NULL );
1230 Conf_SSLOptions.KeyFile = strdup_warn(Arg);
1233 if( strcasecmp( Var, "SSLCertFile" ) == 0 ) {
1234 assert(Conf_SSLOptions.CertFile == NULL );
1235 Conf_SSLOptions.CertFile = strdup_warn(Arg);
1239 if( strcasecmp( Var, "SSLKeyFilePassword" ) == 0 ) {
1240 assert(array_bytes(&Conf_SSLOptions.KeyFilePassword) == 0);
1241 if (!array_copys(&Conf_SSLOptions.KeyFilePassword, Arg))
1242 Config_Error( LOG_ERR, "%s, line %d (section \"Global\"): Could not copy %s: %s!",
1243 NGIRCd_ConfFile, Line, Var, strerror(errno));
1246 if( strcasecmp( Var, "SSLDHFile" ) == 0 ) {
1247 assert(Conf_SSLOptions.DHFile == NULL);
1248 Conf_SSLOptions.DHFile = strdup_warn( Arg );
1253 if (strcasecmp(Var, "SyslogFacility") == 0) {
1254 Conf_SyslogFacility = ngt_SyslogFacilityID(Arg,
1255 Conf_SyslogFacility);
1259 Config_Error(LOG_ERR, "%s, line %d (section \"Global\"): Unknown variable \"%s\"!",
1260 NGIRCd_ConfFile, Line, Var);
1261 } /* Handle_GLOBAL */
1265 Handle_FEATURES(int Line, char *Var, char *Arg)
1268 assert( Var != NULL );
1269 assert( Arg != NULL );
1271 if( strcasecmp( Var, "DNS" ) == 0 ) {
1272 /* do reverse dns lookups when clients connect? */
1273 Conf_DNS = Check_ArgIsTrue( Arg );
1276 if (strcasecmp(Var, "Ident") == 0) {
1277 /* do IDENT lookups when clients connect? */
1278 Conf_Ident = Check_ArgIsTrue(Arg);
1282 if(strcasecmp(Var, "PAM") == 0) {
1283 /* use PAM library to authenticate users */
1284 Conf_PAM = Check_ArgIsTrue(Arg);
1289 Config_Error(LOG_ERR,
1290 "%s, line %d (section \"Features\"): Unknown variable \"%s\"!",
1291 NGIRCd_ConfFile, Line, Var);
1295 Handle_OPERATOR( int Line, char *Var, char *Arg )
1298 struct Conf_Oper *op;
1301 assert( Var != NULL );
1302 assert( Arg != NULL );
1303 assert( Conf_Oper_Count > 0 );
1305 op = array_alloc(&Conf_Opers, sizeof(*op), Conf_Oper_Count - 1);
1307 Config_Error(LOG_ERR, "Could not allocate memory for operator (%d:%s = %s)", Line, Var, Arg);
1311 if (strcasecmp(Var, "Name") == 0) {
1312 /* Name of IRC operator */
1313 len = strlcpy(op->name, Arg, sizeof(op->name));
1314 if (len >= sizeof(op->name))
1315 Config_Error_TooLong(Line, Var);
1318 if (strcasecmp(Var, "Password") == 0) {
1319 /* Password of IRC operator */
1320 len = strlcpy(op->pwd, Arg, sizeof(op->pwd));
1321 if (len >= sizeof(op->pwd))
1322 Config_Error_TooLong(Line, Var);
1325 if (strcasecmp(Var, "Mask") == 0) {
1327 return; /* Hostname already configured */
1328 op->mask = strdup_warn( Arg );
1331 Config_Error( LOG_ERR, "%s, line %d (section \"Operator\"): Unknown variable \"%s\"!",
1332 NGIRCd_ConfFile, Line, Var );
1333 } /* Handle_OPERATOR */
1337 Handle_SERVER( int Line, char *Var, char *Arg )
1343 assert( Var != NULL );
1344 assert( Arg != NULL );
1346 /* Ignore server block if no space is left in server configuration structure */
1347 if( New_Server_Idx <= NONE ) return;
1349 if( strcasecmp( Var, "Host" ) == 0 ) {
1350 /* Hostname of the server */
1351 len = strlcpy( New_Server.host, Arg, sizeof( New_Server.host ));
1352 if (len >= sizeof( New_Server.host ))
1353 Config_Error_TooLong ( Line, Var );
1356 if( strcasecmp( Var, "Name" ) == 0 ) {
1357 /* Name of the server ("Nick"/"ID") */
1358 len = strlcpy( New_Server.name, Arg, sizeof( New_Server.name ));
1359 if (len >= sizeof( New_Server.name ))
1360 Config_Error_TooLong( Line, Var );
1363 if (strcasecmp(Var, "Bind") == 0) {
1364 if (ng_ipaddr_init(&New_Server.bind_addr, Arg, 0))
1367 Config_Error(LOG_ERR, "%s, line %d (section \"Server\"): Can't parse IP address \"%s\"",
1368 NGIRCd_ConfFile, Line, Arg);
1371 if( strcasecmp( Var, "MyPassword" ) == 0 ) {
1372 /* Password of this server which is sent to the peer */
1374 Config_Error(LOG_ERR,
1375 "%s, line %d (section \"Server\"): MyPassword must not start with ':'!",
1376 NGIRCd_ConfFile, Line);
1378 len = strlcpy( New_Server.pwd_in, Arg, sizeof( New_Server.pwd_in ));
1379 if (len >= sizeof( New_Server.pwd_in ))
1380 Config_Error_TooLong( Line, Var );
1383 if( strcasecmp( Var, "PeerPassword" ) == 0 ) {
1384 /* Passwort of the peer which must be received */
1385 len = strlcpy( New_Server.pwd_out, Arg, sizeof( New_Server.pwd_out ));
1386 if (len >= sizeof( New_Server.pwd_out ))
1387 Config_Error_TooLong( Line, Var );
1390 if( strcasecmp( Var, "Port" ) == 0 ) {
1391 /* Port to which this server should connect */
1393 if (port >= 0 && port < 0xFFFF)
1394 New_Server.port = (UINT16)port;
1396 Config_Error(LOG_ERR,
1397 "%s, line %d (section \"Server\"): Illegal port number %ld!",
1398 NGIRCd_ConfFile, Line, port );
1402 if( strcasecmp( Var, "SSLConnect" ) == 0 ) {
1403 New_Server.SSLConnect = Check_ArgIsTrue(Arg);
1407 if( strcasecmp( Var, "Group" ) == 0 ) {
1409 New_Server.group = atoi( Arg );
1410 if (!New_Server.group && strcmp(Arg, "0"))
1411 Config_Error_NaN(Line, Var);
1414 if( strcasecmp( Var, "Passive" ) == 0 ) {
1415 if (Check_ArgIsTrue(Arg))
1416 New_Server.flags |= CONF_SFLAG_DISABLED;
1419 if (strcasecmp(Var, "ServiceMask") == 0) {
1420 len = strlcpy(New_Server.svs_mask, ngt_LowerStr(Arg),
1421 sizeof(New_Server.svs_mask));
1422 if (len >= sizeof(New_Server.svs_mask))
1423 Config_Error_TooLong(Line, Var);
1427 Config_Error( LOG_ERR, "%s, line %d (section \"Server\"): Unknown variable \"%s\"!",
1428 NGIRCd_ConfFile, Line, Var );
1429 } /* Handle_SERVER */
1433 Handle_Channelname(struct Conf_Channel *new_chan, const char *name)
1435 size_t size = sizeof(new_chan->name);
1436 char *dest = new_chan->name;
1438 if (!Channel_IsValidName(name)) {
1440 * maybe user forgot to add a '#'.
1441 * This is only here for user convenience.
1447 return size > strlcpy(dest, name, size);
1452 Handle_CHANNEL(int Line, char *Var, char *Arg)
1456 struct Conf_Channel *chan;
1459 assert( Var != NULL );
1460 assert( Arg != NULL );
1461 assert(Conf_Channel_Count > 0);
1463 chancount = Conf_Channel_Count - 1;
1465 chan = array_alloc(&Conf_Channels, sizeof(*chan), chancount);
1467 Config_Error(LOG_ERR, "Could not allocate memory for predefined channel (%d:%s = %s)", Line, Var, Arg);
1470 if (strcasecmp(Var, "Name") == 0) {
1471 if (!Handle_Channelname(chan, Arg))
1472 Config_Error_TooLong(Line, Var);
1475 if (strcasecmp(Var, "Modes") == 0) {
1477 len = strlcpy(chan->modes, Arg, sizeof(chan->modes));
1478 if (len >= sizeof(chan->modes))
1479 Config_Error_TooLong( Line, Var );
1482 if( strcasecmp( Var, "Topic" ) == 0 ) {
1484 len = strlcpy(chan->topic, Arg, sizeof(chan->topic));
1485 if (len >= sizeof(chan->topic))
1486 Config_Error_TooLong( Line, Var );
1489 if( strcasecmp( Var, "Key" ) == 0 ) {
1490 /* Initial Channel Key (mode k) */
1491 len = strlcpy(chan->key, Arg, sizeof(chan->key));
1492 if (len >= sizeof(chan->key))
1493 Config_Error_TooLong(Line, Var);
1496 if( strcasecmp( Var, "MaxUsers" ) == 0 ) {
1497 /* maximum user limit, mode l */
1498 chan->maxusers = (unsigned long) atol(Arg);
1499 if (!chan->maxusers && strcmp(Arg, "0"))
1500 Config_Error_NaN(Line, Var);
1503 if (strcasecmp(Var, "KeyFile") == 0) {
1505 len = strlcpy(chan->keyfile, Arg, sizeof(chan->keyfile));
1506 if (len >= sizeof(chan->keyfile))
1507 Config_Error_TooLong(Line, Var);
1511 Config_Error( LOG_ERR, "%s, line %d (section \"Channel\"): Unknown variable \"%s\"!",
1512 NGIRCd_ConfFile, Line, Var );
1513 } /* Handle_CHANNEL */
1517 Validate_Config(bool Configtest, bool Rehash)
1519 /* Validate configuration settings. */
1522 int i, servers, servers_once;
1524 bool config_valid = true;
1527 /* Validate configured server name, see RFC 2812 section 2.3.1 */
1528 ptr = Conf_ServerName;
1530 if (*ptr >= 'a' && *ptr <= 'z') continue;
1531 if (*ptr >= 'A' && *ptr <= 'Z') continue;
1532 if (*ptr >= '0' && *ptr <= '9') continue;
1533 if (ptr > Conf_ServerName) {
1534 if (*ptr == '.' || *ptr == '-')
1537 Conf_ServerName[0] = '\0';
1541 if (!Conf_ServerName[0]) {
1542 /* No server name configured! */
1543 config_valid = false;
1544 Config_Error(LOG_ALERT,
1545 "No (valid) server name configured in \"%s\" (section 'Global': 'Name')!",
1547 if (!Configtest && !Rehash) {
1548 Config_Error(LOG_ALERT,
1549 "%s exiting due to fatal errors!",
1555 if (Conf_ServerName[0] && !strchr(Conf_ServerName, '.')) {
1556 /* No dot in server name! */
1557 config_valid = false;
1558 Config_Error(LOG_ALERT,
1559 "Invalid server name configured in \"%s\" (section 'Global': 'Name'): Dot missing!",
1562 Config_Error(LOG_ALERT,
1563 "%s exiting due to fatal errors!",
1570 if (!Conf_ServerAdminMail[0]) {
1571 /* No administrative contact configured! */
1572 config_valid = false;
1573 Config_Error(LOG_ALERT,
1574 "No administrator email address configured in \"%s\" ('AdminEMail')!",
1577 Config_Error(LOG_ALERT,
1578 "%s exiting due to fatal errors!",
1585 if (!Conf_ServerAdmin1[0] && !Conf_ServerAdmin2[0]
1586 && !Conf_ServerAdminMail[0]) {
1587 /* No administrative information configured! */
1588 Config_Error(LOG_WARNING,
1589 "No administrative information configured but required by RFC!");
1593 if (Conf_ServerPwd[0])
1594 Config_Error(LOG_ERR,
1595 "This server uses PAM, \"Password\" will be ignored!");
1599 servers = servers_once = 0;
1600 for (i = 0; i < MAX_SERVERS; i++) {
1601 if (Conf_Server[i].name[0]) {
1603 if (Conf_Server[i].flags & CONF_SFLAG_ONCE)
1608 "Configuration: Operators=%d, Servers=%d[%d], Channels=%d",
1609 Conf_Oper_Count, servers, servers_once, Conf_Channel_Count);
1612 return config_valid;
1613 } /* Validate_Config */
1617 Config_Error_TooLong ( const int Line, const char *Item )
1619 Config_Error( LOG_WARNING, "%s, line %d: Value of \"%s\" too long!", NGIRCd_ConfFile, Line, Item );
1624 Config_Error_NaN( const int Line, const char *Item )
1626 Config_Error( LOG_WARNING, "%s, line %d: Value of \"%s\" is not a number!",
1627 NGIRCd_ConfFile, Line, Item );
1632 static void Config_Error( const int Level, const char *Format, ... )
1634 static void Config_Error( Level, Format, va_alist )
1640 /* Error! Write to console and/or logfile. */
1642 char msg[MAX_LOG_MSG_LEN];
1645 assert( Format != NULL );
1648 va_start( ap, Format );
1652 vsnprintf( msg, MAX_LOG_MSG_LEN, Format, ap );
1655 /* During "normal operations" the log functions of the daemon should
1656 * be used, but during testing of the configuration file, all messages
1657 * should go directly to the console: */
1658 if (Use_Log) Log( Level, "%s", msg );
1660 } /* Config_Error */
1666 Conf_DebugDump(void)
1670 Log(LOG_DEBUG, "Configured servers:");
1671 for (i = 0; i < MAX_SERVERS; i++) {
1672 if (! Conf_Server[i].name[0])
1675 " - %s: %s:%d, last=%ld, group=%d, flags=%d, conn=%d",
1676 Conf_Server[i].name, Conf_Server[i].host,
1677 Conf_Server[i].port, Conf_Server[i].lasttry,
1678 Conf_Server[i].group, Conf_Server[i].flags,
1679 Conf_Server[i].conn_id);
1681 } /* Conf_DebugDump */
1687 Init_Server_Struct( CONF_SERVER *Server )
1689 /* Initialize server configuration structur to default values */
1691 assert( Server != NULL );
1693 memset( Server, 0, sizeof (CONF_SERVER) );
1695 Server->group = NONE;
1696 Server->lasttry = time( NULL ) - Conf_ConnectRetry + STARTUP_DELAY;
1698 if( NGIRCd_Passive ) Server->flags = CONF_SFLAG_DISABLED;
1700 Proc_InitStruct(&Server->res_stat);
1701 Server->conn_id = NONE;
1702 memset(&Server->bind_addr, 0, sizeof(&Server->bind_addr));
1703 } /* Init_Server_Struct */