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)
124 fp = fopen(Filename, "r");
128 Config_Error(LOG_ERR, "Can't read \"%s\" (\"%s\"): %s",
129 Filename, Var, strerror(errno));
136 * Duplicate string and warn on errors.
138 * @returns Pointer to string on success, NULL otherwise.
141 strdup_warn(const char *str)
143 char *ptr = strdup(str);
145 Config_Error(LOG_ERR,
146 "Could not allocate memory for string: %s", str);
151 * Output a comma separated list of ports (integer values).
158 len = array_length(a, sizeof(UINT16));
160 ports = (UINT16*) array_start(a);
161 printf("%u", (unsigned int) *ports);
164 printf(", %u", (unsigned int) *ports);
171 * Parse a comma separated string into an array of port numbers (integers).
174 ports_parse(array *a, int Line, char *Arg)
182 ptr = strtok( Arg, "," );
186 if (port > 0 && port < 0xFFFF) {
187 port16 = (UINT16) port;
188 if (!array_catb(a, (char*)&port16, sizeof port16))
189 Config_Error(LOG_ERR, "%s, line %d Could not add port number %ld: %s",
190 NGIRCd_ConfFile, Line, port, strerror(errno));
192 Config_Error( LOG_ERR, "%s, line %d (section \"Global\"): Illegal port number %ld!",
193 NGIRCd_ConfFile, Line, port );
196 ptr = strtok( NULL, "," );
201 * Initialize configuration module.
207 Validate_Config(false, false);
211 * "Rehash" (reload) server configuration.
213 * @returns true if configuration has been re-read, false on errors.
218 if (!Read_Config(false))
220 Validate_Config(false, true);
222 /* Update CLIENT structure of local server */
223 Client_SetInfo(Client_ThisServer(), Conf_ServerInfo);
228 * Output a boolean value as "yes/no" string.
231 yesno_to_str(int boolean_value)
239 * Free all IRC operator configuration structures.
244 struct Conf_Oper *op;
247 len = array_length(&Conf_Opers, sizeof(*op));
248 op = array_start(&Conf_Opers);
253 array_free(&Conf_Opers);
257 * Output all IRC operator configuration structures.
262 struct Conf_Oper *op;
265 len = array_length(&Conf_Opers, sizeof(*op));
266 op = array_start(&Conf_Opers);
271 printf(" Name = %s\n", op->name);
272 printf(" Password = %s\n", op->pwd);
273 printf(" Mask = %s\n\n", op->mask ? op->mask : "");
279 * Read configuration, validate and output it.
281 * This function waits for a keypress of the user when stdin/stdout are valid
282 * tty's ("you can read our nice message and we can read in your keypress").
284 * @return 0 on succes, 1 on failure(s); therefore the result code can
285 * directly be used by exit() when running "ngircd --configtest".
294 size_t predef_channel_count;
295 struct Conf_Channel *predef_chan;
299 if (! Read_Config(true))
302 config_valid = Validate_Config(true, false);
305 if( isatty( fileno( stdin )) && isatty( fileno( stdout ))) {
306 puts( "OK, press enter to see a dump of your service configuration ..." );
309 puts( "Ok, dump of your server configuration follows:\n" );
313 printf(" Name = %s\n", Conf_ServerName);
314 printf(" AdminInfo1 = %s\n", Conf_ServerAdmin1);
315 printf(" AdminInfo2 = %s\n", Conf_ServerAdmin2);
316 printf(" AdminEMail = %s\n", Conf_ServerAdminMail);
317 printf(" Info = %s\n", Conf_ServerInfo);
318 printf(" Listen = %s\n", Conf_ListenAddress);
319 if (Using_MotdFile) {
320 printf(" MotdFile = %s\n", Conf_MotdFile);
321 printf(" MotdPhrase =\n");
323 printf(" MotdFile = \n");
324 printf(" MotdPhrase = %s\n", array_bytes(&Conf_Motd)
325 ? (const char*) array_start(&Conf_Motd) : "");
328 printf(" Password = %s\n", Conf_ServerPwd);
330 printf(" PidFile = %s\n", Conf_PidFile);
332 ports_puts(&Conf_ListenPorts);
333 grp = getgrgid(Conf_GID);
335 printf(" ServerGID = %s\n", grp->gr_name);
337 printf(" ServerGID = %ld\n", (long)Conf_GID);
338 pwd = getpwuid(Conf_UID);
340 printf(" ServerUID = %s\n", pwd->pw_name);
342 printf(" ServerUID = %ld\n", (long)Conf_UID);
346 printf(" ConnectRetry = %d\n", Conf_ConnectRetry);
347 printf(" MaxConnections = %ld\n", Conf_MaxConnections);
348 printf(" MaxConnectionsIP = %d\n", Conf_MaxConnectionsIP);
349 printf(" MaxJoins = %d\n", Conf_MaxJoins > 0 ? Conf_MaxJoins : -1);
350 printf(" MaxNickLength = %u\n", Conf_MaxNickLength - 1);
351 printf(" PingTimeout = %d\n", Conf_PingTimeout);
352 printf(" PongTimeout = %d\n", Conf_PongTimeout);
356 printf(" AllowRemoteOper = %s\n", yesno_to_str(Conf_AllowRemoteOper));
357 printf(" ChrootDir = %s\n", Conf_Chroot);
358 printf(" CloakHost = %s\n", Conf_CloakHost);
359 printf(" CloakUserToNick = %s\n", yesno_to_str(Conf_CloakUserToNick));
361 printf(" ConnectIPv4 = %s\n", yesno_to_str(Conf_ConnectIPv6));
362 printf(" ConnectIPv6 = %s\n", yesno_to_str(Conf_ConnectIPv4));
364 printf(" DNS = %s\n", yesno_to_str(Conf_DNS));
366 printf(" Ident = %s\n", yesno_to_str(Conf_Ident));
368 printf(" NoticeAuth = %s\n", yesno_to_str(Conf_NoticeAuth));
369 printf(" OperCanUseMode = %s\n", yesno_to_str(Conf_OperCanMode));
370 printf(" OperServerMode = %s\n", yesno_to_str(Conf_OperServerMode));
372 printf(" PAM = %s\n", yesno_to_str(Conf_PAM));
374 printf(" PredefChannelsOnly = %s\n", yesno_to_str(Conf_PredefChannelsOnly));
376 printf(" RequireAuthPing = %s\n", yesno_to_str(Conf_AuthPing));
379 printf(" SSLCertFile = %s\n", Conf_SSLOptions.CertFile);
380 printf(" SSLDHFile = %s\n", Conf_SSLOptions.DHFile);
381 printf(" SSLKeyFile = %s\n", Conf_SSLOptions.KeyFile);
382 if (array_bytes(&Conf_SSLOptions.KeyFilePassword))
383 puts(" SSLKeyFilePassword = <secret>");
385 puts(" SSLKeyFilePassword = ");
386 array_free_wipe(&Conf_SSLOptions.KeyFilePassword);
387 printf(" SSLPorts = ");
388 ports_puts(&Conf_SSLOptions.ListenPorts);
391 printf(" SyslogFacility = %s\n",
392 ngt_SyslogFacilityName(Conf_SyslogFacility));
394 printf(" WebircPassword = %s\n", Conf_WebircPwd);
399 for( i = 0; i < MAX_SERVERS; i++ ) {
400 if( ! Conf_Server[i].name[0] ) continue;
402 /* Valid "Server" section */
404 printf( " Name = %s\n", Conf_Server[i].name );
405 printf( " Host = %s\n", Conf_Server[i].host );
406 printf( " Port = %u\n", (unsigned int)Conf_Server[i].port );
408 printf( " SSLConnect = %s\n", Conf_Server[i].SSLConnect?"yes":"no");
410 printf( " MyPassword = %s\n", Conf_Server[i].pwd_in );
411 printf( " PeerPassword = %s\n", Conf_Server[i].pwd_out );
412 printf( " ServiceMask = %s\n", Conf_Server[i].svs_mask);
413 printf( " Group = %d\n", Conf_Server[i].group );
414 printf( " Passive = %s\n\n", Conf_Server[i].flags & CONF_SFLAG_DISABLED ? "yes" : "no");
417 predef_channel_count = array_length(&Conf_Channels, sizeof(*predef_chan));
418 predef_chan = array_start(&Conf_Channels);
420 for (i = 0; i < predef_channel_count; i++, predef_chan++) {
421 if (!predef_chan->name[0])
424 /* Valid "Channel" section */
426 printf(" Name = %s\n", predef_chan->name);
427 printf(" Modes = %s\n", predef_chan->modes);
428 printf(" Key = %s\n", predef_chan->key);
429 printf(" MaxUsers = %lu\n", predef_chan->maxusers);
430 printf(" Topic = %s\n", predef_chan->topic);
431 printf(" KeyFile = %s\n\n", predef_chan->keyfile);
434 return (config_valid ? 0 : 1);
438 * Remove connection information from configured server.
440 * If the server is set as "once", delete it from our configuration;
441 * otherwise set the time for the next connection attempt.
443 * Non-server connections will be silently ignored.
446 Conf_UnsetServer( CONN_ID Idx )
451 /* Check all our configured servers */
452 for( i = 0; i < MAX_SERVERS; i++ ) {
453 if( Conf_Server[i].conn_id != Idx ) continue;
455 /* Gotcha! Mark server configuration as "unused": */
456 Conf_Server[i].conn_id = NONE;
458 if( Conf_Server[i].flags & CONF_SFLAG_ONCE ) {
459 /* Delete configuration here */
460 Init_Server_Struct( &Conf_Server[i] );
462 /* Set time for next connect attempt */
464 if (Conf_Server[i].lasttry < t - Conf_ConnectRetry) {
465 /* The connection has been "long", so we don't
466 * require the next attempt to be delayed. */
467 Conf_Server[i].lasttry =
468 t - Conf_ConnectRetry + RECONNECT_DELAY;
470 Conf_Server[i].lasttry = t;
476 * Set connection information for specified configured server.
479 Conf_SetServer( int ConfServer, CONN_ID Idx )
481 assert( ConfServer > NONE );
482 assert( Idx > NONE );
484 Conf_Server[ConfServer].conn_id = Idx;
488 * Get index of server in configuration structure.
491 Conf_GetServer( CONN_ID Idx )
495 assert( Idx > NONE );
497 for( i = 0; i < MAX_SERVERS; i++ ) {
498 if( Conf_Server[i].conn_id == Idx ) return i;
504 * Enable a server by name and adjust its port number.
506 * @returns true if a server has been enabled and now has a valid port
507 * number and host name for outgoing connections.
510 Conf_EnableServer( const char *Name, UINT16 Port )
514 assert( Name != NULL );
515 for( i = 0; i < MAX_SERVERS; i++ ) {
516 if( strcasecmp( Conf_Server[i].name, Name ) == 0 ) {
517 /* Gotcha! Set port and enable server: */
518 Conf_Server[i].port = Port;
519 Conf_Server[i].flags &= ~CONF_SFLAG_DISABLED;
520 return (Conf_Server[i].port && Conf_Server[i].host[0]);
527 * Enable a server by name.
529 * The server is only usable as outgoing server, if it has set a valid port
530 * number for outgoing connections!
531 * If not, you have to use Conf_EnableServer() function to make it available.
533 * @returns true if a server has been enabled; false otherwise.
536 Conf_EnablePassiveServer(const char *Name)
540 assert( Name != NULL );
541 for (i = 0; i < MAX_SERVERS; i++) {
542 if ((strcasecmp( Conf_Server[i].name, Name ) == 0)
543 && (Conf_Server[i].port > 0)) {
544 /* BINGO! Enable server */
545 Conf_Server[i].flags &= ~CONF_SFLAG_DISABLED;
553 * Disable a server by name.
554 * An already established connection will be disconnected.
556 * @returns true if a server was found and has been disabled.
559 Conf_DisableServer( const char *Name )
563 assert( Name != NULL );
564 for( i = 0; i < MAX_SERVERS; i++ ) {
565 if( strcasecmp( Conf_Server[i].name, Name ) == 0 ) {
566 /* Gotcha! Disable and disconnect server: */
567 Conf_Server[i].flags |= CONF_SFLAG_DISABLED;
568 if( Conf_Server[i].conn_id > NONE )
569 Conn_Close(Conf_Server[i].conn_id, NULL,
570 "Server link terminated on operator request",
579 * Add a new remote server to our configuration.
581 * @param Name Name of the new server.
582 * @param Port Port number to connect to or 0 for incoming connections.
583 * @param Host Host name to connect to.
584 * @param MyPwd Password that will be sent to the peer.
585 * @param PeerPwd Password that must be received from the peer.
586 * @returns true if the new server has been added; false otherwise.
589 Conf_AddServer(const char *Name, UINT16 Port, const char *Host,
590 const char *MyPwd, const char *PeerPwd)
594 assert( Name != NULL );
595 assert( Host != NULL );
596 assert( MyPwd != NULL );
597 assert( PeerPwd != NULL );
599 /* Search unused item in server configuration structure */
600 for( i = 0; i < MAX_SERVERS; i++ ) {
601 /* Is this item used? */
602 if( ! Conf_Server[i].name[0] ) break;
604 if( i >= MAX_SERVERS ) return false;
606 Init_Server_Struct( &Conf_Server[i] );
607 strlcpy( Conf_Server[i].name, Name, sizeof( Conf_Server[i].name ));
608 strlcpy( Conf_Server[i].host, Host, sizeof( Conf_Server[i].host ));
609 strlcpy( Conf_Server[i].pwd_out, MyPwd, sizeof( Conf_Server[i].pwd_out ));
610 strlcpy( Conf_Server[i].pwd_in, PeerPwd, sizeof( Conf_Server[i].pwd_in ));
611 Conf_Server[i].port = Port;
612 Conf_Server[i].flags = CONF_SFLAG_ONCE;
618 * Check if the given nick name is an service.
620 * @returns true if the given nick name belongs to an "IRC service".
623 Conf_IsService(int ConfServer, const char *Nick)
625 return MatchCaseInsensitive(Conf_Server[ConfServer].svs_mask, Nick);
629 * Initialize configuration settings with their default values.
632 Set_Defaults(bool InitServers)
637 strcpy(Conf_ServerName, "");
638 strcpy(Conf_ServerAdmin1, "");
639 strcpy(Conf_ServerAdmin2, "");
640 strcpy(Conf_ServerAdminMail, "");
641 snprintf(Conf_ServerInfo, sizeof Conf_ServerInfo, "%s %s",
642 PACKAGE_NAME, PACKAGE_VERSION);
643 free(Conf_ListenAddress);
644 Conf_ListenAddress = NULL;
645 array_free(&Conf_Motd);
646 strlcpy(Conf_MotdFile, SYSCONFDIR, sizeof(Conf_MotdFile));
647 strlcat(Conf_MotdFile, MOTD_FILE, sizeof(Conf_MotdFile));
648 strcpy(Conf_ServerPwd, "");
649 strlcpy(Conf_PidFile, PID_FILE, sizeof(Conf_PidFile));
650 Conf_UID = Conf_GID = 0;
653 Conf_ConnectRetry = 60;
654 Conf_MaxConnections = 0;
655 Conf_MaxConnectionsIP = 5;
657 Conf_MaxNickLength = CLIENT_NICK_LEN_DEFAULT;
658 Conf_PingTimeout = 120;
659 Conf_PongTimeout = 20;
662 Conf_AllowRemoteOper = false;
664 Conf_AuthPing = false;
666 strlcpy(Conf_Chroot, CHROOT_DIR, sizeof(Conf_Chroot));
667 strcpy(Conf_CloakHost, "");
668 Conf_CloakUserToNick = false;
669 Conf_ConnectIPv4 = true;
671 Conf_ConnectIPv6 = true;
673 Conf_ConnectIPv6 = false;
681 Conf_NoticeAuth = false;
682 Conf_OperCanMode = false;
683 Conf_OperServerMode = false;
689 Conf_PredefChannelsOnly = false;
692 Conf_SyslogFacility = LOG_LOCAL5;
694 Conf_SyslogFacility = 0;
698 /* Initialize IRC operators and channels */
700 Conf_Channel_Count = 0;
702 /* Initialize server configuration structures */
704 for (i = 0; i < MAX_SERVERS;
705 Init_Server_Struct(&Conf_Server[i++]));
710 * Get number of configured listening ports.
712 * @returns The number of ports (IPv4+IPv6) on which the server should listen.
717 size_t cnt = array_bytes(&Conf_ListenPorts);
719 cnt += array_bytes(&Conf_SSLOptions.ListenPorts);
725 * Read MOTD ("message of the day") file.
727 * @param filename Name of the file to read.
730 Read_Motd(const char *filename)
735 if (*filename == '\0')
738 fp = fopen(filename, "r");
740 Config_Error(LOG_WARNING, "Can't read MOTD file \"%s\": %s",
741 filename, strerror(errno));
745 array_free(&Conf_Motd);
746 Using_MotdFile = true;
748 while (fgets(line, (int)sizeof line, fp)) {
749 ngt_TrimLastChr( line, '\n');
751 /* add text including \0 */
752 if (!array_catb(&Conf_Motd, line, strlen(line) + 1)) {
753 Log(LOG_WARNING, "Cannot add MOTD text: %s", strerror(errno));
761 * Read ngIRCd configuration file.
763 * Please note that this function uses exit(1) on fatal errors and therefore
764 * can result in ngIRCd terminating!
766 * @param ngircd_starting Flag indicating if ngIRCd is starting or not.
767 * @returns true when the configuration file has been read
768 * successfully; false otherwise.
771 Read_Config( bool ngircd_starting )
773 char section[LINE_LEN], str[LINE_LEN], *var, *arg, *ptr;
774 const UINT16 defaultport = 6667;
778 /* Open configuration file */
779 fd = fopen( NGIRCd_ConfFile, "r" );
781 /* No configuration file found! */
782 Config_Error( LOG_ALERT, "Can't read configuration \"%s\": %s",
783 NGIRCd_ConfFile, strerror( errno ));
784 if (!ngircd_starting)
786 Config_Error( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME );
791 Set_Defaults( ngircd_starting );
793 Config_Error( LOG_INFO, "Reading configuration from \"%s\" ...", NGIRCd_ConfFile );
795 /* Clean up server configuration structure: mark all already
796 * configured servers as "once" so that they are deleted
797 * after the next disconnect and delete all unused servers.
798 * And delete all servers which are "duplicates" of servers
799 * that are already marked as "once" (such servers have been
800 * created by the last rehash but are now useless). */
801 for( i = 0; i < MAX_SERVERS; i++ ) {
802 if( Conf_Server[i].conn_id == NONE ) Init_Server_Struct( &Conf_Server[i] );
804 /* This structure is in use ... */
805 if( Conf_Server[i].flags & CONF_SFLAG_ONCE ) {
806 /* Check for duplicates */
807 for( n = 0; n < MAX_SERVERS; n++ ) {
808 if( n == i ) continue;
810 if( Conf_Server[i].conn_id == Conf_Server[n].conn_id ) {
811 Init_Server_Struct( &Conf_Server[n] );
813 Log(LOG_DEBUG,"Deleted unused duplicate server %d (kept %d).",
819 /* Mark server as "once" */
820 Conf_Server[i].flags |= CONF_SFLAG_ONCE;
821 Log( LOG_DEBUG, "Marked server %d as \"once\"", i );
826 /* Initialize variables */
828 strcpy( section, "" );
829 Init_Server_Struct( &New_Server );
830 New_Server_Idx = NONE;
834 /* Read configuration file */
836 if( ! fgets( str, LINE_LEN, fd )) break;
840 /* Skip comments and empty lines */
841 if( str[0] == ';' || str[0] == '#' || str[0] == '\0' ) continue;
843 /* Is this the beginning of a new section? */
844 if(( str[0] == '[' ) && ( str[strlen( str ) - 1] == ']' )) {
845 strlcpy( section, str, sizeof( section ));
846 if (strcasecmp(section, "[GLOBAL]") == 0 ||
847 strcasecmp(section, "[LIMITS]") == 0 ||
848 strcasecmp(section, "[OPTIONS]") == 0)
851 if( strcasecmp( section, "[SERVER]" ) == 0 ) {
852 /* Check if there is already a server to add */
853 if( New_Server.name[0] ) {
854 /* Copy data to "real" server structure */
855 assert( New_Server_Idx > NONE );
856 Conf_Server[New_Server_Idx] = New_Server;
859 /* Re-init structure for new server */
860 Init_Server_Struct( &New_Server );
862 /* Search unused item in server configuration structure */
863 for( i = 0; i < MAX_SERVERS; i++ ) {
864 /* Is this item used? */
865 if( ! Conf_Server[i].name[0] ) break;
867 if( i >= MAX_SERVERS ) {
868 /* Oops, no free item found! */
869 Config_Error( LOG_ERR, "Too many servers configured." );
870 New_Server_Idx = NONE;
872 else New_Server_Idx = i;
875 if (strcasecmp(section, "[CHANNEL]") == 0) {
876 Conf_Channel_Count++;
879 if (strcasecmp(section, "[OPERATOR]") == 0) {
884 Config_Error( LOG_ERR, "%s, line %d: Unknown section \"%s\"!", NGIRCd_ConfFile, line, section );
887 if( section[0] == 0x1 ) continue;
889 /* Split line into variable name and parameters */
890 ptr = strchr( str, '=' );
892 Config_Error( LOG_ERR, "%s, line %d: Syntax error!", NGIRCd_ConfFile, line );
896 var = str; ngt_TrimStr( var );
897 arg = ptr + 1; ngt_TrimStr( arg );
899 if(strcasecmp(section, "[GLOBAL]") == 0)
900 Handle_GLOBAL(line, var, arg);
901 else if(strcasecmp(section, "[LIMITS]") == 0)
902 Handle_LIMITS(line, var, arg);
903 else if(strcasecmp(section, "[OPTIONS]") == 0)
904 Handle_OPTIONS(line, var, arg);
905 else if(strcasecmp(section, "[OPERATOR]") == 0)
906 Handle_OPERATOR(line, var, arg);
907 else if(strcasecmp(section, "[SERVER]") == 0)
908 Handle_SERVER(line, var, arg);
909 else if(strcasecmp(section, "[CHANNEL]") == 0)
910 Handle_CHANNEL(line, var, arg);
912 Config_Error(LOG_ERR,
913 "%s, line %d: Variable \"%s\" outside section!",
914 NGIRCd_ConfFile, line, var);
917 /* Close configuration file */
920 /* Check if there is still a server to add */
921 if( New_Server.name[0] ) {
922 /* Copy data to "real" server structure */
923 assert( New_Server_Idx > NONE );
924 Conf_Server[New_Server_Idx] = New_Server;
927 /* not a single listening port? Add default. */
928 if (no_listenports() &&
929 !array_copyb(&Conf_ListenPorts, (char*) &defaultport, sizeof defaultport))
931 Config_Error(LOG_ALERT, "Could not add default listening Port %u: %s",
932 (unsigned int) defaultport, strerror(errno));
937 if (!Conf_ListenAddress)
938 Conf_ListenAddress = strdup_warn(DEFAULT_LISTEN_ADDRSTR);
940 if (!Conf_ListenAddress) {
941 Config_Error(LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME);
945 /* No MOTD phrase configured? (re)try motd file. */
946 if (array_bytes(&Conf_Motd) == 0)
947 Read_Motd(Conf_MotdFile);
950 /* Make sure that all SSL-related files are readable */
951 CheckFileReadable("SSLCertFile", Conf_SSLOptions.CertFile);
952 CheckFileReadable("SSLDHFile", Conf_SSLOptions.DHFile);
953 CheckFileReadable("SSLKeyFile", Conf_SSLOptions.KeyFile);
960 * Check whether an string argument is true or false.
962 * @param Arg Input string.
963 * @returns true if string has been parsed as "yes"/"true"/"on".
966 Check_ArgIsTrue( const char *Arg )
968 if( strcasecmp( Arg, "yes" ) == 0 ) return true;
969 if( strcasecmp( Arg, "true" ) == 0 ) return true;
970 if( atoi( Arg ) != 0 ) return true;
976 * Handle setting of "MaxNickLength".
978 * @param Line Line number in configuration file.
979 * @raram Arg Input string.
980 * @returns New configured maximum nick name length.
983 Handle_MaxNickLength(int Line, const char *Arg)
987 new = (unsigned) atoi(Arg) + 1;
988 if (new > CLIENT_NICK_LEN) {
989 Config_Error(LOG_WARNING,
990 "%s, line %d: Value of \"MaxNickLength\" exceeds %u!",
991 NGIRCd_ConfFile, Line, CLIENT_NICK_LEN - 1);
992 return CLIENT_NICK_LEN;
995 Config_Error(LOG_WARNING,
996 "%s, line %d: Value of \"MaxNickLength\" must be at least 1!",
997 NGIRCd_ConfFile, Line);
1004 * Output a warning messages if IDENT is configured but not compiled in.
1007 WarnIdent(int UNUSED Line)
1011 /* user has enabled ident lookups explicitly, but ... */
1012 Config_Error(LOG_WARNING,
1013 "%s: line %d: \"Ident = yes\", but ngircd was built without IDENT support!",
1014 NGIRCd_ConfFile, Line);
1020 * Output a warning messages if IPv6 is configured but not compiled in.
1023 WarnIPv6(int UNUSED Line)
1026 if (Conf_ConnectIPv6) {
1027 /* user has enabled IPv6 explicitly, but ... */
1028 Config_Error(LOG_WARNING,
1029 "%s: line %d: \"ConnectIPv6 = yes\", but ngircd was built without IPv6 support!",
1030 NGIRCd_ConfFile, Line);
1036 * Output a warning messages if PAM is configured but not compiled in.
1039 WarnPAM(int UNUSED Line)
1043 Config_Error(LOG_WARNING,
1044 "%s: line %d: \"PAM = yes\", but ngircd was built without PAM support!",
1045 NGIRCd_ConfFile, Line);
1051 * Handle legacy "NoXXX" options in [GLOBAL] section.
1053 * TODO: This function and support for "NoXXX" should be removed starting
1054 * with ngIRCd release 19! (One release after marking it "deprecated").
1056 * @param Var Variable name.
1057 * @param Arg Argument string.
1058 * @returns true if a NoXXX option has been processed; false otherwise.
1061 CheckLegacyNoOption(const char *Var, const char *Arg)
1063 if( strcasecmp( Var, "NoDNS" ) == 0 ) {
1064 Conf_DNS = !Check_ArgIsTrue( Arg );
1067 if (strcasecmp(Var, "NoIdent") == 0) {
1068 Conf_Ident = !Check_ArgIsTrue(Arg);
1071 if(strcasecmp(Var, "NoPAM") == 0) {
1072 Conf_PAM = !Check_ArgIsTrue(Arg);
1079 * Handle deprecated legacy options in [GLOBAL] section.
1081 * TODO: This function and support for these options in the [Global] section
1082 * could be removed starting with ngIRCd release 19 (one release after
1083 * marking it "deprecated").
1085 * @param Var Variable name.
1086 * @param Arg Argument string.
1087 * @returns true if a legacy option has been processed; false otherwise.
1090 CheckLegacyGlobalOption(int Line, char *Var, char *Arg)
1092 if (strcasecmp(Var, "AllowRemoteOper") == 0
1093 || strcasecmp(Var, "ChrootDir") == 0
1094 || strcasecmp(Var, "ConnectIPv4") == 0
1095 || strcasecmp(Var, "ConnectIPv6") == 0
1096 || strcasecmp(Var, "OperCanUseMode") == 0
1097 || strcasecmp(Var, "OperServerMode") == 0
1098 || strcasecmp(Var, "PredefChannelsOnly") == 0
1100 || strcasecmp(Var, "SSLCertFile") == 0
1101 || strcasecmp(Var, "SSLDHFile") == 0
1102 || strcasecmp(Var, "SSLKeyFile") == 0
1103 || strcasecmp(Var, "SSLKeyFilePassword") == 0
1104 || strcasecmp(Var, "SSLPorts") == 0
1106 || strcasecmp(Var, "SyslogFacility") == 0
1107 || strcasecmp(Var, "WebircPassword") == 0) {
1108 Handle_OPTIONS(Line, Var, Arg);
1111 if (strcasecmp(Var, "ConnectRetry") == 0
1112 || strcasecmp(Var, "MaxConnections") == 0
1113 || strcasecmp(Var, "MaxConnectionsIP") == 0
1114 || strcasecmp(Var, "MaxJoins") == 0
1115 || strcasecmp(Var, "MaxNickLength") == 0
1116 || strcasecmp(Var, "PingTimeout") == 0
1117 || strcasecmp(Var, "PongTimeout") == 0) {
1118 Handle_LIMITS(Line, Var, Arg);
1126 * Strip "no" prefix of a string.
1128 * TODO: This function and support for "NoXXX" should be removed starting
1129 * with ngIRCd release 19! (One release after marking it "deprecated").
1131 * @param str Pointer to input string starting with "no".
1132 * @returns New pointer to string without "no" prefix.
1135 NoNo(const char *str)
1137 assert(strncasecmp("no", str, 2) == 0 && str[2]);
1142 * Invert "boolean" string.
1144 * TODO: This function and support for "NoXXX" should be removed starting
1145 * with ngIRCd release 19! (One release after marking it "deprecated").
1147 * @param arg "Boolean" input string.
1148 * @returns Pointer to inverted "boolean string".
1151 InvertArg(const char *arg)
1153 return yesno_to_str(!Check_ArgIsTrue(arg));
1157 * Handle variable in [Global] configuration section.
1159 * @param Line Line numer in configuration file.
1160 * @param Var Variable name.
1161 * @param Arg Variable argument.
1164 Handle_GLOBAL( int Line, char *Var, char *Arg )
1169 const char *section;
1172 assert( Var != NULL );
1173 assert( Arg != NULL );
1175 if (strcasecmp(Var, "Name") == 0) {
1176 len = strlcpy(Conf_ServerName, Arg, sizeof(Conf_ServerName));
1177 if (len >= sizeof(Conf_ServerName))
1178 Config_Error_TooLong(Line, Var);
1181 if (strcasecmp(Var, "AdminInfo1") == 0) {
1182 len = strlcpy(Conf_ServerAdmin1, Arg, sizeof(Conf_ServerAdmin1));
1183 if (len >= sizeof(Conf_ServerAdmin1))
1184 Config_Error_TooLong(Line, Var);
1187 if (strcasecmp(Var, "AdminInfo2") == 0) {
1188 len = strlcpy(Conf_ServerAdmin2, Arg, sizeof(Conf_ServerAdmin2));
1189 if (len >= sizeof(Conf_ServerAdmin2))
1190 Config_Error_TooLong(Line, Var);
1193 if (strcasecmp(Var, "AdminEMail") == 0) {
1194 len = strlcpy(Conf_ServerAdminMail, Arg,
1195 sizeof(Conf_ServerAdminMail));
1196 if (len >= sizeof(Conf_ServerAdminMail))
1197 Config_Error_TooLong(Line, Var);
1200 if (strcasecmp(Var, "Info") == 0) {
1201 len = strlcpy(Conf_ServerInfo, Arg, sizeof(Conf_ServerInfo));
1202 if (len >= sizeof(Conf_ServerInfo))
1203 Config_Error_TooLong(Line, Var);
1206 if (strcasecmp(Var, "Listen") == 0) {
1207 if (Conf_ListenAddress) {
1208 Config_Error(LOG_ERR,
1209 "Multiple Listen= options, ignoring: %s",
1213 Conf_ListenAddress = strdup_warn(Arg);
1214 /* If allocation fails, we're in trouble: we cannot ignore the
1215 * error -- otherwise ngircd would listen on all interfaces. */
1216 if (!Conf_ListenAddress) {
1217 Config_Error(LOG_ALERT,
1218 "%s exiting due to fatal errors!",
1224 if (strcasecmp(Var, "MotdFile") == 0) {
1225 len = strlcpy(Conf_MotdFile, Arg, sizeof(Conf_MotdFile));
1226 if (len >= sizeof(Conf_MotdFile))
1227 Config_Error_TooLong(Line, Var);
1230 if (strcasecmp(Var, "MotdPhrase") == 0) {
1234 if (len >= LINE_LEN) {
1235 Config_Error_TooLong( Line, Var );
1238 if (!array_copyb(&Conf_Motd, Arg, len + 1))
1239 Config_Error(LOG_WARNING, "%s, line %d: Could not append MotdPhrase: %s",
1240 NGIRCd_ConfFile, Line, strerror(errno));
1241 Using_MotdFile = false;
1244 if(strcasecmp(Var, "Password") == 0) {
1245 len = strlcpy(Conf_ServerPwd, Arg, sizeof(Conf_ServerPwd));
1246 if (len >= sizeof(Conf_ServerPwd))
1247 Config_Error_TooLong(Line, Var);
1250 if (strcasecmp(Var, "PidFile") == 0) {
1251 len = strlcpy(Conf_PidFile, Arg, sizeof(Conf_PidFile));
1252 if (len >= sizeof(Conf_PidFile))
1253 Config_Error_TooLong(Line, Var);
1256 if (strcasecmp(Var, "Ports") == 0) {
1257 ports_parse(&Conf_ListenPorts, Line, Arg);
1260 if (strcasecmp(Var, "ServerGID") == 0) {
1261 grp = getgrnam(Arg);
1263 Conf_GID = grp->gr_gid;
1265 Conf_GID = (unsigned int)atoi(Arg);
1266 if (!Conf_GID && strcmp(Arg, "0"))
1267 Config_Error_NaN(Line, Var);
1271 if (strcasecmp(Var, "ServerUID") == 0) {
1272 pwd = getpwnam(Arg);
1274 Conf_UID = pwd->pw_uid;
1276 Conf_UID = (unsigned int)atoi(Arg);
1277 if (!Conf_UID && strcmp(Arg, "0"))
1278 Config_Error_NaN(Line, Var);
1283 if (CheckLegacyNoOption(Var, Arg)) {
1284 Config_Error(LOG_WARNING, "%s, line %d: \"No\"-Prefix has been removed, use \"%s = %s\" in [FEATURES] section instead",
1285 NGIRCd_ConfFile, Line, NoNo(Var), InvertArg(Arg));
1286 if (strcasecmp(Var, "NoIdent") == 0)
1288 else if (strcasecmp(Var, "NoPam") == 0)
1292 if ((section = CheckLegacyGlobalOption(Line, Var, Arg))) {
1293 /** TODO: This function and support for these options in the
1294 * [Global] section could be removed starting with ngIRCd
1295 * release 19 (one release after marking it "deprecated"). */
1296 Config_Error(LOG_WARNING,
1297 "%s, line %d (section \"Global\"): \"%s\" is deprecated here, move it to %s!",
1298 NGIRCd_ConfFile, Line, Var, section);
1302 Config_Error_Section(Line, Var, "Global");
1306 * Handle variable in [Limits] configuration section.
1308 * @param Line Line numer in configuration file.
1309 * @param Var Variable name.
1310 * @param Arg Variable argument.
1313 Handle_LIMITS(int Line, char *Var, char *Arg)
1316 assert(Var != NULL);
1317 assert(Arg != NULL);
1319 if (strcasecmp(Var, "ConnectRetry") == 0) {
1320 Conf_ConnectRetry = atoi(Arg);
1321 if (Conf_ConnectRetry < 5) {
1322 Config_Error(LOG_WARNING,
1323 "%s, line %d: Value of \"ConnectRetry\" too low!",
1324 NGIRCd_ConfFile, Line);
1325 Conf_ConnectRetry = 5;
1329 if (strcasecmp(Var, "MaxConnections") == 0) {
1330 Conf_MaxConnections = atol(Arg);
1331 if (!Conf_MaxConnections && strcmp(Arg, "0"))
1332 Config_Error_NaN(Line, Var);
1335 if (strcasecmp(Var, "MaxConnectionsIP") == 0) {
1336 Conf_MaxConnectionsIP = atoi(Arg);
1337 if (!Conf_MaxConnectionsIP && strcmp(Arg, "0"))
1338 Config_Error_NaN(Line, Var);
1341 if (strcasecmp(Var, "MaxJoins") == 0) {
1342 Conf_MaxJoins = atoi(Arg);
1343 if (!Conf_MaxJoins && strcmp(Arg, "0"))
1344 Config_Error_NaN(Line, Var);
1347 if (strcasecmp(Var, "MaxNickLength") == 0) {
1348 Conf_MaxNickLength = Handle_MaxNickLength(Line, Arg);
1351 if (strcasecmp(Var, "PingTimeout") == 0) {
1352 Conf_PingTimeout = atoi(Arg);
1353 if (Conf_PingTimeout < 5) {
1354 Config_Error(LOG_WARNING,
1355 "%s, line %d: Value of \"PingTimeout\" too low!",
1356 NGIRCd_ConfFile, Line);
1357 Conf_PingTimeout = 5;
1361 if (strcasecmp(Var, "PongTimeout") == 0) {
1362 Conf_PongTimeout = atoi(Arg);
1363 if (Conf_PongTimeout < 5) {
1364 Config_Error(LOG_WARNING,
1365 "%s, line %d: Value of \"PongTimeout\" too low!",
1366 NGIRCd_ConfFile, Line);
1367 Conf_PongTimeout = 5;
1372 Config_Error_Section(Line, Var, "Limits");
1376 * Handle variable in [Options] configuration section.
1378 * @param Line Line numer in configuration file.
1379 * @param Var Variable name.
1380 * @param Arg Variable argument.
1383 Handle_OPTIONS(int Line, char *Var, char *Arg)
1388 assert(Var != NULL);
1389 assert(Arg != NULL);
1391 if (strcasecmp(Var, "AllowRemoteOper") == 0) {
1392 Conf_AllowRemoteOper = Check_ArgIsTrue(Arg);
1395 if (strcasecmp(Var, "ChrootDir") == 0) {
1396 len = strlcpy(Conf_Chroot, Arg, sizeof(Conf_Chroot));
1397 if (len >= sizeof(Conf_Chroot))
1398 Config_Error_TooLong(Line, Var);
1401 if (strcasecmp(Var, "CloakHost") == 0) {
1402 len = strlcpy(Conf_CloakHost, Arg, sizeof(Conf_CloakHost));
1403 if (len >= sizeof(Conf_CloakHost))
1404 Config_Error_TooLong(Line, Var);
1407 if (strcasecmp(Var, "CloakUserToNick") == 0) {
1408 Conf_CloakUserToNick = Check_ArgIsTrue(Arg);
1411 if (strcasecmp(Var, "ConnectIPv6") == 0) {
1412 Conf_ConnectIPv6 = Check_ArgIsTrue(Arg);
1416 if (strcasecmp(Var, "ConnectIPv4") == 0) {
1417 Conf_ConnectIPv4 = Check_ArgIsTrue(Arg);
1420 if (strcasecmp(Var, "DNS") == 0) {
1421 Conf_DNS = Check_ArgIsTrue(Arg);
1424 if (strcasecmp(Var, "Ident") == 0) {
1425 Conf_Ident = Check_ArgIsTrue(Arg);
1429 if (strcasecmp(Var, "NoticeAuth") == 0) {
1430 Conf_NoticeAuth = Check_ArgIsTrue(Arg);
1433 if (strcasecmp(Var, "OperCanUseMode") == 0) {
1434 Conf_OperCanMode = Check_ArgIsTrue(Arg);
1437 if (strcasecmp(Var, "OperServerMode") == 0) {
1438 Conf_OperServerMode = Check_ArgIsTrue(Arg);
1441 if (strcasecmp(Var, "PAM") == 0) {
1442 Conf_PAM = Check_ArgIsTrue(Arg);
1446 if (strcasecmp(Var, "PredefChannelsOnly") == 0) {
1447 Conf_PredefChannelsOnly = Check_ArgIsTrue(Arg);
1451 if (strcasecmp(Var, "RequireAuthPing") == 0) {
1452 Conf_AuthPing = Check_ArgIsTrue(Arg);
1457 if (strcasecmp(Var, "SSLCertFile") == 0) {
1458 assert(Conf_SSLOptions.CertFile == NULL);
1459 Conf_SSLOptions.CertFile = strdup_warn(Arg);
1462 if (strcasecmp(Var, "SSLDHFile") == 0) {
1463 assert(Conf_SSLOptions.DHFile == NULL);
1464 Conf_SSLOptions.DHFile = strdup_warn(Arg);
1467 if (strcasecmp(Var, "SSLKeyFile") == 0) {
1468 assert(Conf_SSLOptions.KeyFile == NULL);
1469 Conf_SSLOptions.KeyFile = strdup_warn(Arg);
1472 if (strcasecmp(Var, "SSLKeyFilePassword") == 0) {
1473 assert(array_bytes(&Conf_SSLOptions.KeyFilePassword) == 0);
1474 if (!array_copys(&Conf_SSLOptions.KeyFilePassword, Arg))
1475 Config_Error(LOG_ERR,
1476 "%s, line %d (section \"Global\"): Could not copy %s: %s!",
1477 NGIRCd_ConfFile, Line, Var,
1481 if (strcasecmp(Var, "SSLPorts") == 0) {
1482 ports_parse(&Conf_SSLOptions.ListenPorts, Line, Arg);
1487 if (strcasecmp(Var, "SyslogFacility") == 0) {
1488 Conf_SyslogFacility = ngt_SyslogFacilityID(Arg,
1489 Conf_SyslogFacility);
1493 if (strcasecmp(Var, "WebircPassword") == 0) {
1494 len = strlcpy(Conf_WebircPwd, Arg, sizeof(Conf_WebircPwd));
1495 if (len >= sizeof(Conf_WebircPwd))
1496 Config_Error_TooLong(Line, Var);
1500 Config_Error_Section(Line, Var, "Options");
1504 * Handle variable in [Operator] configuration section.
1506 * @param Line Line numer in configuration file.
1507 * @param Var Variable name.
1508 * @param Arg Variable argument.
1511 Handle_OPERATOR( int Line, char *Var, char *Arg )
1514 struct Conf_Oper *op;
1517 assert( Var != NULL );
1518 assert( Arg != NULL );
1519 assert( Conf_Oper_Count > 0 );
1521 op = array_alloc(&Conf_Opers, sizeof(*op), Conf_Oper_Count - 1);
1523 Config_Error(LOG_ERR, "Could not allocate memory for operator (%d:%s = %s)", Line, Var, Arg);
1527 if (strcasecmp(Var, "Name") == 0) {
1528 /* Name of IRC operator */
1529 len = strlcpy(op->name, Arg, sizeof(op->name));
1530 if (len >= sizeof(op->name))
1531 Config_Error_TooLong(Line, Var);
1534 if (strcasecmp(Var, "Password") == 0) {
1535 /* Password of IRC operator */
1536 len = strlcpy(op->pwd, Arg, sizeof(op->pwd));
1537 if (len >= sizeof(op->pwd))
1538 Config_Error_TooLong(Line, Var);
1541 if (strcasecmp(Var, "Mask") == 0) {
1543 return; /* Hostname already configured */
1544 op->mask = strdup_warn( Arg );
1548 Config_Error_Section(Line, Var, "Operator");
1552 * Handle variable in [Server] configuration section.
1554 * @param Line Line numer in configuration file.
1555 * @param Var Variable name.
1556 * @param Arg Variable argument.
1559 Handle_SERVER( int Line, char *Var, char *Arg )
1565 assert( Var != NULL );
1566 assert( Arg != NULL );
1568 /* Ignore server block if no space is left in server configuration structure */
1569 if( New_Server_Idx <= NONE ) return;
1571 if( strcasecmp( Var, "Host" ) == 0 ) {
1572 /* Hostname of the server */
1573 len = strlcpy( New_Server.host, Arg, sizeof( New_Server.host ));
1574 if (len >= sizeof( New_Server.host ))
1575 Config_Error_TooLong ( Line, Var );
1578 if( strcasecmp( Var, "Name" ) == 0 ) {
1579 /* Name of the server ("Nick"/"ID") */
1580 len = strlcpy( New_Server.name, Arg, sizeof( New_Server.name ));
1581 if (len >= sizeof( New_Server.name ))
1582 Config_Error_TooLong( Line, Var );
1585 if (strcasecmp(Var, "Bind") == 0) {
1586 if (ng_ipaddr_init(&New_Server.bind_addr, Arg, 0))
1589 Config_Error(LOG_ERR, "%s, line %d (section \"Server\"): Can't parse IP address \"%s\"",
1590 NGIRCd_ConfFile, Line, Arg);
1593 if( strcasecmp( Var, "MyPassword" ) == 0 ) {
1594 /* Password of this server which is sent to the peer */
1596 Config_Error(LOG_ERR,
1597 "%s, line %d (section \"Server\"): MyPassword must not start with ':'!",
1598 NGIRCd_ConfFile, Line);
1600 len = strlcpy( New_Server.pwd_in, Arg, sizeof( New_Server.pwd_in ));
1601 if (len >= sizeof( New_Server.pwd_in ))
1602 Config_Error_TooLong( Line, Var );
1605 if( strcasecmp( Var, "PeerPassword" ) == 0 ) {
1606 /* Passwort of the peer which must be received */
1607 len = strlcpy( New_Server.pwd_out, Arg, sizeof( New_Server.pwd_out ));
1608 if (len >= sizeof( New_Server.pwd_out ))
1609 Config_Error_TooLong( Line, Var );
1612 if( strcasecmp( Var, "Port" ) == 0 ) {
1613 /* Port to which this server should connect */
1615 if (port >= 0 && port < 0xFFFF)
1616 New_Server.port = (UINT16)port;
1618 Config_Error(LOG_ERR,
1619 "%s, line %d (section \"Server\"): Illegal port number %ld!",
1620 NGIRCd_ConfFile, Line, port );
1624 if( strcasecmp( Var, "SSLConnect" ) == 0 ) {
1625 New_Server.SSLConnect = Check_ArgIsTrue(Arg);
1629 if( strcasecmp( Var, "Group" ) == 0 ) {
1631 New_Server.group = atoi( Arg );
1632 if (!New_Server.group && strcmp(Arg, "0"))
1633 Config_Error_NaN(Line, Var);
1636 if( strcasecmp( Var, "Passive" ) == 0 ) {
1637 if (Check_ArgIsTrue(Arg))
1638 New_Server.flags |= CONF_SFLAG_DISABLED;
1641 if (strcasecmp(Var, "ServiceMask") == 0) {
1642 len = strlcpy(New_Server.svs_mask, ngt_LowerStr(Arg),
1643 sizeof(New_Server.svs_mask));
1644 if (len >= sizeof(New_Server.svs_mask))
1645 Config_Error_TooLong(Line, Var);
1649 Config_Error_Section(Line, Var, "Server");
1653 * Copy channel name into channel structure.
1655 * If the channel name is not valid because of a missing prefix ('#', '&'),
1656 * a default prefix of '#' will be added.
1658 * @param new_chan New already allocated channel structure.
1659 * @param name Name of the new channel.
1660 * @returns true on success, false otherwise.
1663 Handle_Channelname(struct Conf_Channel *new_chan, const char *name)
1665 size_t size = sizeof(new_chan->name);
1666 char *dest = new_chan->name;
1668 if (!Channel_IsValidName(name)) {
1670 * maybe user forgot to add a '#'.
1671 * This is only here for user convenience.
1677 return size > strlcpy(dest, name, size);
1681 * Handle variable in [Channel] configuration section.
1683 * @param Line Line numer in configuration file.
1684 * @param Var Variable name.
1685 * @param Arg Variable argument.
1688 Handle_CHANNEL(int Line, char *Var, char *Arg)
1692 struct Conf_Channel *chan;
1695 assert( Var != NULL );
1696 assert( Arg != NULL );
1697 assert(Conf_Channel_Count > 0);
1699 chancount = Conf_Channel_Count - 1;
1701 chan = array_alloc(&Conf_Channels, sizeof(*chan), chancount);
1703 Config_Error(LOG_ERR, "Could not allocate memory for predefined channel (%d:%s = %s)", Line, Var, Arg);
1706 if (strcasecmp(Var, "Name") == 0) {
1707 if (!Handle_Channelname(chan, Arg))
1708 Config_Error_TooLong(Line, Var);
1711 if (strcasecmp(Var, "Modes") == 0) {
1713 len = strlcpy(chan->modes, Arg, sizeof(chan->modes));
1714 if (len >= sizeof(chan->modes))
1715 Config_Error_TooLong( Line, Var );
1718 if( strcasecmp( Var, "Topic" ) == 0 ) {
1720 len = strlcpy(chan->topic, Arg, sizeof(chan->topic));
1721 if (len >= sizeof(chan->topic))
1722 Config_Error_TooLong( Line, Var );
1725 if( strcasecmp( Var, "Key" ) == 0 ) {
1726 /* Initial Channel Key (mode k) */
1727 len = strlcpy(chan->key, Arg, sizeof(chan->key));
1728 if (len >= sizeof(chan->key))
1729 Config_Error_TooLong(Line, Var);
1732 if( strcasecmp( Var, "MaxUsers" ) == 0 ) {
1733 /* maximum user limit, mode l */
1734 chan->maxusers = (unsigned long) atol(Arg);
1735 if (!chan->maxusers && strcmp(Arg, "0"))
1736 Config_Error_NaN(Line, Var);
1739 if (strcasecmp(Var, "KeyFile") == 0) {
1741 len = strlcpy(chan->keyfile, Arg, sizeof(chan->keyfile));
1742 if (len >= sizeof(chan->keyfile))
1743 Config_Error_TooLong(Line, Var);
1747 Config_Error_Section(Line, Var, "Channel");
1751 * Validate server configuration.
1753 * Please note that this function uses exit(1) on fatal errors and therefore
1754 * can result in ngIRCd terminating!
1756 * @param Configtest true if the daemon has been called with "--configtest".
1757 * @param Rehash true if re-reading configuration on runtime.
1758 * @returns true if configuration is valid.
1761 Validate_Config(bool Configtest, bool Rehash)
1763 /* Validate configuration settings. */
1766 int i, servers, servers_once;
1768 bool config_valid = true;
1771 /* Validate configured server name, see RFC 2812 section 2.3.1 */
1772 ptr = Conf_ServerName;
1774 if (*ptr >= 'a' && *ptr <= 'z') continue;
1775 if (*ptr >= 'A' && *ptr <= 'Z') continue;
1776 if (*ptr >= '0' && *ptr <= '9') continue;
1777 if (ptr > Conf_ServerName) {
1778 if (*ptr == '.' || *ptr == '-')
1781 Conf_ServerName[0] = '\0';
1785 if (!Conf_ServerName[0]) {
1786 /* No server name configured! */
1787 config_valid = false;
1788 Config_Error(LOG_ALERT,
1789 "No (valid) server name configured in \"%s\" (section 'Global': 'Name')!",
1791 if (!Configtest && !Rehash) {
1792 Config_Error(LOG_ALERT,
1793 "%s exiting due to fatal errors!",
1799 if (Conf_ServerName[0] && !strchr(Conf_ServerName, '.')) {
1800 /* No dot in server name! */
1801 config_valid = false;
1802 Config_Error(LOG_ALERT,
1803 "Invalid server name configured in \"%s\" (section 'Global': 'Name'): Dot missing!",
1806 Config_Error(LOG_ALERT,
1807 "%s exiting due to fatal errors!",
1814 if (!Conf_ServerAdminMail[0]) {
1815 /* No administrative contact configured! */
1816 config_valid = false;
1817 Config_Error(LOG_ALERT,
1818 "No administrator email address configured in \"%s\" ('AdminEMail')!",
1821 Config_Error(LOG_ALERT,
1822 "%s exiting due to fatal errors!",
1829 if (!Conf_ServerAdmin1[0] && !Conf_ServerAdmin2[0]
1830 && !Conf_ServerAdminMail[0]) {
1831 /* No administrative information configured! */
1832 Config_Error(LOG_WARNING,
1833 "No administrative information configured but required by RFC!");
1837 if (Conf_ServerPwd[0])
1838 Config_Error(LOG_ERR,
1839 "This server uses PAM, \"Password\" will be ignored!");
1843 servers = servers_once = 0;
1844 for (i = 0; i < MAX_SERVERS; i++) {
1845 if (Conf_Server[i].name[0]) {
1847 if (Conf_Server[i].flags & CONF_SFLAG_ONCE)
1852 "Configuration: Operators=%d, Servers=%d[%d], Channels=%d",
1853 Conf_Oper_Count, servers, servers_once, Conf_Channel_Count);
1856 return config_valid;
1860 * Output "line too long" warning.
1862 * @param Line Line number in configuration file.
1863 * @param Item Affected variable name.
1866 Config_Error_TooLong ( const int Line, const char *Item )
1868 Config_Error( LOG_WARNING, "%s, line %d: Value of \"%s\" too long!", NGIRCd_ConfFile, Line, Item );
1872 * Output "unknown variable" warning.
1874 * @param Line Line number in configuration file.
1875 * @param Item Affected variable name.
1876 * @param Section Section name.
1879 Config_Error_Section(const int Line, const char *Item, const char *Section)
1881 Config_Error(LOG_ERR, "%s, line %d (section \"%s\"): Unknown variable \"%s\"!",
1882 NGIRCd_ConfFile, Line, Section, Item);
1886 * Output "not a number" warning.
1888 * @param Line Line number in configuration file.
1889 * @param Item Affected variable name.
1892 Config_Error_NaN( const int Line, const char *Item )
1894 Config_Error( LOG_WARNING, "%s, line %d: Value of \"%s\" is not a number!",
1895 NGIRCd_ConfFile, Line, Item );
1899 * Output configuration error to console and/or logfile.
1901 * On runtime, the normal log functions of the daemon are used. But when
1902 * testing the configuration ("--configtest"), all messages go directly
1905 * @param Level Severity level of the message.
1906 * @param Format Format string; see printf() function.
1909 static void Config_Error( const int Level, const char *Format, ... )
1911 static void Config_Error( Level, Format, va_alist )
1917 char msg[MAX_LOG_MSG_LEN];
1920 assert( Format != NULL );
1923 va_start( ap, Format );
1927 vsnprintf( msg, MAX_LOG_MSG_LEN, Format, ap );
1930 if (Use_Log) Log( Level, "%s", msg );
1937 * Dump internal state of the "configuration module".
1940 Conf_DebugDump(void)
1944 Log(LOG_DEBUG, "Configured servers:");
1945 for (i = 0; i < MAX_SERVERS; i++) {
1946 if (! Conf_Server[i].name[0])
1949 " - %s: %s:%d, last=%ld, group=%d, flags=%d, conn=%d",
1950 Conf_Server[i].name, Conf_Server[i].host,
1951 Conf_Server[i].port, Conf_Server[i].lasttry,
1952 Conf_Server[i].group, Conf_Server[i].flags,
1953 Conf_Server[i].conn_id);
1960 * Initialize server configuration structur to default values.
1962 * @param Server Pointer to server structure to initialize.
1965 Init_Server_Struct( CONF_SERVER *Server )
1967 assert( Server != NULL );
1969 memset( Server, 0, sizeof (CONF_SERVER) );
1971 Server->group = NONE;
1972 Server->lasttry = time( NULL ) - Conf_ConnectRetry + STARTUP_DELAY;
1974 if( NGIRCd_Passive ) Server->flags = CONF_SFLAG_DISABLED;
1976 Proc_InitStruct(&Server->res_stat);
1977 Server->conn_id = NONE;
1978 memset(&Server->bind_addr, 0, sizeof(&Server->bind_addr));