2 * ngIRCd -- The Next Generation IRC Daemon
3 * Copyright (c)2001-2012 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)
35 #include <sys/types.h>
52 static bool Use_Log = true, Using_MotdFile = true;
53 static CONF_SERVER New_Server;
54 static int New_Server_Idx;
56 static char Conf_MotdFile[FNAME_LEN];
58 static void Set_Defaults PARAMS(( bool InitServers ));
59 static bool Read_Config PARAMS(( bool TestOnly, bool IsStarting ));
60 static bool Validate_Config PARAMS(( bool TestOnly, bool Rehash ));
62 static void Handle_GLOBAL PARAMS(( int Line, char *Var, char *Arg ));
63 static void Handle_LIMITS PARAMS(( int Line, char *Var, char *Arg ));
64 static void Handle_OPTIONS PARAMS(( int Line, char *Var, char *Arg ));
65 static void Handle_OPERATOR PARAMS(( int Line, char *Var, char *Arg ));
66 static void Handle_SERVER PARAMS(( int Line, char *Var, char *Arg ));
67 static void Handle_CHANNEL PARAMS(( int Line, char *Var, char *Arg ));
69 static void Config_Error PARAMS(( const int Level, const char *Format, ... ));
71 static void Config_Error_NaN PARAMS(( const int LINE, const char *Value ));
72 static void Config_Error_Section PARAMS(( const int Line, const char *Item,
73 const char *Section ));
74 static void Config_Error_TooLong PARAMS(( const int LINE, const char *Value ));
76 static void Init_Server_Struct PARAMS(( CONF_SERVER *Server ));
80 #define DEFAULT_LISTEN_ADDRSTR "::,0.0.0.0"
82 #define DEFAULT_LISTEN_ADDRSTR "0.0.0.0"
88 static void Handle_SSL PARAMS(( int Line, char *Var, char *Ark ));
90 struct SSLOptions Conf_SSLOptions;
93 * Initialize SSL configuration.
98 free(Conf_SSLOptions.KeyFile);
99 Conf_SSLOptions.KeyFile = NULL;
101 free(Conf_SSLOptions.CertFile);
102 Conf_SSLOptions.CertFile = NULL;
104 free(Conf_SSLOptions.DHFile);
105 Conf_SSLOptions.DHFile = NULL;
106 array_free_wipe(&Conf_SSLOptions.KeyFilePassword);
108 array_free(&Conf_SSLOptions.ListenPorts);
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.
209 Read_Config(false, true);
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, 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, 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 = %d\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(" CloakHostModeX = %s\n", Conf_CloakHostModeX);
362 printf(" CloakHostSalt = %s\n", Conf_CloakHostSalt);
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(" MorePrivacy = %s\n", yesno_to_str(Conf_MorePrivacy));
373 printf(" NoticeAuth = %s\n", yesno_to_str(Conf_NoticeAuth));
374 printf(" OperCanUseMode = %s\n", yesno_to_str(Conf_OperCanMode));
375 printf(" OperChanPAutoOp = %s\n", yesno_to_str(Conf_OperChanPAutoOp));
376 printf(" OperServerMode = %s\n", yesno_to_str(Conf_OperServerMode));
378 printf(" PAM = %s\n", yesno_to_str(Conf_PAM));
379 printf(" PAMIsOptional = %s\n", yesno_to_str(Conf_PAMIsOptional));
381 printf(" PredefChannelsOnly = %s\n", yesno_to_str(Conf_PredefChannelsOnly));
383 printf(" RequireAuthPing = %s\n", yesno_to_str(Conf_AuthPing));
385 printf(" ScrubCTCP = %s\n", yesno_to_str(Conf_ScrubCTCP));
387 printf(" SyslogFacility = %s\n",
388 ngt_SyslogFacilityName(Conf_SyslogFacility));
390 printf(" WebircPassword = %s\n", Conf_WebircPwd);
395 printf(" CertFile = %s\n", Conf_SSLOptions.CertFile
396 ? Conf_SSLOptions.CertFile : "");
397 printf(" DHFile = %s\n", Conf_SSLOptions.DHFile
398 ? Conf_SSLOptions.DHFile : "");
399 printf(" KeyFile = %s\n", Conf_SSLOptions.KeyFile
400 ? Conf_SSLOptions.KeyFile : "");
401 if (array_bytes(&Conf_SSLOptions.KeyFilePassword))
402 puts(" KeyFilePassword = <secret>");
404 puts(" KeyFilePassword = ");
405 array_free_wipe(&Conf_SSLOptions.KeyFilePassword);
407 ports_puts(&Conf_SSLOptions.ListenPorts);
413 for( i = 0; i < MAX_SERVERS; i++ ) {
414 if( ! Conf_Server[i].name[0] ) continue;
416 /* Valid "Server" section */
418 printf( " Name = %s\n", Conf_Server[i].name );
419 printf( " Host = %s\n", Conf_Server[i].host );
420 printf( " Port = %u\n", (unsigned int)Conf_Server[i].port );
422 printf( " SSLConnect = %s\n", Conf_Server[i].SSLConnect?"yes":"no");
424 printf( " MyPassword = %s\n", Conf_Server[i].pwd_in );
425 printf( " PeerPassword = %s\n", Conf_Server[i].pwd_out );
426 printf( " ServiceMask = %s\n", Conf_Server[i].svs_mask);
427 printf( " Group = %d\n", Conf_Server[i].group );
428 printf( " Passive = %s\n\n", Conf_Server[i].flags & CONF_SFLAG_DISABLED ? "yes" : "no");
431 predef_channel_count = array_length(&Conf_Channels, sizeof(*predef_chan));
432 predef_chan = array_start(&Conf_Channels);
434 for (i = 0; i < predef_channel_count; i++, predef_chan++) {
435 if (!predef_chan->name[0])
438 /* Valid "Channel" section */
440 printf(" Name = %s\n", predef_chan->name);
441 printf(" Modes = %s\n", predef_chan->modes);
442 printf(" Key = %s\n", predef_chan->key);
443 printf(" MaxUsers = %lu\n", predef_chan->maxusers);
444 printf(" Topic = %s\n", predef_chan->topic);
445 printf(" KeyFile = %s\n\n", predef_chan->keyfile);
448 return (config_valid ? 0 : 1);
452 * Remove connection information from configured server.
454 * If the server is set as "once", delete it from our configuration;
455 * otherwise set the time for the next connection attempt.
457 * Non-server connections will be silently ignored.
460 Conf_UnsetServer( CONN_ID Idx )
465 /* Check all our configured servers */
466 for( i = 0; i < MAX_SERVERS; i++ ) {
467 if( Conf_Server[i].conn_id != Idx ) continue;
469 /* Gotcha! Mark server configuration as "unused": */
470 Conf_Server[i].conn_id = NONE;
472 if( Conf_Server[i].flags & CONF_SFLAG_ONCE ) {
473 /* Delete configuration here */
474 Init_Server_Struct( &Conf_Server[i] );
476 /* Set time for next connect attempt */
478 if (Conf_Server[i].lasttry < t - Conf_ConnectRetry) {
479 /* The connection has been "long", so we don't
480 * require the next attempt to be delayed. */
481 Conf_Server[i].lasttry =
482 t - Conf_ConnectRetry + RECONNECT_DELAY;
484 Conf_Server[i].lasttry = t;
490 * Set connection information for specified configured server.
493 Conf_SetServer( int ConfServer, CONN_ID Idx )
495 assert( ConfServer > NONE );
496 assert( Idx > NONE );
498 if (Conf_Server[ConfServer].conn_id > NONE &&
499 Conf_Server[ConfServer].conn_id != Idx) {
501 "Trying to update connection index for already registered server \"%s\": %d/%d - ignored.",
502 Conf_Server[ConfServer].name,
503 Conf_Server[ConfServer].conn_id, Idx);
506 Conf_Server[ConfServer].conn_id = Idx;
510 * Get index of server in configuration structure.
513 Conf_GetServer( CONN_ID Idx )
517 assert( Idx > NONE );
519 for( i = 0; i < MAX_SERVERS; i++ ) {
520 if( Conf_Server[i].conn_id == Idx ) return i;
526 * Enable a server by name and adjust its port number.
528 * @returns true if a server has been enabled and now has a valid port
529 * number and host name for outgoing connections.
532 Conf_EnableServer( const char *Name, UINT16 Port )
536 assert( Name != NULL );
537 for( i = 0; i < MAX_SERVERS; i++ ) {
538 if( strcasecmp( Conf_Server[i].name, Name ) == 0 ) {
539 /* Gotcha! Set port and enable server: */
540 Conf_Server[i].port = Port;
541 Conf_Server[i].flags &= ~CONF_SFLAG_DISABLED;
542 return (Conf_Server[i].port && Conf_Server[i].host[0]);
549 * Enable a server by name.
551 * The server is only usable as outgoing server, if it has set a valid port
552 * number for outgoing connections!
553 * If not, you have to use Conf_EnableServer() function to make it available.
555 * @returns true if a server has been enabled; false otherwise.
558 Conf_EnablePassiveServer(const char *Name)
562 assert( Name != NULL );
563 for (i = 0; i < MAX_SERVERS; i++) {
564 if ((strcasecmp( Conf_Server[i].name, Name ) == 0)
565 && (Conf_Server[i].port > 0)) {
566 /* BINGO! Enable server */
567 Conf_Server[i].flags &= ~CONF_SFLAG_DISABLED;
575 * Disable a server by name.
576 * An already established connection will be disconnected.
578 * @returns true if a server was found and has been disabled.
581 Conf_DisableServer( const char *Name )
585 assert( Name != NULL );
586 for( i = 0; i < MAX_SERVERS; i++ ) {
587 if( strcasecmp( Conf_Server[i].name, Name ) == 0 ) {
588 /* Gotcha! Disable and disconnect server: */
589 Conf_Server[i].flags |= CONF_SFLAG_DISABLED;
590 if( Conf_Server[i].conn_id > NONE )
591 Conn_Close(Conf_Server[i].conn_id, NULL,
592 "Server link terminated on operator request",
601 * Add a new remote server to our configuration.
603 * @param Name Name of the new server.
604 * @param Port Port number to connect to or 0 for incoming connections.
605 * @param Host Host name to connect to.
606 * @param MyPwd Password that will be sent to the peer.
607 * @param PeerPwd Password that must be received from the peer.
608 * @returns true if the new server has been added; false otherwise.
611 Conf_AddServer(const char *Name, UINT16 Port, const char *Host,
612 const char *MyPwd, const char *PeerPwd)
616 assert( Name != NULL );
617 assert( Host != NULL );
618 assert( MyPwd != NULL );
619 assert( PeerPwd != NULL );
621 /* Search unused item in server configuration structure */
622 for( i = 0; i < MAX_SERVERS; i++ ) {
623 /* Is this item used? */
624 if( ! Conf_Server[i].name[0] ) break;
626 if( i >= MAX_SERVERS ) return false;
628 Init_Server_Struct( &Conf_Server[i] );
629 strlcpy( Conf_Server[i].name, Name, sizeof( Conf_Server[i].name ));
630 strlcpy( Conf_Server[i].host, Host, sizeof( Conf_Server[i].host ));
631 strlcpy( Conf_Server[i].pwd_out, MyPwd, sizeof( Conf_Server[i].pwd_out ));
632 strlcpy( Conf_Server[i].pwd_in, PeerPwd, sizeof( Conf_Server[i].pwd_in ));
633 Conf_Server[i].port = Port;
634 Conf_Server[i].flags = CONF_SFLAG_ONCE;
640 * Check if the given nick name is reserved for services on a particular server.
642 * @param ConfServer The server index to check.
643 * @param Nick The nick name to check.
644 * @returns true if the given nick name belongs to an "IRC service".
647 Conf_NickIsService(int ConfServer, const char *Nick)
649 assert (ConfServer >= 0);
650 assert (ConfServer < MAX_SERVERS);
652 return MatchCaseInsensitiveList(Conf_Server[ConfServer].svs_mask,
657 * Check if the given nick name is blocked for "normal client" use.
659 * @param ConfServer The server index or NONE to check all configured servers.
660 * @param Nick The nick name to check.
661 * @returns true if the given nick name belongs to an "IRC service".
664 Conf_NickIsBlocked(const char *Nick)
668 for(i = 0; i < MAX_SERVERS; i++) {
669 if (!Conf_Server[i].name[0])
671 if (Conf_NickIsService(i, Nick))
678 * Initialize configuration settings with their default values.
681 Set_Defaults(bool InitServers)
684 char random[RANDOM_SALT_LEN + 1];
687 strcpy(Conf_ServerName, "");
688 strcpy(Conf_ServerAdmin1, "");
689 strcpy(Conf_ServerAdmin2, "");
690 strcpy(Conf_ServerAdminMail, "");
691 snprintf(Conf_ServerInfo, sizeof Conf_ServerInfo, "%s %s",
692 PACKAGE_NAME, PACKAGE_VERSION);
693 free(Conf_ListenAddress);
694 Conf_ListenAddress = NULL;
695 array_free(&Conf_ListenPorts);
696 array_free(&Conf_Motd);
697 strlcpy(Conf_MotdFile, SYSCONFDIR, sizeof(Conf_MotdFile));
698 strlcat(Conf_MotdFile, MOTD_FILE, sizeof(Conf_MotdFile));
699 strcpy(Conf_ServerPwd, "");
700 strlcpy(Conf_PidFile, PID_FILE, sizeof(Conf_PidFile));
701 Conf_UID = Conf_GID = 0;
704 Conf_ConnectRetry = 60;
705 Conf_MaxConnections = 0;
706 Conf_MaxConnectionsIP = 5;
708 Conf_MaxNickLength = CLIENT_NICK_LEN_DEFAULT;
709 Conf_PingTimeout = 120;
710 Conf_PongTimeout = 20;
713 Conf_AllowRemoteOper = false;
715 Conf_AuthPing = false;
717 strlcpy(Conf_Chroot, CHROOT_DIR, sizeof(Conf_Chroot));
718 strcpy(Conf_CloakHost, "");
719 strcpy(Conf_CloakHostModeX, "");
720 strcpy(Conf_CloakHostSalt, ngt_RandomStr(random, RANDOM_SALT_LEN));
721 Conf_CloakUserToNick = false;
722 Conf_ConnectIPv4 = true;
724 Conf_ConnectIPv6 = true;
726 Conf_ConnectIPv6 = false;
734 Conf_MorePrivacy = false;
735 Conf_NoticeAuth = false;
736 Conf_OperCanMode = false;
737 Conf_OperChanPAutoOp = true;
738 Conf_OperServerMode = false;
744 Conf_PAMIsOptional = false;
745 Conf_PredefChannelsOnly = false;
747 Conf_ScrubCTCP = false;
749 Conf_SyslogFacility = LOG_LOCAL5;
751 Conf_SyslogFacility = 0;
755 /* Initialize server configuration structures */
757 for (i = 0; i < MAX_SERVERS;
758 Init_Server_Struct(&Conf_Server[i++]));
763 * Get number of configured listening ports.
765 * @returns The number of ports (IPv4+IPv6) on which the server should listen.
770 size_t cnt = array_bytes(&Conf_ListenPorts);
772 cnt += array_bytes(&Conf_SSLOptions.ListenPorts);
778 * Read MOTD ("message of the day") file.
780 * @param filename Name of the file to read.
783 Read_Motd(const char *filename)
788 if (*filename == '\0')
791 fp = fopen(filename, "r");
793 Config_Error(LOG_WARNING, "Can't read MOTD file \"%s\": %s",
794 filename, strerror(errno));
798 array_free(&Conf_Motd);
799 Using_MotdFile = true;
801 while (fgets(line, (int)sizeof line, fp)) {
802 ngt_TrimLastChr( line, '\n');
804 /* add text including \0 */
805 if (!array_catb(&Conf_Motd, line, strlen(line) + 1)) {
806 Log(LOG_WARNING, "Cannot add MOTD text: %s", strerror(errno));
814 * Read ngIRCd configuration file.
816 * Please note that this function uses exit(1) on fatal errors and therefore
817 * can result in ngIRCd terminating!
819 * @param ngircd_starting Flag indicating if ngIRCd is starting or not.
820 * @returns true when the configuration file has been read
821 * successfully; false otherwise.
824 Read_Config(bool TestOnly, bool IsStarting)
826 char section[LINE_LEN], str[LINE_LEN], *var, *arg, *ptr;
827 const UINT16 defaultport = 6667;
832 /* Open configuration file */
833 fd = fopen( NGIRCd_ConfFile, "r" );
835 /* No configuration file found! */
836 Config_Error( LOG_ALERT, "Can't read configuration \"%s\": %s",
837 NGIRCd_ConfFile, strerror( errno ));
840 Config_Error( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME );
845 Set_Defaults(IsStarting);
848 Config_Error(LOG_INFO,
849 "Reading configuration from \"%s\" ...",
852 /* Clean up server configuration structure: mark all already
853 * configured servers as "once" so that they are deleted
854 * after the next disconnect and delete all unused servers.
855 * And delete all servers which are "duplicates" of servers
856 * that are already marked as "once" (such servers have been
857 * created by the last rehash but are now useless). */
858 for( i = 0; i < MAX_SERVERS; i++ ) {
859 if( Conf_Server[i].conn_id == NONE ) Init_Server_Struct( &Conf_Server[i] );
861 /* This structure is in use ... */
862 if( Conf_Server[i].flags & CONF_SFLAG_ONCE ) {
863 /* Check for duplicates */
864 for( n = 0; n < MAX_SERVERS; n++ ) {
865 if( n == i ) continue;
867 if( Conf_Server[i].conn_id == Conf_Server[n].conn_id ) {
868 Init_Server_Struct( &Conf_Server[n] );
870 Log(LOG_DEBUG,"Deleted unused duplicate server %d (kept %d).",
876 /* Mark server as "once" */
877 Conf_Server[i].flags |= CONF_SFLAG_ONCE;
878 Log( LOG_DEBUG, "Marked server %d as \"once\"", i );
883 /* Initialize variables */
885 strcpy( section, "" );
886 Init_Server_Struct( &New_Server );
887 New_Server_Idx = NONE;
891 /* Read configuration file */
893 if( ! fgets( str, LINE_LEN, fd )) break;
897 /* Skip comments and empty lines */
898 if( str[0] == ';' || str[0] == '#' || str[0] == '\0' ) continue;
900 /* Is this the beginning of a new section? */
901 if(( str[0] == '[' ) && ( str[strlen( str ) - 1] == ']' )) {
902 strlcpy( section, str, sizeof( section ));
903 if (strcasecmp(section, "[GLOBAL]") == 0
904 || strcasecmp(section, "[LIMITS]") == 0
905 || strcasecmp(section, "[OPTIONS]") == 0
907 || strcasecmp(section, "[SSL]") == 0
912 if( strcasecmp( section, "[SERVER]" ) == 0 ) {
913 /* Check if there is already a server to add */
914 if( New_Server.name[0] ) {
915 /* Copy data to "real" server structure */
916 assert( New_Server_Idx > NONE );
917 Conf_Server[New_Server_Idx] = New_Server;
920 /* Re-init structure for new server */
921 Init_Server_Struct( &New_Server );
923 /* Search unused item in server configuration structure */
924 for( i = 0; i < MAX_SERVERS; i++ ) {
925 /* Is this item used? */
926 if( ! Conf_Server[i].name[0] ) break;
928 if( i >= MAX_SERVERS ) {
929 /* Oops, no free item found! */
930 Config_Error( LOG_ERR, "Too many servers configured." );
931 New_Server_Idx = NONE;
933 else New_Server_Idx = i;
937 if (strcasecmp(section, "[CHANNEL]") == 0) {
938 count = array_length(&Conf_Channels,
939 sizeof(struct Conf_Channel));
940 if (!array_alloc(&Conf_Channels,
941 sizeof(struct Conf_Channel),
943 Config_Error(LOG_ERR,
944 "Could not allocate memory for new operator (line %d)",
950 if (strcasecmp(section, "[OPERATOR]") == 0) {
951 count = array_length(&Conf_Opers,
952 sizeof(struct Conf_Oper));
953 if (!array_alloc(&Conf_Opers,
954 sizeof(struct Conf_Oper),
956 Config_Error(LOG_ERR,
957 "Could not allocate memory for new channel (line &d)",
963 Config_Error(LOG_ERR,
964 "%s, line %d: Unknown section \"%s\"!",
965 NGIRCd_ConfFile, line, section);
968 if( section[0] == 0x1 ) continue;
970 /* Split line into variable name and parameters */
971 ptr = strchr( str, '=' );
973 Config_Error( LOG_ERR, "%s, line %d: Syntax error!", NGIRCd_ConfFile, line );
977 var = str; ngt_TrimStr( var );
978 arg = ptr + 1; ngt_TrimStr( arg );
980 if(strcasecmp(section, "[GLOBAL]") == 0)
981 Handle_GLOBAL(line, var, arg);
982 else if(strcasecmp(section, "[LIMITS]") == 0)
983 Handle_LIMITS(line, var, arg);
984 else if(strcasecmp(section, "[OPTIONS]") == 0)
985 Handle_OPTIONS(line, var, arg);
987 else if(strcasecmp(section, "[SSL]") == 0)
988 Handle_SSL(line, var, arg);
990 else if(strcasecmp(section, "[OPERATOR]") == 0)
991 Handle_OPERATOR(line, var, arg);
992 else if(strcasecmp(section, "[SERVER]") == 0)
993 Handle_SERVER(line, var, arg);
994 else if(strcasecmp(section, "[CHANNEL]") == 0)
995 Handle_CHANNEL(line, var, arg);
997 Config_Error(LOG_ERR,
998 "%s, line %d: Variable \"%s\" outside section!",
999 NGIRCd_ConfFile, line, var);
1002 /* Close configuration file */
1005 /* Check if there is still a server to add */
1006 if( New_Server.name[0] ) {
1007 /* Copy data to "real" server structure */
1008 assert( New_Server_Idx > NONE );
1009 Conf_Server[New_Server_Idx] = New_Server;
1012 /* not a single listening port? Add default. */
1013 if (no_listenports() &&
1014 !array_copyb(&Conf_ListenPorts, (char*) &defaultport, sizeof defaultport))
1016 Config_Error(LOG_ALERT, "Could not add default listening Port %u: %s",
1017 (unsigned int) defaultport, strerror(errno));
1022 if (!Conf_ListenAddress)
1023 Conf_ListenAddress = strdup_warn(DEFAULT_LISTEN_ADDRSTR);
1025 if (!Conf_ListenAddress) {
1026 Config_Error(LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME);
1030 /* No MOTD phrase configured? (re)try motd file. */
1031 if (array_bytes(&Conf_Motd) == 0)
1032 Read_Motd(Conf_MotdFile);
1035 /* Make sure that all SSL-related files are readable */
1036 CheckFileReadable("CertFile", Conf_SSLOptions.CertFile);
1037 CheckFileReadable("DHFile", Conf_SSLOptions.DHFile);
1038 CheckFileReadable("KeyFile", Conf_SSLOptions.KeyFile);
1045 * Check whether a string argument is "true" or "false".
1047 * @param Arg Input string.
1048 * @returns true if the input string has been parsed as "yes", "true"
1049 * (case insensitive) or a non-zero integer value.
1052 Check_ArgIsTrue(const char *Arg)
1054 if (strcasecmp(Arg, "yes") == 0)
1056 if (strcasecmp(Arg, "true") == 0)
1065 * Handle setting of "MaxNickLength".
1067 * @param Line Line number in configuration file.
1068 * @raram Arg Input string.
1069 * @returns New configured maximum nick name length.
1072 Handle_MaxNickLength(int Line, const char *Arg)
1076 new = (unsigned) atoi(Arg) + 1;
1077 if (new > CLIENT_NICK_LEN) {
1078 Config_Error(LOG_WARNING,
1079 "%s, line %d: Value of \"MaxNickLength\" exceeds %u!",
1080 NGIRCd_ConfFile, Line, CLIENT_NICK_LEN - 1);
1081 return CLIENT_NICK_LEN;
1084 Config_Error(LOG_WARNING,
1085 "%s, line %d: Value of \"MaxNickLength\" must be at least 1!",
1086 NGIRCd_ConfFile, Line);
1093 * Output a warning messages if IDENT is configured but not compiled in.
1096 WarnIdent(int UNUSED Line)
1100 /* user has enabled ident lookups explicitly, but ... */
1101 Config_Error(LOG_WARNING,
1102 "%s: line %d: \"Ident = yes\", but ngircd was built without IDENT support!",
1103 NGIRCd_ConfFile, Line);
1109 * Output a warning messages if IPv6 is configured but not compiled in.
1112 WarnIPv6(int UNUSED Line)
1115 if (Conf_ConnectIPv6) {
1116 /* user has enabled IPv6 explicitly, but ... */
1117 Config_Error(LOG_WARNING,
1118 "%s: line %d: \"ConnectIPv6 = yes\", but ngircd was built without IPv6 support!",
1119 NGIRCd_ConfFile, Line);
1125 * Output a warning messages if PAM is configured but not compiled in.
1128 WarnPAM(int UNUSED Line)
1132 Config_Error(LOG_WARNING,
1133 "%s: line %d: \"PAM = yes\", but ngircd was built without PAM support!",
1134 NGIRCd_ConfFile, Line);
1140 * Handle legacy "NoXXX" options in [GLOBAL] section.
1142 * TODO: This function and support for "NoXXX" could be removed starting
1143 * with ngIRCd release 19 (one release after marking it "deprecated").
1145 * @param Var Variable name.
1146 * @param Arg Argument string.
1147 * @returns true if a NoXXX option has been processed; false otherwise.
1150 CheckLegacyNoOption(const char *Var, const char *Arg)
1152 if(strcasecmp(Var, "NoDNS") == 0) {
1153 Conf_DNS = !Check_ArgIsTrue( Arg );
1156 if (strcasecmp(Var, "NoIdent") == 0) {
1157 Conf_Ident = !Check_ArgIsTrue(Arg);
1160 if(strcasecmp(Var, "NoPAM") == 0) {
1161 Conf_PAM = !Check_ArgIsTrue(Arg);
1168 * Handle deprecated legacy options in [GLOBAL] section.
1170 * TODO: This function and support for these options in the [Global] section
1171 * could be removed starting with ngIRCd release 19 (one release after
1172 * marking it "deprecated").
1174 * @param Var Variable name.
1175 * @param Arg Argument string.
1176 * @returns true if a legacy option has been processed; false otherwise.
1179 CheckLegacyGlobalOption(int Line, char *Var, char *Arg)
1181 if (strcasecmp(Var, "AllowRemoteOper") == 0
1182 || strcasecmp(Var, "ChrootDir") == 0
1183 || strcasecmp(Var, "ConnectIPv4") == 0
1184 || strcasecmp(Var, "ConnectIPv6") == 0
1185 || strcasecmp(Var, "OperCanUseMode") == 0
1186 || strcasecmp(Var, "OperChanPAutoOp") == 0
1187 || strcasecmp(Var, "OperServerMode") == 0
1188 || strcasecmp(Var, "PredefChannelsOnly") == 0
1189 || strcasecmp(Var, "SyslogFacility") == 0
1190 || strcasecmp(Var, "WebircPassword") == 0) {
1191 Handle_OPTIONS(Line, Var, Arg);
1194 if (strcasecmp(Var, "ConnectRetry") == 0
1195 || strcasecmp(Var, "MaxConnections") == 0
1196 || strcasecmp(Var, "MaxConnectionsIP") == 0
1197 || strcasecmp(Var, "MaxJoins") == 0
1198 || strcasecmp(Var, "MaxNickLength") == 0
1199 || strcasecmp(Var, "PingTimeout") == 0
1200 || strcasecmp(Var, "PongTimeout") == 0) {
1201 Handle_LIMITS(Line, Var, Arg);
1205 if (strcasecmp(Var, "SSLCertFile") == 0
1206 || strcasecmp(Var, "SSLDHFile") == 0
1207 || strcasecmp(Var, "SSLKeyFile") == 0
1208 || strcasecmp(Var, "SSLKeyFilePassword") == 0
1209 || strcasecmp(Var, "SSLPorts") == 0) {
1210 Handle_SSL(Line, Var + 3, Arg);
1219 * Strip "no" prefix of a string.
1221 * TODO: This function and support for "NoXXX" should be removed starting
1222 * with ngIRCd release 19! (One release after marking it "deprecated").
1224 * @param str Pointer to input string starting with "no".
1225 * @returns New pointer to string without "no" prefix.
1228 NoNo(const char *str)
1230 assert(strncasecmp("no", str, 2) == 0 && str[2]);
1235 * Invert "boolean" string.
1237 * TODO: This function and support for "NoXXX" should be removed starting
1238 * with ngIRCd release 19! (One release after marking it "deprecated").
1240 * @param arg "Boolean" input string.
1241 * @returns Pointer to inverted "boolean string".
1244 InvertArg(const char *arg)
1246 return yesno_to_str(!Check_ArgIsTrue(arg));
1250 * Handle variable in [Global] configuration section.
1252 * @param Line Line numer in configuration file.
1253 * @param Var Variable name.
1254 * @param Arg Variable argument.
1257 Handle_GLOBAL( int Line, char *Var, char *Arg )
1262 const char *section;
1265 assert(Var != NULL);
1266 assert(Arg != NULL);
1268 if (strcasecmp(Var, "Name") == 0) {
1269 len = strlcpy(Conf_ServerName, Arg, sizeof(Conf_ServerName));
1270 if (len >= sizeof(Conf_ServerName))
1271 Config_Error_TooLong(Line, Var);
1274 if (strcasecmp(Var, "AdminInfo1") == 0) {
1275 len = strlcpy(Conf_ServerAdmin1, Arg, sizeof(Conf_ServerAdmin1));
1276 if (len >= sizeof(Conf_ServerAdmin1))
1277 Config_Error_TooLong(Line, Var);
1280 if (strcasecmp(Var, "AdminInfo2") == 0) {
1281 len = strlcpy(Conf_ServerAdmin2, Arg, sizeof(Conf_ServerAdmin2));
1282 if (len >= sizeof(Conf_ServerAdmin2))
1283 Config_Error_TooLong(Line, Var);
1286 if (strcasecmp(Var, "AdminEMail") == 0) {
1287 len = strlcpy(Conf_ServerAdminMail, Arg,
1288 sizeof(Conf_ServerAdminMail));
1289 if (len >= sizeof(Conf_ServerAdminMail))
1290 Config_Error_TooLong(Line, Var);
1293 if (strcasecmp(Var, "Info") == 0) {
1294 len = strlcpy(Conf_ServerInfo, Arg, sizeof(Conf_ServerInfo));
1295 if (len >= sizeof(Conf_ServerInfo))
1296 Config_Error_TooLong(Line, Var);
1299 if (strcasecmp(Var, "Listen") == 0) {
1300 if (Conf_ListenAddress) {
1301 Config_Error(LOG_ERR,
1302 "Multiple Listen= options, ignoring: %s",
1306 Conf_ListenAddress = strdup_warn(Arg);
1307 /* If allocation fails, we're in trouble: we cannot ignore the
1308 * error -- otherwise ngircd would listen on all interfaces. */
1309 if (!Conf_ListenAddress) {
1310 Config_Error(LOG_ALERT,
1311 "%s exiting due to fatal errors!",
1317 if (strcasecmp(Var, "MotdFile") == 0) {
1318 len = strlcpy(Conf_MotdFile, Arg, sizeof(Conf_MotdFile));
1319 if (len >= sizeof(Conf_MotdFile))
1320 Config_Error_TooLong(Line, Var);
1323 if (strcasecmp(Var, "MotdPhrase") == 0) {
1327 if (len >= LINE_LEN) {
1328 Config_Error_TooLong(Line, Var);
1331 if (!array_copyb(&Conf_Motd, Arg, len + 1))
1332 Config_Error(LOG_WARNING,
1333 "%s, line %d: Could not append MotdPhrase: %s",
1334 NGIRCd_ConfFile, Line, strerror(errno));
1335 Using_MotdFile = false;
1338 if(strcasecmp(Var, "Password") == 0) {
1339 len = strlcpy(Conf_ServerPwd, Arg, sizeof(Conf_ServerPwd));
1340 if (len >= sizeof(Conf_ServerPwd))
1341 Config_Error_TooLong(Line, Var);
1344 if (strcasecmp(Var, "PidFile") == 0) {
1345 len = strlcpy(Conf_PidFile, Arg, sizeof(Conf_PidFile));
1346 if (len >= sizeof(Conf_PidFile))
1347 Config_Error_TooLong(Line, Var);
1350 if (strcasecmp(Var, "Ports") == 0) {
1351 ports_parse(&Conf_ListenPorts, Line, Arg);
1354 if (strcasecmp(Var, "ServerGID") == 0) {
1355 grp = getgrnam(Arg);
1357 Conf_GID = grp->gr_gid;
1359 Conf_GID = (unsigned int)atoi(Arg);
1360 if (!Conf_GID && strcmp(Arg, "0"))
1361 Config_Error(LOG_WARNING,
1362 "%s, line %d: Value of \"%s\" is not a valid group name or ID!",
1363 NGIRCd_ConfFile, Line, Var);
1367 if (strcasecmp(Var, "ServerUID") == 0) {
1368 pwd = getpwnam(Arg);
1370 Conf_UID = pwd->pw_uid;
1372 Conf_UID = (unsigned int)atoi(Arg);
1373 if (!Conf_UID && strcmp(Arg, "0"))
1374 Config_Error(LOG_WARNING,
1375 "%s, line %d: Value of \"%s\" is not a valid user name or ID!",
1376 NGIRCd_ConfFile, Line, Var);
1381 if (CheckLegacyNoOption(Var, Arg)) {
1382 /* TODO: This function and support for "NoXXX" could be
1383 * be removed starting with ngIRCd release 19 (one release
1384 * after marking it "deprecated"). */
1385 Config_Error(LOG_WARNING,
1386 "%s, line %d (section \"Global\"): \"No\"-Prefix is deprecated, use \"%s = %s\" in [Options] section!",
1387 NGIRCd_ConfFile, Line, NoNo(Var), InvertArg(Arg));
1388 if (strcasecmp(Var, "NoIdent") == 0)
1390 else if (strcasecmp(Var, "NoPam") == 0)
1394 if ((section = CheckLegacyGlobalOption(Line, Var, Arg))) {
1395 /** TODO: This function and support for these options in the
1396 * [Global] section could be removed starting with ngIRCd
1397 * release 19 (one release after marking it "deprecated"). */
1398 if (strncasecmp(Var, "SSL", 3) == 0) {
1399 Config_Error(LOG_WARNING,
1400 "%s, line %d (section \"Global\"): \"%s\" is deprecated here, move it to %s and rename to \"%s\"!",
1401 NGIRCd_ConfFile, Line, Var, section,
1404 Config_Error(LOG_WARNING,
1405 "%s, line %d (section \"Global\"): \"%s\" is deprecated here, move it to %s!",
1406 NGIRCd_ConfFile, Line, Var, section);
1411 Config_Error_Section(Line, Var, "Global");
1415 * Handle variable in [Limits] configuration section.
1417 * @param Line Line numer in configuration file.
1418 * @param Var Variable name.
1419 * @param Arg Variable argument.
1422 Handle_LIMITS(int Line, char *Var, char *Arg)
1425 assert(Var != NULL);
1426 assert(Arg != NULL);
1428 if (strcasecmp(Var, "ConnectRetry") == 0) {
1429 Conf_ConnectRetry = atoi(Arg);
1430 if (Conf_ConnectRetry < 5) {
1431 Config_Error(LOG_WARNING,
1432 "%s, line %d: Value of \"ConnectRetry\" too low!",
1433 NGIRCd_ConfFile, Line);
1434 Conf_ConnectRetry = 5;
1438 if (strcasecmp(Var, "MaxConnections") == 0) {
1439 Conf_MaxConnections = atoi(Arg);
1440 if (!Conf_MaxConnections && strcmp(Arg, "0"))
1441 Config_Error_NaN(Line, Var);
1444 if (strcasecmp(Var, "MaxConnectionsIP") == 0) {
1445 Conf_MaxConnectionsIP = atoi(Arg);
1446 if (!Conf_MaxConnectionsIP && strcmp(Arg, "0"))
1447 Config_Error_NaN(Line, Var);
1450 if (strcasecmp(Var, "MaxJoins") == 0) {
1451 Conf_MaxJoins = atoi(Arg);
1452 if (!Conf_MaxJoins && strcmp(Arg, "0"))
1453 Config_Error_NaN(Line, Var);
1456 if (strcasecmp(Var, "MaxNickLength") == 0) {
1457 Conf_MaxNickLength = Handle_MaxNickLength(Line, Arg);
1460 if (strcasecmp(Var, "PingTimeout") == 0) {
1461 Conf_PingTimeout = atoi(Arg);
1462 if (Conf_PingTimeout < 5) {
1463 Config_Error(LOG_WARNING,
1464 "%s, line %d: Value of \"PingTimeout\" too low!",
1465 NGIRCd_ConfFile, Line);
1466 Conf_PingTimeout = 5;
1470 if (strcasecmp(Var, "PongTimeout") == 0) {
1471 Conf_PongTimeout = atoi(Arg);
1472 if (Conf_PongTimeout < 5) {
1473 Config_Error(LOG_WARNING,
1474 "%s, line %d: Value of \"PongTimeout\" too low!",
1475 NGIRCd_ConfFile, Line);
1476 Conf_PongTimeout = 5;
1481 Config_Error_Section(Line, Var, "Limits");
1485 * Handle variable in [Options] configuration section.
1487 * @param Line Line numer in configuration file.
1488 * @param Var Variable name.
1489 * @param Arg Variable argument.
1492 Handle_OPTIONS(int Line, char *Var, char *Arg)
1497 assert(Var != NULL);
1498 assert(Arg != NULL);
1500 if (strcasecmp(Var, "AllowRemoteOper") == 0) {
1501 Conf_AllowRemoteOper = Check_ArgIsTrue(Arg);
1504 if (strcasecmp(Var, "ChrootDir") == 0) {
1505 len = strlcpy(Conf_Chroot, Arg, sizeof(Conf_Chroot));
1506 if (len >= sizeof(Conf_Chroot))
1507 Config_Error_TooLong(Line, Var);
1510 if (strcasecmp(Var, "CloakHost") == 0) {
1511 len = strlcpy(Conf_CloakHost, Arg, sizeof(Conf_CloakHost));
1512 if (len >= sizeof(Conf_CloakHost))
1513 Config_Error_TooLong(Line, Var);
1516 if (strcasecmp(Var, "CloakHostModeX") == 0) {
1517 len = strlcpy(Conf_CloakHostModeX, Arg, sizeof(Conf_CloakHostModeX));
1518 if (len >= sizeof(Conf_CloakHostModeX))
1519 Config_Error_TooLong(Line, Var);
1522 if (strcasecmp(Var, "CloakHostSalt") == 0) {
1523 len = strlcpy(Conf_CloakHostSalt, Arg, sizeof(Conf_CloakHostSalt));
1524 if (len >= sizeof(Conf_CloakHostSalt))
1525 Config_Error_TooLong(Line, Var);
1528 if (strcasecmp(Var, "CloakUserToNick") == 0) {
1529 Conf_CloakUserToNick = Check_ArgIsTrue(Arg);
1532 if (strcasecmp(Var, "ConnectIPv6") == 0) {
1533 Conf_ConnectIPv6 = Check_ArgIsTrue(Arg);
1537 if (strcasecmp(Var, "ConnectIPv4") == 0) {
1538 Conf_ConnectIPv4 = Check_ArgIsTrue(Arg);
1541 if (strcasecmp(Var, "DNS") == 0) {
1542 Conf_DNS = Check_ArgIsTrue(Arg);
1545 if (strcasecmp(Var, "Ident") == 0) {
1546 Conf_Ident = Check_ArgIsTrue(Arg);
1550 if (strcasecmp(Var, "MorePrivacy") == 0) {
1551 Conf_MorePrivacy = Check_ArgIsTrue(Arg);
1554 if (strcasecmp(Var, "NoticeAuth") == 0) {
1555 Conf_NoticeAuth = Check_ArgIsTrue(Arg);
1558 if (strcasecmp(Var, "OperCanUseMode") == 0) {
1559 Conf_OperCanMode = Check_ArgIsTrue(Arg);
1562 if (strcasecmp(Var, "OperChanPAutoOp") == 0) {
1563 Conf_OperChanPAutoOp = Check_ArgIsTrue(Arg);
1566 if (strcasecmp(Var, "OperServerMode") == 0) {
1567 Conf_OperServerMode = Check_ArgIsTrue(Arg);
1570 if (strcasecmp(Var, "PAM") == 0) {
1571 Conf_PAM = Check_ArgIsTrue(Arg);
1575 if (strcasecmp(Var, "PAMIsOptional") == 0 ) {
1576 Conf_PAMIsOptional = Check_ArgIsTrue(Arg);
1579 if (strcasecmp(Var, "PredefChannelsOnly") == 0) {
1580 Conf_PredefChannelsOnly = Check_ArgIsTrue(Arg);
1584 if (strcasecmp(Var, "RequireAuthPing") == 0) {
1585 Conf_AuthPing = Check_ArgIsTrue(Arg);
1589 if (strcasecmp(Var, "ScrubCTCP") == 0) {
1590 Conf_ScrubCTCP = Check_ArgIsTrue(Arg);
1594 if (strcasecmp(Var, "SyslogFacility") == 0) {
1595 Conf_SyslogFacility = ngt_SyslogFacilityID(Arg,
1596 Conf_SyslogFacility);
1600 if (strcasecmp(Var, "WebircPassword") == 0) {
1601 len = strlcpy(Conf_WebircPwd, Arg, sizeof(Conf_WebircPwd));
1602 if (len >= sizeof(Conf_WebircPwd))
1603 Config_Error_TooLong(Line, Var);
1607 Config_Error_Section(Line, Var, "Options");
1613 * Handle variable in [SSL] configuration section.
1615 * @param Line Line numer in configuration file.
1616 * @param Var Variable name.
1617 * @param Arg Variable argument.
1620 Handle_SSL(int Line, char *Var, char *Arg)
1623 assert(Var != NULL);
1624 assert(Arg != NULL);
1626 if (strcasecmp(Var, "CertFile") == 0) {
1627 assert(Conf_SSLOptions.CertFile == NULL);
1628 Conf_SSLOptions.CertFile = strdup_warn(Arg);
1631 if (strcasecmp(Var, "DHFile") == 0) {
1632 assert(Conf_SSLOptions.DHFile == NULL);
1633 Conf_SSLOptions.DHFile = strdup_warn(Arg);
1636 if (strcasecmp(Var, "KeyFile") == 0) {
1637 assert(Conf_SSLOptions.KeyFile == NULL);
1638 Conf_SSLOptions.KeyFile = strdup_warn(Arg);
1641 if (strcasecmp(Var, "KeyFilePassword") == 0) {
1642 assert(array_bytes(&Conf_SSLOptions.KeyFilePassword) == 0);
1643 if (!array_copys(&Conf_SSLOptions.KeyFilePassword, Arg))
1644 Config_Error(LOG_ERR,
1645 "%s, line %d (section \"SSL\"): Could not copy %s: %s!",
1646 NGIRCd_ConfFile, Line, Var,
1650 if (strcasecmp(Var, "Ports") == 0) {
1651 ports_parse(&Conf_SSLOptions.ListenPorts, Line, Arg);
1655 Config_Error_Section(Line, Var, "SSL");
1661 * Handle variable in [Operator] configuration section.
1663 * @param Line Line numer in configuration file.
1664 * @param Var Variable name.
1665 * @param Arg Variable argument.
1668 Handle_OPERATOR( int Line, char *Var, char *Arg )
1671 struct Conf_Oper *op;
1674 assert( Var != NULL );
1675 assert( Arg != NULL );
1677 op = array_get(&Conf_Opers, sizeof(*op),
1678 array_length(&Conf_Opers, sizeof(*op)) - 1);
1682 if (strcasecmp(Var, "Name") == 0) {
1683 /* Name of IRC operator */
1684 len = strlcpy(op->name, Arg, sizeof(op->name));
1685 if (len >= sizeof(op->name))
1686 Config_Error_TooLong(Line, Var);
1689 if (strcasecmp(Var, "Password") == 0) {
1690 /* Password of IRC operator */
1691 len = strlcpy(op->pwd, Arg, sizeof(op->pwd));
1692 if (len >= sizeof(op->pwd))
1693 Config_Error_TooLong(Line, Var);
1696 if (strcasecmp(Var, "Mask") == 0) {
1698 return; /* Hostname already configured */
1699 op->mask = strdup_warn( Arg );
1703 Config_Error_Section(Line, Var, "Operator");
1707 * Handle variable in [Server] configuration section.
1709 * @param Line Line numer in configuration file.
1710 * @param Var Variable name.
1711 * @param Arg Variable argument.
1714 Handle_SERVER( int Line, char *Var, char *Arg )
1720 assert( Var != NULL );
1721 assert( Arg != NULL );
1723 /* Ignore server block if no space is left in server configuration structure */
1724 if( New_Server_Idx <= NONE ) return;
1726 if( strcasecmp( Var, "Host" ) == 0 ) {
1727 /* Hostname of the server */
1728 len = strlcpy( New_Server.host, Arg, sizeof( New_Server.host ));
1729 if (len >= sizeof( New_Server.host ))
1730 Config_Error_TooLong ( Line, Var );
1733 if( strcasecmp( Var, "Name" ) == 0 ) {
1734 /* Name of the server ("Nick"/"ID") */
1735 len = strlcpy( New_Server.name, Arg, sizeof( New_Server.name ));
1736 if (len >= sizeof( New_Server.name ))
1737 Config_Error_TooLong( Line, Var );
1740 if (strcasecmp(Var, "Bind") == 0) {
1741 if (ng_ipaddr_init(&New_Server.bind_addr, Arg, 0))
1744 Config_Error(LOG_ERR, "%s, line %d (section \"Server\"): Can't parse IP address \"%s\"",
1745 NGIRCd_ConfFile, Line, Arg);
1748 if( strcasecmp( Var, "MyPassword" ) == 0 ) {
1749 /* Password of this server which is sent to the peer */
1751 Config_Error(LOG_ERR,
1752 "%s, line %d (section \"Server\"): MyPassword must not start with ':'!",
1753 NGIRCd_ConfFile, Line);
1755 len = strlcpy( New_Server.pwd_in, Arg, sizeof( New_Server.pwd_in ));
1756 if (len >= sizeof( New_Server.pwd_in ))
1757 Config_Error_TooLong( Line, Var );
1760 if( strcasecmp( Var, "PeerPassword" ) == 0 ) {
1761 /* Passwort of the peer which must be received */
1762 len = strlcpy( New_Server.pwd_out, Arg, sizeof( New_Server.pwd_out ));
1763 if (len >= sizeof( New_Server.pwd_out ))
1764 Config_Error_TooLong( Line, Var );
1767 if( strcasecmp( Var, "Port" ) == 0 ) {
1768 /* Port to which this server should connect */
1770 if (port >= 0 && port < 0xFFFF)
1771 New_Server.port = (UINT16)port;
1773 Config_Error(LOG_ERR,
1774 "%s, line %d (section \"Server\"): Illegal port number %ld!",
1775 NGIRCd_ConfFile, Line, port );
1779 if( strcasecmp( Var, "SSLConnect" ) == 0 ) {
1780 New_Server.SSLConnect = Check_ArgIsTrue(Arg);
1784 if( strcasecmp( Var, "Group" ) == 0 ) {
1786 New_Server.group = atoi( Arg );
1787 if (!New_Server.group && strcmp(Arg, "0"))
1788 Config_Error_NaN(Line, Var);
1791 if( strcasecmp( Var, "Passive" ) == 0 ) {
1792 if (Check_ArgIsTrue(Arg))
1793 New_Server.flags |= CONF_SFLAG_DISABLED;
1796 if (strcasecmp(Var, "ServiceMask") == 0) {
1797 len = strlcpy(New_Server.svs_mask, ngt_LowerStr(Arg),
1798 sizeof(New_Server.svs_mask));
1799 if (len >= sizeof(New_Server.svs_mask))
1800 Config_Error_TooLong(Line, Var);
1804 Config_Error_Section(Line, Var, "Server");
1808 * Copy channel name into channel structure.
1810 * If the channel name is not valid because of a missing prefix ('#', '&'),
1811 * a default prefix of '#' will be added.
1813 * @param new_chan New already allocated channel structure.
1814 * @param name Name of the new channel.
1815 * @returns true on success, false otherwise.
1818 Handle_Channelname(struct Conf_Channel *new_chan, const char *name)
1820 size_t size = sizeof(new_chan->name);
1821 char *dest = new_chan->name;
1823 if (!Channel_IsValidName(name)) {
1825 * maybe user forgot to add a '#'.
1826 * This is only here for user convenience.
1832 return size > strlcpy(dest, name, size);
1836 * Handle variable in [Channel] configuration section.
1838 * @param Line Line numer in configuration file.
1839 * @param Var Variable name.
1840 * @param Arg Variable argument.
1843 Handle_CHANNEL(int Line, char *Var, char *Arg)
1846 struct Conf_Channel *chan;
1849 assert( Var != NULL );
1850 assert( Arg != NULL );
1852 chan = array_get(&Conf_Channels, sizeof(*chan),
1853 array_length(&Conf_Channels, sizeof(*chan)) - 1);
1857 if (strcasecmp(Var, "Name") == 0) {
1858 if (!Handle_Channelname(chan, Arg))
1859 Config_Error_TooLong(Line, Var);
1862 if (strcasecmp(Var, "Modes") == 0) {
1864 len = strlcpy(chan->modes, Arg, sizeof(chan->modes));
1865 if (len >= sizeof(chan->modes))
1866 Config_Error_TooLong( Line, Var );
1869 if( strcasecmp( Var, "Topic" ) == 0 ) {
1871 len = strlcpy(chan->topic, Arg, sizeof(chan->topic));
1872 if (len >= sizeof(chan->topic))
1873 Config_Error_TooLong( Line, Var );
1876 if( strcasecmp( Var, "Key" ) == 0 ) {
1877 /* Initial Channel Key (mode k) */
1878 len = strlcpy(chan->key, Arg, sizeof(chan->key));
1879 if (len >= sizeof(chan->key))
1880 Config_Error_TooLong(Line, Var);
1883 if( strcasecmp( Var, "MaxUsers" ) == 0 ) {
1884 /* maximum user limit, mode l */
1885 chan->maxusers = (unsigned long) atol(Arg);
1886 if (!chan->maxusers && strcmp(Arg, "0"))
1887 Config_Error_NaN(Line, Var);
1890 if (strcasecmp(Var, "KeyFile") == 0) {
1892 len = strlcpy(chan->keyfile, Arg, sizeof(chan->keyfile));
1893 if (len >= sizeof(chan->keyfile))
1894 Config_Error_TooLong(Line, Var);
1898 Config_Error_Section(Line, Var, "Channel");
1902 * Validate server configuration.
1904 * Please note that this function uses exit(1) on fatal errors and therefore
1905 * can result in ngIRCd terminating!
1907 * @param Configtest true if the daemon has been called with "--configtest".
1908 * @param Rehash true if re-reading configuration on runtime.
1909 * @returns true if configuration is valid.
1912 Validate_Config(bool Configtest, bool Rehash)
1914 /* Validate configuration settings. */
1917 int i, servers, servers_once;
1919 bool config_valid = true;
1922 /* Emit a warning when the config file is not a full path name */
1923 if (NGIRCd_ConfFile[0] && NGIRCd_ConfFile[0] != '/') {
1924 Config_Error(LOG_WARNING,
1925 "Not specifying a full path name to \"%s\" can cause problems when rehashing the server!",
1929 /* Validate configured server name, see RFC 2812 section 2.3.1 */
1930 ptr = Conf_ServerName;
1932 if (*ptr >= 'a' && *ptr <= 'z') continue;
1933 if (*ptr >= 'A' && *ptr <= 'Z') continue;
1934 if (*ptr >= '0' && *ptr <= '9') continue;
1935 if (ptr > Conf_ServerName) {
1936 if (*ptr == '.' || *ptr == '-')
1939 Conf_ServerName[0] = '\0';
1943 if (!Conf_ServerName[0]) {
1944 /* No server name configured! */
1945 config_valid = false;
1946 Config_Error(LOG_ALERT,
1947 "No (valid) server name configured in \"%s\" (section 'Global': 'Name')!",
1949 if (!Configtest && !Rehash) {
1950 Config_Error(LOG_ALERT,
1951 "%s exiting due to fatal errors!",
1957 if (Conf_ServerName[0] && !strchr(Conf_ServerName, '.')) {
1958 /* No dot in server name! */
1959 config_valid = false;
1960 Config_Error(LOG_ALERT,
1961 "Invalid server name configured in \"%s\" (section 'Global': 'Name'): Dot missing!",
1964 Config_Error(LOG_ALERT,
1965 "%s exiting due to fatal errors!",
1972 if (!Conf_ServerAdminMail[0]) {
1973 /* No administrative contact configured! */
1974 config_valid = false;
1975 Config_Error(LOG_ALERT,
1976 "No administrator email address configured in \"%s\" ('AdminEMail')!",
1979 Config_Error(LOG_ALERT,
1980 "%s exiting due to fatal errors!",
1987 if (!Conf_ServerAdmin1[0] && !Conf_ServerAdmin2[0]
1988 && !Conf_ServerAdminMail[0]) {
1989 /* No administrative information configured! */
1990 Config_Error(LOG_WARNING,
1991 "No administrative information configured but required by RFC!");
1995 if (Conf_ServerPwd[0])
1996 Config_Error(LOG_ERR,
1997 "This server uses PAM, \"Password\" in [Global] section will be ignored!");
2001 servers = servers_once = 0;
2002 for (i = 0; i < MAX_SERVERS; i++) {
2003 if (Conf_Server[i].name[0]) {
2005 if (Conf_Server[i].flags & CONF_SFLAG_ONCE)
2010 "Configuration: Operators=%ld, Servers=%d[%d], Channels=%ld",
2011 array_length(&Conf_Opers, sizeof(struct Conf_Oper)),
2012 servers, servers_once,
2013 array_length(&Conf_Channels, sizeof(struct Conf_Channel)));
2016 return config_valid;
2020 * Output "line too long" warning.
2022 * @param Line Line number in configuration file.
2023 * @param Item Affected variable name.
2026 Config_Error_TooLong ( const int Line, const char *Item )
2028 Config_Error( LOG_WARNING, "%s, line %d: Value of \"%s\" too long!", NGIRCd_ConfFile, Line, Item );
2032 * Output "unknown variable" warning.
2034 * @param Line Line number in configuration file.
2035 * @param Item Affected variable name.
2036 * @param Section Section name.
2039 Config_Error_Section(const int Line, const char *Item, const char *Section)
2041 Config_Error(LOG_ERR, "%s, line %d (section \"%s\"): Unknown variable \"%s\"!",
2042 NGIRCd_ConfFile, Line, Section, Item);
2046 * Output "not a number" warning.
2048 * @param Line Line number in configuration file.
2049 * @param Item Affected variable name.
2052 Config_Error_NaN( const int Line, const char *Item )
2054 Config_Error( LOG_WARNING, "%s, line %d: Value of \"%s\" is not a number!",
2055 NGIRCd_ConfFile, Line, Item );
2059 * Output configuration error to console and/or logfile.
2061 * On runtime, the normal log functions of the daemon are used. But when
2062 * testing the configuration ("--configtest"), all messages go directly
2065 * @param Level Severity level of the message.
2066 * @param Format Format string; see printf() function.
2069 static void Config_Error( const int Level, const char *Format, ... )
2071 static void Config_Error( Level, Format, va_alist )
2077 char msg[MAX_LOG_MSG_LEN];
2080 assert( Format != NULL );
2083 va_start( ap, Format );
2087 vsnprintf( msg, MAX_LOG_MSG_LEN, Format, ap );
2091 if (Level <= LOG_WARNING)
2092 printf(" - %s\n", msg);
2096 Log(Level, "%s", msg);
2102 * Dump internal state of the "configuration module".
2105 Conf_DebugDump(void)
2109 Log(LOG_DEBUG, "Configured servers:");
2110 for (i = 0; i < MAX_SERVERS; i++) {
2111 if (! Conf_Server[i].name[0])
2114 " - %s: %s:%d, last=%ld, group=%d, flags=%d, conn=%d",
2115 Conf_Server[i].name, Conf_Server[i].host,
2116 Conf_Server[i].port, Conf_Server[i].lasttry,
2117 Conf_Server[i].group, Conf_Server[i].flags,
2118 Conf_Server[i].conn_id);
2125 * Initialize server configuration structur to default values.
2127 * @param Server Pointer to server structure to initialize.
2130 Init_Server_Struct( CONF_SERVER *Server )
2132 assert( Server != NULL );
2134 memset( Server, 0, sizeof (CONF_SERVER) );
2136 Server->group = NONE;
2137 Server->lasttry = time( NULL ) - Conf_ConnectRetry + STARTUP_DELAY;
2139 if( NGIRCd_Passive ) Server->flags = CONF_SFLAG_DISABLED;
2141 Proc_InitStruct(&Server->res_stat);
2142 Server->conn_id = NONE;
2143 memset(&Server->bind_addr, 0, sizeof(Server->bind_addr));