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 char Conf_MotdFile[FNAME_LEN];
60 static void Set_Defaults PARAMS(( bool InitServers ));
61 static bool Read_Config PARAMS(( bool ngircd_starting ));
62 static bool Validate_Config PARAMS(( bool TestOnly, bool Rehash ));
64 static void Handle_GLOBAL PARAMS(( int Line, char *Var, char *Arg ));
65 static void Handle_LIMITS PARAMS(( int Line, char *Var, char *Arg ));
66 static void Handle_OPTIONS PARAMS(( int Line, char *Var, char *Arg ));
67 static void Handle_OPERATOR PARAMS(( int Line, char *Var, char *Arg ));
68 static void Handle_SERVER PARAMS(( int Line, char *Var, char *Arg ));
69 static void Handle_CHANNEL PARAMS(( int Line, char *Var, char *Arg ));
71 static void Config_Error PARAMS(( const int Level, const char *Format, ... ));
73 static void Config_Error_NaN PARAMS(( const int LINE, const char *Value ));
74 static void Config_Error_Section PARAMS(( const int Line, const char *Item,
75 const char *Section ));
76 static void Config_Error_TooLong PARAMS(( const int LINE, const char *Value ));
78 static void Init_Server_Struct PARAMS(( CONF_SERVER *Server ));
82 #define DEFAULT_LISTEN_ADDRSTR "::,0.0.0.0"
84 #define DEFAULT_LISTEN_ADDRSTR "0.0.0.0"
90 static void Handle_SSL PARAMS(( int Line, char *Var, char *Ark ));
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 count = array_length(&Conf_Opers, sizeof(*op));
269 op = array_start(&Conf_Opers);
270 for (i = 0; i < count; i++, op++) {
275 printf(" Name = %s\n", op->name);
276 printf(" Password = %s\n", op->pwd);
277 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(" MorePrivacy = %s\n", yesno_to_str(Conf_MorePrivacy));
371 printf(" NoticeAuth = %s\n", yesno_to_str(Conf_NoticeAuth));
372 printf(" OperCanUseMode = %s\n", yesno_to_str(Conf_OperCanMode));
373 printf(" OperServerMode = %s\n", yesno_to_str(Conf_OperServerMode));
375 printf(" PAM = %s\n", yesno_to_str(Conf_PAM));
376 printf(" PAMIsOptional = %s\n", yesno_to_str(Conf_PAMIsOptional));
378 printf(" PredefChannelsOnly = %s\n", yesno_to_str(Conf_PredefChannelsOnly));
380 printf(" RequireAuthPing = %s\n", yesno_to_str(Conf_AuthPing));
382 printf(" ScrubCTCP = %s\n", yesno_to_str(Conf_ScrubCTCP));
384 printf(" SyslogFacility = %s\n",
385 ngt_SyslogFacilityName(Conf_SyslogFacility));
387 printf(" WebircPassword = %s\n", Conf_WebircPwd);
392 printf(" CertFile = %s\n", Conf_SSLOptions.CertFile
393 ? Conf_SSLOptions.CertFile : "");
394 printf(" DHFile = %s\n", Conf_SSLOptions.DHFile
395 ? Conf_SSLOptions.DHFile : "");
396 printf(" KeyFile = %s\n", Conf_SSLOptions.KeyFile
397 ? Conf_SSLOptions.KeyFile : "");
398 if (array_bytes(&Conf_SSLOptions.KeyFilePassword))
399 puts(" KeyFilePassword = <secret>");
401 puts(" KeyFilePassword = ");
402 array_free_wipe(&Conf_SSLOptions.KeyFilePassword);
404 ports_puts(&Conf_SSLOptions.ListenPorts);
410 for( i = 0; i < MAX_SERVERS; i++ ) {
411 if( ! Conf_Server[i].name[0] ) continue;
413 /* Valid "Server" section */
415 printf( " Name = %s\n", Conf_Server[i].name );
416 printf( " Host = %s\n", Conf_Server[i].host );
417 printf( " Port = %u\n", (unsigned int)Conf_Server[i].port );
419 printf( " SSLConnect = %s\n", Conf_Server[i].SSLConnect?"yes":"no");
421 printf( " MyPassword = %s\n", Conf_Server[i].pwd_in );
422 printf( " PeerPassword = %s\n", Conf_Server[i].pwd_out );
423 printf( " ServiceMask = %s\n", Conf_Server[i].svs_mask);
424 printf( " Group = %d\n", Conf_Server[i].group );
425 printf( " Passive = %s\n\n", Conf_Server[i].flags & CONF_SFLAG_DISABLED ? "yes" : "no");
428 predef_channel_count = array_length(&Conf_Channels, sizeof(*predef_chan));
429 predef_chan = array_start(&Conf_Channels);
431 for (i = 0; i < predef_channel_count; i++, predef_chan++) {
432 if (!predef_chan->name[0])
435 /* Valid "Channel" section */
437 printf(" Name = %s\n", predef_chan->name);
438 printf(" Modes = %s\n", predef_chan->modes);
439 printf(" Key = %s\n", predef_chan->key);
440 printf(" MaxUsers = %lu\n", predef_chan->maxusers);
441 printf(" Topic = %s\n", predef_chan->topic);
442 printf(" KeyFile = %s\n\n", predef_chan->keyfile);
445 return (config_valid ? 0 : 1);
449 * Remove connection information from configured server.
451 * If the server is set as "once", delete it from our configuration;
452 * otherwise set the time for the next connection attempt.
454 * Non-server connections will be silently ignored.
457 Conf_UnsetServer( CONN_ID Idx )
462 /* Check all our configured servers */
463 for( i = 0; i < MAX_SERVERS; i++ ) {
464 if( Conf_Server[i].conn_id != Idx ) continue;
466 /* Gotcha! Mark server configuration as "unused": */
467 Conf_Server[i].conn_id = NONE;
469 if( Conf_Server[i].flags & CONF_SFLAG_ONCE ) {
470 /* Delete configuration here */
471 Init_Server_Struct( &Conf_Server[i] );
473 /* Set time for next connect attempt */
475 if (Conf_Server[i].lasttry < t - Conf_ConnectRetry) {
476 /* The connection has been "long", so we don't
477 * require the next attempt to be delayed. */
478 Conf_Server[i].lasttry =
479 t - Conf_ConnectRetry + RECONNECT_DELAY;
481 Conf_Server[i].lasttry = t;
487 * Set connection information for specified configured server.
490 Conf_SetServer( int ConfServer, CONN_ID Idx )
492 assert( ConfServer > NONE );
493 assert( Idx > NONE );
495 Conf_Server[ConfServer].conn_id = Idx;
499 * Get index of server in configuration structure.
502 Conf_GetServer( CONN_ID Idx )
506 assert( Idx > NONE );
508 for( i = 0; i < MAX_SERVERS; i++ ) {
509 if( Conf_Server[i].conn_id == Idx ) return i;
515 * Enable a server by name and adjust its port number.
517 * @returns true if a server has been enabled and now has a valid port
518 * number and host name for outgoing connections.
521 Conf_EnableServer( const char *Name, UINT16 Port )
525 assert( Name != NULL );
526 for( i = 0; i < MAX_SERVERS; i++ ) {
527 if( strcasecmp( Conf_Server[i].name, Name ) == 0 ) {
528 /* Gotcha! Set port and enable server: */
529 Conf_Server[i].port = Port;
530 Conf_Server[i].flags &= ~CONF_SFLAG_DISABLED;
531 return (Conf_Server[i].port && Conf_Server[i].host[0]);
538 * Enable a server by name.
540 * The server is only usable as outgoing server, if it has set a valid port
541 * number for outgoing connections!
542 * If not, you have to use Conf_EnableServer() function to make it available.
544 * @returns true if a server has been enabled; false otherwise.
547 Conf_EnablePassiveServer(const char *Name)
551 assert( Name != NULL );
552 for (i = 0; i < MAX_SERVERS; i++) {
553 if ((strcasecmp( Conf_Server[i].name, Name ) == 0)
554 && (Conf_Server[i].port > 0)) {
555 /* BINGO! Enable server */
556 Conf_Server[i].flags &= ~CONF_SFLAG_DISABLED;
564 * Disable a server by name.
565 * An already established connection will be disconnected.
567 * @returns true if a server was found and has been disabled.
570 Conf_DisableServer( const char *Name )
574 assert( Name != NULL );
575 for( i = 0; i < MAX_SERVERS; i++ ) {
576 if( strcasecmp( Conf_Server[i].name, Name ) == 0 ) {
577 /* Gotcha! Disable and disconnect server: */
578 Conf_Server[i].flags |= CONF_SFLAG_DISABLED;
579 if( Conf_Server[i].conn_id > NONE )
580 Conn_Close(Conf_Server[i].conn_id, NULL,
581 "Server link terminated on operator request",
590 * Add a new remote server to our configuration.
592 * @param Name Name of the new server.
593 * @param Port Port number to connect to or 0 for incoming connections.
594 * @param Host Host name to connect to.
595 * @param MyPwd Password that will be sent to the peer.
596 * @param PeerPwd Password that must be received from the peer.
597 * @returns true if the new server has been added; false otherwise.
600 Conf_AddServer(const char *Name, UINT16 Port, const char *Host,
601 const char *MyPwd, const char *PeerPwd)
605 assert( Name != NULL );
606 assert( Host != NULL );
607 assert( MyPwd != NULL );
608 assert( PeerPwd != NULL );
610 /* Search unused item in server configuration structure */
611 for( i = 0; i < MAX_SERVERS; i++ ) {
612 /* Is this item used? */
613 if( ! Conf_Server[i].name[0] ) break;
615 if( i >= MAX_SERVERS ) return false;
617 Init_Server_Struct( &Conf_Server[i] );
618 strlcpy( Conf_Server[i].name, Name, sizeof( Conf_Server[i].name ));
619 strlcpy( Conf_Server[i].host, Host, sizeof( Conf_Server[i].host ));
620 strlcpy( Conf_Server[i].pwd_out, MyPwd, sizeof( Conf_Server[i].pwd_out ));
621 strlcpy( Conf_Server[i].pwd_in, PeerPwd, sizeof( Conf_Server[i].pwd_in ));
622 Conf_Server[i].port = Port;
623 Conf_Server[i].flags = CONF_SFLAG_ONCE;
629 * Check if the given nick name is an service.
631 * @returns true if the given nick name belongs to an "IRC service".
634 Conf_IsService(int ConfServer, const char *Nick)
636 return MatchCaseInsensitive(Conf_Server[ConfServer].svs_mask, Nick);
640 * Initialize configuration settings with their default values.
643 Set_Defaults(bool InitServers)
648 strcpy(Conf_ServerName, "");
649 strcpy(Conf_ServerAdmin1, "");
650 strcpy(Conf_ServerAdmin2, "");
651 strcpy(Conf_ServerAdminMail, "");
652 snprintf(Conf_ServerInfo, sizeof Conf_ServerInfo, "%s %s",
653 PACKAGE_NAME, PACKAGE_VERSION);
654 free(Conf_ListenAddress);
655 Conf_ListenAddress = NULL;
656 array_free(&Conf_Motd);
657 strlcpy(Conf_MotdFile, SYSCONFDIR, sizeof(Conf_MotdFile));
658 strlcat(Conf_MotdFile, MOTD_FILE, sizeof(Conf_MotdFile));
659 strcpy(Conf_ServerPwd, "");
660 strlcpy(Conf_PidFile, PID_FILE, sizeof(Conf_PidFile));
661 Conf_UID = Conf_GID = 0;
664 Conf_ConnectRetry = 60;
665 Conf_MaxConnections = 0;
666 Conf_MaxConnectionsIP = 5;
668 Conf_MaxNickLength = CLIENT_NICK_LEN_DEFAULT;
669 Conf_PingTimeout = 120;
670 Conf_PongTimeout = 20;
673 Conf_AllowRemoteOper = false;
675 Conf_AuthPing = false;
677 strlcpy(Conf_Chroot, CHROOT_DIR, sizeof(Conf_Chroot));
678 strcpy(Conf_CloakHost, "");
679 Conf_CloakUserToNick = false;
680 Conf_ConnectIPv4 = true;
682 Conf_ConnectIPv6 = true;
684 Conf_ConnectIPv6 = false;
692 Conf_MorePrivacy = false;
693 Conf_NoticeAuth = false;
694 Conf_OperCanMode = false;
695 Conf_OperServerMode = false;
701 Conf_PAMIsOptional = false;
702 Conf_PredefChannelsOnly = false;
704 Conf_ScrubCTCP = false;
706 Conf_SyslogFacility = LOG_LOCAL5;
708 Conf_SyslogFacility = 0;
712 /* Initialize server configuration structures */
714 for (i = 0; i < MAX_SERVERS;
715 Init_Server_Struct(&Conf_Server[i++]));
720 * Get number of configured listening ports.
722 * @returns The number of ports (IPv4+IPv6) on which the server should listen.
727 size_t cnt = array_bytes(&Conf_ListenPorts);
729 cnt += array_bytes(&Conf_SSLOptions.ListenPorts);
735 * Read MOTD ("message of the day") file.
737 * @param filename Name of the file to read.
740 Read_Motd(const char *filename)
745 if (*filename == '\0')
748 fp = fopen(filename, "r");
750 Config_Error(LOG_WARNING, "Can't read MOTD file \"%s\": %s",
751 filename, strerror(errno));
755 array_free(&Conf_Motd);
756 Using_MotdFile = true;
758 while (fgets(line, (int)sizeof line, fp)) {
759 ngt_TrimLastChr( line, '\n');
761 /* add text including \0 */
762 if (!array_catb(&Conf_Motd, line, strlen(line) + 1)) {
763 Log(LOG_WARNING, "Cannot add MOTD text: %s", strerror(errno));
771 * Read ngIRCd configuration file.
773 * Please note that this function uses exit(1) on fatal errors and therefore
774 * can result in ngIRCd terminating!
776 * @param ngircd_starting Flag indicating if ngIRCd is starting or not.
777 * @returns true when the configuration file has been read
778 * successfully; false otherwise.
781 Read_Config( bool ngircd_starting )
783 char section[LINE_LEN], str[LINE_LEN], *var, *arg, *ptr;
784 const UINT16 defaultport = 6667;
789 /* Open configuration file */
790 fd = fopen( NGIRCd_ConfFile, "r" );
792 /* No configuration file found! */
793 Config_Error( LOG_ALERT, "Can't read configuration \"%s\": %s",
794 NGIRCd_ConfFile, strerror( errno ));
795 if (!ngircd_starting)
797 Config_Error( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME );
802 Set_Defaults( ngircd_starting );
804 Config_Error( LOG_INFO, "Reading configuration from \"%s\" ...", NGIRCd_ConfFile );
806 /* Clean up server configuration structure: mark all already
807 * configured servers as "once" so that they are deleted
808 * after the next disconnect and delete all unused servers.
809 * And delete all servers which are "duplicates" of servers
810 * that are already marked as "once" (such servers have been
811 * created by the last rehash but are now useless). */
812 for( i = 0; i < MAX_SERVERS; i++ ) {
813 if( Conf_Server[i].conn_id == NONE ) Init_Server_Struct( &Conf_Server[i] );
815 /* This structure is in use ... */
816 if( Conf_Server[i].flags & CONF_SFLAG_ONCE ) {
817 /* Check for duplicates */
818 for( n = 0; n < MAX_SERVERS; n++ ) {
819 if( n == i ) continue;
821 if( Conf_Server[i].conn_id == Conf_Server[n].conn_id ) {
822 Init_Server_Struct( &Conf_Server[n] );
824 Log(LOG_DEBUG,"Deleted unused duplicate server %d (kept %d).",
830 /* Mark server as "once" */
831 Conf_Server[i].flags |= CONF_SFLAG_ONCE;
832 Log( LOG_DEBUG, "Marked server %d as \"once\"", i );
837 /* Initialize variables */
839 strcpy( section, "" );
840 Init_Server_Struct( &New_Server );
841 New_Server_Idx = NONE;
845 /* Read configuration file */
847 if( ! fgets( str, LINE_LEN, fd )) break;
851 /* Skip comments and empty lines */
852 if( str[0] == ';' || str[0] == '#' || str[0] == '\0' ) continue;
854 /* Is this the beginning of a new section? */
855 if(( str[0] == '[' ) && ( str[strlen( str ) - 1] == ']' )) {
856 strlcpy( section, str, sizeof( section ));
857 if (strcasecmp(section, "[GLOBAL]") == 0
858 || strcasecmp(section, "[LIMITS]") == 0
859 || strcasecmp(section, "[OPTIONS]") == 0
861 || strcasecmp(section, "[SSL]") == 0
866 if( strcasecmp( section, "[SERVER]" ) == 0 ) {
867 /* Check if there is already a server to add */
868 if( New_Server.name[0] ) {
869 /* Copy data to "real" server structure */
870 assert( New_Server_Idx > NONE );
871 Conf_Server[New_Server_Idx] = New_Server;
874 /* Re-init structure for new server */
875 Init_Server_Struct( &New_Server );
877 /* Search unused item in server configuration structure */
878 for( i = 0; i < MAX_SERVERS; i++ ) {
879 /* Is this item used? */
880 if( ! Conf_Server[i].name[0] ) break;
882 if( i >= MAX_SERVERS ) {
883 /* Oops, no free item found! */
884 Config_Error( LOG_ERR, "Too many servers configured." );
885 New_Server_Idx = NONE;
887 else New_Server_Idx = i;
891 if (strcasecmp(section, "[CHANNEL]") == 0) {
892 count = array_length(&Conf_Channels,
893 sizeof(struct Conf_Channel));
894 if (!array_alloc(&Conf_Channels,
895 sizeof(struct Conf_Channel),
897 Config_Error(LOG_ERR,
898 "Could not allocate memory for new operator (line %d)",
904 if (strcasecmp(section, "[OPERATOR]") == 0) {
905 count = array_length(&Conf_Opers,
906 sizeof(struct Conf_Oper));
907 if (!array_alloc(&Conf_Opers,
908 sizeof(struct Conf_Oper),
910 Config_Error(LOG_ERR,
911 "Could not allocate memory for new channel (line &d)",
917 Config_Error(LOG_ERR,
918 "%s, line %d: Unknown section \"%s\"!",
919 NGIRCd_ConfFile, line, section);
922 if( section[0] == 0x1 ) continue;
924 /* Split line into variable name and parameters */
925 ptr = strchr( str, '=' );
927 Config_Error( LOG_ERR, "%s, line %d: Syntax error!", NGIRCd_ConfFile, line );
931 var = str; ngt_TrimStr( var );
932 arg = ptr + 1; ngt_TrimStr( arg );
934 if(strcasecmp(section, "[GLOBAL]") == 0)
935 Handle_GLOBAL(line, var, arg);
936 else if(strcasecmp(section, "[LIMITS]") == 0)
937 Handle_LIMITS(line, var, arg);
938 else if(strcasecmp(section, "[OPTIONS]") == 0)
939 Handle_OPTIONS(line, var, arg);
941 else if(strcasecmp(section, "[SSL]") == 0)
942 Handle_SSL(line, var, arg);
944 else if(strcasecmp(section, "[OPERATOR]") == 0)
945 Handle_OPERATOR(line, var, arg);
946 else if(strcasecmp(section, "[SERVER]") == 0)
947 Handle_SERVER(line, var, arg);
948 else if(strcasecmp(section, "[CHANNEL]") == 0)
949 Handle_CHANNEL(line, var, arg);
951 Config_Error(LOG_ERR,
952 "%s, line %d: Variable \"%s\" outside section!",
953 NGIRCd_ConfFile, line, var);
956 /* Close configuration file */
959 /* Check if there is still a server to add */
960 if( New_Server.name[0] ) {
961 /* Copy data to "real" server structure */
962 assert( New_Server_Idx > NONE );
963 Conf_Server[New_Server_Idx] = New_Server;
966 /* not a single listening port? Add default. */
967 if (no_listenports() &&
968 !array_copyb(&Conf_ListenPorts, (char*) &defaultport, sizeof defaultport))
970 Config_Error(LOG_ALERT, "Could not add default listening Port %u: %s",
971 (unsigned int) defaultport, strerror(errno));
976 if (!Conf_ListenAddress)
977 Conf_ListenAddress = strdup_warn(DEFAULT_LISTEN_ADDRSTR);
979 if (!Conf_ListenAddress) {
980 Config_Error(LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME);
984 /* No MOTD phrase configured? (re)try motd file. */
985 if (array_bytes(&Conf_Motd) == 0)
986 Read_Motd(Conf_MotdFile);
989 /* Make sure that all SSL-related files are readable */
990 CheckFileReadable("CertFile", Conf_SSLOptions.CertFile);
991 CheckFileReadable("DHFile", Conf_SSLOptions.DHFile);
992 CheckFileReadable("KeyFile", Conf_SSLOptions.KeyFile);
999 * Check whether a string argument is "true" or "false".
1001 * @param Arg Input string.
1002 * @returns true if the input string has been parsed as "yes", "true"
1003 * (case insensitive) or a non-zero integer value.
1006 Check_ArgIsTrue(const char *Arg)
1008 if (strcasecmp(Arg, "yes") == 0)
1010 if (strcasecmp(Arg, "true") == 0)
1019 * Handle setting of "MaxNickLength".
1021 * @param Line Line number in configuration file.
1022 * @raram Arg Input string.
1023 * @returns New configured maximum nick name length.
1026 Handle_MaxNickLength(int Line, const char *Arg)
1030 new = (unsigned) atoi(Arg) + 1;
1031 if (new > CLIENT_NICK_LEN) {
1032 Config_Error(LOG_WARNING,
1033 "%s, line %d: Value of \"MaxNickLength\" exceeds %u!",
1034 NGIRCd_ConfFile, Line, CLIENT_NICK_LEN - 1);
1035 return CLIENT_NICK_LEN;
1038 Config_Error(LOG_WARNING,
1039 "%s, line %d: Value of \"MaxNickLength\" must be at least 1!",
1040 NGIRCd_ConfFile, Line);
1047 * Output a warning messages if IDENT is configured but not compiled in.
1050 WarnIdent(int UNUSED Line)
1054 /* user has enabled ident lookups explicitly, but ... */
1055 Config_Error(LOG_WARNING,
1056 "%s: line %d: \"Ident = yes\", but ngircd was built without IDENT support!",
1057 NGIRCd_ConfFile, Line);
1063 * Output a warning messages if IPv6 is configured but not compiled in.
1066 WarnIPv6(int UNUSED Line)
1069 if (Conf_ConnectIPv6) {
1070 /* user has enabled IPv6 explicitly, but ... */
1071 Config_Error(LOG_WARNING,
1072 "%s: line %d: \"ConnectIPv6 = yes\", but ngircd was built without IPv6 support!",
1073 NGIRCd_ConfFile, Line);
1079 * Output a warning messages if PAM is configured but not compiled in.
1082 WarnPAM(int UNUSED Line)
1086 Config_Error(LOG_WARNING,
1087 "%s: line %d: \"PAM = yes\", but ngircd was built without PAM support!",
1088 NGIRCd_ConfFile, Line);
1094 * Handle legacy "NoXXX" options in [GLOBAL] section.
1096 * TODO: This function and support for "NoXXX" could be removed starting
1097 * with ngIRCd release 19 (one release after marking it "deprecated").
1099 * @param Var Variable name.
1100 * @param Arg Argument string.
1101 * @returns true if a NoXXX option has been processed; false otherwise.
1104 CheckLegacyNoOption(const char *Var, const char *Arg)
1106 if(strcasecmp(Var, "NoDNS") == 0) {
1107 Conf_DNS = !Check_ArgIsTrue( Arg );
1110 if (strcasecmp(Var, "NoIdent") == 0) {
1111 Conf_Ident = !Check_ArgIsTrue(Arg);
1114 if(strcasecmp(Var, "NoPAM") == 0) {
1115 Conf_PAM = !Check_ArgIsTrue(Arg);
1122 * Handle deprecated legacy options in [GLOBAL] section.
1124 * TODO: This function and support for these options in the [Global] section
1125 * could be removed starting with ngIRCd release 19 (one release after
1126 * marking it "deprecated").
1128 * @param Var Variable name.
1129 * @param Arg Argument string.
1130 * @returns true if a legacy option has been processed; false otherwise.
1133 CheckLegacyGlobalOption(int Line, char *Var, char *Arg)
1135 if (strcasecmp(Var, "AllowRemoteOper") == 0
1136 || strcasecmp(Var, "ChrootDir") == 0
1137 || strcasecmp(Var, "ConnectIPv4") == 0
1138 || strcasecmp(Var, "ConnectIPv6") == 0
1139 || strcasecmp(Var, "OperCanUseMode") == 0
1140 || strcasecmp(Var, "OperServerMode") == 0
1141 || strcasecmp(Var, "PredefChannelsOnly") == 0
1142 || strcasecmp(Var, "SyslogFacility") == 0
1143 || strcasecmp(Var, "WebircPassword") == 0) {
1144 Handle_OPTIONS(Line, Var, Arg);
1147 if (strcasecmp(Var, "ConnectRetry") == 0
1148 || strcasecmp(Var, "MaxConnections") == 0
1149 || strcasecmp(Var, "MaxConnectionsIP") == 0
1150 || strcasecmp(Var, "MaxJoins") == 0
1151 || strcasecmp(Var, "MaxNickLength") == 0
1152 || strcasecmp(Var, "PingTimeout") == 0
1153 || strcasecmp(Var, "PongTimeout") == 0) {
1154 Handle_LIMITS(Line, Var, Arg);
1158 if (strcasecmp(Var, "SSLCertFile") == 0
1159 || strcasecmp(Var, "SSLDHFile") == 0
1160 || strcasecmp(Var, "SSLKeyFile") == 0
1161 || strcasecmp(Var, "SSLKeyFilePassword") == 0
1162 || strcasecmp(Var, "SSLPorts") == 0) {
1163 Handle_SSL(Line, Var + 3, Arg);
1172 * Strip "no" prefix of a string.
1174 * TODO: This function and support for "NoXXX" should be removed starting
1175 * with ngIRCd release 19! (One release after marking it "deprecated").
1177 * @param str Pointer to input string starting with "no".
1178 * @returns New pointer to string without "no" prefix.
1181 NoNo(const char *str)
1183 assert(strncasecmp("no", str, 2) == 0 && str[2]);
1188 * Invert "boolean" string.
1190 * TODO: This function and support for "NoXXX" should be removed starting
1191 * with ngIRCd release 19! (One release after marking it "deprecated").
1193 * @param arg "Boolean" input string.
1194 * @returns Pointer to inverted "boolean string".
1197 InvertArg(const char *arg)
1199 return yesno_to_str(!Check_ArgIsTrue(arg));
1203 * Handle variable in [Global] configuration section.
1205 * @param Line Line numer in configuration file.
1206 * @param Var Variable name.
1207 * @param Arg Variable argument.
1210 Handle_GLOBAL( int Line, char *Var, char *Arg )
1215 const char *section;
1218 assert(Var != NULL);
1219 assert(Arg != NULL);
1221 if (strcasecmp(Var, "Name") == 0) {
1222 len = strlcpy(Conf_ServerName, Arg, sizeof(Conf_ServerName));
1223 if (len >= sizeof(Conf_ServerName))
1224 Config_Error_TooLong(Line, Var);
1227 if (strcasecmp(Var, "AdminInfo1") == 0) {
1228 len = strlcpy(Conf_ServerAdmin1, Arg, sizeof(Conf_ServerAdmin1));
1229 if (len >= sizeof(Conf_ServerAdmin1))
1230 Config_Error_TooLong(Line, Var);
1233 if (strcasecmp(Var, "AdminInfo2") == 0) {
1234 len = strlcpy(Conf_ServerAdmin2, Arg, sizeof(Conf_ServerAdmin2));
1235 if (len >= sizeof(Conf_ServerAdmin2))
1236 Config_Error_TooLong(Line, Var);
1239 if (strcasecmp(Var, "AdminEMail") == 0) {
1240 len = strlcpy(Conf_ServerAdminMail, Arg,
1241 sizeof(Conf_ServerAdminMail));
1242 if (len >= sizeof(Conf_ServerAdminMail))
1243 Config_Error_TooLong(Line, Var);
1246 if (strcasecmp(Var, "Info") == 0) {
1247 len = strlcpy(Conf_ServerInfo, Arg, sizeof(Conf_ServerInfo));
1248 if (len >= sizeof(Conf_ServerInfo))
1249 Config_Error_TooLong(Line, Var);
1252 if (strcasecmp(Var, "Listen") == 0) {
1253 if (Conf_ListenAddress) {
1254 Config_Error(LOG_ERR,
1255 "Multiple Listen= options, ignoring: %s",
1259 Conf_ListenAddress = strdup_warn(Arg);
1260 /* If allocation fails, we're in trouble: we cannot ignore the
1261 * error -- otherwise ngircd would listen on all interfaces. */
1262 if (!Conf_ListenAddress) {
1263 Config_Error(LOG_ALERT,
1264 "%s exiting due to fatal errors!",
1270 if (strcasecmp(Var, "MotdFile") == 0) {
1271 len = strlcpy(Conf_MotdFile, Arg, sizeof(Conf_MotdFile));
1272 if (len >= sizeof(Conf_MotdFile))
1273 Config_Error_TooLong(Line, Var);
1276 if (strcasecmp(Var, "MotdPhrase") == 0) {
1280 if (len >= LINE_LEN) {
1281 Config_Error_TooLong(Line, Var);
1284 if (!array_copyb(&Conf_Motd, Arg, len + 1))
1285 Config_Error(LOG_WARNING,
1286 "%s, line %d: Could not append MotdPhrase: %s",
1287 NGIRCd_ConfFile, Line, strerror(errno));
1288 Using_MotdFile = false;
1291 if(strcasecmp(Var, "Password") == 0) {
1292 len = strlcpy(Conf_ServerPwd, Arg, sizeof(Conf_ServerPwd));
1293 if (len >= sizeof(Conf_ServerPwd))
1294 Config_Error_TooLong(Line, Var);
1297 if (strcasecmp(Var, "PidFile") == 0) {
1298 len = strlcpy(Conf_PidFile, Arg, sizeof(Conf_PidFile));
1299 if (len >= sizeof(Conf_PidFile))
1300 Config_Error_TooLong(Line, Var);
1303 if (strcasecmp(Var, "Ports") == 0) {
1304 ports_parse(&Conf_ListenPorts, Line, Arg);
1307 if (strcasecmp(Var, "ServerGID") == 0) {
1308 grp = getgrnam(Arg);
1310 Conf_GID = grp->gr_gid;
1312 Conf_GID = (unsigned int)atoi(Arg);
1313 if (!Conf_GID && strcmp(Arg, "0"))
1314 Config_Error(LOG_WARNING,
1315 "%s, line %d: Value of \"%s\" is not a valid group name or ID!",
1316 NGIRCd_ConfFile, Line, Var);
1320 if (strcasecmp(Var, "ServerUID") == 0) {
1321 pwd = getpwnam(Arg);
1323 Conf_UID = pwd->pw_uid;
1325 Conf_UID = (unsigned int)atoi(Arg);
1326 if (!Conf_UID && strcmp(Arg, "0"))
1327 Config_Error(LOG_WARNING,
1328 "%s, line %d: Value of \"%s\" is not a valid user name or ID!",
1329 NGIRCd_ConfFile, Line, Var);
1334 if (CheckLegacyNoOption(Var, Arg)) {
1335 /* TODO: This function and support for "NoXXX" could be
1336 * be removed starting with ngIRCd release 19 (one release
1337 * after marking it "deprecated"). */
1338 Config_Error(LOG_WARNING,
1339 "%s, line %d (section \"Global\"): \"No\"-Prefix is deprecated, use \"%s = %s\" in [Options] section!",
1340 NGIRCd_ConfFile, Line, NoNo(Var), InvertArg(Arg));
1341 if (strcasecmp(Var, "NoIdent") == 0)
1343 else if (strcasecmp(Var, "NoPam") == 0)
1347 if ((section = CheckLegacyGlobalOption(Line, Var, Arg))) {
1348 /** TODO: This function and support for these options in the
1349 * [Global] section could be removed starting with ngIRCd
1350 * release 19 (one release after marking it "deprecated"). */
1351 if (strncasecmp(Var, "SSL", 3) == 0) {
1352 Config_Error(LOG_WARNING,
1353 "%s, line %d (section \"Global\"): \"%s\" is deprecated here, move it to %s and rename to \"%s\"!",
1354 NGIRCd_ConfFile, Line, Var, section,
1357 Config_Error(LOG_WARNING,
1358 "%s, line %d (section \"Global\"): \"%s\" is deprecated here, move it to %s!",
1359 NGIRCd_ConfFile, Line, Var, section);
1364 Config_Error_Section(Line, Var, "Global");
1368 * Handle variable in [Limits] configuration section.
1370 * @param Line Line numer in configuration file.
1371 * @param Var Variable name.
1372 * @param Arg Variable argument.
1375 Handle_LIMITS(int Line, char *Var, char *Arg)
1378 assert(Var != NULL);
1379 assert(Arg != NULL);
1381 if (strcasecmp(Var, "ConnectRetry") == 0) {
1382 Conf_ConnectRetry = atoi(Arg);
1383 if (Conf_ConnectRetry < 5) {
1384 Config_Error(LOG_WARNING,
1385 "%s, line %d: Value of \"ConnectRetry\" too low!",
1386 NGIRCd_ConfFile, Line);
1387 Conf_ConnectRetry = 5;
1391 if (strcasecmp(Var, "MaxConnections") == 0) {
1392 Conf_MaxConnections = atol(Arg);
1393 if (!Conf_MaxConnections && strcmp(Arg, "0"))
1394 Config_Error_NaN(Line, Var);
1397 if (strcasecmp(Var, "MaxConnectionsIP") == 0) {
1398 Conf_MaxConnectionsIP = atoi(Arg);
1399 if (!Conf_MaxConnectionsIP && strcmp(Arg, "0"))
1400 Config_Error_NaN(Line, Var);
1403 if (strcasecmp(Var, "MaxJoins") == 0) {
1404 Conf_MaxJoins = atoi(Arg);
1405 if (!Conf_MaxJoins && strcmp(Arg, "0"))
1406 Config_Error_NaN(Line, Var);
1409 if (strcasecmp(Var, "MaxNickLength") == 0) {
1410 Conf_MaxNickLength = Handle_MaxNickLength(Line, Arg);
1413 if (strcasecmp(Var, "PingTimeout") == 0) {
1414 Conf_PingTimeout = atoi(Arg);
1415 if (Conf_PingTimeout < 5) {
1416 Config_Error(LOG_WARNING,
1417 "%s, line %d: Value of \"PingTimeout\" too low!",
1418 NGIRCd_ConfFile, Line);
1419 Conf_PingTimeout = 5;
1423 if (strcasecmp(Var, "PongTimeout") == 0) {
1424 Conf_PongTimeout = atoi(Arg);
1425 if (Conf_PongTimeout < 5) {
1426 Config_Error(LOG_WARNING,
1427 "%s, line %d: Value of \"PongTimeout\" too low!",
1428 NGIRCd_ConfFile, Line);
1429 Conf_PongTimeout = 5;
1434 Config_Error_Section(Line, Var, "Limits");
1438 * Handle variable in [Options] configuration section.
1440 * @param Line Line numer in configuration file.
1441 * @param Var Variable name.
1442 * @param Arg Variable argument.
1445 Handle_OPTIONS(int Line, char *Var, char *Arg)
1450 assert(Var != NULL);
1451 assert(Arg != NULL);
1453 if (strcasecmp(Var, "AllowRemoteOper") == 0) {
1454 Conf_AllowRemoteOper = Check_ArgIsTrue(Arg);
1457 if (strcasecmp(Var, "ChrootDir") == 0) {
1458 len = strlcpy(Conf_Chroot, Arg, sizeof(Conf_Chroot));
1459 if (len >= sizeof(Conf_Chroot))
1460 Config_Error_TooLong(Line, Var);
1463 if (strcasecmp(Var, "CloakHost") == 0) {
1464 len = strlcpy(Conf_CloakHost, Arg, sizeof(Conf_CloakHost));
1465 if (len >= sizeof(Conf_CloakHost))
1466 Config_Error_TooLong(Line, Var);
1469 if (strcasecmp(Var, "CloakUserToNick") == 0) {
1470 Conf_CloakUserToNick = Check_ArgIsTrue(Arg);
1473 if (strcasecmp(Var, "ConnectIPv6") == 0) {
1474 Conf_ConnectIPv6 = Check_ArgIsTrue(Arg);
1478 if (strcasecmp(Var, "ConnectIPv4") == 0) {
1479 Conf_ConnectIPv4 = Check_ArgIsTrue(Arg);
1482 if (strcasecmp(Var, "DNS") == 0) {
1483 Conf_DNS = Check_ArgIsTrue(Arg);
1486 if (strcasecmp(Var, "Ident") == 0) {
1487 Conf_Ident = Check_ArgIsTrue(Arg);
1491 if (strcasecmp(Var, "MorePrivacy") == 0) {
1492 Conf_MorePrivacy = Check_ArgIsTrue(Arg);
1495 if (strcasecmp(Var, "NoticeAuth") == 0) {
1496 Conf_NoticeAuth = Check_ArgIsTrue(Arg);
1499 if (strcasecmp(Var, "OperCanUseMode") == 0) {
1500 Conf_OperCanMode = Check_ArgIsTrue(Arg);
1503 if (strcasecmp(Var, "OperServerMode") == 0) {
1504 Conf_OperServerMode = Check_ArgIsTrue(Arg);
1507 if (strcasecmp(Var, "PAM") == 0) {
1508 Conf_PAM = Check_ArgIsTrue(Arg);
1512 if (strcasecmp(Var, "PAMIsOptional") == 0 ) {
1513 Conf_PAMIsOptional = Check_ArgIsTrue(Arg);
1516 if (strcasecmp(Var, "PredefChannelsOnly") == 0) {
1517 Conf_PredefChannelsOnly = Check_ArgIsTrue(Arg);
1521 if (strcasecmp(Var, "RequireAuthPing") == 0) {
1522 Conf_AuthPing = Check_ArgIsTrue(Arg);
1526 if (strcasecmp(Var, "ScrubCTCP") == 0) {
1527 Conf_ScrubCTCP = Check_ArgIsTrue(Arg);
1531 if (strcasecmp(Var, "SyslogFacility") == 0) {
1532 Conf_SyslogFacility = ngt_SyslogFacilityID(Arg,
1533 Conf_SyslogFacility);
1537 if (strcasecmp(Var, "WebircPassword") == 0) {
1538 len = strlcpy(Conf_WebircPwd, Arg, sizeof(Conf_WebircPwd));
1539 if (len >= sizeof(Conf_WebircPwd))
1540 Config_Error_TooLong(Line, Var);
1544 Config_Error_Section(Line, Var, "Options");
1550 * Handle variable in [SSL] configuration section.
1552 * @param Line Line numer in configuration file.
1553 * @param Var Variable name.
1554 * @param Arg Variable argument.
1557 Handle_SSL(int Line, char *Var, char *Arg)
1560 assert(Var != NULL);
1561 assert(Arg != NULL);
1563 if (strcasecmp(Var, "CertFile") == 0) {
1564 assert(Conf_SSLOptions.CertFile == NULL);
1565 Conf_SSLOptions.CertFile = strdup_warn(Arg);
1568 if (strcasecmp(Var, "DHFile") == 0) {
1569 assert(Conf_SSLOptions.DHFile == NULL);
1570 Conf_SSLOptions.DHFile = strdup_warn(Arg);
1573 if (strcasecmp(Var, "KeyFile") == 0) {
1574 assert(Conf_SSLOptions.KeyFile == NULL);
1575 Conf_SSLOptions.KeyFile = strdup_warn(Arg);
1578 if (strcasecmp(Var, "KeyFilePassword") == 0) {
1579 assert(array_bytes(&Conf_SSLOptions.KeyFilePassword) == 0);
1580 if (!array_copys(&Conf_SSLOptions.KeyFilePassword, Arg))
1581 Config_Error(LOG_ERR,
1582 "%s, line %d (section \"SSL\"): Could not copy %s: %s!",
1583 NGIRCd_ConfFile, Line, Var,
1587 if (strcasecmp(Var, "Ports") == 0) {
1588 ports_parse(&Conf_SSLOptions.ListenPorts, Line, Arg);
1592 Config_Error_Section(Line, Var, "SSL");
1598 * Handle variable in [Operator] configuration section.
1600 * @param Line Line numer in configuration file.
1601 * @param Var Variable name.
1602 * @param Arg Variable argument.
1605 Handle_OPERATOR( int Line, char *Var, char *Arg )
1608 struct Conf_Oper *op;
1611 assert( Var != NULL );
1612 assert( Arg != NULL );
1614 op = array_get(&Conf_Opers, sizeof(*op),
1615 array_length(&Conf_Opers, sizeof(*op)) - 1);
1619 if (strcasecmp(Var, "Name") == 0) {
1620 /* Name of IRC operator */
1621 len = strlcpy(op->name, Arg, sizeof(op->name));
1622 if (len >= sizeof(op->name))
1623 Config_Error_TooLong(Line, Var);
1626 if (strcasecmp(Var, "Password") == 0) {
1627 /* Password of IRC operator */
1628 len = strlcpy(op->pwd, Arg, sizeof(op->pwd));
1629 if (len >= sizeof(op->pwd))
1630 Config_Error_TooLong(Line, Var);
1633 if (strcasecmp(Var, "Mask") == 0) {
1635 return; /* Hostname already configured */
1636 op->mask = strdup_warn( Arg );
1640 Config_Error_Section(Line, Var, "Operator");
1644 * Handle variable in [Server] configuration section.
1646 * @param Line Line numer in configuration file.
1647 * @param Var Variable name.
1648 * @param Arg Variable argument.
1651 Handle_SERVER( int Line, char *Var, char *Arg )
1657 assert( Var != NULL );
1658 assert( Arg != NULL );
1660 /* Ignore server block if no space is left in server configuration structure */
1661 if( New_Server_Idx <= NONE ) return;
1663 if( strcasecmp( Var, "Host" ) == 0 ) {
1664 /* Hostname of the server */
1665 len = strlcpy( New_Server.host, Arg, sizeof( New_Server.host ));
1666 if (len >= sizeof( New_Server.host ))
1667 Config_Error_TooLong ( Line, Var );
1670 if( strcasecmp( Var, "Name" ) == 0 ) {
1671 /* Name of the server ("Nick"/"ID") */
1672 len = strlcpy( New_Server.name, Arg, sizeof( New_Server.name ));
1673 if (len >= sizeof( New_Server.name ))
1674 Config_Error_TooLong( Line, Var );
1677 if (strcasecmp(Var, "Bind") == 0) {
1678 if (ng_ipaddr_init(&New_Server.bind_addr, Arg, 0))
1681 Config_Error(LOG_ERR, "%s, line %d (section \"Server\"): Can't parse IP address \"%s\"",
1682 NGIRCd_ConfFile, Line, Arg);
1685 if( strcasecmp( Var, "MyPassword" ) == 0 ) {
1686 /* Password of this server which is sent to the peer */
1688 Config_Error(LOG_ERR,
1689 "%s, line %d (section \"Server\"): MyPassword must not start with ':'!",
1690 NGIRCd_ConfFile, Line);
1692 len = strlcpy( New_Server.pwd_in, Arg, sizeof( New_Server.pwd_in ));
1693 if (len >= sizeof( New_Server.pwd_in ))
1694 Config_Error_TooLong( Line, Var );
1697 if( strcasecmp( Var, "PeerPassword" ) == 0 ) {
1698 /* Passwort of the peer which must be received */
1699 len = strlcpy( New_Server.pwd_out, Arg, sizeof( New_Server.pwd_out ));
1700 if (len >= sizeof( New_Server.pwd_out ))
1701 Config_Error_TooLong( Line, Var );
1704 if( strcasecmp( Var, "Port" ) == 0 ) {
1705 /* Port to which this server should connect */
1707 if (port >= 0 && port < 0xFFFF)
1708 New_Server.port = (UINT16)port;
1710 Config_Error(LOG_ERR,
1711 "%s, line %d (section \"Server\"): Illegal port number %ld!",
1712 NGIRCd_ConfFile, Line, port );
1716 if( strcasecmp( Var, "SSLConnect" ) == 0 ) {
1717 New_Server.SSLConnect = Check_ArgIsTrue(Arg);
1721 if( strcasecmp( Var, "Group" ) == 0 ) {
1723 New_Server.group = atoi( Arg );
1724 if (!New_Server.group && strcmp(Arg, "0"))
1725 Config_Error_NaN(Line, Var);
1728 if( strcasecmp( Var, "Passive" ) == 0 ) {
1729 if (Check_ArgIsTrue(Arg))
1730 New_Server.flags |= CONF_SFLAG_DISABLED;
1733 if (strcasecmp(Var, "ServiceMask") == 0) {
1734 len = strlcpy(New_Server.svs_mask, ngt_LowerStr(Arg),
1735 sizeof(New_Server.svs_mask));
1736 if (len >= sizeof(New_Server.svs_mask))
1737 Config_Error_TooLong(Line, Var);
1741 Config_Error_Section(Line, Var, "Server");
1745 * Copy channel name into channel structure.
1747 * If the channel name is not valid because of a missing prefix ('#', '&'),
1748 * a default prefix of '#' will be added.
1750 * @param new_chan New already allocated channel structure.
1751 * @param name Name of the new channel.
1752 * @returns true on success, false otherwise.
1755 Handle_Channelname(struct Conf_Channel *new_chan, const char *name)
1757 size_t size = sizeof(new_chan->name);
1758 char *dest = new_chan->name;
1760 if (!Channel_IsValidName(name)) {
1762 * maybe user forgot to add a '#'.
1763 * This is only here for user convenience.
1769 return size > strlcpy(dest, name, size);
1773 * Handle variable in [Channel] configuration section.
1775 * @param Line Line numer in configuration file.
1776 * @param Var Variable name.
1777 * @param Arg Variable argument.
1780 Handle_CHANNEL(int Line, char *Var, char *Arg)
1783 struct Conf_Channel *chan;
1786 assert( Var != NULL );
1787 assert( Arg != NULL );
1789 chan = array_get(&Conf_Channels, sizeof(*chan),
1790 array_length(&Conf_Channels, sizeof(*chan)) - 1);
1794 if (strcasecmp(Var, "Name") == 0) {
1795 if (!Handle_Channelname(chan, Arg))
1796 Config_Error_TooLong(Line, Var);
1799 if (strcasecmp(Var, "Modes") == 0) {
1801 len = strlcpy(chan->modes, Arg, sizeof(chan->modes));
1802 if (len >= sizeof(chan->modes))
1803 Config_Error_TooLong( Line, Var );
1806 if( strcasecmp( Var, "Topic" ) == 0 ) {
1808 len = strlcpy(chan->topic, Arg, sizeof(chan->topic));
1809 if (len >= sizeof(chan->topic))
1810 Config_Error_TooLong( Line, Var );
1813 if( strcasecmp( Var, "Key" ) == 0 ) {
1814 /* Initial Channel Key (mode k) */
1815 len = strlcpy(chan->key, Arg, sizeof(chan->key));
1816 if (len >= sizeof(chan->key))
1817 Config_Error_TooLong(Line, Var);
1820 if( strcasecmp( Var, "MaxUsers" ) == 0 ) {
1821 /* maximum user limit, mode l */
1822 chan->maxusers = (unsigned long) atol(Arg);
1823 if (!chan->maxusers && strcmp(Arg, "0"))
1824 Config_Error_NaN(Line, Var);
1827 if (strcasecmp(Var, "KeyFile") == 0) {
1829 len = strlcpy(chan->keyfile, Arg, sizeof(chan->keyfile));
1830 if (len >= sizeof(chan->keyfile))
1831 Config_Error_TooLong(Line, Var);
1835 Config_Error_Section(Line, Var, "Channel");
1839 * Validate server configuration.
1841 * Please note that this function uses exit(1) on fatal errors and therefore
1842 * can result in ngIRCd terminating!
1844 * @param Configtest true if the daemon has been called with "--configtest".
1845 * @param Rehash true if re-reading configuration on runtime.
1846 * @returns true if configuration is valid.
1849 Validate_Config(bool Configtest, bool Rehash)
1851 /* Validate configuration settings. */
1854 int i, servers, servers_once;
1856 bool config_valid = true;
1859 /* Validate configured server name, see RFC 2812 section 2.3.1 */
1860 ptr = Conf_ServerName;
1862 if (*ptr >= 'a' && *ptr <= 'z') continue;
1863 if (*ptr >= 'A' && *ptr <= 'Z') continue;
1864 if (*ptr >= '0' && *ptr <= '9') continue;
1865 if (ptr > Conf_ServerName) {
1866 if (*ptr == '.' || *ptr == '-')
1869 Conf_ServerName[0] = '\0';
1873 if (!Conf_ServerName[0]) {
1874 /* No server name configured! */
1875 config_valid = false;
1876 Config_Error(LOG_ALERT,
1877 "No (valid) server name configured in \"%s\" (section 'Global': 'Name')!",
1879 if (!Configtest && !Rehash) {
1880 Config_Error(LOG_ALERT,
1881 "%s exiting due to fatal errors!",
1887 if (Conf_ServerName[0] && !strchr(Conf_ServerName, '.')) {
1888 /* No dot in server name! */
1889 config_valid = false;
1890 Config_Error(LOG_ALERT,
1891 "Invalid server name configured in \"%s\" (section 'Global': 'Name'): Dot missing!",
1894 Config_Error(LOG_ALERT,
1895 "%s exiting due to fatal errors!",
1902 if (!Conf_ServerAdminMail[0]) {
1903 /* No administrative contact configured! */
1904 config_valid = false;
1905 Config_Error(LOG_ALERT,
1906 "No administrator email address configured in \"%s\" ('AdminEMail')!",
1909 Config_Error(LOG_ALERT,
1910 "%s exiting due to fatal errors!",
1917 if (!Conf_ServerAdmin1[0] && !Conf_ServerAdmin2[0]
1918 && !Conf_ServerAdminMail[0]) {
1919 /* No administrative information configured! */
1920 Config_Error(LOG_WARNING,
1921 "No administrative information configured but required by RFC!");
1925 if (Conf_ServerPwd[0])
1926 Config_Error(LOG_ERR,
1927 "This server uses PAM, \"Password\" in [Global] section will be ignored!");
1931 servers = servers_once = 0;
1932 for (i = 0; i < MAX_SERVERS; i++) {
1933 if (Conf_Server[i].name[0]) {
1935 if (Conf_Server[i].flags & CONF_SFLAG_ONCE)
1940 "Configuration: Operators=%ld, Servers=%d[%d], Channels=%ld",
1941 array_length(&Conf_Opers, sizeof(struct Conf_Oper)),
1942 servers, servers_once,
1943 array_length(&Conf_Channels, sizeof(struct Conf_Channel)));
1946 return config_valid;
1950 * Output "line too long" warning.
1952 * @param Line Line number in configuration file.
1953 * @param Item Affected variable name.
1956 Config_Error_TooLong ( const int Line, const char *Item )
1958 Config_Error( LOG_WARNING, "%s, line %d: Value of \"%s\" too long!", NGIRCd_ConfFile, Line, Item );
1962 * Output "unknown variable" warning.
1964 * @param Line Line number in configuration file.
1965 * @param Item Affected variable name.
1966 * @param Section Section name.
1969 Config_Error_Section(const int Line, const char *Item, const char *Section)
1971 Config_Error(LOG_ERR, "%s, line %d (section \"%s\"): Unknown variable \"%s\"!",
1972 NGIRCd_ConfFile, Line, Section, Item);
1976 * Output "not a number" warning.
1978 * @param Line Line number in configuration file.
1979 * @param Item Affected variable name.
1982 Config_Error_NaN( const int Line, const char *Item )
1984 Config_Error( LOG_WARNING, "%s, line %d: Value of \"%s\" is not a number!",
1985 NGIRCd_ConfFile, Line, Item );
1989 * Output configuration error to console and/or logfile.
1991 * On runtime, the normal log functions of the daemon are used. But when
1992 * testing the configuration ("--configtest"), all messages go directly
1995 * @param Level Severity level of the message.
1996 * @param Format Format string; see printf() function.
1999 static void Config_Error( const int Level, const char *Format, ... )
2001 static void Config_Error( Level, Format, va_alist )
2007 char msg[MAX_LOG_MSG_LEN];
2010 assert( Format != NULL );
2013 va_start( ap, Format );
2017 vsnprintf( msg, MAX_LOG_MSG_LEN, Format, ap );
2021 if (Level <= LOG_WARNING)
2022 printf(" - %s\n", msg);
2026 Log(Level, "%s", msg);
2032 * Dump internal state of the "configuration module".
2035 Conf_DebugDump(void)
2039 Log(LOG_DEBUG, "Configured servers:");
2040 for (i = 0; i < MAX_SERVERS; i++) {
2041 if (! Conf_Server[i].name[0])
2044 " - %s: %s:%d, last=%ld, group=%d, flags=%d, conn=%d",
2045 Conf_Server[i].name, Conf_Server[i].host,
2046 Conf_Server[i].port, Conf_Server[i].lasttry,
2047 Conf_Server[i].group, Conf_Server[i].flags,
2048 Conf_Server[i].conn_id);
2055 * Initialize server configuration structur to default values.
2057 * @param Server Pointer to server structure to initialize.
2060 Init_Server_Struct( CONF_SERVER *Server )
2062 assert( Server != NULL );
2064 memset( Server, 0, sizeof (CONF_SERVER) );
2066 Server->group = NONE;
2067 Server->lasttry = time( NULL ) - Conf_ConnectRetry + STARTUP_DELAY;
2069 if( NGIRCd_Passive ) Server->flags = CONF_SFLAG_DISABLED;
2071 Proc_InitStruct(&Server->res_stat);
2072 Server->conn_id = NONE;
2073 memset(&Server->bind_addr, 0, sizeof(Server->bind_addr));