2 * ngIRCd -- The Next Generation IRC Daemon
3 * Copyright (c)2001-2011 Alexander Barton (alex@barton.de) and Contributors.
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_Section PARAMS(( const int Line, const char *Item,
76 const char *Section ));
77 static void Config_Error_TooLong PARAMS(( const int LINE, const char *Value ));
79 static void Init_Server_Struct PARAMS(( CONF_SERVER *Server ));
82 #define DEFAULT_LISTEN_ADDRSTR "::,0.0.0.0"
84 #define DEFAULT_LISTEN_ADDRSTR "0.0.0.0"
88 struct SSLOptions Conf_SSLOptions;
93 free(Conf_SSLOptions.KeyFile);
94 Conf_SSLOptions.KeyFile = NULL;
96 free(Conf_SSLOptions.CertFile);
97 Conf_SSLOptions.CertFile = NULL;
99 free(Conf_SSLOptions.DHFile);
100 Conf_SSLOptions.DHFile = NULL;
101 array_free_wipe(&Conf_SSLOptions.KeyFilePassword);
105 ssl_print_configvar(const char *name, const char *file)
110 printf(" %s =\n", name);
114 fp = fopen(file, "r");
118 fprintf(stderr, "ERROR: %s \"%s\": %s\n",
119 name, file, strerror(errno));
121 printf(" %s = %s\n", name, file);
130 ret = ssl_print_configvar("SSLKeyFile", Conf_SSLOptions.KeyFile);
132 if (!ssl_print_configvar("SSLCertFile", Conf_SSLOptions.CertFile))
135 if (!ssl_print_configvar("SSLDHFile", Conf_SSLOptions.DHFile))
138 if (array_bytes(&Conf_SSLOptions.KeyFilePassword))
139 puts(" SSLKeyFilePassword = <secret>");
141 array_free_wipe(&Conf_SSLOptions.KeyFilePassword);
148 strdup_warn(const char *str)
150 char *ptr = strdup(str);
152 Config_Error(LOG_ERR, "Could not allocate mem for string: %s", str);
162 len = array_length(a, sizeof(UINT16));
164 ports = (UINT16*) array_start(a);
165 printf("%u", (unsigned int) *ports);
168 printf(", %u", (unsigned int) *ports);
176 ports_parse(array *a, int Line, char *Arg)
184 /* Ports on that the server should listen. More port numbers
185 * must be separated by "," */
186 ptr = strtok( Arg, "," );
190 if (port > 0 && port < 0xFFFF) {
191 port16 = (UINT16) port;
192 if (!array_catb(a, (char*)&port16, sizeof port16))
193 Config_Error(LOG_ERR, "%s, line %d Could not add port number %ld: %s",
194 NGIRCd_ConfFile, Line, port, strerror(errno));
196 Config_Error( LOG_ERR, "%s, line %d (section \"Global\"): Illegal port number %ld!",
197 NGIRCd_ConfFile, Line, port );
200 ptr = strtok( NULL, "," );
209 Validate_Config(false, false);
216 if (!Read_Config(false))
218 Validate_Config(false, true);
220 /* Update CLIENT structure of local server */
221 Client_SetInfo(Client_ThisServer(), Conf_ServerInfo);
223 } /* Config_Rehash */
227 yesno_to_str(int boolean_value)
238 struct Conf_Oper *op;
241 len = array_length(&Conf_Opers, sizeof(*op));
242 op = array_start(&Conf_Opers);
247 array_free(&Conf_Opers);
253 struct Conf_Oper *op;
256 len = array_length(&Conf_Opers, sizeof(*op));
257 op = array_start(&Conf_Opers);
262 printf(" Name = %s\n", op->name);
263 printf(" Password = %s\n", op->pwd);
264 printf(" Mask = %s\n\n", op->mask ? op->mask : "");
273 /* Read configuration, validate and output it. */
279 size_t predef_channel_count;
280 struct Conf_Channel *predef_chan;
284 if (! Read_Config(true))
287 config_valid = Validate_Config(true, false);
289 /* If stdin and stdout ("you can read our nice message and we can
290 * read in your keypress") are valid tty's, wait for a key: */
291 if( isatty( fileno( stdin )) && isatty( fileno( stdout ))) {
292 puts( "OK, press enter to see a dump of your service configuration ..." );
295 puts( "Ok, dump of your server configuration follows:\n" );
299 printf(" Name = %s\n", Conf_ServerName);
300 printf(" Info = %s\n", Conf_ServerInfo);
302 printf(" Password = %s\n", Conf_ServerPwd);
304 printf(" WebircPassword = %s\n", Conf_WebircPwd);
305 printf(" AdminInfo1 = %s\n", Conf_ServerAdmin1);
306 printf(" AdminInfo2 = %s\n", Conf_ServerAdmin2);
307 printf(" AdminEMail = %s\n", Conf_ServerAdminMail);
308 if (Using_MotdFile) {
309 printf(" MotdFile = %s\n", Conf_MotdFile);
310 printf(" MotdPhrase =\n");
312 printf(" MotdFile = \n");
313 printf(" MotdPhrase = %s\n", array_bytes(&Conf_Motd)
314 ? (const char*) array_start(&Conf_Motd) : "");
316 printf(" ChrootDir = %s\n", Conf_Chroot);
317 printf(" PidFile = %s\n", Conf_PidFile);
318 printf(" Listen = %s\n", Conf_ListenAddress);
319 fputs(" Ports = ", stdout);
320 ports_puts(&Conf_ListenPorts);
322 fputs(" SSLPorts = ", stdout);
323 ports_puts(&Conf_SSLOptions.ListenPorts);
325 config_valid = false;
328 pwd = getpwuid(Conf_UID);
330 printf(" ServerUID = %s\n", pwd->pw_name);
332 printf(" ServerUID = %ld\n", (long)Conf_UID);
333 grp = getgrgid(Conf_GID);
335 printf(" ServerGID = %s\n", grp->gr_name);
337 printf(" ServerGID = %ld\n", (long)Conf_GID);
339 printf(" SyslogFacility = %s\n",
340 ngt_SyslogFacilityName(Conf_SyslogFacility));
342 printf(" PingTimeout = %d\n", Conf_PingTimeout);
343 printf(" PongTimeout = %d\n", Conf_PongTimeout);
344 printf(" ConnectRetry = %d\n", Conf_ConnectRetry);
345 printf(" OperCanUseMode = %s\n", yesno_to_str(Conf_OperCanMode));
346 printf(" OperServerMode = %s\n", yesno_to_str(Conf_OperServerMode));
347 printf(" AllowRemoteOper = %s\n", yesno_to_str(Conf_AllowRemoteOper));
348 printf(" PredefChannelsOnly = %s\n", yesno_to_str(Conf_PredefChannelsOnly));
350 printf(" ConnectIPv4 = %s\n", yesno_to_str(Conf_ConnectIPv6));
351 printf(" ConnectIPv6 = %s\n", yesno_to_str(Conf_ConnectIPv4));
353 printf(" MaxConnections = %ld\n", Conf_MaxConnections);
354 printf(" MaxConnectionsIP = %d\n", Conf_MaxConnectionsIP);
355 printf(" MaxJoins = %d\n", Conf_MaxJoins > 0 ? Conf_MaxJoins : -1);
356 printf(" MaxNickLength = %u\n", Conf_MaxNickLength - 1);
357 printf(" NoticeAuth = %s\n", yesno_to_str(Conf_NoticeAuth));
358 printf(" CloakHost = %s\n", Conf_CloakHost);
359 printf(" CloakUserToNick = %s\n", yesno_to_str(Conf_CloakUserToNick));
361 printf(" RequireAuthPing = %s\n", yesno_to_str(Conf_AuthPing));
364 printf("\n[FEATURES]\n");
365 printf(" DNS = %s\n", yesno_to_str(Conf_DNS));
366 printf(" Ident = %s\n", yesno_to_str(Conf_Ident));
367 printf(" PAM = %s\n", yesno_to_str(Conf_PAM));
372 for( i = 0; i < MAX_SERVERS; i++ ) {
373 if( ! Conf_Server[i].name[0] ) continue;
375 /* Valid "Server" section */
377 printf( " Name = %s\n", Conf_Server[i].name );
378 printf( " Host = %s\n", Conf_Server[i].host );
379 printf( " Port = %u\n", (unsigned int)Conf_Server[i].port );
381 printf( " SSLConnect = %s\n", Conf_Server[i].SSLConnect?"yes":"no");
383 printf( " MyPassword = %s\n", Conf_Server[i].pwd_in );
384 printf( " PeerPassword = %s\n", Conf_Server[i].pwd_out );
385 printf( " ServiceMask = %s\n", Conf_Server[i].svs_mask);
386 printf( " Group = %d\n", Conf_Server[i].group );
387 printf( " Passive = %s\n\n", Conf_Server[i].flags & CONF_SFLAG_DISABLED ? "yes" : "no");
390 predef_channel_count = array_length(&Conf_Channels, sizeof(*predef_chan));
391 predef_chan = array_start(&Conf_Channels);
393 for (i = 0; i < predef_channel_count; i++, predef_chan++) {
394 if (!predef_chan->name[0])
397 /* Valid "Channel" section */
399 printf(" Name = %s\n", predef_chan->name);
400 printf(" Modes = %s\n", predef_chan->modes);
401 printf(" Key = %s\n", predef_chan->key);
402 printf(" MaxUsers = %lu\n", predef_chan->maxusers);
403 printf(" Topic = %s\n", predef_chan->topic);
404 printf(" KeyFile = %s\n\n", predef_chan->keyfile);
407 return (config_valid ? 0 : 1);
412 Conf_UnsetServer( CONN_ID Idx )
414 /* Set next time for next connection attempt, if this is a server
415 * link that is (still) configured here. If the server is set as
416 * "once", delete it from our configuration.
417 * Non-Server-Connections will be silently ignored. */
422 /* Check all our configured servers */
423 for( i = 0; i < MAX_SERVERS; i++ ) {
424 if( Conf_Server[i].conn_id != Idx ) continue;
426 /* Gotcha! Mark server configuration as "unused": */
427 Conf_Server[i].conn_id = NONE;
429 if( Conf_Server[i].flags & CONF_SFLAG_ONCE ) {
430 /* Delete configuration here */
431 Init_Server_Struct( &Conf_Server[i] );
433 /* Set time for next connect attempt */
435 if (Conf_Server[i].lasttry < t - Conf_ConnectRetry) {
436 /* The connection has been "long", so we don't
437 * require the next attempt to be delayed. */
438 Conf_Server[i].lasttry =
439 t - Conf_ConnectRetry + RECONNECT_DELAY;
441 Conf_Server[i].lasttry = t;
444 } /* Conf_UnsetServer */
448 Conf_SetServer( int ConfServer, CONN_ID Idx )
450 /* Set connection for specified configured server */
452 assert( ConfServer > NONE );
453 assert( Idx > NONE );
455 Conf_Server[ConfServer].conn_id = Idx;
456 } /* Conf_SetServer */
460 Conf_GetServer( CONN_ID Idx )
462 /* Get index of server in configuration structure */
466 assert( Idx > NONE );
468 for( i = 0; i < MAX_SERVERS; i++ ) {
469 if( Conf_Server[i].conn_id == Idx ) return i;
472 } /* Conf_GetServer */
476 Conf_EnableServer( const char *Name, UINT16 Port )
478 /* Enable specified server and adjust port */
482 assert( Name != NULL );
484 for( i = 0; i < MAX_SERVERS; i++ ) {
485 if( strcasecmp( Conf_Server[i].name, Name ) == 0 ) {
486 /* Gotcha! Set port and enable server: */
487 Conf_Server[i].port = Port;
488 Conf_Server[i].flags &= ~CONF_SFLAG_DISABLED;
489 return (Conf_Server[i].port && Conf_Server[i].host[0]);
493 } /* Conf_EnableServer */
497 Conf_EnablePassiveServer(const char *Name)
499 /* Enable specified server */
502 assert( Name != NULL );
503 for (i = 0; i < MAX_SERVERS; i++) {
504 if ((strcasecmp( Conf_Server[i].name, Name ) == 0) && (Conf_Server[i].port > 0)) {
505 /* BINGO! Enable server */
506 Conf_Server[i].flags &= ~CONF_SFLAG_DISABLED;
511 } /* Conf_EnablePassiveServer */
515 Conf_DisableServer( const char *Name )
517 /* Enable specified server and adjust port */
521 assert( Name != NULL );
523 for( i = 0; i < MAX_SERVERS; i++ ) {
524 if( strcasecmp( Conf_Server[i].name, Name ) == 0 ) {
525 /* Gotcha! Disable and disconnect server: */
526 Conf_Server[i].flags |= CONF_SFLAG_DISABLED;
527 if( Conf_Server[i].conn_id > NONE ) Conn_Close( Conf_Server[i].conn_id, NULL, "Server link terminated on operator request", true);
532 } /* Conf_DisableServer */
536 Conf_AddServer( const char *Name, UINT16 Port, const char *Host, const char *MyPwd, const char *PeerPwd )
538 /* Add new server to configuration */
542 assert( Name != NULL );
543 assert( Host != NULL );
544 assert( MyPwd != NULL );
545 assert( PeerPwd != NULL );
547 /* Search unused item in server configuration structure */
548 for( i = 0; i < MAX_SERVERS; i++ ) {
549 /* Is this item used? */
550 if( ! Conf_Server[i].name[0] ) break;
552 if( i >= MAX_SERVERS ) return false;
554 Init_Server_Struct( &Conf_Server[i] );
555 strlcpy( Conf_Server[i].name, Name, sizeof( Conf_Server[i].name ));
556 strlcpy( Conf_Server[i].host, Host, sizeof( Conf_Server[i].host ));
557 strlcpy( Conf_Server[i].pwd_out, MyPwd, sizeof( Conf_Server[i].pwd_out ));
558 strlcpy( Conf_Server[i].pwd_in, PeerPwd, sizeof( Conf_Server[i].pwd_in ));
559 Conf_Server[i].port = Port;
560 Conf_Server[i].flags = CONF_SFLAG_ONCE;
563 } /* Conf_AddServer */
567 * Check if the given nick name is an service
570 Conf_IsService(int ConfServer, const char *Nick)
572 return MatchCaseInsensitive(Conf_Server[ConfServer].svs_mask, Nick);
573 } /* Conf_IsService */
577 Set_Defaults_Optional(void)
593 * Initialize configuration settings with their default values.
596 Set_Defaults(bool InitServers)
600 strcpy(Conf_ServerName, "");
601 snprintf(Conf_ServerInfo, sizeof Conf_ServerInfo, "%s %s",
602 PACKAGE_NAME, PACKAGE_VERSION);
603 strcpy(Conf_ServerPwd, "");
605 strcpy(Conf_ServerAdmin1, "");
606 strcpy(Conf_ServerAdmin2, "");
607 strcpy(Conf_ServerAdminMail, "");
609 strlcpy(Conf_MotdFile, SYSCONFDIR, sizeof(Conf_MotdFile));
610 strlcat(Conf_MotdFile, MOTD_FILE, sizeof(Conf_MotdFile));
612 Conf_UID = Conf_GID = 0;
613 strlcpy(Conf_Chroot, CHROOT_DIR, sizeof(Conf_Chroot));
614 strlcpy(Conf_PidFile, PID_FILE, sizeof(Conf_PidFile));
616 free(Conf_ListenAddress);
617 Conf_ListenAddress = NULL;
619 Conf_PingTimeout = 120;
620 Conf_PongTimeout = 20;
621 Conf_ConnectRetry = 60;
623 Conf_NoticeAuth = false;
626 Conf_Channel_Count = 0;
628 Conf_OperCanMode = false;
629 Conf_OperServerMode = false;
630 Conf_AllowRemoteOper = false;
631 Conf_PredefChannelsOnly = false;
633 Conf_ConnectIPv4 = true;
634 Conf_ConnectIPv6 = true;
636 Conf_MaxConnections = 0;
637 Conf_MaxConnectionsIP = 5;
639 Conf_MaxNickLength = CLIENT_NICK_LEN_DEFAULT;
641 strcpy(Conf_CloakHost, "");
642 Conf_CloakUserToNick = false;
646 Conf_SyslogFacility = LOG_LOCAL5;
648 Conf_SyslogFacility = 0;
653 Conf_AuthPing = false;
656 Set_Defaults_Optional();
658 /* Initialize server configuration structures */
660 for (i = 0; i < MAX_SERVERS;
661 Init_Server_Struct(&Conf_Server[i++]));
664 /* Free MOTD; this is important when reloading the configuration */
665 array_free(&Conf_Motd);
672 size_t cnt = array_bytes(&Conf_ListenPorts);
674 cnt += array_bytes(&Conf_SSLOptions.ListenPorts);
680 Read_Motd(const char *filename)
685 if (*filename == '\0')
688 fp = fopen(filename, "r");
690 Config_Error(LOG_WARNING, "Can't read MOTD file \"%s\": %s",
691 filename, strerror(errno));
695 array_free(&Conf_Motd);
696 Using_MotdFile = true;
698 while (fgets(line, (int)sizeof line, fp)) {
699 ngt_TrimLastChr( line, '\n');
701 /* add text including \0 */
702 if (!array_catb(&Conf_Motd, line, strlen(line) + 1)) {
703 Log(LOG_WARNING, "Cannot add MOTD text: %s", strerror(errno));
711 Read_Config( bool ngircd_starting )
713 /* Read configuration file. */
715 char section[LINE_LEN], str[LINE_LEN], *var, *arg, *ptr;
716 const UINT16 defaultport = 6667;
720 /* Open configuration file */
721 fd = fopen( NGIRCd_ConfFile, "r" );
723 /* No configuration file found! */
724 Config_Error( LOG_ALERT, "Can't read configuration \"%s\": %s",
725 NGIRCd_ConfFile, strerror( errno ));
726 if (!ngircd_starting)
728 Config_Error( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME );
733 Set_Defaults( ngircd_starting );
735 Config_Error( LOG_INFO, "Reading configuration from \"%s\" ...", NGIRCd_ConfFile );
737 /* Clean up server configuration structure: mark all already
738 * configured servers as "once" so that they are deleted
739 * after the next disconnect and delete all unused servers.
740 * And delete all servers which are "duplicates" of servers
741 * that are already marked as "once" (such servers have been
742 * created by the last rehash but are now useless). */
743 for( i = 0; i < MAX_SERVERS; i++ ) {
744 if( Conf_Server[i].conn_id == NONE ) Init_Server_Struct( &Conf_Server[i] );
746 /* This structure is in use ... */
747 if( Conf_Server[i].flags & CONF_SFLAG_ONCE ) {
748 /* Check for duplicates */
749 for( n = 0; n < MAX_SERVERS; n++ ) {
750 if( n == i ) continue;
752 if( Conf_Server[i].conn_id == Conf_Server[n].conn_id ) {
753 Init_Server_Struct( &Conf_Server[n] );
755 Log(LOG_DEBUG,"Deleted unused duplicate server %d (kept %d).",
761 /* Mark server as "once" */
762 Conf_Server[i].flags |= CONF_SFLAG_ONCE;
763 Log( LOG_DEBUG, "Marked server %d as \"once\"", i );
768 /* Initialize variables */
770 strcpy( section, "" );
771 Init_Server_Struct( &New_Server );
772 New_Server_Idx = NONE;
776 /* Read configuration file */
778 if( ! fgets( str, LINE_LEN, fd )) break;
782 /* Skip comments and empty lines */
783 if( str[0] == ';' || str[0] == '#' || str[0] == '\0' ) continue;
785 /* Is this the beginning of a new section? */
786 if(( str[0] == '[' ) && ( str[strlen( str ) - 1] == ']' )) {
787 strlcpy( section, str, sizeof( section ));
788 if (strcasecmp( section, "[GLOBAL]" ) == 0 ||
789 strcasecmp( section, "[FEATURES]") == 0)
792 if( strcasecmp( section, "[SERVER]" ) == 0 ) {
793 /* Check if there is already a server to add */
794 if( New_Server.name[0] ) {
795 /* Copy data to "real" server structure */
796 assert( New_Server_Idx > NONE );
797 Conf_Server[New_Server_Idx] = New_Server;
800 /* Re-init structure for new server */
801 Init_Server_Struct( &New_Server );
803 /* Search unused item in server configuration structure */
804 for( i = 0; i < MAX_SERVERS; i++ ) {
805 /* Is this item used? */
806 if( ! Conf_Server[i].name[0] ) break;
808 if( i >= MAX_SERVERS ) {
809 /* Oops, no free item found! */
810 Config_Error( LOG_ERR, "Too many servers configured." );
811 New_Server_Idx = NONE;
813 else New_Server_Idx = i;
816 if (strcasecmp(section, "[CHANNEL]") == 0) {
817 Conf_Channel_Count++;
820 if (strcasecmp(section, "[OPERATOR]") == 0) {
825 Config_Error( LOG_ERR, "%s, line %d: Unknown section \"%s\"!", NGIRCd_ConfFile, line, section );
828 if( section[0] == 0x1 ) continue;
830 /* Split line into variable name and parameters */
831 ptr = strchr( str, '=' );
833 Config_Error( LOG_ERR, "%s, line %d: Syntax error!", NGIRCd_ConfFile, line );
837 var = str; ngt_TrimStr( var );
838 arg = ptr + 1; ngt_TrimStr( arg );
840 if( strcasecmp( section, "[GLOBAL]" ) == 0 ) Handle_GLOBAL( line, var, arg );
841 else if( strcasecmp( section, "[FEATURES]" ) == 0 ) Handle_FEATURES( line, var, arg );
842 else if( strcasecmp( section, "[OPERATOR]" ) == 0 ) Handle_OPERATOR( line, var, arg );
843 else if( strcasecmp( section, "[SERVER]" ) == 0 ) Handle_SERVER( line, var, arg );
844 else if( strcasecmp( section, "[CHANNEL]" ) == 0 ) Handle_CHANNEL( line, var, arg );
845 else Config_Error( LOG_ERR, "%s, line %d: Variable \"%s\" outside section!", NGIRCd_ConfFile, line, var );
848 /* Close configuration file */
851 /* Check if there is still 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;
858 /* not a single listening port? Add default. */
859 if (no_listenports() &&
860 !array_copyb(&Conf_ListenPorts, (char*) &defaultport, sizeof defaultport))
862 Config_Error(LOG_ALERT, "Could not add default listening Port %u: %s",
863 (unsigned int) defaultport, strerror(errno));
868 if (!Conf_ListenAddress)
869 Conf_ListenAddress = strdup_warn(DEFAULT_LISTEN_ADDRSTR);
871 if (!Conf_ListenAddress) {
872 Config_Error(LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME);
876 /* No MOTD phrase configured? (re)try motd file. */
877 if (array_bytes(&Conf_Motd) == 0)
878 Read_Motd(Conf_MotdFile);
884 Check_ArgIsTrue( const char *Arg )
886 if( strcasecmp( Arg, "yes" ) == 0 ) return true;
887 if( strcasecmp( Arg, "true" ) == 0 ) return true;
888 if( atoi( Arg ) != 0 ) return true;
891 } /* Check_ArgIsTrue */
895 Handle_MaxNickLength(int Line, const char *Arg)
899 new = (unsigned) atoi(Arg) + 1;
900 if (new > CLIENT_NICK_LEN) {
901 Config_Error(LOG_WARNING,
902 "%s, line %d: Value of \"MaxNickLength\" exceeds %u!",
903 NGIRCd_ConfFile, Line, CLIENT_NICK_LEN - 1);
904 return CLIENT_NICK_LEN;
907 Config_Error(LOG_WARNING,
908 "%s, line %d: Value of \"MaxNickLength\" must be at least 1!",
909 NGIRCd_ConfFile, Line);
913 } /* Handle_MaxNickLength */
917 WarnIdent(int UNUSED Line)
921 /* user has enabled ident lookups explicitly, but ... */
922 Config_Error(LOG_WARNING,
923 "%s: line %d: %s=True, but ngircd was built without support",
924 NGIRCd_ConfFile, Line, "Ident");
930 WarnPAM(int UNUSED Line)
934 Config_Error(LOG_WARNING,
935 "%s: line %d: %s=True, but ngircd was built without support",
936 NGIRCd_ConfFile, Line, "PAM");
942 CheckLegacyNoOption(const char *Var, const char *Arg)
944 if( strcasecmp( Var, "NoDNS" ) == 0 ) {
945 Conf_DNS = !Check_ArgIsTrue( Arg );
948 if (strcasecmp(Var, "NoIdent") == 0) {
949 Conf_Ident = !Check_ArgIsTrue(Arg);
952 if(strcasecmp(Var, "NoPAM") == 0) {
953 Conf_PAM = !Check_ArgIsTrue(Arg);
960 NoNo(const char *str)
962 assert(strncasecmp("no", str, 2) == 0 && str[2]);
967 InvertArg(const char *arg)
969 return yesno_to_str(!Check_ArgIsTrue(arg));
973 Handle_GLOBAL( int Line, char *Var, char *Arg )
980 assert( Var != NULL );
981 assert( Arg != NULL );
983 if( strcasecmp( Var, "Name" ) == 0 ) {
985 len = strlcpy( Conf_ServerName, Arg, sizeof( Conf_ServerName ));
986 if (len >= sizeof( Conf_ServerName ))
987 Config_Error_TooLong( Line, Var );
990 if( strcasecmp( Var, "CloakHost" ) == 0 ) {
991 /* Client hostname */
992 len = strlcpy( Conf_CloakHost, Arg, sizeof( Conf_CloakHost ));
993 if (len >= sizeof( Conf_CloakHost ))
994 Config_Error_TooLong( Line, Var );
997 if( strcasecmp( Var, "CloakUserToNick" ) == 0 ) {
998 /* Use client nick name as user name */
999 Conf_CloakUserToNick = Check_ArgIsTrue( Arg );
1002 if( strcasecmp( Var, "Info" ) == 0 ) {
1003 /* Info text of server */
1004 len = strlcpy( Conf_ServerInfo, Arg, sizeof( Conf_ServerInfo ));
1005 if (len >= sizeof( Conf_ServerInfo ))
1006 Config_Error_TooLong ( Line, Var );
1009 if( strcasecmp( Var, "Password" ) == 0 ) {
1010 /* Global server password */
1011 len = strlcpy( Conf_ServerPwd, Arg, sizeof( Conf_ServerPwd ));
1012 if (len >= sizeof( Conf_ServerPwd ))
1013 Config_Error_TooLong( Line, Var );
1016 if (strcasecmp(Var, "WebircPassword") == 0) {
1017 /* Password required for WEBIRC command */
1018 len = strlcpy(Conf_WebircPwd, Arg, sizeof(Conf_WebircPwd));
1019 if (len >= sizeof(Conf_WebircPwd))
1020 Config_Error_TooLong(Line, Var);
1023 if( strcasecmp( Var, "AdminInfo1" ) == 0 ) {
1024 /* Administrative info #1 */
1025 len = strlcpy( Conf_ServerAdmin1, Arg, sizeof( Conf_ServerAdmin1 ));
1026 if (len >= sizeof( Conf_ServerAdmin1 ))
1027 Config_Error_TooLong ( Line, Var );
1030 if( strcasecmp( Var, "AdminInfo2" ) == 0 ) {
1031 /* Administrative info #2 */
1032 len = strlcpy( Conf_ServerAdmin2, Arg, sizeof( Conf_ServerAdmin2 ));
1033 if (len >= sizeof( Conf_ServerAdmin2 ))
1034 Config_Error_TooLong ( Line, Var );
1037 if( strcasecmp( Var, "AdminEMail" ) == 0 ) {
1038 /* Administrative email contact */
1039 len = strlcpy( Conf_ServerAdminMail, Arg, sizeof( Conf_ServerAdminMail ));
1040 if (len >= sizeof( Conf_ServerAdminMail ))
1041 Config_Error_TooLong( Line, Var );
1045 if( strcasecmp( Var, "Ports" ) == 0 ) {
1046 ports_parse(&Conf_ListenPorts, Line, Arg);
1049 if( strcasecmp( Var, "MotdFile" ) == 0 ) {
1050 len = strlcpy( Conf_MotdFile, Arg, sizeof( Conf_MotdFile ));
1051 if (len >= sizeof( Conf_MotdFile ))
1052 Config_Error_TooLong( Line, Var );
1055 if( strcasecmp( Var, "MotdPhrase" ) == 0 ) {
1056 /* "Message of the day" phrase (instead of file) */
1060 if (len >= LINE_LEN) {
1061 Config_Error_TooLong( Line, Var );
1064 if (!array_copyb(&Conf_Motd, Arg, len + 1))
1065 Config_Error(LOG_WARNING, "%s, line %d: Could not append MotdPhrase: %s",
1066 NGIRCd_ConfFile, Line, strerror(errno));
1067 Using_MotdFile = false;
1070 if( strcasecmp( Var, "ChrootDir" ) == 0 ) {
1071 /* directory for chroot() */
1072 len = strlcpy( Conf_Chroot, Arg, sizeof( Conf_Chroot ));
1073 if (len >= sizeof( Conf_Chroot ))
1074 Config_Error_TooLong( Line, Var );
1077 if ( strcasecmp( Var, "PidFile" ) == 0 ) {
1078 /* name of pidfile */
1079 len = strlcpy( Conf_PidFile, Arg, sizeof( Conf_PidFile ));
1080 if (len >= sizeof( Conf_PidFile ))
1081 Config_Error_TooLong( Line, Var );
1084 if( strcasecmp( Var, "ServerUID" ) == 0 ) {
1085 /* UID the daemon should switch to */
1086 pwd = getpwnam( Arg );
1087 if( pwd ) Conf_UID = pwd->pw_uid;
1089 Conf_UID = (unsigned int)atoi( Arg );
1090 if (!Conf_UID && strcmp(Arg, "0"))
1091 Config_Error_NaN(Line, Var);
1095 if( strcasecmp( Var, "ServerGID" ) == 0 ) {
1096 /* GID the daemon should use */
1097 grp = getgrnam( Arg );
1098 if( grp ) Conf_GID = grp->gr_gid;
1100 Conf_GID = (unsigned int)atoi(Arg);
1101 if (!Conf_GID && strcmp(Arg, "0"))
1102 Config_Error_NaN( Line, Var );
1106 if( strcasecmp( Var, "PingTimeout" ) == 0 ) {
1108 Conf_PingTimeout = atoi( Arg );
1109 if( Conf_PingTimeout < 5 ) {
1110 Config_Error( LOG_WARNING, "%s, line %d: Value of \"PingTimeout\" too low!",
1111 NGIRCd_ConfFile, Line );
1112 Conf_PingTimeout = 5;
1116 if( strcasecmp( Var, "PongTimeout" ) == 0 ) {
1118 Conf_PongTimeout = atoi( Arg );
1119 if( Conf_PongTimeout < 5 ) {
1120 Config_Error( LOG_WARNING, "%s, line %d: Value of \"PongTimeout\" too low!",
1121 NGIRCd_ConfFile, Line );
1122 Conf_PongTimeout = 5;
1126 if( strcasecmp( Var, "ConnectRetry" ) == 0 ) {
1127 /* Seconds between connection attempts to other servers */
1128 Conf_ConnectRetry = atoi( Arg );
1129 if( Conf_ConnectRetry < 5 ) {
1130 Config_Error( LOG_WARNING, "%s, line %d: Value of \"ConnectRetry\" too low!",
1131 NGIRCd_ConfFile, Line );
1132 Conf_ConnectRetry = 5;
1136 if( strcasecmp( Var, "PredefChannelsOnly" ) == 0 ) {
1137 /* Should we only allow pre-defined-channels? (i.e. users cannot create their own channels) */
1138 Conf_PredefChannelsOnly = Check_ArgIsTrue( Arg );
1142 if (CheckLegacyNoOption(Var, Arg)) {
1143 Config_Error(LOG_WARNING, "%s, line %d: \"No\"-Prefix has been removed, use \"%s = %s\" in [FEATURES] section instead",
1144 NGIRCd_ConfFile, Line, NoNo(Var), InvertArg(Arg));
1145 if (strcasecmp(Var, "NoIdent") == 0)
1147 else if (strcasecmp(Var, "NoPam") == 0)
1152 /* the default setting for all the WANT_IPV6 special options is 'true' */
1153 if( strcasecmp( Var, "ConnectIPv6" ) == 0 ) {
1154 /* connect to other hosts using ipv6, if they have an AAAA record? */
1155 Conf_ConnectIPv6 = Check_ArgIsTrue( Arg );
1158 if( strcasecmp( Var, "ConnectIPv4" ) == 0 ) {
1159 /* connect to other hosts using ipv4.
1160 * again, this can be used for ipv6-only setups */
1161 Conf_ConnectIPv4 = Check_ArgIsTrue( Arg );
1165 if( strcasecmp( Var, "OperCanUseMode" ) == 0 ) {
1166 /* Are IRC operators allowed to use MODE in channels they aren't Op in? */
1167 Conf_OperCanMode = Check_ArgIsTrue( Arg );
1170 if( strcasecmp( Var, "OperServerMode" ) == 0 ) {
1171 /* Mask IRC operator as if coming from the server? (ircd-irc2 compat hack) */
1172 Conf_OperServerMode = Check_ArgIsTrue( Arg );
1175 if(strcasecmp(Var, "AllowRemoteOper") == 0) {
1176 /* Are remote IRC operators allowed to control this server? */
1177 Conf_AllowRemoteOper = Check_ArgIsTrue(Arg);
1180 if( strcasecmp( Var, "MaxConnections" ) == 0 ) {
1181 /* Maximum number of connections. 0 -> "no limit". */
1182 Conf_MaxConnections = atol( Arg );
1183 if (!Conf_MaxConnections && strcmp(Arg, "0"))
1184 Config_Error_NaN(Line, Var);
1187 if( strcasecmp( Var, "MaxConnectionsIP" ) == 0 ) {
1188 /* Maximum number of simultaneous connections from one IP. 0 -> "no limit" */
1189 Conf_MaxConnectionsIP = atoi( Arg );
1190 if (!Conf_MaxConnectionsIP && strcmp(Arg, "0"))
1191 Config_Error_NaN(Line, Var);
1194 if( strcasecmp( Var, "MaxJoins" ) == 0 ) {
1195 /* Maximum number of channels a user can join. 0 -> "no limit". */
1196 Conf_MaxJoins = atoi( Arg );
1197 if (!Conf_MaxJoins && strcmp(Arg, "0"))
1198 Config_Error_NaN(Line, Var);
1201 if( strcasecmp( Var, "MaxNickLength" ) == 0 ) {
1202 /* Maximum length of a nick name; must be same on all servers
1203 * within the IRC network! */
1204 Conf_MaxNickLength = Handle_MaxNickLength(Line, Arg);
1207 if(strcasecmp(Var, "NoticeAuth") == 0) {
1208 /* send NOTICE AUTH messages to clients on connect */
1209 Conf_NoticeAuth = Check_ArgIsTrue(Arg);
1213 if( strcasecmp( Var, "Listen" ) == 0 ) {
1214 /* IP-Address to bind sockets */
1215 if (Conf_ListenAddress) {
1216 Config_Error(LOG_ERR, "Multiple Listen= options, ignoring: %s", Arg);
1219 Conf_ListenAddress = strdup_warn(Arg);
1221 * if allocation fails, we're in trouble:
1222 * we cannot ignore the error -- otherwise ngircd
1223 * would listen on all interfaces.
1225 if (!Conf_ListenAddress) {
1226 Config_Error(LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME);
1233 if( strcasecmp( Var, "SSLPorts" ) == 0 ) {
1234 ports_parse(&Conf_SSLOptions.ListenPorts, Line, Arg);
1238 if( strcasecmp( Var, "SSLKeyFile" ) == 0 ) {
1239 assert(Conf_SSLOptions.KeyFile == NULL );
1240 Conf_SSLOptions.KeyFile = strdup_warn(Arg);
1243 if( strcasecmp( Var, "SSLCertFile" ) == 0 ) {
1244 assert(Conf_SSLOptions.CertFile == NULL );
1245 Conf_SSLOptions.CertFile = strdup_warn(Arg);
1249 if( strcasecmp( Var, "SSLKeyFilePassword" ) == 0 ) {
1250 assert(array_bytes(&Conf_SSLOptions.KeyFilePassword) == 0);
1251 if (!array_copys(&Conf_SSLOptions.KeyFilePassword, Arg))
1252 Config_Error( LOG_ERR, "%s, line %d (section \"Global\"): Could not copy %s: %s!",
1253 NGIRCd_ConfFile, Line, Var, strerror(errno));
1256 if( strcasecmp( Var, "SSLDHFile" ) == 0 ) {
1257 assert(Conf_SSLOptions.DHFile == NULL);
1258 Conf_SSLOptions.DHFile = strdup_warn( Arg );
1263 if (strcasecmp(Var, "SyslogFacility") == 0) {
1264 Conf_SyslogFacility = ngt_SyslogFacilityID(Arg,
1265 Conf_SyslogFacility);
1270 if (strcasecmp(Var, "RequireAuthPing") == 0 ) {
1271 /* Require new clients to do an "autheticatin PING-PONG" */
1272 Conf_AuthPing = Check_ArgIsTrue(Arg);
1277 Config_Error_Section(Line, Var, "Global");
1282 Handle_FEATURES(int Line, char *Var, char *Arg)
1285 assert( Var != NULL );
1286 assert( Arg != NULL );
1288 if( strcasecmp( Var, "DNS" ) == 0 ) {
1289 /* do reverse dns lookups when clients connect? */
1290 Conf_DNS = Check_ArgIsTrue( Arg );
1293 if (strcasecmp(Var, "Ident") == 0) {
1294 /* do IDENT lookups when clients connect? */
1295 Conf_Ident = Check_ArgIsTrue(Arg);
1299 if(strcasecmp(Var, "PAM") == 0) {
1300 /* use PAM library to authenticate users */
1301 Conf_PAM = Check_ArgIsTrue(Arg);
1306 Config_Error_Section(Line, Var, "Options");
1310 Handle_OPERATOR( int Line, char *Var, char *Arg )
1313 struct Conf_Oper *op;
1316 assert( Var != NULL );
1317 assert( Arg != NULL );
1318 assert( Conf_Oper_Count > 0 );
1320 op = array_alloc(&Conf_Opers, sizeof(*op), Conf_Oper_Count - 1);
1322 Config_Error(LOG_ERR, "Could not allocate memory for operator (%d:%s = %s)", Line, Var, Arg);
1326 if (strcasecmp(Var, "Name") == 0) {
1327 /* Name of IRC operator */
1328 len = strlcpy(op->name, Arg, sizeof(op->name));
1329 if (len >= sizeof(op->name))
1330 Config_Error_TooLong(Line, Var);
1333 if (strcasecmp(Var, "Password") == 0) {
1334 /* Password of IRC operator */
1335 len = strlcpy(op->pwd, Arg, sizeof(op->pwd));
1336 if (len >= sizeof(op->pwd))
1337 Config_Error_TooLong(Line, Var);
1340 if (strcasecmp(Var, "Mask") == 0) {
1342 return; /* Hostname already configured */
1343 op->mask = strdup_warn( Arg );
1347 Config_Error_Section(Line, Var, "Operator");
1351 Handle_SERVER( int Line, char *Var, char *Arg )
1357 assert( Var != NULL );
1358 assert( Arg != NULL );
1360 /* Ignore server block if no space is left in server configuration structure */
1361 if( New_Server_Idx <= NONE ) return;
1363 if( strcasecmp( Var, "Host" ) == 0 ) {
1364 /* Hostname of the server */
1365 len = strlcpy( New_Server.host, Arg, sizeof( New_Server.host ));
1366 if (len >= sizeof( New_Server.host ))
1367 Config_Error_TooLong ( Line, Var );
1370 if( strcasecmp( Var, "Name" ) == 0 ) {
1371 /* Name of the server ("Nick"/"ID") */
1372 len = strlcpy( New_Server.name, Arg, sizeof( New_Server.name ));
1373 if (len >= sizeof( New_Server.name ))
1374 Config_Error_TooLong( Line, Var );
1377 if (strcasecmp(Var, "Bind") == 0) {
1378 if (ng_ipaddr_init(&New_Server.bind_addr, Arg, 0))
1381 Config_Error(LOG_ERR, "%s, line %d (section \"Server\"): Can't parse IP address \"%s\"",
1382 NGIRCd_ConfFile, Line, Arg);
1385 if( strcasecmp( Var, "MyPassword" ) == 0 ) {
1386 /* Password of this server which is sent to the peer */
1388 Config_Error(LOG_ERR,
1389 "%s, line %d (section \"Server\"): MyPassword must not start with ':'!",
1390 NGIRCd_ConfFile, Line);
1392 len = strlcpy( New_Server.pwd_in, Arg, sizeof( New_Server.pwd_in ));
1393 if (len >= sizeof( New_Server.pwd_in ))
1394 Config_Error_TooLong( Line, Var );
1397 if( strcasecmp( Var, "PeerPassword" ) == 0 ) {
1398 /* Passwort of the peer which must be received */
1399 len = strlcpy( New_Server.pwd_out, Arg, sizeof( New_Server.pwd_out ));
1400 if (len >= sizeof( New_Server.pwd_out ))
1401 Config_Error_TooLong( Line, Var );
1404 if( strcasecmp( Var, "Port" ) == 0 ) {
1405 /* Port to which this server should connect */
1407 if (port >= 0 && port < 0xFFFF)
1408 New_Server.port = (UINT16)port;
1410 Config_Error(LOG_ERR,
1411 "%s, line %d (section \"Server\"): Illegal port number %ld!",
1412 NGIRCd_ConfFile, Line, port );
1416 if( strcasecmp( Var, "SSLConnect" ) == 0 ) {
1417 New_Server.SSLConnect = Check_ArgIsTrue(Arg);
1421 if( strcasecmp( Var, "Group" ) == 0 ) {
1423 New_Server.group = atoi( Arg );
1424 if (!New_Server.group && strcmp(Arg, "0"))
1425 Config_Error_NaN(Line, Var);
1428 if( strcasecmp( Var, "Passive" ) == 0 ) {
1429 if (Check_ArgIsTrue(Arg))
1430 New_Server.flags |= CONF_SFLAG_DISABLED;
1433 if (strcasecmp(Var, "ServiceMask") == 0) {
1434 len = strlcpy(New_Server.svs_mask, ngt_LowerStr(Arg),
1435 sizeof(New_Server.svs_mask));
1436 if (len >= sizeof(New_Server.svs_mask))
1437 Config_Error_TooLong(Line, Var);
1441 Config_Error_Section(Line, Var, "Server");
1446 Handle_Channelname(struct Conf_Channel *new_chan, const char *name)
1448 size_t size = sizeof(new_chan->name);
1449 char *dest = new_chan->name;
1451 if (!Channel_IsValidName(name)) {
1453 * maybe user forgot to add a '#'.
1454 * This is only here for user convenience.
1460 return size > strlcpy(dest, name, size);
1465 Handle_CHANNEL(int Line, char *Var, char *Arg)
1469 struct Conf_Channel *chan;
1472 assert( Var != NULL );
1473 assert( Arg != NULL );
1474 assert(Conf_Channel_Count > 0);
1476 chancount = Conf_Channel_Count - 1;
1478 chan = array_alloc(&Conf_Channels, sizeof(*chan), chancount);
1480 Config_Error(LOG_ERR, "Could not allocate memory for predefined channel (%d:%s = %s)", Line, Var, Arg);
1483 if (strcasecmp(Var, "Name") == 0) {
1484 if (!Handle_Channelname(chan, Arg))
1485 Config_Error_TooLong(Line, Var);
1488 if (strcasecmp(Var, "Modes") == 0) {
1490 len = strlcpy(chan->modes, Arg, sizeof(chan->modes));
1491 if (len >= sizeof(chan->modes))
1492 Config_Error_TooLong( Line, Var );
1495 if( strcasecmp( Var, "Topic" ) == 0 ) {
1497 len = strlcpy(chan->topic, Arg, sizeof(chan->topic));
1498 if (len >= sizeof(chan->topic))
1499 Config_Error_TooLong( Line, Var );
1502 if( strcasecmp( Var, "Key" ) == 0 ) {
1503 /* Initial Channel Key (mode k) */
1504 len = strlcpy(chan->key, Arg, sizeof(chan->key));
1505 if (len >= sizeof(chan->key))
1506 Config_Error_TooLong(Line, Var);
1509 if( strcasecmp( Var, "MaxUsers" ) == 0 ) {
1510 /* maximum user limit, mode l */
1511 chan->maxusers = (unsigned long) atol(Arg);
1512 if (!chan->maxusers && strcmp(Arg, "0"))
1513 Config_Error_NaN(Line, Var);
1516 if (strcasecmp(Var, "KeyFile") == 0) {
1518 len = strlcpy(chan->keyfile, Arg, sizeof(chan->keyfile));
1519 if (len >= sizeof(chan->keyfile))
1520 Config_Error_TooLong(Line, Var);
1524 Config_Error_Section(Line, Var, "Channel");
1528 Validate_Config(bool Configtest, bool Rehash)
1530 /* Validate configuration settings. */
1533 int i, servers, servers_once;
1535 bool config_valid = true;
1538 /* Validate configured server name, see RFC 2812 section 2.3.1 */
1539 ptr = Conf_ServerName;
1541 if (*ptr >= 'a' && *ptr <= 'z') continue;
1542 if (*ptr >= 'A' && *ptr <= 'Z') continue;
1543 if (*ptr >= '0' && *ptr <= '9') continue;
1544 if (ptr > Conf_ServerName) {
1545 if (*ptr == '.' || *ptr == '-')
1548 Conf_ServerName[0] = '\0';
1552 if (!Conf_ServerName[0]) {
1553 /* No server name configured! */
1554 config_valid = false;
1555 Config_Error(LOG_ALERT,
1556 "No (valid) server name configured in \"%s\" (section 'Global': 'Name')!",
1558 if (!Configtest && !Rehash) {
1559 Config_Error(LOG_ALERT,
1560 "%s exiting due to fatal errors!",
1566 if (Conf_ServerName[0] && !strchr(Conf_ServerName, '.')) {
1567 /* No dot in server name! */
1568 config_valid = false;
1569 Config_Error(LOG_ALERT,
1570 "Invalid server name configured in \"%s\" (section 'Global': 'Name'): Dot missing!",
1573 Config_Error(LOG_ALERT,
1574 "%s exiting due to fatal errors!",
1581 if (!Conf_ServerAdminMail[0]) {
1582 /* No administrative contact configured! */
1583 config_valid = false;
1584 Config_Error(LOG_ALERT,
1585 "No administrator email address configured in \"%s\" ('AdminEMail')!",
1588 Config_Error(LOG_ALERT,
1589 "%s exiting due to fatal errors!",
1596 if (!Conf_ServerAdmin1[0] && !Conf_ServerAdmin2[0]
1597 && !Conf_ServerAdminMail[0]) {
1598 /* No administrative information configured! */
1599 Config_Error(LOG_WARNING,
1600 "No administrative information configured but required by RFC!");
1604 if (Conf_ServerPwd[0])
1605 Config_Error(LOG_ERR,
1606 "This server uses PAM, \"Password\" will be ignored!");
1610 servers = servers_once = 0;
1611 for (i = 0; i < MAX_SERVERS; i++) {
1612 if (Conf_Server[i].name[0]) {
1614 if (Conf_Server[i].flags & CONF_SFLAG_ONCE)
1619 "Configuration: Operators=%d, Servers=%d[%d], Channels=%d",
1620 Conf_Oper_Count, servers, servers_once, Conf_Channel_Count);
1623 return config_valid;
1624 } /* Validate_Config */
1628 Config_Error_TooLong ( const int Line, const char *Item )
1630 Config_Error( LOG_WARNING, "%s, line %d: Value of \"%s\" too long!", NGIRCd_ConfFile, Line, Item );
1634 Config_Error_Section(const int Line, const char *Item, const char *Section)
1636 Config_Error(LOG_ERR, "%s, line %d (section \"%s\"): Unknown variable \"%s\"!",
1637 NGIRCd_ConfFile, Line, Section, Item);
1641 Config_Error_NaN( const int Line, const char *Item )
1643 Config_Error( LOG_WARNING, "%s, line %d: Value of \"%s\" is not a number!",
1644 NGIRCd_ConfFile, Line, Item );
1648 static void Config_Error( const int Level, const char *Format, ... )
1650 static void Config_Error( Level, Format, va_alist )
1656 /* Error! Write to console and/or logfile. */
1658 char msg[MAX_LOG_MSG_LEN];
1661 assert( Format != NULL );
1664 va_start( ap, Format );
1668 vsnprintf( msg, MAX_LOG_MSG_LEN, Format, ap );
1671 /* During "normal operations" the log functions of the daemon should
1672 * be used, but during testing of the configuration file, all messages
1673 * should go directly to the console: */
1674 if (Use_Log) Log( Level, "%s", msg );
1676 } /* Config_Error */
1682 Conf_DebugDump(void)
1686 Log(LOG_DEBUG, "Configured servers:");
1687 for (i = 0; i < MAX_SERVERS; i++) {
1688 if (! Conf_Server[i].name[0])
1691 " - %s: %s:%d, last=%ld, group=%d, flags=%d, conn=%d",
1692 Conf_Server[i].name, Conf_Server[i].host,
1693 Conf_Server[i].port, Conf_Server[i].lasttry,
1694 Conf_Server[i].group, Conf_Server[i].flags,
1695 Conf_Server[i].conn_id);
1697 } /* Conf_DebugDump */
1703 Init_Server_Struct( CONF_SERVER *Server )
1705 /* Initialize server configuration structur to default values */
1707 assert( Server != NULL );
1709 memset( Server, 0, sizeof (CONF_SERVER) );
1711 Server->group = NONE;
1712 Server->lasttry = time( NULL ) - Conf_ConnectRetry + STARTUP_DELAY;
1714 if( NGIRCd_Passive ) Server->flags = CONF_SFLAG_DISABLED;
1716 Proc_InitStruct(&Server->res_stat);
1717 Server->conn_id = NONE;
1718 memset(&Server->bind_addr, 0, sizeof(&Server->bind_addr));
1719 } /* Init_Server_Struct */