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 static void Handle_SSL PARAMS(( int Line, char *Var, char *Ark ));
94 struct SSLOptions Conf_SSLOptions;
97 * Initialize SSL configuration.
102 free(Conf_SSLOptions.KeyFile);
103 Conf_SSLOptions.KeyFile = NULL;
105 free(Conf_SSLOptions.CertFile);
106 Conf_SSLOptions.CertFile = NULL;
108 free(Conf_SSLOptions.DHFile);
109 Conf_SSLOptions.DHFile = NULL;
110 array_free_wipe(&Conf_SSLOptions.KeyFilePassword);
114 * Make sure that a configured file is readable.
116 * Currently, this function is only used for SSL-related options ...
118 * @param Var Configuration variable
119 * @param Filename Configured filename
122 CheckFileReadable(const char *Var, const char *Filename)
129 fp = fopen(Filename, "r");
133 Config_Error(LOG_ERR, "Can't read \"%s\" (\"%s\"): %s",
134 Filename, Var, strerror(errno));
141 * Duplicate string and warn on errors.
143 * @returns Pointer to string on success, NULL otherwise.
146 strdup_warn(const char *str)
148 char *ptr = strdup(str);
150 Config_Error(LOG_ERR,
151 "Could not allocate memory for string: %s", str);
156 * Output a comma separated list of ports (integer values).
163 len = array_length(a, sizeof(UINT16));
165 ports = (UINT16*) array_start(a);
166 printf("%u", (unsigned int) *ports);
169 printf(", %u", (unsigned int) *ports);
176 * Parse a comma separated string into an array of port numbers (integers).
179 ports_parse(array *a, int Line, char *Arg)
187 ptr = strtok( Arg, "," );
191 if (port > 0 && port < 0xFFFF) {
192 port16 = (UINT16) port;
193 if (!array_catb(a, (char*)&port16, sizeof port16))
194 Config_Error(LOG_ERR, "%s, line %d Could not add port number %ld: %s",
195 NGIRCd_ConfFile, Line, port, strerror(errno));
197 Config_Error( LOG_ERR, "%s, line %d (section \"Global\"): Illegal port number %ld!",
198 NGIRCd_ConfFile, Line, port );
201 ptr = strtok( NULL, "," );
206 * Initialize configuration module.
212 Validate_Config(false, false);
216 * "Rehash" (reload) server configuration.
218 * @returns true if configuration has been re-read, false on errors.
223 if (!Read_Config(false))
225 Validate_Config(false, true);
227 /* Update CLIENT structure of local server */
228 Client_SetInfo(Client_ThisServer(), Conf_ServerInfo);
233 * Output a boolean value as "yes/no" string.
236 yesno_to_str(int boolean_value)
244 * Free all IRC operator configuration structures.
249 struct Conf_Oper *op;
252 len = array_length(&Conf_Opers, sizeof(*op));
253 op = array_start(&Conf_Opers);
258 array_free(&Conf_Opers);
262 * Output all IRC operator configuration structures.
267 struct Conf_Oper *op;
270 len = array_length(&Conf_Opers, sizeof(*op));
271 op = array_start(&Conf_Opers);
276 printf(" Name = %s\n", op->name);
277 printf(" Password = %s\n", op->pwd);
278 printf(" Mask = %s\n\n", op->mask ? op->mask : "");
284 * Read configuration, validate and output it.
286 * This function waits for a keypress of the user when stdin/stdout are valid
287 * tty's ("you can read our nice message and we can read in your keypress").
289 * @return 0 on succes, 1 on failure(s); therefore the result code can
290 * directly be used by exit() when running "ngircd --configtest".
299 size_t predef_channel_count;
300 struct Conf_Channel *predef_chan;
304 if (! Read_Config(true))
307 config_valid = Validate_Config(true, false);
310 if(isatty(fileno(stdin)) && isatty(fileno(stdout))) {
311 puts("OK, press enter to see a dump of your server configuration ...");
314 puts("Ok, dump of your server configuration follows:\n");
317 printf(" Name = %s\n", Conf_ServerName);
318 printf(" AdminInfo1 = %s\n", Conf_ServerAdmin1);
319 printf(" AdminInfo2 = %s\n", Conf_ServerAdmin2);
320 printf(" AdminEMail = %s\n", Conf_ServerAdminMail);
321 printf(" Info = %s\n", Conf_ServerInfo);
322 printf(" Listen = %s\n", Conf_ListenAddress);
323 if (Using_MotdFile) {
324 printf(" MotdFile = %s\n", Conf_MotdFile);
325 printf(" MotdPhrase =\n");
327 printf(" MotdFile = \n");
328 printf(" MotdPhrase = %s\n", array_bytes(&Conf_Motd)
329 ? (const char*) array_start(&Conf_Motd) : "");
332 printf(" Password = %s\n", Conf_ServerPwd);
334 printf(" PidFile = %s\n", Conf_PidFile);
336 ports_puts(&Conf_ListenPorts);
337 grp = getgrgid(Conf_GID);
339 printf(" ServerGID = %s\n", grp->gr_name);
341 printf(" ServerGID = %ld\n", (long)Conf_GID);
342 pwd = getpwuid(Conf_UID);
344 printf(" ServerUID = %s\n", pwd->pw_name);
346 printf(" ServerUID = %ld\n", (long)Conf_UID);
350 printf(" ConnectRetry = %d\n", Conf_ConnectRetry);
351 printf(" MaxConnections = %ld\n", Conf_MaxConnections);
352 printf(" MaxConnectionsIP = %d\n", Conf_MaxConnectionsIP);
353 printf(" MaxJoins = %d\n", Conf_MaxJoins > 0 ? Conf_MaxJoins : -1);
354 printf(" MaxNickLength = %u\n", Conf_MaxNickLength - 1);
355 printf(" PingTimeout = %d\n", Conf_PingTimeout);
356 printf(" PongTimeout = %d\n", Conf_PongTimeout);
360 printf(" AllowRemoteOper = %s\n", yesno_to_str(Conf_AllowRemoteOper));
361 printf(" ChrootDir = %s\n", Conf_Chroot);
362 printf(" CloakHost = %s\n", Conf_CloakHost);
363 printf(" CloakUserToNick = %s\n", yesno_to_str(Conf_CloakUserToNick));
365 printf(" ConnectIPv4 = %s\n", yesno_to_str(Conf_ConnectIPv6));
366 printf(" ConnectIPv6 = %s\n", yesno_to_str(Conf_ConnectIPv4));
368 printf(" DNS = %s\n", yesno_to_str(Conf_DNS));
370 printf(" Ident = %s\n", yesno_to_str(Conf_Ident));
372 printf(" NoticeAuth = %s\n", yesno_to_str(Conf_NoticeAuth));
373 printf(" OperCanUseMode = %s\n", yesno_to_str(Conf_OperCanMode));
374 printf(" OperServerMode = %s\n", yesno_to_str(Conf_OperServerMode));
376 printf(" PAM = %s\n", yesno_to_str(Conf_PAM));
378 printf(" PredefChannelsOnly = %s\n", yesno_to_str(Conf_PredefChannelsOnly));
380 printf(" RequireAuthPing = %s\n", yesno_to_str(Conf_AuthPing));
383 printf(" SyslogFacility = %s\n",
384 ngt_SyslogFacilityName(Conf_SyslogFacility));
386 printf(" WebircPassword = %s\n", Conf_WebircPwd);
391 printf(" CertFile = %s\n", Conf_SSLOptions.CertFile
392 ? Conf_SSLOptions.CertFile : "");
393 printf(" DHFile = %s\n", Conf_SSLOptions.DHFile
394 ? Conf_SSLOptions.DHFile : "");
395 printf(" KeyFile = %s\n", Conf_SSLOptions.KeyFile
396 ? Conf_SSLOptions.KeyFile : "");
397 if (array_bytes(&Conf_SSLOptions.KeyFilePassword))
398 puts(" KeyFilePassword = <secret>");
400 puts(" KeyFilePassword = ");
401 array_free_wipe(&Conf_SSLOptions.KeyFilePassword);
403 ports_puts(&Conf_SSLOptions.ListenPorts);
409 for( i = 0; i < MAX_SERVERS; i++ ) {
410 if( ! Conf_Server[i].name[0] ) continue;
412 /* Valid "Server" section */
414 printf( " Name = %s\n", Conf_Server[i].name );
415 printf( " Host = %s\n", Conf_Server[i].host );
416 printf( " Port = %u\n", (unsigned int)Conf_Server[i].port );
418 printf( " SSLConnect = %s\n", Conf_Server[i].SSLConnect?"yes":"no");
420 printf( " MyPassword = %s\n", Conf_Server[i].pwd_in );
421 printf( " PeerPassword = %s\n", Conf_Server[i].pwd_out );
422 printf( " ServiceMask = %s\n", Conf_Server[i].svs_mask);
423 printf( " Group = %d\n", Conf_Server[i].group );
424 printf( " Passive = %s\n\n", Conf_Server[i].flags & CONF_SFLAG_DISABLED ? "yes" : "no");
427 predef_channel_count = array_length(&Conf_Channels, sizeof(*predef_chan));
428 predef_chan = array_start(&Conf_Channels);
430 for (i = 0; i < predef_channel_count; i++, predef_chan++) {
431 if (!predef_chan->name[0])
434 /* Valid "Channel" section */
436 printf(" Name = %s\n", predef_chan->name);
437 printf(" Modes = %s\n", predef_chan->modes);
438 printf(" Key = %s\n", predef_chan->key);
439 printf(" MaxUsers = %lu\n", predef_chan->maxusers);
440 printf(" Topic = %s\n", predef_chan->topic);
441 printf(" KeyFile = %s\n\n", predef_chan->keyfile);
444 return (config_valid ? 0 : 1);
448 * Remove connection information from configured server.
450 * If the server is set as "once", delete it from our configuration;
451 * otherwise set the time for the next connection attempt.
453 * Non-server connections will be silently ignored.
456 Conf_UnsetServer( CONN_ID Idx )
461 /* Check all our configured servers */
462 for( i = 0; i < MAX_SERVERS; i++ ) {
463 if( Conf_Server[i].conn_id != Idx ) continue;
465 /* Gotcha! Mark server configuration as "unused": */
466 Conf_Server[i].conn_id = NONE;
468 if( Conf_Server[i].flags & CONF_SFLAG_ONCE ) {
469 /* Delete configuration here */
470 Init_Server_Struct( &Conf_Server[i] );
472 /* Set time for next connect attempt */
474 if (Conf_Server[i].lasttry < t - Conf_ConnectRetry) {
475 /* The connection has been "long", so we don't
476 * require the next attempt to be delayed. */
477 Conf_Server[i].lasttry =
478 t - Conf_ConnectRetry + RECONNECT_DELAY;
480 Conf_Server[i].lasttry = t;
486 * Set connection information for specified configured server.
489 Conf_SetServer( int ConfServer, CONN_ID Idx )
491 assert( ConfServer > NONE );
492 assert( Idx > NONE );
494 Conf_Server[ConfServer].conn_id = Idx;
498 * Get index of server in configuration structure.
501 Conf_GetServer( CONN_ID Idx )
505 assert( Idx > NONE );
507 for( i = 0; i < MAX_SERVERS; i++ ) {
508 if( Conf_Server[i].conn_id == Idx ) return i;
514 * Enable a server by name and adjust its port number.
516 * @returns true if a server has been enabled and now has a valid port
517 * number and host name for outgoing connections.
520 Conf_EnableServer( const char *Name, UINT16 Port )
524 assert( Name != NULL );
525 for( i = 0; i < MAX_SERVERS; i++ ) {
526 if( strcasecmp( Conf_Server[i].name, Name ) == 0 ) {
527 /* Gotcha! Set port and enable server: */
528 Conf_Server[i].port = Port;
529 Conf_Server[i].flags &= ~CONF_SFLAG_DISABLED;
530 return (Conf_Server[i].port && Conf_Server[i].host[0]);
537 * Enable a server by name.
539 * The server is only usable as outgoing server, if it has set a valid port
540 * number for outgoing connections!
541 * If not, you have to use Conf_EnableServer() function to make it available.
543 * @returns true if a server has been enabled; false otherwise.
546 Conf_EnablePassiveServer(const char *Name)
550 assert( Name != NULL );
551 for (i = 0; i < MAX_SERVERS; i++) {
552 if ((strcasecmp( Conf_Server[i].name, Name ) == 0)
553 && (Conf_Server[i].port > 0)) {
554 /* BINGO! Enable server */
555 Conf_Server[i].flags &= ~CONF_SFLAG_DISABLED;
563 * Disable a server by name.
564 * An already established connection will be disconnected.
566 * @returns true if a server was found and has been disabled.
569 Conf_DisableServer( const char *Name )
573 assert( Name != NULL );
574 for( i = 0; i < MAX_SERVERS; i++ ) {
575 if( strcasecmp( Conf_Server[i].name, Name ) == 0 ) {
576 /* Gotcha! Disable and disconnect server: */
577 Conf_Server[i].flags |= CONF_SFLAG_DISABLED;
578 if( Conf_Server[i].conn_id > NONE )
579 Conn_Close(Conf_Server[i].conn_id, NULL,
580 "Server link terminated on operator request",
589 * Add a new remote server to our configuration.
591 * @param Name Name of the new server.
592 * @param Port Port number to connect to or 0 for incoming connections.
593 * @param Host Host name to connect to.
594 * @param MyPwd Password that will be sent to the peer.
595 * @param PeerPwd Password that must be received from the peer.
596 * @returns true if the new server has been added; false otherwise.
599 Conf_AddServer(const char *Name, UINT16 Port, const char *Host,
600 const char *MyPwd, const char *PeerPwd)
604 assert( Name != NULL );
605 assert( Host != NULL );
606 assert( MyPwd != NULL );
607 assert( PeerPwd != NULL );
609 /* Search unused item in server configuration structure */
610 for( i = 0; i < MAX_SERVERS; i++ ) {
611 /* Is this item used? */
612 if( ! Conf_Server[i].name[0] ) break;
614 if( i >= MAX_SERVERS ) return false;
616 Init_Server_Struct( &Conf_Server[i] );
617 strlcpy( Conf_Server[i].name, Name, sizeof( Conf_Server[i].name ));
618 strlcpy( Conf_Server[i].host, Host, sizeof( Conf_Server[i].host ));
619 strlcpy( Conf_Server[i].pwd_out, MyPwd, sizeof( Conf_Server[i].pwd_out ));
620 strlcpy( Conf_Server[i].pwd_in, PeerPwd, sizeof( Conf_Server[i].pwd_in ));
621 Conf_Server[i].port = Port;
622 Conf_Server[i].flags = CONF_SFLAG_ONCE;
628 * Check if the given nick name is an service.
630 * @returns true if the given nick name belongs to an "IRC service".
633 Conf_IsService(int ConfServer, const char *Nick)
635 return MatchCaseInsensitive(Conf_Server[ConfServer].svs_mask, Nick);
639 * Initialize configuration settings with their default values.
642 Set_Defaults(bool InitServers)
647 strcpy(Conf_ServerName, "");
648 strcpy(Conf_ServerAdmin1, "");
649 strcpy(Conf_ServerAdmin2, "");
650 strcpy(Conf_ServerAdminMail, "");
651 snprintf(Conf_ServerInfo, sizeof Conf_ServerInfo, "%s %s",
652 PACKAGE_NAME, PACKAGE_VERSION);
653 free(Conf_ListenAddress);
654 Conf_ListenAddress = NULL;
655 array_free(&Conf_Motd);
656 strlcpy(Conf_MotdFile, SYSCONFDIR, sizeof(Conf_MotdFile));
657 strlcat(Conf_MotdFile, MOTD_FILE, sizeof(Conf_MotdFile));
658 strcpy(Conf_ServerPwd, "");
659 strlcpy(Conf_PidFile, PID_FILE, sizeof(Conf_PidFile));
660 Conf_UID = Conf_GID = 0;
663 Conf_ConnectRetry = 60;
664 Conf_MaxConnections = 0;
665 Conf_MaxConnectionsIP = 5;
667 Conf_MaxNickLength = CLIENT_NICK_LEN_DEFAULT;
668 Conf_PingTimeout = 120;
669 Conf_PongTimeout = 20;
672 Conf_AllowRemoteOper = false;
674 Conf_AuthPing = false;
676 strlcpy(Conf_Chroot, CHROOT_DIR, sizeof(Conf_Chroot));
677 strcpy(Conf_CloakHost, "");
678 Conf_CloakUserToNick = false;
679 Conf_ConnectIPv4 = true;
681 Conf_ConnectIPv6 = true;
683 Conf_ConnectIPv6 = false;
691 Conf_NoticeAuth = false;
692 Conf_OperCanMode = false;
693 Conf_OperServerMode = false;
699 Conf_PredefChannelsOnly = false;
702 Conf_SyslogFacility = LOG_LOCAL5;
704 Conf_SyslogFacility = 0;
708 /* Initialize IRC operators and channels */
710 Conf_Channel_Count = 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;
788 /* Open configuration file */
789 fd = fopen( NGIRCd_ConfFile, "r" );
791 /* No configuration file found! */
792 Config_Error( LOG_ALERT, "Can't read configuration \"%s\": %s",
793 NGIRCd_ConfFile, strerror( errno ));
794 if (!ngircd_starting)
796 Config_Error( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME );
801 Set_Defaults( ngircd_starting );
803 Config_Error( LOG_INFO, "Reading configuration from \"%s\" ...", NGIRCd_ConfFile );
805 /* Clean up server configuration structure: mark all already
806 * configured servers as "once" so that they are deleted
807 * after the next disconnect and delete all unused servers.
808 * And delete all servers which are "duplicates" of servers
809 * that are already marked as "once" (such servers have been
810 * created by the last rehash but are now useless). */
811 for( i = 0; i < MAX_SERVERS; i++ ) {
812 if( Conf_Server[i].conn_id == NONE ) Init_Server_Struct( &Conf_Server[i] );
814 /* This structure is in use ... */
815 if( Conf_Server[i].flags & CONF_SFLAG_ONCE ) {
816 /* Check for duplicates */
817 for( n = 0; n < MAX_SERVERS; n++ ) {
818 if( n == i ) continue;
820 if( Conf_Server[i].conn_id == Conf_Server[n].conn_id ) {
821 Init_Server_Struct( &Conf_Server[n] );
823 Log(LOG_DEBUG,"Deleted unused duplicate server %d (kept %d).",
829 /* Mark server as "once" */
830 Conf_Server[i].flags |= CONF_SFLAG_ONCE;
831 Log( LOG_DEBUG, "Marked server %d as \"once\"", i );
836 /* Initialize variables */
838 strcpy( section, "" );
839 Init_Server_Struct( &New_Server );
840 New_Server_Idx = NONE;
844 /* Read configuration file */
846 if( ! fgets( str, LINE_LEN, fd )) break;
850 /* Skip comments and empty lines */
851 if( str[0] == ';' || str[0] == '#' || str[0] == '\0' ) continue;
853 /* Is this the beginning of a new section? */
854 if(( str[0] == '[' ) && ( str[strlen( str ) - 1] == ']' )) {
855 strlcpy( section, str, sizeof( section ));
856 if (strcasecmp(section, "[GLOBAL]") == 0 ||
857 strcasecmp(section, "[LIMITS]") == 0 ||
858 strcasecmp(section, "[OPTIONS]") == 0 ||
859 strcasecmp(section, "[SSL]") == 0)
862 if( strcasecmp( section, "[SERVER]" ) == 0 ) {
863 /* Check if there is already a server to add */
864 if( New_Server.name[0] ) {
865 /* Copy data to "real" server structure */
866 assert( New_Server_Idx > NONE );
867 Conf_Server[New_Server_Idx] = New_Server;
870 /* Re-init structure for new server */
871 Init_Server_Struct( &New_Server );
873 /* Search unused item in server configuration structure */
874 for( i = 0; i < MAX_SERVERS; i++ ) {
875 /* Is this item used? */
876 if( ! Conf_Server[i].name[0] ) break;
878 if( i >= MAX_SERVERS ) {
879 /* Oops, no free item found! */
880 Config_Error( LOG_ERR, "Too many servers configured." );
881 New_Server_Idx = NONE;
883 else New_Server_Idx = i;
886 if (strcasecmp(section, "[CHANNEL]") == 0) {
887 Conf_Channel_Count++;
890 if (strcasecmp(section, "[OPERATOR]") == 0) {
895 Config_Error(LOG_ERR,
896 "%s, line %d: Unknown section \"%s\"!",
897 NGIRCd_ConfFile, line, section);
900 if( section[0] == 0x1 ) continue;
902 /* Split line into variable name and parameters */
903 ptr = strchr( str, '=' );
905 Config_Error( LOG_ERR, "%s, line %d: Syntax error!", NGIRCd_ConfFile, line );
909 var = str; ngt_TrimStr( var );
910 arg = ptr + 1; ngt_TrimStr( arg );
912 if(strcasecmp(section, "[GLOBAL]") == 0)
913 Handle_GLOBAL(line, var, arg);
914 else if(strcasecmp(section, "[LIMITS]") == 0)
915 Handle_LIMITS(line, var, arg);
916 else if(strcasecmp(section, "[OPTIONS]") == 0)
917 Handle_OPTIONS(line, var, arg);
919 else if(strcasecmp(section, "[SSL]") == 0)
920 Handle_SSL(line, var, arg);
922 else if(strcasecmp(section, "[OPERATOR]") == 0)
923 Handle_OPERATOR(line, var, arg);
924 else if(strcasecmp(section, "[SERVER]") == 0)
925 Handle_SERVER(line, var, arg);
926 else if(strcasecmp(section, "[CHANNEL]") == 0)
927 Handle_CHANNEL(line, var, arg);
929 Config_Error(LOG_ERR,
930 "%s, line %d: Variable \"%s\" outside section!",
931 NGIRCd_ConfFile, line, var);
934 /* Close configuration file */
937 /* Check if there is still a server to add */
938 if( New_Server.name[0] ) {
939 /* Copy data to "real" server structure */
940 assert( New_Server_Idx > NONE );
941 Conf_Server[New_Server_Idx] = New_Server;
944 /* not a single listening port? Add default. */
945 if (no_listenports() &&
946 !array_copyb(&Conf_ListenPorts, (char*) &defaultport, sizeof defaultport))
948 Config_Error(LOG_ALERT, "Could not add default listening Port %u: %s",
949 (unsigned int) defaultport, strerror(errno));
954 if (!Conf_ListenAddress)
955 Conf_ListenAddress = strdup_warn(DEFAULT_LISTEN_ADDRSTR);
957 if (!Conf_ListenAddress) {
958 Config_Error(LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME);
962 /* No MOTD phrase configured? (re)try motd file. */
963 if (array_bytes(&Conf_Motd) == 0)
964 Read_Motd(Conf_MotdFile);
967 /* Make sure that all SSL-related files are readable */
968 CheckFileReadable("CertFile", Conf_SSLOptions.CertFile);
969 CheckFileReadable("DHFile", Conf_SSLOptions.DHFile);
970 CheckFileReadable("KeyFile", Conf_SSLOptions.KeyFile);
977 * Check whether an string argument is true or false.
979 * @param Arg Input string.
980 * @returns true if string has been parsed as "yes"/"true"/"on".
983 Check_ArgIsTrue( const char *Arg )
985 if( strcasecmp( Arg, "yes" ) == 0 ) return true;
986 if( strcasecmp( Arg, "true" ) == 0 ) return true;
987 if( atoi( Arg ) != 0 ) return true;
993 * Handle setting of "MaxNickLength".
995 * @param Line Line number in configuration file.
996 * @raram Arg Input string.
997 * @returns New configured maximum nick name length.
1000 Handle_MaxNickLength(int Line, const char *Arg)
1004 new = (unsigned) atoi(Arg) + 1;
1005 if (new > CLIENT_NICK_LEN) {
1006 Config_Error(LOG_WARNING,
1007 "%s, line %d: Value of \"MaxNickLength\" exceeds %u!",
1008 NGIRCd_ConfFile, Line, CLIENT_NICK_LEN - 1);
1009 return CLIENT_NICK_LEN;
1012 Config_Error(LOG_WARNING,
1013 "%s, line %d: Value of \"MaxNickLength\" must be at least 1!",
1014 NGIRCd_ConfFile, Line);
1021 * Output a warning messages if IDENT is configured but not compiled in.
1024 WarnIdent(int UNUSED Line)
1028 /* user has enabled ident lookups explicitly, but ... */
1029 Config_Error(LOG_WARNING,
1030 "%s: line %d: \"Ident = yes\", but ngircd was built without IDENT support!",
1031 NGIRCd_ConfFile, Line);
1037 * Output a warning messages if IPv6 is configured but not compiled in.
1040 WarnIPv6(int UNUSED Line)
1043 if (Conf_ConnectIPv6) {
1044 /* user has enabled IPv6 explicitly, but ... */
1045 Config_Error(LOG_WARNING,
1046 "%s: line %d: \"ConnectIPv6 = yes\", but ngircd was built without IPv6 support!",
1047 NGIRCd_ConfFile, Line);
1053 * Output a warning messages if PAM is configured but not compiled in.
1056 WarnPAM(int UNUSED Line)
1060 Config_Error(LOG_WARNING,
1061 "%s: line %d: \"PAM = yes\", but ngircd was built without PAM support!",
1062 NGIRCd_ConfFile, Line);
1068 * Handle legacy "NoXXX" options in [GLOBAL] section.
1070 * TODO: This function and support for "NoXXX" could be removed starting
1071 * with ngIRCd release 19 (one release after marking it "deprecated").
1073 * @param Var Variable name.
1074 * @param Arg Argument string.
1075 * @returns true if a NoXXX option has been processed; false otherwise.
1078 CheckLegacyNoOption(const char *Var, const char *Arg)
1080 if(strcasecmp(Var, "NoDNS") == 0) {
1081 Conf_DNS = !Check_ArgIsTrue( Arg );
1084 if (strcasecmp(Var, "NoIdent") == 0) {
1085 Conf_Ident = !Check_ArgIsTrue(Arg);
1088 if(strcasecmp(Var, "NoPAM") == 0) {
1089 Conf_PAM = !Check_ArgIsTrue(Arg);
1096 * Handle deprecated legacy options in [GLOBAL] section.
1098 * TODO: This function and support for these options in the [Global] section
1099 * could be removed starting with ngIRCd release 19 (one release after
1100 * marking it "deprecated").
1102 * @param Var Variable name.
1103 * @param Arg Argument string.
1104 * @returns true if a legacy option has been processed; false otherwise.
1107 CheckLegacyGlobalOption(int Line, char *Var, char *Arg)
1109 if (strcasecmp(Var, "AllowRemoteOper") == 0
1110 || strcasecmp(Var, "ChrootDir") == 0
1111 || strcasecmp(Var, "ConnectIPv4") == 0
1112 || strcasecmp(Var, "ConnectIPv6") == 0
1113 || strcasecmp(Var, "OperCanUseMode") == 0
1114 || strcasecmp(Var, "OperServerMode") == 0
1115 || strcasecmp(Var, "PredefChannelsOnly") == 0
1116 || strcasecmp(Var, "SyslogFacility") == 0
1117 || strcasecmp(Var, "WebircPassword") == 0) {
1118 Handle_OPTIONS(Line, Var, Arg);
1121 if (strcasecmp(Var, "ConnectRetry") == 0
1122 || strcasecmp(Var, "MaxConnections") == 0
1123 || strcasecmp(Var, "MaxConnectionsIP") == 0
1124 || strcasecmp(Var, "MaxJoins") == 0
1125 || strcasecmp(Var, "MaxNickLength") == 0
1126 || strcasecmp(Var, "PingTimeout") == 0
1127 || strcasecmp(Var, "PongTimeout") == 0) {
1128 Handle_LIMITS(Line, Var, Arg);
1132 if (strcasecmp(Var, "SSLCertFile") == 0
1133 || strcasecmp(Var, "SSLDHFile") == 0
1134 || strcasecmp(Var, "SSLKeyFile") == 0
1135 || strcasecmp(Var, "SSLKeyFilePassword") == 0
1136 || strcasecmp(Var, "SSLPorts") == 0) {
1137 Handle_SSL(Line, Var + 3, Arg);
1146 * Strip "no" prefix of a string.
1148 * TODO: This function and support for "NoXXX" should be removed starting
1149 * with ngIRCd release 19! (One release after marking it "deprecated").
1151 * @param str Pointer to input string starting with "no".
1152 * @returns New pointer to string without "no" prefix.
1155 NoNo(const char *str)
1157 assert(strncasecmp("no", str, 2) == 0 && str[2]);
1162 * Invert "boolean" string.
1164 * TODO: This function and support for "NoXXX" should be removed starting
1165 * with ngIRCd release 19! (One release after marking it "deprecated").
1167 * @param arg "Boolean" input string.
1168 * @returns Pointer to inverted "boolean string".
1171 InvertArg(const char *arg)
1173 return yesno_to_str(!Check_ArgIsTrue(arg));
1177 * Handle variable in [Global] configuration section.
1179 * @param Line Line numer in configuration file.
1180 * @param Var Variable name.
1181 * @param Arg Variable argument.
1184 Handle_GLOBAL( int Line, char *Var, char *Arg )
1189 const char *section;
1192 assert(Var != NULL);
1193 assert(Arg != NULL);
1195 if (strcasecmp(Var, "Name") == 0) {
1196 len = strlcpy(Conf_ServerName, Arg, sizeof(Conf_ServerName));
1197 if (len >= sizeof(Conf_ServerName))
1198 Config_Error_TooLong(Line, Var);
1201 if (strcasecmp(Var, "AdminInfo1") == 0) {
1202 len = strlcpy(Conf_ServerAdmin1, Arg, sizeof(Conf_ServerAdmin1));
1203 if (len >= sizeof(Conf_ServerAdmin1))
1204 Config_Error_TooLong(Line, Var);
1207 if (strcasecmp(Var, "AdminInfo2") == 0) {
1208 len = strlcpy(Conf_ServerAdmin2, Arg, sizeof(Conf_ServerAdmin2));
1209 if (len >= sizeof(Conf_ServerAdmin2))
1210 Config_Error_TooLong(Line, Var);
1213 if (strcasecmp(Var, "AdminEMail") == 0) {
1214 len = strlcpy(Conf_ServerAdminMail, Arg,
1215 sizeof(Conf_ServerAdminMail));
1216 if (len >= sizeof(Conf_ServerAdminMail))
1217 Config_Error_TooLong(Line, Var);
1220 if (strcasecmp(Var, "Info") == 0) {
1221 len = strlcpy(Conf_ServerInfo, Arg, sizeof(Conf_ServerInfo));
1222 if (len >= sizeof(Conf_ServerInfo))
1223 Config_Error_TooLong(Line, Var);
1226 if (strcasecmp(Var, "Listen") == 0) {
1227 if (Conf_ListenAddress) {
1228 Config_Error(LOG_ERR,
1229 "Multiple Listen= options, ignoring: %s",
1233 Conf_ListenAddress = strdup_warn(Arg);
1234 /* If allocation fails, we're in trouble: we cannot ignore the
1235 * error -- otherwise ngircd would listen on all interfaces. */
1236 if (!Conf_ListenAddress) {
1237 Config_Error(LOG_ALERT,
1238 "%s exiting due to fatal errors!",
1244 if (strcasecmp(Var, "MotdFile") == 0) {
1245 len = strlcpy(Conf_MotdFile, Arg, sizeof(Conf_MotdFile));
1246 if (len >= sizeof(Conf_MotdFile))
1247 Config_Error_TooLong(Line, Var);
1250 if (strcasecmp(Var, "MotdPhrase") == 0) {
1254 if (len >= LINE_LEN) {
1255 Config_Error_TooLong(Line, Var);
1258 if (!array_copyb(&Conf_Motd, Arg, len + 1))
1259 Config_Error(LOG_WARNING,
1260 "%s, line %d: Could not append MotdPhrase: %s",
1261 NGIRCd_ConfFile, Line, strerror(errno));
1262 Using_MotdFile = false;
1265 if(strcasecmp(Var, "Password") == 0) {
1266 len = strlcpy(Conf_ServerPwd, Arg, sizeof(Conf_ServerPwd));
1267 if (len >= sizeof(Conf_ServerPwd))
1268 Config_Error_TooLong(Line, Var);
1271 if (strcasecmp(Var, "PidFile") == 0) {
1272 len = strlcpy(Conf_PidFile, Arg, sizeof(Conf_PidFile));
1273 if (len >= sizeof(Conf_PidFile))
1274 Config_Error_TooLong(Line, Var);
1277 if (strcasecmp(Var, "Ports") == 0) {
1278 ports_parse(&Conf_ListenPorts, Line, Arg);
1281 if (strcasecmp(Var, "ServerGID") == 0) {
1282 grp = getgrnam(Arg);
1284 Conf_GID = grp->gr_gid;
1286 Conf_GID = (unsigned int)atoi(Arg);
1287 if (!Conf_GID && strcmp(Arg, "0"))
1288 Config_Error_NaN(Line, Var);
1292 if (strcasecmp(Var, "ServerUID") == 0) {
1293 pwd = getpwnam(Arg);
1295 Conf_UID = pwd->pw_uid;
1297 Conf_UID = (unsigned int)atoi(Arg);
1298 if (!Conf_UID && strcmp(Arg, "0"))
1299 Config_Error_NaN(Line, Var);
1304 if (CheckLegacyNoOption(Var, Arg)) {
1305 /* TODO: This function and support for "NoXXX" could be
1306 * be removed starting with ngIRCd release 19 (one release
1307 * after marking it "deprecated"). */
1308 Config_Error(LOG_WARNING,
1309 "%s, line %d (section \"Global\"): \"No\"-Prefix is deprecated, use \"%s = %s\" in [Options] section!",
1310 NGIRCd_ConfFile, Line, NoNo(Var), InvertArg(Arg));
1311 if (strcasecmp(Var, "NoIdent") == 0)
1313 else if (strcasecmp(Var, "NoPam") == 0)
1317 if ((section = CheckLegacyGlobalOption(Line, Var, Arg))) {
1318 /** TODO: This function and support for these options in the
1319 * [Global] section could be removed starting with ngIRCd
1320 * release 19 (one release after marking it "deprecated"). */
1321 if (strncasecmp(Var, "SSL", 3) == 0) {
1322 Config_Error(LOG_WARNING,
1323 "%s, line %d (section \"Global\"): \"%s\" is deprecated here, move it to %s and rename to \"%s\"!",
1324 NGIRCd_ConfFile, Line, Var, section,
1327 Config_Error(LOG_WARNING,
1328 "%s, line %d (section \"Global\"): \"%s\" is deprecated here, move it to %s!",
1329 NGIRCd_ConfFile, Line, Var, section);
1334 Config_Error_Section(Line, Var, "Global");
1338 * Handle variable in [Limits] configuration section.
1340 * @param Line Line numer in configuration file.
1341 * @param Var Variable name.
1342 * @param Arg Variable argument.
1345 Handle_LIMITS(int Line, char *Var, char *Arg)
1348 assert(Var != NULL);
1349 assert(Arg != NULL);
1351 if (strcasecmp(Var, "ConnectRetry") == 0) {
1352 Conf_ConnectRetry = atoi(Arg);
1353 if (Conf_ConnectRetry < 5) {
1354 Config_Error(LOG_WARNING,
1355 "%s, line %d: Value of \"ConnectRetry\" too low!",
1356 NGIRCd_ConfFile, Line);
1357 Conf_ConnectRetry = 5;
1361 if (strcasecmp(Var, "MaxConnections") == 0) {
1362 Conf_MaxConnections = atol(Arg);
1363 if (!Conf_MaxConnections && strcmp(Arg, "0"))
1364 Config_Error_NaN(Line, Var);
1367 if (strcasecmp(Var, "MaxConnectionsIP") == 0) {
1368 Conf_MaxConnectionsIP = atoi(Arg);
1369 if (!Conf_MaxConnectionsIP && strcmp(Arg, "0"))
1370 Config_Error_NaN(Line, Var);
1373 if (strcasecmp(Var, "MaxJoins") == 0) {
1374 Conf_MaxJoins = atoi(Arg);
1375 if (!Conf_MaxJoins && strcmp(Arg, "0"))
1376 Config_Error_NaN(Line, Var);
1379 if (strcasecmp(Var, "MaxNickLength") == 0) {
1380 Conf_MaxNickLength = Handle_MaxNickLength(Line, Arg);
1383 if (strcasecmp(Var, "PingTimeout") == 0) {
1384 Conf_PingTimeout = atoi(Arg);
1385 if (Conf_PingTimeout < 5) {
1386 Config_Error(LOG_WARNING,
1387 "%s, line %d: Value of \"PingTimeout\" too low!",
1388 NGIRCd_ConfFile, Line);
1389 Conf_PingTimeout = 5;
1393 if (strcasecmp(Var, "PongTimeout") == 0) {
1394 Conf_PongTimeout = atoi(Arg);
1395 if (Conf_PongTimeout < 5) {
1396 Config_Error(LOG_WARNING,
1397 "%s, line %d: Value of \"PongTimeout\" too low!",
1398 NGIRCd_ConfFile, Line);
1399 Conf_PongTimeout = 5;
1404 Config_Error_Section(Line, Var, "Limits");
1408 * Handle variable in [Options] configuration section.
1410 * @param Line Line numer in configuration file.
1411 * @param Var Variable name.
1412 * @param Arg Variable argument.
1415 Handle_OPTIONS(int Line, char *Var, char *Arg)
1420 assert(Var != NULL);
1421 assert(Arg != NULL);
1423 if (strcasecmp(Var, "AllowRemoteOper") == 0) {
1424 Conf_AllowRemoteOper = Check_ArgIsTrue(Arg);
1427 if (strcasecmp(Var, "ChrootDir") == 0) {
1428 len = strlcpy(Conf_Chroot, Arg, sizeof(Conf_Chroot));
1429 if (len >= sizeof(Conf_Chroot))
1430 Config_Error_TooLong(Line, Var);
1433 if (strcasecmp(Var, "CloakHost") == 0) {
1434 len = strlcpy(Conf_CloakHost, Arg, sizeof(Conf_CloakHost));
1435 if (len >= sizeof(Conf_CloakHost))
1436 Config_Error_TooLong(Line, Var);
1439 if (strcasecmp(Var, "CloakUserToNick") == 0) {
1440 Conf_CloakUserToNick = Check_ArgIsTrue(Arg);
1443 if (strcasecmp(Var, "ConnectIPv6") == 0) {
1444 Conf_ConnectIPv6 = Check_ArgIsTrue(Arg);
1448 if (strcasecmp(Var, "ConnectIPv4") == 0) {
1449 Conf_ConnectIPv4 = Check_ArgIsTrue(Arg);
1452 if (strcasecmp(Var, "DNS") == 0) {
1453 Conf_DNS = Check_ArgIsTrue(Arg);
1456 if (strcasecmp(Var, "Ident") == 0) {
1457 Conf_Ident = Check_ArgIsTrue(Arg);
1461 if (strcasecmp(Var, "NoticeAuth") == 0) {
1462 Conf_NoticeAuth = Check_ArgIsTrue(Arg);
1465 if (strcasecmp(Var, "OperCanUseMode") == 0) {
1466 Conf_OperCanMode = Check_ArgIsTrue(Arg);
1469 if (strcasecmp(Var, "OperServerMode") == 0) {
1470 Conf_OperServerMode = Check_ArgIsTrue(Arg);
1473 if (strcasecmp(Var, "PAM") == 0) {
1474 Conf_PAM = Check_ArgIsTrue(Arg);
1478 if (strcasecmp(Var, "PredefChannelsOnly") == 0) {
1479 Conf_PredefChannelsOnly = Check_ArgIsTrue(Arg);
1483 if (strcasecmp(Var, "RequireAuthPing") == 0) {
1484 Conf_AuthPing = Check_ArgIsTrue(Arg);
1489 if (strcasecmp(Var, "SyslogFacility") == 0) {
1490 Conf_SyslogFacility = ngt_SyslogFacilityID(Arg,
1491 Conf_SyslogFacility);
1495 if (strcasecmp(Var, "WebircPassword") == 0) {
1496 len = strlcpy(Conf_WebircPwd, Arg, sizeof(Conf_WebircPwd));
1497 if (len >= sizeof(Conf_WebircPwd))
1498 Config_Error_TooLong(Line, Var);
1502 Config_Error_Section(Line, Var, "Options");
1508 * Handle variable in [SSL] configuration section.
1510 * @param Line Line numer in configuration file.
1511 * @param Var Variable name.
1512 * @param Arg Variable argument.
1515 Handle_SSL(int Line, char *Var, char *Arg)
1518 assert(Var != NULL);
1519 assert(Arg != NULL);
1521 if (strcasecmp(Var, "CertFile") == 0) {
1522 assert(Conf_SSLOptions.CertFile == NULL);
1523 Conf_SSLOptions.CertFile = strdup_warn(Arg);
1526 if (strcasecmp(Var, "DHFile") == 0) {
1527 assert(Conf_SSLOptions.DHFile == NULL);
1528 Conf_SSLOptions.DHFile = strdup_warn(Arg);
1531 if (strcasecmp(Var, "KeyFile") == 0) {
1532 assert(Conf_SSLOptions.KeyFile == NULL);
1533 Conf_SSLOptions.KeyFile = strdup_warn(Arg);
1536 if (strcasecmp(Var, "KeyFilePassword") == 0) {
1537 assert(array_bytes(&Conf_SSLOptions.KeyFilePassword) == 0);
1538 if (!array_copys(&Conf_SSLOptions.KeyFilePassword, Arg))
1539 Config_Error(LOG_ERR,
1540 "%s, line %d (section \"SSL\"): Could not copy %s: %s!",
1541 NGIRCd_ConfFile, Line, Var,
1545 if (strcasecmp(Var, "Ports") == 0) {
1546 ports_parse(&Conf_SSLOptions.ListenPorts, Line, Arg);
1550 Config_Error_Section(Line, Var, "SSL");
1556 * Handle variable in [Operator] configuration section.
1558 * @param Line Line numer in configuration file.
1559 * @param Var Variable name.
1560 * @param Arg Variable argument.
1563 Handle_OPERATOR( int Line, char *Var, char *Arg )
1566 struct Conf_Oper *op;
1569 assert( Var != NULL );
1570 assert( Arg != NULL );
1571 assert( Conf_Oper_Count > 0 );
1573 op = array_alloc(&Conf_Opers, sizeof(*op), Conf_Oper_Count - 1);
1575 Config_Error(LOG_ERR, "Could not allocate memory for operator (%d:%s = %s)", Line, Var, Arg);
1579 if (strcasecmp(Var, "Name") == 0) {
1580 /* Name of IRC operator */
1581 len = strlcpy(op->name, Arg, sizeof(op->name));
1582 if (len >= sizeof(op->name))
1583 Config_Error_TooLong(Line, Var);
1586 if (strcasecmp(Var, "Password") == 0) {
1587 /* Password of IRC operator */
1588 len = strlcpy(op->pwd, Arg, sizeof(op->pwd));
1589 if (len >= sizeof(op->pwd))
1590 Config_Error_TooLong(Line, Var);
1593 if (strcasecmp(Var, "Mask") == 0) {
1595 return; /* Hostname already configured */
1596 op->mask = strdup_warn( Arg );
1600 Config_Error_Section(Line, Var, "Operator");
1604 * Handle variable in [Server] configuration section.
1606 * @param Line Line numer in configuration file.
1607 * @param Var Variable name.
1608 * @param Arg Variable argument.
1611 Handle_SERVER( int Line, char *Var, char *Arg )
1617 assert( Var != NULL );
1618 assert( Arg != NULL );
1620 /* Ignore server block if no space is left in server configuration structure */
1621 if( New_Server_Idx <= NONE ) return;
1623 if( strcasecmp( Var, "Host" ) == 0 ) {
1624 /* Hostname of the server */
1625 len = strlcpy( New_Server.host, Arg, sizeof( New_Server.host ));
1626 if (len >= sizeof( New_Server.host ))
1627 Config_Error_TooLong ( Line, Var );
1630 if( strcasecmp( Var, "Name" ) == 0 ) {
1631 /* Name of the server ("Nick"/"ID") */
1632 len = strlcpy( New_Server.name, Arg, sizeof( New_Server.name ));
1633 if (len >= sizeof( New_Server.name ))
1634 Config_Error_TooLong( Line, Var );
1637 if (strcasecmp(Var, "Bind") == 0) {
1638 if (ng_ipaddr_init(&New_Server.bind_addr, Arg, 0))
1641 Config_Error(LOG_ERR, "%s, line %d (section \"Server\"): Can't parse IP address \"%s\"",
1642 NGIRCd_ConfFile, Line, Arg);
1645 if( strcasecmp( Var, "MyPassword" ) == 0 ) {
1646 /* Password of this server which is sent to the peer */
1648 Config_Error(LOG_ERR,
1649 "%s, line %d (section \"Server\"): MyPassword must not start with ':'!",
1650 NGIRCd_ConfFile, Line);
1652 len = strlcpy( New_Server.pwd_in, Arg, sizeof( New_Server.pwd_in ));
1653 if (len >= sizeof( New_Server.pwd_in ))
1654 Config_Error_TooLong( Line, Var );
1657 if( strcasecmp( Var, "PeerPassword" ) == 0 ) {
1658 /* Passwort of the peer which must be received */
1659 len = strlcpy( New_Server.pwd_out, Arg, sizeof( New_Server.pwd_out ));
1660 if (len >= sizeof( New_Server.pwd_out ))
1661 Config_Error_TooLong( Line, Var );
1664 if( strcasecmp( Var, "Port" ) == 0 ) {
1665 /* Port to which this server should connect */
1667 if (port >= 0 && port < 0xFFFF)
1668 New_Server.port = (UINT16)port;
1670 Config_Error(LOG_ERR,
1671 "%s, line %d (section \"Server\"): Illegal port number %ld!",
1672 NGIRCd_ConfFile, Line, port );
1676 if( strcasecmp( Var, "SSLConnect" ) == 0 ) {
1677 New_Server.SSLConnect = Check_ArgIsTrue(Arg);
1681 if( strcasecmp( Var, "Group" ) == 0 ) {
1683 New_Server.group = atoi( Arg );
1684 if (!New_Server.group && strcmp(Arg, "0"))
1685 Config_Error_NaN(Line, Var);
1688 if( strcasecmp( Var, "Passive" ) == 0 ) {
1689 if (Check_ArgIsTrue(Arg))
1690 New_Server.flags |= CONF_SFLAG_DISABLED;
1693 if (strcasecmp(Var, "ServiceMask") == 0) {
1694 len = strlcpy(New_Server.svs_mask, ngt_LowerStr(Arg),
1695 sizeof(New_Server.svs_mask));
1696 if (len >= sizeof(New_Server.svs_mask))
1697 Config_Error_TooLong(Line, Var);
1701 Config_Error_Section(Line, Var, "Server");
1705 * Copy channel name into channel structure.
1707 * If the channel name is not valid because of a missing prefix ('#', '&'),
1708 * a default prefix of '#' will be added.
1710 * @param new_chan New already allocated channel structure.
1711 * @param name Name of the new channel.
1712 * @returns true on success, false otherwise.
1715 Handle_Channelname(struct Conf_Channel *new_chan, const char *name)
1717 size_t size = sizeof(new_chan->name);
1718 char *dest = new_chan->name;
1720 if (!Channel_IsValidName(name)) {
1722 * maybe user forgot to add a '#'.
1723 * This is only here for user convenience.
1729 return size > strlcpy(dest, name, size);
1733 * Handle variable in [Channel] configuration section.
1735 * @param Line Line numer in configuration file.
1736 * @param Var Variable name.
1737 * @param Arg Variable argument.
1740 Handle_CHANNEL(int Line, char *Var, char *Arg)
1744 struct Conf_Channel *chan;
1747 assert( Var != NULL );
1748 assert( Arg != NULL );
1749 assert(Conf_Channel_Count > 0);
1751 chancount = Conf_Channel_Count - 1;
1753 chan = array_alloc(&Conf_Channels, sizeof(*chan), chancount);
1755 Config_Error(LOG_ERR, "Could not allocate memory for predefined channel (%d:%s = %s)", Line, Var, Arg);
1758 if (strcasecmp(Var, "Name") == 0) {
1759 if (!Handle_Channelname(chan, Arg))
1760 Config_Error_TooLong(Line, Var);
1763 if (strcasecmp(Var, "Modes") == 0) {
1765 len = strlcpy(chan->modes, Arg, sizeof(chan->modes));
1766 if (len >= sizeof(chan->modes))
1767 Config_Error_TooLong( Line, Var );
1770 if( strcasecmp( Var, "Topic" ) == 0 ) {
1772 len = strlcpy(chan->topic, Arg, sizeof(chan->topic));
1773 if (len >= sizeof(chan->topic))
1774 Config_Error_TooLong( Line, Var );
1777 if( strcasecmp( Var, "Key" ) == 0 ) {
1778 /* Initial Channel Key (mode k) */
1779 len = strlcpy(chan->key, Arg, sizeof(chan->key));
1780 if (len >= sizeof(chan->key))
1781 Config_Error_TooLong(Line, Var);
1784 if( strcasecmp( Var, "MaxUsers" ) == 0 ) {
1785 /* maximum user limit, mode l */
1786 chan->maxusers = (unsigned long) atol(Arg);
1787 if (!chan->maxusers && strcmp(Arg, "0"))
1788 Config_Error_NaN(Line, Var);
1791 if (strcasecmp(Var, "KeyFile") == 0) {
1793 len = strlcpy(chan->keyfile, Arg, sizeof(chan->keyfile));
1794 if (len >= sizeof(chan->keyfile))
1795 Config_Error_TooLong(Line, Var);
1799 Config_Error_Section(Line, Var, "Channel");
1803 * Validate server configuration.
1805 * Please note that this function uses exit(1) on fatal errors and therefore
1806 * can result in ngIRCd terminating!
1808 * @param Configtest true if the daemon has been called with "--configtest".
1809 * @param Rehash true if re-reading configuration on runtime.
1810 * @returns true if configuration is valid.
1813 Validate_Config(bool Configtest, bool Rehash)
1815 /* Validate configuration settings. */
1818 int i, servers, servers_once;
1820 bool config_valid = true;
1823 /* Validate configured server name, see RFC 2812 section 2.3.1 */
1824 ptr = Conf_ServerName;
1826 if (*ptr >= 'a' && *ptr <= 'z') continue;
1827 if (*ptr >= 'A' && *ptr <= 'Z') continue;
1828 if (*ptr >= '0' && *ptr <= '9') continue;
1829 if (ptr > Conf_ServerName) {
1830 if (*ptr == '.' || *ptr == '-')
1833 Conf_ServerName[0] = '\0';
1837 if (!Conf_ServerName[0]) {
1838 /* No server name configured! */
1839 config_valid = false;
1840 Config_Error(LOG_ALERT,
1841 "No (valid) server name configured in \"%s\" (section 'Global': 'Name')!",
1843 if (!Configtest && !Rehash) {
1844 Config_Error(LOG_ALERT,
1845 "%s exiting due to fatal errors!",
1851 if (Conf_ServerName[0] && !strchr(Conf_ServerName, '.')) {
1852 /* No dot in server name! */
1853 config_valid = false;
1854 Config_Error(LOG_ALERT,
1855 "Invalid server name configured in \"%s\" (section 'Global': 'Name'): Dot missing!",
1858 Config_Error(LOG_ALERT,
1859 "%s exiting due to fatal errors!",
1866 if (!Conf_ServerAdminMail[0]) {
1867 /* No administrative contact configured! */
1868 config_valid = false;
1869 Config_Error(LOG_ALERT,
1870 "No administrator email address configured in \"%s\" ('AdminEMail')!",
1873 Config_Error(LOG_ALERT,
1874 "%s exiting due to fatal errors!",
1881 if (!Conf_ServerAdmin1[0] && !Conf_ServerAdmin2[0]
1882 && !Conf_ServerAdminMail[0]) {
1883 /* No administrative information configured! */
1884 Config_Error(LOG_WARNING,
1885 "No administrative information configured but required by RFC!");
1889 if (Conf_ServerPwd[0])
1890 Config_Error(LOG_ERR,
1891 "This server uses PAM, \"Password\" in [Global] section will be ignored!");
1895 servers = servers_once = 0;
1896 for (i = 0; i < MAX_SERVERS; i++) {
1897 if (Conf_Server[i].name[0]) {
1899 if (Conf_Server[i].flags & CONF_SFLAG_ONCE)
1904 "Configuration: Operators=%d, Servers=%d[%d], Channels=%d",
1905 Conf_Oper_Count, servers, servers_once, Conf_Channel_Count);
1908 return config_valid;
1912 * Output "line too long" warning.
1914 * @param Line Line number in configuration file.
1915 * @param Item Affected variable name.
1918 Config_Error_TooLong ( const int Line, const char *Item )
1920 Config_Error( LOG_WARNING, "%s, line %d: Value of \"%s\" too long!", NGIRCd_ConfFile, Line, Item );
1924 * Output "unknown variable" warning.
1926 * @param Line Line number in configuration file.
1927 * @param Item Affected variable name.
1928 * @param Section Section name.
1931 Config_Error_Section(const int Line, const char *Item, const char *Section)
1933 Config_Error(LOG_ERR, "%s, line %d (section \"%s\"): Unknown variable \"%s\"!",
1934 NGIRCd_ConfFile, Line, Section, Item);
1938 * Output "not a number" warning.
1940 * @param Line Line number in configuration file.
1941 * @param Item Affected variable name.
1944 Config_Error_NaN( const int Line, const char *Item )
1946 Config_Error( LOG_WARNING, "%s, line %d: Value of \"%s\" is not a number!",
1947 NGIRCd_ConfFile, Line, Item );
1951 * Output configuration error to console and/or logfile.
1953 * On runtime, the normal log functions of the daemon are used. But when
1954 * testing the configuration ("--configtest"), all messages go directly
1957 * @param Level Severity level of the message.
1958 * @param Format Format string; see printf() function.
1961 static void Config_Error( const int Level, const char *Format, ... )
1963 static void Config_Error( Level, Format, va_alist )
1969 char msg[MAX_LOG_MSG_LEN];
1972 assert( Format != NULL );
1975 va_start( ap, Format );
1979 vsnprintf( msg, MAX_LOG_MSG_LEN, Format, ap );
1983 if (Level <= LOG_WARNING)
1984 printf(" - %s\n", msg);
1988 Log(Level, "%s", msg);
1994 * Dump internal state of the "configuration module".
1997 Conf_DebugDump(void)
2001 Log(LOG_DEBUG, "Configured servers:");
2002 for (i = 0; i < MAX_SERVERS; i++) {
2003 if (! Conf_Server[i].name[0])
2006 " - %s: %s:%d, last=%ld, group=%d, flags=%d, conn=%d",
2007 Conf_Server[i].name, Conf_Server[i].host,
2008 Conf_Server[i].port, Conf_Server[i].lasttry,
2009 Conf_Server[i].group, Conf_Server[i].flags,
2010 Conf_Server[i].conn_id);
2017 * Initialize server configuration structur to default values.
2019 * @param Server Pointer to server structure to initialize.
2022 Init_Server_Struct( CONF_SERVER *Server )
2024 assert( Server != NULL );
2026 memset( Server, 0, sizeof (CONF_SERVER) );
2028 Server->group = NONE;
2029 Server->lasttry = time( NULL ) - Conf_ConnectRetry + STARTUP_DELAY;
2031 if( NGIRCd_Passive ) Server->flags = CONF_SFLAG_DISABLED;
2033 Proc_InitStruct(&Server->res_stat);
2034 Server->conn_id = NONE;
2035 memset(&Server->bind_addr, 0, sizeof(&Server->bind_addr));