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_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 ));
73 static void Config_Error PARAMS(( const int Level, const char *Format, ... ));
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 ));
80 static void Init_Server_Struct PARAMS(( CONF_SERVER *Server ));
84 #define DEFAULT_LISTEN_ADDRSTR "::,0.0.0.0"
86 #define DEFAULT_LISTEN_ADDRSTR "0.0.0.0"
92 struct SSLOptions Conf_SSLOptions;
95 * Initialize SSL configuration.
100 free(Conf_SSLOptions.KeyFile);
101 Conf_SSLOptions.KeyFile = NULL;
103 free(Conf_SSLOptions.CertFile);
104 Conf_SSLOptions.CertFile = NULL;
106 free(Conf_SSLOptions.DHFile);
107 Conf_SSLOptions.DHFile = NULL;
108 array_free_wipe(&Conf_SSLOptions.KeyFilePassword);
112 * Make sure that a configured file is readable.
114 * Currently, this function is only used for SSL-related options ...
116 * @param Var Configuration variable
117 * @param Filename Configured filename
120 CheckFileReadable(const char *Var, const char *Filename)
127 fp = fopen(Filename, "r");
131 Config_Error(LOG_ERR, "Can't read \"%s\" (\"%s\"): %s",
132 Filename, Var, strerror(errno));
139 * Duplicate string and warn on errors.
141 * @returns Pointer to string on success, NULL otherwise.
144 strdup_warn(const char *str)
146 char *ptr = strdup(str);
148 Config_Error(LOG_ERR,
149 "Could not allocate memory for string: %s", str);
154 * Output a comma separated list of ports (integer values).
161 len = array_length(a, sizeof(UINT16));
163 ports = (UINT16*) array_start(a);
164 printf("%u", (unsigned int) *ports);
167 printf(", %u", (unsigned int) *ports);
174 * Parse a comma separated string into an array of port numbers (integers).
177 ports_parse(array *a, int Line, char *Arg)
185 ptr = strtok( Arg, "," );
189 if (port > 0 && port < 0xFFFF) {
190 port16 = (UINT16) port;
191 if (!array_catb(a, (char*)&port16, sizeof port16))
192 Config_Error(LOG_ERR, "%s, line %d Could not add port number %ld: %s",
193 NGIRCd_ConfFile, Line, port, strerror(errno));
195 Config_Error( LOG_ERR, "%s, line %d (section \"Global\"): Illegal port number %ld!",
196 NGIRCd_ConfFile, Line, port );
199 ptr = strtok( NULL, "," );
204 * Initialize configuration module.
210 Validate_Config(false, false);
214 * "Rehash" (reload) server configuration.
216 * @returns true if configuration has been re-read, false on errors.
221 if (!Read_Config(false))
223 Validate_Config(false, true);
225 /* Update CLIENT structure of local server */
226 Client_SetInfo(Client_ThisServer(), Conf_ServerInfo);
231 * Output a boolean value as "yes/no" string.
234 yesno_to_str(int boolean_value)
242 * Free all IRC operator configuration structures.
247 struct Conf_Oper *op;
250 len = array_length(&Conf_Opers, sizeof(*op));
251 op = array_start(&Conf_Opers);
256 array_free(&Conf_Opers);
260 * Output all IRC operator configuration structures.
265 struct Conf_Oper *op;
268 len = array_length(&Conf_Opers, sizeof(*op));
269 op = array_start(&Conf_Opers);
274 printf(" Name = %s\n", op->name);
275 printf(" Password = %s\n", op->pwd);
276 printf(" Mask = %s\n\n", op->mask ? op->mask : "");
282 * Read configuration, validate and output it.
284 * This function waits for a keypress of the user when stdin/stdout are valid
285 * tty's ("you can read our nice message and we can read in your keypress").
287 * @return 0 on succes, 1 on failure(s); therefore the result code can
288 * directly be used by exit() when running "ngircd --configtest".
297 size_t predef_channel_count;
298 struct Conf_Channel *predef_chan;
302 if (! Read_Config(true))
305 config_valid = Validate_Config(true, false);
308 if(isatty(fileno(stdin)) && isatty(fileno(stdout))) {
309 puts("OK, press enter to see a dump of your server configuration ...");
312 puts("Ok, dump of your server configuration follows:\n");
315 printf(" Name = %s\n", Conf_ServerName);
316 printf(" AdminInfo1 = %s\n", Conf_ServerAdmin1);
317 printf(" AdminInfo2 = %s\n", Conf_ServerAdmin2);
318 printf(" AdminEMail = %s\n", Conf_ServerAdminMail);
319 printf(" Info = %s\n", Conf_ServerInfo);
320 printf(" Listen = %s\n", Conf_ListenAddress);
321 if (Using_MotdFile) {
322 printf(" MotdFile = %s\n", Conf_MotdFile);
323 printf(" MotdPhrase =\n");
325 printf(" MotdFile = \n");
326 printf(" MotdPhrase = %s\n", array_bytes(&Conf_Motd)
327 ? (const char*) array_start(&Conf_Motd) : "");
330 printf(" Password = %s\n", Conf_ServerPwd);
332 printf(" PidFile = %s\n", Conf_PidFile);
334 ports_puts(&Conf_ListenPorts);
335 grp = getgrgid(Conf_GID);
337 printf(" ServerGID = %s\n", grp->gr_name);
339 printf(" ServerGID = %ld\n", (long)Conf_GID);
340 pwd = getpwuid(Conf_UID);
342 printf(" ServerUID = %s\n", pwd->pw_name);
344 printf(" ServerUID = %ld\n", (long)Conf_UID);
348 printf(" ConnectRetry = %d\n", Conf_ConnectRetry);
349 printf(" MaxConnections = %ld\n", Conf_MaxConnections);
350 printf(" MaxConnectionsIP = %d\n", Conf_MaxConnectionsIP);
351 printf(" MaxJoins = %d\n", Conf_MaxJoins > 0 ? Conf_MaxJoins : -1);
352 printf(" MaxNickLength = %u\n", Conf_MaxNickLength - 1);
353 printf(" PingTimeout = %d\n", Conf_PingTimeout);
354 printf(" PongTimeout = %d\n", Conf_PongTimeout);
358 printf(" AllowRemoteOper = %s\n", yesno_to_str(Conf_AllowRemoteOper));
359 printf(" ChrootDir = %s\n", Conf_Chroot);
360 printf(" CloakHost = %s\n", Conf_CloakHost);
361 printf(" CloakUserToNick = %s\n", yesno_to_str(Conf_CloakUserToNick));
363 printf(" ConnectIPv4 = %s\n", yesno_to_str(Conf_ConnectIPv6));
364 printf(" ConnectIPv6 = %s\n", yesno_to_str(Conf_ConnectIPv4));
366 printf(" DNS = %s\n", yesno_to_str(Conf_DNS));
368 printf(" Ident = %s\n", yesno_to_str(Conf_Ident));
370 printf(" NoticeAuth = %s\n", yesno_to_str(Conf_NoticeAuth));
371 printf(" OperCanUseMode = %s\n", yesno_to_str(Conf_OperCanMode));
372 printf(" OperServerMode = %s\n", yesno_to_str(Conf_OperServerMode));
374 printf(" PAM = %s\n", yesno_to_str(Conf_PAM));
376 printf(" PredefChannelsOnly = %s\n", yesno_to_str(Conf_PredefChannelsOnly));
378 printf(" RequireAuthPing = %s\n", yesno_to_str(Conf_AuthPing));
381 printf(" SSLCertFile = %s\n", Conf_SSLOptions.CertFile);
382 printf(" SSLDHFile = %s\n", Conf_SSLOptions.DHFile);
383 printf(" SSLKeyFile = %s\n", Conf_SSLOptions.KeyFile);
384 if (array_bytes(&Conf_SSLOptions.KeyFilePassword))
385 puts(" SSLKeyFilePassword = <secret>");
387 puts(" SSLKeyFilePassword = ");
388 array_free_wipe(&Conf_SSLOptions.KeyFilePassword);
389 printf(" SSLPorts = ");
390 ports_puts(&Conf_SSLOptions.ListenPorts);
393 printf(" SyslogFacility = %s\n",
394 ngt_SyslogFacilityName(Conf_SyslogFacility));
396 printf(" WebircPassword = %s\n", Conf_WebircPwd);
401 for( i = 0; i < MAX_SERVERS; i++ ) {
402 if( ! Conf_Server[i].name[0] ) continue;
404 /* Valid "Server" section */
406 printf( " Name = %s\n", Conf_Server[i].name );
407 printf( " Host = %s\n", Conf_Server[i].host );
408 printf( " Port = %u\n", (unsigned int)Conf_Server[i].port );
410 printf( " SSLConnect = %s\n", Conf_Server[i].SSLConnect?"yes":"no");
412 printf( " MyPassword = %s\n", Conf_Server[i].pwd_in );
413 printf( " PeerPassword = %s\n", Conf_Server[i].pwd_out );
414 printf( " ServiceMask = %s\n", Conf_Server[i].svs_mask);
415 printf( " Group = %d\n", Conf_Server[i].group );
416 printf( " Passive = %s\n\n", Conf_Server[i].flags & CONF_SFLAG_DISABLED ? "yes" : "no");
419 predef_channel_count = array_length(&Conf_Channels, sizeof(*predef_chan));
420 predef_chan = array_start(&Conf_Channels);
422 for (i = 0; i < predef_channel_count; i++, predef_chan++) {
423 if (!predef_chan->name[0])
426 /* Valid "Channel" section */
428 printf(" Name = %s\n", predef_chan->name);
429 printf(" Modes = %s\n", predef_chan->modes);
430 printf(" Key = %s\n", predef_chan->key);
431 printf(" MaxUsers = %lu\n", predef_chan->maxusers);
432 printf(" Topic = %s\n", predef_chan->topic);
433 printf(" KeyFile = %s\n\n", predef_chan->keyfile);
436 return (config_valid ? 0 : 1);
440 * Remove connection information from configured server.
442 * If the server is set as "once", delete it from our configuration;
443 * otherwise set the time for the next connection attempt.
445 * Non-server connections will be silently ignored.
448 Conf_UnsetServer( CONN_ID Idx )
453 /* Check all our configured servers */
454 for( i = 0; i < MAX_SERVERS; i++ ) {
455 if( Conf_Server[i].conn_id != Idx ) continue;
457 /* Gotcha! Mark server configuration as "unused": */
458 Conf_Server[i].conn_id = NONE;
460 if( Conf_Server[i].flags & CONF_SFLAG_ONCE ) {
461 /* Delete configuration here */
462 Init_Server_Struct( &Conf_Server[i] );
464 /* Set time for next connect attempt */
466 if (Conf_Server[i].lasttry < t - Conf_ConnectRetry) {
467 /* The connection has been "long", so we don't
468 * require the next attempt to be delayed. */
469 Conf_Server[i].lasttry =
470 t - Conf_ConnectRetry + RECONNECT_DELAY;
472 Conf_Server[i].lasttry = t;
478 * Set connection information for specified configured server.
481 Conf_SetServer( int ConfServer, CONN_ID Idx )
483 assert( ConfServer > NONE );
484 assert( Idx > NONE );
486 Conf_Server[ConfServer].conn_id = Idx;
490 * Get index of server in configuration structure.
493 Conf_GetServer( CONN_ID Idx )
497 assert( Idx > NONE );
499 for( i = 0; i < MAX_SERVERS; i++ ) {
500 if( Conf_Server[i].conn_id == Idx ) return i;
506 * Enable a server by name and adjust its port number.
508 * @returns true if a server has been enabled and now has a valid port
509 * number and host name for outgoing connections.
512 Conf_EnableServer( const char *Name, UINT16 Port )
516 assert( Name != NULL );
517 for( i = 0; i < MAX_SERVERS; i++ ) {
518 if( strcasecmp( Conf_Server[i].name, Name ) == 0 ) {
519 /* Gotcha! Set port and enable server: */
520 Conf_Server[i].port = Port;
521 Conf_Server[i].flags &= ~CONF_SFLAG_DISABLED;
522 return (Conf_Server[i].port && Conf_Server[i].host[0]);
529 * Enable a server by name.
531 * The server is only usable as outgoing server, if it has set a valid port
532 * number for outgoing connections!
533 * If not, you have to use Conf_EnableServer() function to make it available.
535 * @returns true if a server has been enabled; false otherwise.
538 Conf_EnablePassiveServer(const char *Name)
542 assert( Name != NULL );
543 for (i = 0; i < MAX_SERVERS; i++) {
544 if ((strcasecmp( Conf_Server[i].name, Name ) == 0)
545 && (Conf_Server[i].port > 0)) {
546 /* BINGO! Enable server */
547 Conf_Server[i].flags &= ~CONF_SFLAG_DISABLED;
555 * Disable a server by name.
556 * An already established connection will be disconnected.
558 * @returns true if a server was found and has been disabled.
561 Conf_DisableServer( const char *Name )
565 assert( Name != NULL );
566 for( i = 0; i < MAX_SERVERS; i++ ) {
567 if( strcasecmp( Conf_Server[i].name, Name ) == 0 ) {
568 /* Gotcha! Disable and disconnect server: */
569 Conf_Server[i].flags |= CONF_SFLAG_DISABLED;
570 if( Conf_Server[i].conn_id > NONE )
571 Conn_Close(Conf_Server[i].conn_id, NULL,
572 "Server link terminated on operator request",
581 * Add a new remote server to our configuration.
583 * @param Name Name of the new server.
584 * @param Port Port number to connect to or 0 for incoming connections.
585 * @param Host Host name to connect to.
586 * @param MyPwd Password that will be sent to the peer.
587 * @param PeerPwd Password that must be received from the peer.
588 * @returns true if the new server has been added; false otherwise.
591 Conf_AddServer(const char *Name, UINT16 Port, const char *Host,
592 const char *MyPwd, const char *PeerPwd)
596 assert( Name != NULL );
597 assert( Host != NULL );
598 assert( MyPwd != NULL );
599 assert( PeerPwd != NULL );
601 /* Search unused item in server configuration structure */
602 for( i = 0; i < MAX_SERVERS; i++ ) {
603 /* Is this item used? */
604 if( ! Conf_Server[i].name[0] ) break;
606 if( i >= MAX_SERVERS ) return false;
608 Init_Server_Struct( &Conf_Server[i] );
609 strlcpy( Conf_Server[i].name, Name, sizeof( Conf_Server[i].name ));
610 strlcpy( Conf_Server[i].host, Host, sizeof( Conf_Server[i].host ));
611 strlcpy( Conf_Server[i].pwd_out, MyPwd, sizeof( Conf_Server[i].pwd_out ));
612 strlcpy( Conf_Server[i].pwd_in, PeerPwd, sizeof( Conf_Server[i].pwd_in ));
613 Conf_Server[i].port = Port;
614 Conf_Server[i].flags = CONF_SFLAG_ONCE;
620 * Check if the given nick name is an service.
622 * @returns true if the given nick name belongs to an "IRC service".
625 Conf_IsService(int ConfServer, const char *Nick)
627 return MatchCaseInsensitive(Conf_Server[ConfServer].svs_mask, Nick);
631 * Initialize configuration settings with their default values.
634 Set_Defaults(bool InitServers)
639 strcpy(Conf_ServerName, "");
640 strcpy(Conf_ServerAdmin1, "");
641 strcpy(Conf_ServerAdmin2, "");
642 strcpy(Conf_ServerAdminMail, "");
643 snprintf(Conf_ServerInfo, sizeof Conf_ServerInfo, "%s %s",
644 PACKAGE_NAME, PACKAGE_VERSION);
645 free(Conf_ListenAddress);
646 Conf_ListenAddress = NULL;
647 array_free(&Conf_Motd);
648 strlcpy(Conf_MotdFile, SYSCONFDIR, sizeof(Conf_MotdFile));
649 strlcat(Conf_MotdFile, MOTD_FILE, sizeof(Conf_MotdFile));
650 strcpy(Conf_ServerPwd, "");
651 strlcpy(Conf_PidFile, PID_FILE, sizeof(Conf_PidFile));
652 Conf_UID = Conf_GID = 0;
655 Conf_ConnectRetry = 60;
656 Conf_MaxConnections = 0;
657 Conf_MaxConnectionsIP = 5;
659 Conf_MaxNickLength = CLIENT_NICK_LEN_DEFAULT;
660 Conf_PingTimeout = 120;
661 Conf_PongTimeout = 20;
664 Conf_AllowRemoteOper = false;
666 Conf_AuthPing = false;
668 strlcpy(Conf_Chroot, CHROOT_DIR, sizeof(Conf_Chroot));
669 strcpy(Conf_CloakHost, "");
670 Conf_CloakUserToNick = false;
671 Conf_ConnectIPv4 = true;
673 Conf_ConnectIPv6 = true;
675 Conf_ConnectIPv6 = false;
683 Conf_NoticeAuth = false;
684 Conf_OperCanMode = false;
685 Conf_OperServerMode = false;
691 Conf_PredefChannelsOnly = false;
694 Conf_SyslogFacility = LOG_LOCAL5;
696 Conf_SyslogFacility = 0;
700 /* Initialize IRC operators and channels */
702 Conf_Channel_Count = 0;
704 /* Initialize server configuration structures */
706 for (i = 0; i < MAX_SERVERS;
707 Init_Server_Struct(&Conf_Server[i++]));
712 * Get number of configured listening ports.
714 * @returns The number of ports (IPv4+IPv6) on which the server should listen.
719 size_t cnt = array_bytes(&Conf_ListenPorts);
721 cnt += array_bytes(&Conf_SSLOptions.ListenPorts);
727 * Read MOTD ("message of the day") file.
729 * @param filename Name of the file to read.
732 Read_Motd(const char *filename)
737 if (*filename == '\0')
740 fp = fopen(filename, "r");
742 Config_Error(LOG_WARNING, "Can't read MOTD file \"%s\": %s",
743 filename, strerror(errno));
747 array_free(&Conf_Motd);
748 Using_MotdFile = true;
750 while (fgets(line, (int)sizeof line, fp)) {
751 ngt_TrimLastChr( line, '\n');
753 /* add text including \0 */
754 if (!array_catb(&Conf_Motd, line, strlen(line) + 1)) {
755 Log(LOG_WARNING, "Cannot add MOTD text: %s", strerror(errno));
763 * Read ngIRCd configuration file.
765 * Please note that this function uses exit(1) on fatal errors and therefore
766 * can result in ngIRCd terminating!
768 * @param ngircd_starting Flag indicating if ngIRCd is starting or not.
769 * @returns true when the configuration file has been read
770 * successfully; false otherwise.
773 Read_Config( bool ngircd_starting )
775 char section[LINE_LEN], str[LINE_LEN], *var, *arg, *ptr;
776 const UINT16 defaultport = 6667;
780 /* Open configuration file */
781 fd = fopen( NGIRCd_ConfFile, "r" );
783 /* No configuration file found! */
784 Config_Error( LOG_ALERT, "Can't read configuration \"%s\": %s",
785 NGIRCd_ConfFile, strerror( errno ));
786 if (!ngircd_starting)
788 Config_Error( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME );
793 Set_Defaults( ngircd_starting );
795 Config_Error( LOG_INFO, "Reading configuration from \"%s\" ...", NGIRCd_ConfFile );
797 /* Clean up server configuration structure: mark all already
798 * configured servers as "once" so that they are deleted
799 * after the next disconnect and delete all unused servers.
800 * And delete all servers which are "duplicates" of servers
801 * that are already marked as "once" (such servers have been
802 * created by the last rehash but are now useless). */
803 for( i = 0; i < MAX_SERVERS; i++ ) {
804 if( Conf_Server[i].conn_id == NONE ) Init_Server_Struct( &Conf_Server[i] );
806 /* This structure is in use ... */
807 if( Conf_Server[i].flags & CONF_SFLAG_ONCE ) {
808 /* Check for duplicates */
809 for( n = 0; n < MAX_SERVERS; n++ ) {
810 if( n == i ) continue;
812 if( Conf_Server[i].conn_id == Conf_Server[n].conn_id ) {
813 Init_Server_Struct( &Conf_Server[n] );
815 Log(LOG_DEBUG,"Deleted unused duplicate server %d (kept %d).",
821 /* Mark server as "once" */
822 Conf_Server[i].flags |= CONF_SFLAG_ONCE;
823 Log( LOG_DEBUG, "Marked server %d as \"once\"", i );
828 /* Initialize variables */
830 strcpy( section, "" );
831 Init_Server_Struct( &New_Server );
832 New_Server_Idx = NONE;
836 /* Read configuration file */
838 if( ! fgets( str, LINE_LEN, fd )) break;
842 /* Skip comments and empty lines */
843 if( str[0] == ';' || str[0] == '#' || str[0] == '\0' ) continue;
845 /* Is this the beginning of a new section? */
846 if(( str[0] == '[' ) && ( str[strlen( str ) - 1] == ']' )) {
847 strlcpy( section, str, sizeof( section ));
848 if (strcasecmp(section, "[GLOBAL]") == 0 ||
849 strcasecmp(section, "[LIMITS]") == 0 ||
850 strcasecmp(section, "[OPTIONS]") == 0)
853 if( strcasecmp( section, "[SERVER]" ) == 0 ) {
854 /* Check if there is already a server to add */
855 if( New_Server.name[0] ) {
856 /* Copy data to "real" server structure */
857 assert( New_Server_Idx > NONE );
858 Conf_Server[New_Server_Idx] = New_Server;
861 /* Re-init structure for new server */
862 Init_Server_Struct( &New_Server );
864 /* Search unused item in server configuration structure */
865 for( i = 0; i < MAX_SERVERS; i++ ) {
866 /* Is this item used? */
867 if( ! Conf_Server[i].name[0] ) break;
869 if( i >= MAX_SERVERS ) {
870 /* Oops, no free item found! */
871 Config_Error( LOG_ERR, "Too many servers configured." );
872 New_Server_Idx = NONE;
874 else New_Server_Idx = i;
877 if (strcasecmp(section, "[CHANNEL]") == 0) {
878 Conf_Channel_Count++;
881 if (strcasecmp(section, "[OPERATOR]") == 0) {
886 Config_Error(LOG_ERR,
887 "%s, line %d: Unknown section \"%s\"!",
888 NGIRCd_ConfFile, line, section);
891 if( section[0] == 0x1 ) continue;
893 /* Split line into variable name and parameters */
894 ptr = strchr( str, '=' );
896 Config_Error( LOG_ERR, "%s, line %d: Syntax error!", NGIRCd_ConfFile, line );
900 var = str; ngt_TrimStr( var );
901 arg = ptr + 1; ngt_TrimStr( arg );
903 if(strcasecmp(section, "[GLOBAL]") == 0)
904 Handle_GLOBAL(line, var, arg);
905 else if(strcasecmp(section, "[LIMITS]") == 0)
906 Handle_LIMITS(line, var, arg);
907 else if(strcasecmp(section, "[OPTIONS]") == 0)
908 Handle_OPTIONS(line, var, arg);
909 else if(strcasecmp(section, "[OPERATOR]") == 0)
910 Handle_OPERATOR(line, var, arg);
911 else if(strcasecmp(section, "[SERVER]") == 0)
912 Handle_SERVER(line, var, arg);
913 else if(strcasecmp(section, "[CHANNEL]") == 0)
914 Handle_CHANNEL(line, var, arg);
916 Config_Error(LOG_ERR,
917 "%s, line %d: Variable \"%s\" outside section!",
918 NGIRCd_ConfFile, line, var);
921 /* Close configuration file */
924 /* Check if there is still a server to add */
925 if( New_Server.name[0] ) {
926 /* Copy data to "real" server structure */
927 assert( New_Server_Idx > NONE );
928 Conf_Server[New_Server_Idx] = New_Server;
931 /* not a single listening port? Add default. */
932 if (no_listenports() &&
933 !array_copyb(&Conf_ListenPorts, (char*) &defaultport, sizeof defaultport))
935 Config_Error(LOG_ALERT, "Could not add default listening Port %u: %s",
936 (unsigned int) defaultport, strerror(errno));
941 if (!Conf_ListenAddress)
942 Conf_ListenAddress = strdup_warn(DEFAULT_LISTEN_ADDRSTR);
944 if (!Conf_ListenAddress) {
945 Config_Error(LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME);
949 /* No MOTD phrase configured? (re)try motd file. */
950 if (array_bytes(&Conf_Motd) == 0)
951 Read_Motd(Conf_MotdFile);
954 /* Make sure that all SSL-related files are readable */
955 CheckFileReadable("SSLCertFile", Conf_SSLOptions.CertFile);
956 CheckFileReadable("SSLDHFile", Conf_SSLOptions.DHFile);
957 CheckFileReadable("SSLKeyFile", Conf_SSLOptions.KeyFile);
964 * Check whether an string argument is true or false.
966 * @param Arg Input string.
967 * @returns true if string has been parsed as "yes"/"true"/"on".
970 Check_ArgIsTrue( const char *Arg )
972 if( strcasecmp( Arg, "yes" ) == 0 ) return true;
973 if( strcasecmp( Arg, "true" ) == 0 ) return true;
974 if( atoi( Arg ) != 0 ) return true;
980 * Handle setting of "MaxNickLength".
982 * @param Line Line number in configuration file.
983 * @raram Arg Input string.
984 * @returns New configured maximum nick name length.
987 Handle_MaxNickLength(int Line, const char *Arg)
991 new = (unsigned) atoi(Arg) + 1;
992 if (new > CLIENT_NICK_LEN) {
993 Config_Error(LOG_WARNING,
994 "%s, line %d: Value of \"MaxNickLength\" exceeds %u!",
995 NGIRCd_ConfFile, Line, CLIENT_NICK_LEN - 1);
996 return CLIENT_NICK_LEN;
999 Config_Error(LOG_WARNING,
1000 "%s, line %d: Value of \"MaxNickLength\" must be at least 1!",
1001 NGIRCd_ConfFile, Line);
1008 * Output a warning messages if IDENT is configured but not compiled in.
1011 WarnIdent(int UNUSED Line)
1015 /* user has enabled ident lookups explicitly, but ... */
1016 Config_Error(LOG_WARNING,
1017 "%s: line %d: \"Ident = yes\", but ngircd was built without IDENT support!",
1018 NGIRCd_ConfFile, Line);
1024 * Output a warning messages if IPv6 is configured but not compiled in.
1027 WarnIPv6(int UNUSED Line)
1030 if (Conf_ConnectIPv6) {
1031 /* user has enabled IPv6 explicitly, but ... */
1032 Config_Error(LOG_WARNING,
1033 "%s: line %d: \"ConnectIPv6 = yes\", but ngircd was built without IPv6 support!",
1034 NGIRCd_ConfFile, Line);
1040 * Output a warning messages if PAM is configured but not compiled in.
1043 WarnPAM(int UNUSED Line)
1047 Config_Error(LOG_WARNING,
1048 "%s: line %d: \"PAM = yes\", but ngircd was built without PAM support!",
1049 NGIRCd_ConfFile, Line);
1055 * Handle legacy "NoXXX" options in [GLOBAL] section.
1057 * TODO: This function and support for "NoXXX" could be removed starting
1058 * with ngIRCd release 19 (one release after marking it "deprecated").
1060 * @param Var Variable name.
1061 * @param Arg Argument string.
1062 * @returns true if a NoXXX option has been processed; false otherwise.
1065 CheckLegacyNoOption(const char *Var, const char *Arg)
1067 if(strcasecmp(Var, "NoDNS") == 0) {
1068 Conf_DNS = !Check_ArgIsTrue( Arg );
1071 if (strcasecmp(Var, "NoIdent") == 0) {
1072 Conf_Ident = !Check_ArgIsTrue(Arg);
1075 if(strcasecmp(Var, "NoPAM") == 0) {
1076 Conf_PAM = !Check_ArgIsTrue(Arg);
1083 * Handle deprecated legacy options in [GLOBAL] section.
1085 * TODO: This function and support for these options in the [Global] section
1086 * could be removed starting with ngIRCd release 19 (one release after
1087 * marking it "deprecated").
1089 * @param Var Variable name.
1090 * @param Arg Argument string.
1091 * @returns true if a legacy option has been processed; false otherwise.
1094 CheckLegacyGlobalOption(int Line, char *Var, char *Arg)
1096 if (strcasecmp(Var, "AllowRemoteOper") == 0
1097 || strcasecmp(Var, "ChrootDir") == 0
1098 || strcasecmp(Var, "ConnectIPv4") == 0
1099 || strcasecmp(Var, "ConnectIPv6") == 0
1100 || strcasecmp(Var, "OperCanUseMode") == 0
1101 || strcasecmp(Var, "OperServerMode") == 0
1102 || strcasecmp(Var, "PredefChannelsOnly") == 0
1104 || strcasecmp(Var, "SSLCertFile") == 0
1105 || strcasecmp(Var, "SSLDHFile") == 0
1106 || strcasecmp(Var, "SSLKeyFile") == 0
1107 || strcasecmp(Var, "SSLKeyFilePassword") == 0
1108 || strcasecmp(Var, "SSLPorts") == 0
1110 || strcasecmp(Var, "SyslogFacility") == 0
1111 || strcasecmp(Var, "WebircPassword") == 0) {
1112 Handle_OPTIONS(Line, Var, Arg);
1115 if (strcasecmp(Var, "ConnectRetry") == 0
1116 || strcasecmp(Var, "MaxConnections") == 0
1117 || strcasecmp(Var, "MaxConnectionsIP") == 0
1118 || strcasecmp(Var, "MaxJoins") == 0
1119 || strcasecmp(Var, "MaxNickLength") == 0
1120 || strcasecmp(Var, "PingTimeout") == 0
1121 || strcasecmp(Var, "PongTimeout") == 0) {
1122 Handle_LIMITS(Line, Var, Arg);
1130 * Strip "no" prefix of a string.
1132 * TODO: This function and support for "NoXXX" should be removed starting
1133 * with ngIRCd release 19! (One release after marking it "deprecated").
1135 * @param str Pointer to input string starting with "no".
1136 * @returns New pointer to string without "no" prefix.
1139 NoNo(const char *str)
1141 assert(strncasecmp("no", str, 2) == 0 && str[2]);
1146 * Invert "boolean" string.
1148 * TODO: This function and support for "NoXXX" should be removed starting
1149 * with ngIRCd release 19! (One release after marking it "deprecated").
1151 * @param arg "Boolean" input string.
1152 * @returns Pointer to inverted "boolean string".
1155 InvertArg(const char *arg)
1157 return yesno_to_str(!Check_ArgIsTrue(arg));
1161 * Handle variable in [Global] configuration section.
1163 * @param Line Line numer in configuration file.
1164 * @param Var Variable name.
1165 * @param Arg Variable argument.
1168 Handle_GLOBAL( int Line, char *Var, char *Arg )
1173 const char *section;
1176 assert(Var != NULL);
1177 assert(Arg != NULL);
1179 if (strcasecmp(Var, "Name") == 0) {
1180 len = strlcpy(Conf_ServerName, Arg, sizeof(Conf_ServerName));
1181 if (len >= sizeof(Conf_ServerName))
1182 Config_Error_TooLong(Line, Var);
1185 if (strcasecmp(Var, "AdminInfo1") == 0) {
1186 len = strlcpy(Conf_ServerAdmin1, Arg, sizeof(Conf_ServerAdmin1));
1187 if (len >= sizeof(Conf_ServerAdmin1))
1188 Config_Error_TooLong(Line, Var);
1191 if (strcasecmp(Var, "AdminInfo2") == 0) {
1192 len = strlcpy(Conf_ServerAdmin2, Arg, sizeof(Conf_ServerAdmin2));
1193 if (len >= sizeof(Conf_ServerAdmin2))
1194 Config_Error_TooLong(Line, Var);
1197 if (strcasecmp(Var, "AdminEMail") == 0) {
1198 len = strlcpy(Conf_ServerAdminMail, Arg,
1199 sizeof(Conf_ServerAdminMail));
1200 if (len >= sizeof(Conf_ServerAdminMail))
1201 Config_Error_TooLong(Line, Var);
1204 if (strcasecmp(Var, "Info") == 0) {
1205 len = strlcpy(Conf_ServerInfo, Arg, sizeof(Conf_ServerInfo));
1206 if (len >= sizeof(Conf_ServerInfo))
1207 Config_Error_TooLong(Line, Var);
1210 if (strcasecmp(Var, "Listen") == 0) {
1211 if (Conf_ListenAddress) {
1212 Config_Error(LOG_ERR,
1213 "Multiple Listen= options, ignoring: %s",
1217 Conf_ListenAddress = strdup_warn(Arg);
1218 /* If allocation fails, we're in trouble: we cannot ignore the
1219 * error -- otherwise ngircd would listen on all interfaces. */
1220 if (!Conf_ListenAddress) {
1221 Config_Error(LOG_ALERT,
1222 "%s exiting due to fatal errors!",
1228 if (strcasecmp(Var, "MotdFile") == 0) {
1229 len = strlcpy(Conf_MotdFile, Arg, sizeof(Conf_MotdFile));
1230 if (len >= sizeof(Conf_MotdFile))
1231 Config_Error_TooLong(Line, Var);
1234 if (strcasecmp(Var, "MotdPhrase") == 0) {
1238 if (len >= LINE_LEN) {
1239 Config_Error_TooLong(Line, Var);
1242 if (!array_copyb(&Conf_Motd, Arg, len + 1))
1243 Config_Error(LOG_WARNING,
1244 "%s, line %d: Could not append MotdPhrase: %s",
1245 NGIRCd_ConfFile, Line, strerror(errno));
1246 Using_MotdFile = false;
1249 if(strcasecmp(Var, "Password") == 0) {
1250 len = strlcpy(Conf_ServerPwd, Arg, sizeof(Conf_ServerPwd));
1251 if (len >= sizeof(Conf_ServerPwd))
1252 Config_Error_TooLong(Line, Var);
1255 if (strcasecmp(Var, "PidFile") == 0) {
1256 len = strlcpy(Conf_PidFile, Arg, sizeof(Conf_PidFile));
1257 if (len >= sizeof(Conf_PidFile))
1258 Config_Error_TooLong(Line, Var);
1261 if (strcasecmp(Var, "Ports") == 0) {
1262 ports_parse(&Conf_ListenPorts, Line, Arg);
1265 if (strcasecmp(Var, "ServerGID") == 0) {
1266 grp = getgrnam(Arg);
1268 Conf_GID = grp->gr_gid;
1270 Conf_GID = (unsigned int)atoi(Arg);
1271 if (!Conf_GID && strcmp(Arg, "0"))
1272 Config_Error_NaN(Line, Var);
1276 if (strcasecmp(Var, "ServerUID") == 0) {
1277 pwd = getpwnam(Arg);
1279 Conf_UID = pwd->pw_uid;
1281 Conf_UID = (unsigned int)atoi(Arg);
1282 if (!Conf_UID && strcmp(Arg, "0"))
1283 Config_Error_NaN(Line, Var);
1288 if (CheckLegacyNoOption(Var, Arg)) {
1289 /* TODO: This function and support for "NoXXX" could be
1290 * be removed starting with ngIRCd release 19 (one release
1291 * after marking it "deprecated"). */
1292 Config_Error(LOG_WARNING,
1293 "%s, line %d (section \"Global\"): \"No\"-Prefix is deprecated, use \"%s = %s\" in [Options] section!",
1294 NGIRCd_ConfFile, Line, NoNo(Var), InvertArg(Arg));
1295 if (strcasecmp(Var, "NoIdent") == 0)
1297 else if (strcasecmp(Var, "NoPam") == 0)
1301 if ((section = CheckLegacyGlobalOption(Line, Var, Arg))) {
1302 /** TODO: This function and support for these options in the
1303 * [Global] section could be removed starting with ngIRCd
1304 * release 19 (one release after marking it "deprecated"). */
1305 Config_Error(LOG_WARNING,
1306 "%s, line %d (section \"Global\"): \"%s\" is deprecated here, move it to %s!",
1307 NGIRCd_ConfFile, Line, Var, section);
1311 Config_Error_Section(Line, Var, "Global");
1315 * Handle variable in [Limits] configuration section.
1317 * @param Line Line numer in configuration file.
1318 * @param Var Variable name.
1319 * @param Arg Variable argument.
1322 Handle_LIMITS(int Line, char *Var, char *Arg)
1325 assert(Var != NULL);
1326 assert(Arg != NULL);
1328 if (strcasecmp(Var, "ConnectRetry") == 0) {
1329 Conf_ConnectRetry = atoi(Arg);
1330 if (Conf_ConnectRetry < 5) {
1331 Config_Error(LOG_WARNING,
1332 "%s, line %d: Value of \"ConnectRetry\" too low!",
1333 NGIRCd_ConfFile, Line);
1334 Conf_ConnectRetry = 5;
1338 if (strcasecmp(Var, "MaxConnections") == 0) {
1339 Conf_MaxConnections = atol(Arg);
1340 if (!Conf_MaxConnections && strcmp(Arg, "0"))
1341 Config_Error_NaN(Line, Var);
1344 if (strcasecmp(Var, "MaxConnectionsIP") == 0) {
1345 Conf_MaxConnectionsIP = atoi(Arg);
1346 if (!Conf_MaxConnectionsIP && strcmp(Arg, "0"))
1347 Config_Error_NaN(Line, Var);
1350 if (strcasecmp(Var, "MaxJoins") == 0) {
1351 Conf_MaxJoins = atoi(Arg);
1352 if (!Conf_MaxJoins && strcmp(Arg, "0"))
1353 Config_Error_NaN(Line, Var);
1356 if (strcasecmp(Var, "MaxNickLength") == 0) {
1357 Conf_MaxNickLength = Handle_MaxNickLength(Line, Arg);
1360 if (strcasecmp(Var, "PingTimeout") == 0) {
1361 Conf_PingTimeout = atoi(Arg);
1362 if (Conf_PingTimeout < 5) {
1363 Config_Error(LOG_WARNING,
1364 "%s, line %d: Value of \"PingTimeout\" too low!",
1365 NGIRCd_ConfFile, Line);
1366 Conf_PingTimeout = 5;
1370 if (strcasecmp(Var, "PongTimeout") == 0) {
1371 Conf_PongTimeout = atoi(Arg);
1372 if (Conf_PongTimeout < 5) {
1373 Config_Error(LOG_WARNING,
1374 "%s, line %d: Value of \"PongTimeout\" too low!",
1375 NGIRCd_ConfFile, Line);
1376 Conf_PongTimeout = 5;
1381 Config_Error_Section(Line, Var, "Limits");
1385 * Handle variable in [Options] configuration section.
1387 * @param Line Line numer in configuration file.
1388 * @param Var Variable name.
1389 * @param Arg Variable argument.
1392 Handle_OPTIONS(int Line, char *Var, char *Arg)
1397 assert(Var != NULL);
1398 assert(Arg != NULL);
1400 if (strcasecmp(Var, "AllowRemoteOper") == 0) {
1401 Conf_AllowRemoteOper = Check_ArgIsTrue(Arg);
1404 if (strcasecmp(Var, "ChrootDir") == 0) {
1405 len = strlcpy(Conf_Chroot, Arg, sizeof(Conf_Chroot));
1406 if (len >= sizeof(Conf_Chroot))
1407 Config_Error_TooLong(Line, Var);
1410 if (strcasecmp(Var, "CloakHost") == 0) {
1411 len = strlcpy(Conf_CloakHost, Arg, sizeof(Conf_CloakHost));
1412 if (len >= sizeof(Conf_CloakHost))
1413 Config_Error_TooLong(Line, Var);
1416 if (strcasecmp(Var, "CloakUserToNick") == 0) {
1417 Conf_CloakUserToNick = Check_ArgIsTrue(Arg);
1420 if (strcasecmp(Var, "ConnectIPv6") == 0) {
1421 Conf_ConnectIPv6 = Check_ArgIsTrue(Arg);
1425 if (strcasecmp(Var, "ConnectIPv4") == 0) {
1426 Conf_ConnectIPv4 = Check_ArgIsTrue(Arg);
1429 if (strcasecmp(Var, "DNS") == 0) {
1430 Conf_DNS = Check_ArgIsTrue(Arg);
1433 if (strcasecmp(Var, "Ident") == 0) {
1434 Conf_Ident = Check_ArgIsTrue(Arg);
1438 if (strcasecmp(Var, "NoticeAuth") == 0) {
1439 Conf_NoticeAuth = Check_ArgIsTrue(Arg);
1442 if (strcasecmp(Var, "OperCanUseMode") == 0) {
1443 Conf_OperCanMode = Check_ArgIsTrue(Arg);
1446 if (strcasecmp(Var, "OperServerMode") == 0) {
1447 Conf_OperServerMode = Check_ArgIsTrue(Arg);
1450 if (strcasecmp(Var, "PAM") == 0) {
1451 Conf_PAM = Check_ArgIsTrue(Arg);
1455 if (strcasecmp(Var, "PredefChannelsOnly") == 0) {
1456 Conf_PredefChannelsOnly = Check_ArgIsTrue(Arg);
1460 if (strcasecmp(Var, "RequireAuthPing") == 0) {
1461 Conf_AuthPing = Check_ArgIsTrue(Arg);
1466 if (strcasecmp(Var, "SSLCertFile") == 0) {
1467 assert(Conf_SSLOptions.CertFile == NULL);
1468 Conf_SSLOptions.CertFile = strdup_warn(Arg);
1471 if (strcasecmp(Var, "SSLDHFile") == 0) {
1472 assert(Conf_SSLOptions.DHFile == NULL);
1473 Conf_SSLOptions.DHFile = strdup_warn(Arg);
1476 if (strcasecmp(Var, "SSLKeyFile") == 0) {
1477 assert(Conf_SSLOptions.KeyFile == NULL);
1478 Conf_SSLOptions.KeyFile = strdup_warn(Arg);
1481 if (strcasecmp(Var, "SSLKeyFilePassword") == 0) {
1482 assert(array_bytes(&Conf_SSLOptions.KeyFilePassword) == 0);
1483 if (!array_copys(&Conf_SSLOptions.KeyFilePassword, Arg))
1484 Config_Error(LOG_ERR,
1485 "%s, line %d (section \"Global\"): Could not copy %s: %s!",
1486 NGIRCd_ConfFile, Line, Var,
1490 if (strcasecmp(Var, "SSLPorts") == 0) {
1491 ports_parse(&Conf_SSLOptions.ListenPorts, Line, Arg);
1496 if (strcasecmp(Var, "SyslogFacility") == 0) {
1497 Conf_SyslogFacility = ngt_SyslogFacilityID(Arg,
1498 Conf_SyslogFacility);
1502 if (strcasecmp(Var, "WebircPassword") == 0) {
1503 len = strlcpy(Conf_WebircPwd, Arg, sizeof(Conf_WebircPwd));
1504 if (len >= sizeof(Conf_WebircPwd))
1505 Config_Error_TooLong(Line, Var);
1509 Config_Error_Section(Line, Var, "Options");
1513 * Handle variable in [Operator] configuration section.
1515 * @param Line Line numer in configuration file.
1516 * @param Var Variable name.
1517 * @param Arg Variable argument.
1520 Handle_OPERATOR( int Line, char *Var, char *Arg )
1523 struct Conf_Oper *op;
1526 assert( Var != NULL );
1527 assert( Arg != NULL );
1528 assert( Conf_Oper_Count > 0 );
1530 op = array_alloc(&Conf_Opers, sizeof(*op), Conf_Oper_Count - 1);
1532 Config_Error(LOG_ERR, "Could not allocate memory for operator (%d:%s = %s)", Line, Var, Arg);
1536 if (strcasecmp(Var, "Name") == 0) {
1537 /* Name of IRC operator */
1538 len = strlcpy(op->name, Arg, sizeof(op->name));
1539 if (len >= sizeof(op->name))
1540 Config_Error_TooLong(Line, Var);
1543 if (strcasecmp(Var, "Password") == 0) {
1544 /* Password of IRC operator */
1545 len = strlcpy(op->pwd, Arg, sizeof(op->pwd));
1546 if (len >= sizeof(op->pwd))
1547 Config_Error_TooLong(Line, Var);
1550 if (strcasecmp(Var, "Mask") == 0) {
1552 return; /* Hostname already configured */
1553 op->mask = strdup_warn( Arg );
1557 Config_Error_Section(Line, Var, "Operator");
1561 * Handle variable in [Server] configuration section.
1563 * @param Line Line numer in configuration file.
1564 * @param Var Variable name.
1565 * @param Arg Variable argument.
1568 Handle_SERVER( int Line, char *Var, char *Arg )
1574 assert( Var != NULL );
1575 assert( Arg != NULL );
1577 /* Ignore server block if no space is left in server configuration structure */
1578 if( New_Server_Idx <= NONE ) return;
1580 if( strcasecmp( Var, "Host" ) == 0 ) {
1581 /* Hostname of the server */
1582 len = strlcpy( New_Server.host, Arg, sizeof( New_Server.host ));
1583 if (len >= sizeof( New_Server.host ))
1584 Config_Error_TooLong ( Line, Var );
1587 if( strcasecmp( Var, "Name" ) == 0 ) {
1588 /* Name of the server ("Nick"/"ID") */
1589 len = strlcpy( New_Server.name, Arg, sizeof( New_Server.name ));
1590 if (len >= sizeof( New_Server.name ))
1591 Config_Error_TooLong( Line, Var );
1594 if (strcasecmp(Var, "Bind") == 0) {
1595 if (ng_ipaddr_init(&New_Server.bind_addr, Arg, 0))
1598 Config_Error(LOG_ERR, "%s, line %d (section \"Server\"): Can't parse IP address \"%s\"",
1599 NGIRCd_ConfFile, Line, Arg);
1602 if( strcasecmp( Var, "MyPassword" ) == 0 ) {
1603 /* Password of this server which is sent to the peer */
1605 Config_Error(LOG_ERR,
1606 "%s, line %d (section \"Server\"): MyPassword must not start with ':'!",
1607 NGIRCd_ConfFile, Line);
1609 len = strlcpy( New_Server.pwd_in, Arg, sizeof( New_Server.pwd_in ));
1610 if (len >= sizeof( New_Server.pwd_in ))
1611 Config_Error_TooLong( Line, Var );
1614 if( strcasecmp( Var, "PeerPassword" ) == 0 ) {
1615 /* Passwort of the peer which must be received */
1616 len = strlcpy( New_Server.pwd_out, Arg, sizeof( New_Server.pwd_out ));
1617 if (len >= sizeof( New_Server.pwd_out ))
1618 Config_Error_TooLong( Line, Var );
1621 if( strcasecmp( Var, "Port" ) == 0 ) {
1622 /* Port to which this server should connect */
1624 if (port >= 0 && port < 0xFFFF)
1625 New_Server.port = (UINT16)port;
1627 Config_Error(LOG_ERR,
1628 "%s, line %d (section \"Server\"): Illegal port number %ld!",
1629 NGIRCd_ConfFile, Line, port );
1633 if( strcasecmp( Var, "SSLConnect" ) == 0 ) {
1634 New_Server.SSLConnect = Check_ArgIsTrue(Arg);
1638 if( strcasecmp( Var, "Group" ) == 0 ) {
1640 New_Server.group = atoi( Arg );
1641 if (!New_Server.group && strcmp(Arg, "0"))
1642 Config_Error_NaN(Line, Var);
1645 if( strcasecmp( Var, "Passive" ) == 0 ) {
1646 if (Check_ArgIsTrue(Arg))
1647 New_Server.flags |= CONF_SFLAG_DISABLED;
1650 if (strcasecmp(Var, "ServiceMask") == 0) {
1651 len = strlcpy(New_Server.svs_mask, ngt_LowerStr(Arg),
1652 sizeof(New_Server.svs_mask));
1653 if (len >= sizeof(New_Server.svs_mask))
1654 Config_Error_TooLong(Line, Var);
1658 Config_Error_Section(Line, Var, "Server");
1662 * Copy channel name into channel structure.
1664 * If the channel name is not valid because of a missing prefix ('#', '&'),
1665 * a default prefix of '#' will be added.
1667 * @param new_chan New already allocated channel structure.
1668 * @param name Name of the new channel.
1669 * @returns true on success, false otherwise.
1672 Handle_Channelname(struct Conf_Channel *new_chan, const char *name)
1674 size_t size = sizeof(new_chan->name);
1675 char *dest = new_chan->name;
1677 if (!Channel_IsValidName(name)) {
1679 * maybe user forgot to add a '#'.
1680 * This is only here for user convenience.
1686 return size > strlcpy(dest, name, size);
1690 * Handle variable in [Channel] configuration section.
1692 * @param Line Line numer in configuration file.
1693 * @param Var Variable name.
1694 * @param Arg Variable argument.
1697 Handle_CHANNEL(int Line, char *Var, char *Arg)
1701 struct Conf_Channel *chan;
1704 assert( Var != NULL );
1705 assert( Arg != NULL );
1706 assert(Conf_Channel_Count > 0);
1708 chancount = Conf_Channel_Count - 1;
1710 chan = array_alloc(&Conf_Channels, sizeof(*chan), chancount);
1712 Config_Error(LOG_ERR, "Could not allocate memory for predefined channel (%d:%s = %s)", Line, Var, Arg);
1715 if (strcasecmp(Var, "Name") == 0) {
1716 if (!Handle_Channelname(chan, Arg))
1717 Config_Error_TooLong(Line, Var);
1720 if (strcasecmp(Var, "Modes") == 0) {
1722 len = strlcpy(chan->modes, Arg, sizeof(chan->modes));
1723 if (len >= sizeof(chan->modes))
1724 Config_Error_TooLong( Line, Var );
1727 if( strcasecmp( Var, "Topic" ) == 0 ) {
1729 len = strlcpy(chan->topic, Arg, sizeof(chan->topic));
1730 if (len >= sizeof(chan->topic))
1731 Config_Error_TooLong( Line, Var );
1734 if( strcasecmp( Var, "Key" ) == 0 ) {
1735 /* Initial Channel Key (mode k) */
1736 len = strlcpy(chan->key, Arg, sizeof(chan->key));
1737 if (len >= sizeof(chan->key))
1738 Config_Error_TooLong(Line, Var);
1741 if( strcasecmp( Var, "MaxUsers" ) == 0 ) {
1742 /* maximum user limit, mode l */
1743 chan->maxusers = (unsigned long) atol(Arg);
1744 if (!chan->maxusers && strcmp(Arg, "0"))
1745 Config_Error_NaN(Line, Var);
1748 if (strcasecmp(Var, "KeyFile") == 0) {
1750 len = strlcpy(chan->keyfile, Arg, sizeof(chan->keyfile));
1751 if (len >= sizeof(chan->keyfile))
1752 Config_Error_TooLong(Line, Var);
1756 Config_Error_Section(Line, Var, "Channel");
1760 * Validate server configuration.
1762 * Please note that this function uses exit(1) on fatal errors and therefore
1763 * can result in ngIRCd terminating!
1765 * @param Configtest true if the daemon has been called with "--configtest".
1766 * @param Rehash true if re-reading configuration on runtime.
1767 * @returns true if configuration is valid.
1770 Validate_Config(bool Configtest, bool Rehash)
1772 /* Validate configuration settings. */
1775 int i, servers, servers_once;
1777 bool config_valid = true;
1780 /* Validate configured server name, see RFC 2812 section 2.3.1 */
1781 ptr = Conf_ServerName;
1783 if (*ptr >= 'a' && *ptr <= 'z') continue;
1784 if (*ptr >= 'A' && *ptr <= 'Z') continue;
1785 if (*ptr >= '0' && *ptr <= '9') continue;
1786 if (ptr > Conf_ServerName) {
1787 if (*ptr == '.' || *ptr == '-')
1790 Conf_ServerName[0] = '\0';
1794 if (!Conf_ServerName[0]) {
1795 /* No server name configured! */
1796 config_valid = false;
1797 Config_Error(LOG_ALERT,
1798 "No (valid) server name configured in \"%s\" (section 'Global': 'Name')!",
1800 if (!Configtest && !Rehash) {
1801 Config_Error(LOG_ALERT,
1802 "%s exiting due to fatal errors!",
1808 if (Conf_ServerName[0] && !strchr(Conf_ServerName, '.')) {
1809 /* No dot in server name! */
1810 config_valid = false;
1811 Config_Error(LOG_ALERT,
1812 "Invalid server name configured in \"%s\" (section 'Global': 'Name'): Dot missing!",
1815 Config_Error(LOG_ALERT,
1816 "%s exiting due to fatal errors!",
1823 if (!Conf_ServerAdminMail[0]) {
1824 /* No administrative contact configured! */
1825 config_valid = false;
1826 Config_Error(LOG_ALERT,
1827 "No administrator email address configured in \"%s\" ('AdminEMail')!",
1830 Config_Error(LOG_ALERT,
1831 "%s exiting due to fatal errors!",
1838 if (!Conf_ServerAdmin1[0] && !Conf_ServerAdmin2[0]
1839 && !Conf_ServerAdminMail[0]) {
1840 /* No administrative information configured! */
1841 Config_Error(LOG_WARNING,
1842 "No administrative information configured but required by RFC!");
1846 if (Conf_ServerPwd[0])
1847 Config_Error(LOG_ERR,
1848 "This server uses PAM, \"Password\" in [Global] section will be ignored!");
1852 servers = servers_once = 0;
1853 for (i = 0; i < MAX_SERVERS; i++) {
1854 if (Conf_Server[i].name[0]) {
1856 if (Conf_Server[i].flags & CONF_SFLAG_ONCE)
1861 "Configuration: Operators=%d, Servers=%d[%d], Channels=%d",
1862 Conf_Oper_Count, servers, servers_once, Conf_Channel_Count);
1865 return config_valid;
1869 * Output "line too long" warning.
1871 * @param Line Line number in configuration file.
1872 * @param Item Affected variable name.
1875 Config_Error_TooLong ( const int Line, const char *Item )
1877 Config_Error( LOG_WARNING, "%s, line %d: Value of \"%s\" too long!", NGIRCd_ConfFile, Line, Item );
1881 * Output "unknown variable" warning.
1883 * @param Line Line number in configuration file.
1884 * @param Item Affected variable name.
1885 * @param Section Section name.
1888 Config_Error_Section(const int Line, const char *Item, const char *Section)
1890 Config_Error(LOG_ERR, "%s, line %d (section \"%s\"): Unknown variable \"%s\"!",
1891 NGIRCd_ConfFile, Line, Section, Item);
1895 * Output "not a number" warning.
1897 * @param Line Line number in configuration file.
1898 * @param Item Affected variable name.
1901 Config_Error_NaN( const int Line, const char *Item )
1903 Config_Error( LOG_WARNING, "%s, line %d: Value of \"%s\" is not a number!",
1904 NGIRCd_ConfFile, Line, Item );
1908 * Output configuration error to console and/or logfile.
1910 * On runtime, the normal log functions of the daemon are used. But when
1911 * testing the configuration ("--configtest"), all messages go directly
1914 * @param Level Severity level of the message.
1915 * @param Format Format string; see printf() function.
1918 static void Config_Error( const int Level, const char *Format, ... )
1920 static void Config_Error( Level, Format, va_alist )
1926 char msg[MAX_LOG_MSG_LEN];
1929 assert( Format != NULL );
1932 va_start( ap, Format );
1936 vsnprintf( msg, MAX_LOG_MSG_LEN, Format, ap );
1940 if (Level <= LOG_WARNING)
1941 printf(" - %s\n", msg);
1945 Log(Level, "%s", msg);
1951 * Dump internal state of the "configuration module".
1954 Conf_DebugDump(void)
1958 Log(LOG_DEBUG, "Configured servers:");
1959 for (i = 0; i < MAX_SERVERS; i++) {
1960 if (! Conf_Server[i].name[0])
1963 " - %s: %s:%d, last=%ld, group=%d, flags=%d, conn=%d",
1964 Conf_Server[i].name, Conf_Server[i].host,
1965 Conf_Server[i].port, Conf_Server[i].lasttry,
1966 Conf_Server[i].group, Conf_Server[i].flags,
1967 Conf_Server[i].conn_id);
1974 * Initialize server configuration structur to default values.
1976 * @param Server Pointer to server structure to initialize.
1979 Init_Server_Struct( CONF_SERVER *Server )
1981 assert( Server != NULL );
1983 memset( Server, 0, sizeof (CONF_SERVER) );
1985 Server->group = NONE;
1986 Server->lasttry = time( NULL ) - Conf_ConnectRetry + STARTUP_DELAY;
1988 if( NGIRCd_Passive ) Server->flags = CONF_SFLAG_DISABLED;
1990 Proc_InitStruct(&Server->res_stat);
1991 Server->conn_id = NONE;
1992 memset(&Server->bind_addr, 0, sizeof(&Server->bind_addr));