]> arthur.barton.de Git - ngircd.git/commitdiff
Use a default "IncludeDir" only when no config file was specified
authorAlexander Barton <alex@barton.de>
Sun, 21 Jan 2024 18:41:39 +0000 (19:41 +0100)
committerAlexander Barton <alex@barton.de>
Sun, 21 Jan 2024 19:15:47 +0000 (20:15 +0100)
No longer use a default built-in value for the "IncludeDir" directive
when a configuration file was explicitly specified on the command line
using "--config"/"-f": This way no default include directory is scanned
when a possibly non-default configuration file is used which
(intentionally) did not specify an "IncludeDir" directive.

With this patch you now can use "-f /dev/null" for checking all built-in
defaults, regardless of any local configuration files in the default
drop-in directory (which would have been read in until this change).

ChangeLog
doc/sample-ngircd.conf.tmpl
man/ngircd.conf.5.tmpl
src/ngircd/conf.c
src/ngircd/ngircd.c

index bd82b1edcb573b995750f28c1ca29ab5944430af..1472e98b0964e5849e45fceced2dcd09cde84abf 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
 
 ngIRCd 27
 
+  - No longer use a default built-in value for the "IncludeDir" directive when
+    a configuration file was explicitly specified on the command line using
+    "--config"/"-f": This way no default include directory is scanned when a
+    possibly non-default configuration file is used which (intentionally) did
+    not specify an "IncludeDir" directive. So now you can use "-f /dev/null"
+    for checking all built-in defaults, regardless of any local configuration
+    files in the default drop-in directory (which would have been read in
+    until this change).
   - The server "Name" in the "[Global]" section of the configuration file no
     longer needs to be set: When not set (or empty), ngIRCd now tries to
     deduce a valid IRC server name from the local host name ("node name"),
index 79360869dee175dcf12f10a7a61d9a47e80a1100..d59b139b17e7967f83d1247763775dd2a6030ba2 100644 (file)
@@ -35,7 +35,8 @@
        ;AdminEMail = admin@irc.server
 
        # Text file which contains the ngIRCd help text. This file is required
-       # to display help texts when using the "HELP <cmd>" command.
+       # to display help texts when using the "HELP <cmd>" command. Default: a
+       # built-in standard path (check "ngircd --configtest").
        ;HelpFile = :DOCDIR:/Commands.txt
 
        # Info text of the server. This will be shown by WHOIS and
@@ -50,7 +51,8 @@
        ;Listen = 127.0.0.1,192.168.0.1
 
        # Text file with the "message of the day" (MOTD). This message will
-       # be shown to all users connecting to the server:
+       # be shown to all users connecting to the server: Default: a built-in
+       # standard path (check "ngircd --configtest").
        ;MotdFile = :ETCDIR:/ngircd.motd
 
        # A simple Phrase (<127 chars) if you don't want to use a motd file.
 
        # Directory containing configuration snippets (*.conf), that should
        # be read in after parsing this configuration file.
+       # Default: a built-in directory name when no configuration file was
+       # explicitly given on the command line (check "ngircd --configtest"),
+       # none (empty) otherwise.
        ;IncludeDir = :ETCDIR:/conf.d
 
        # Enhance user privacy slightly (useful for IRC server on TOR or I2P)
index 01e5408e610535fa8b83ddf8bec3243e89e474f5..9d37e5fad1efd5d35d433fd97c21640feb3a90d4 100644 (file)
@@ -107,7 +107,8 @@ command. This information is not required by the server but by RFC!
 Text file which contains the ngIRCd help text. This file is required
 to display help texts when using the "HELP <cmd>" command.
 Please note: Changes made to this file take effect when ngircd starts up
-or is instructed to re-read its configuration file.
+or is instructed to re-read its configuration file. Default: a built-in
+standard path.
 .TP
 \fBInfo\fR (string)
 Info text of the server. This will be shown by WHOIS and LINKS requests for
@@ -123,7 +124,7 @@ IP addresses and interfaces by default.
 Text file with the "message of the day" (MOTD). This message will be shown to
 all users connecting to the server. Please note: Changes made to this file
 take effect when ngircd starts up or is instructed to re-read its
-configuration file.
+configuration file. Default: a built-in standard path.
 .TP
 \fBMotdPhrase\fR (string)
 A simple Phrase (<127 chars) if you don't want to use a MOTD file.
@@ -294,7 +295,17 @@ Default: yes.
 \fBIncludeDir\fR (string)
 Directory containing configuration snippets (*.conf), that should be read in
 after parsing the current configuration file.
-Default: none.
+Default: a built-in directory name when no configuration file was explicitly
+given on the command line (check "ngircd --configtest"), none (empty)
+otherwise.
+.PP
+.RS
+This way no default include directory is used when a possibly non-default
+configuration file was explicitly specified using "--config"/"-f" on the
+command line which (intentionally) did not specify an
+.I "IncludeDir"
+directive.
+.RE
 .TP
 \fBMorePrivacy\fR (boolean)
 This will cause ngIRCd to censor user idle time, logon time as well as the
index ec3238373084c79140357e7cd5a646e408c362c3..eaa5e932494a0697e9b7bcfe9ca713f09153a85e 100644 (file)
@@ -903,26 +903,44 @@ Read_Config(bool TestOnly, bool IsStarting)
        struct dirent *entry;
        int i, n;
        FILE *fd;
-       DIR *dh;
+       DIR *dh = NULL;
+
+       if (!NGIRCd_ConfFile[0]) {
+               /* No configuration file name explicitly given on the command
+                * line, use defaults but ignore errors when this file can't be
+                * read later on. */
+               strlcpy(file, SYSCONFDIR, sizeof(file));
+               strlcat(file, CONFIG_FILE, sizeof(file));
+               ptr = file;
+       } else
+               ptr = NGIRCd_ConfFile;
 
-       Config_Error(LOG_INFO, "Using configuration file \"%s\" ...", NGIRCd_ConfFile);
+       Config_Error(LOG_INFO, "Using %s configuration file \"%s\" ...",
+                    !NGIRCd_ConfFile[0] ? "default" : "specified", ptr);
 
        /* Open configuration file */
-       fd = fopen( NGIRCd_ConfFile, "r" );
-       if( ! fd ) {
-               /* No configuration file found! */
-               Config_Error( LOG_ALERT, "Can't read configuration \"%s\": %s",
-                                       NGIRCd_ConfFile, strerror( errno ));
-               if (!IsStarting)
-                       return false;
-               Config_Error( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME );
-               exit( 1 );
+       fd = fopen(ptr, "r");
+       if (!fd) {
+               if (NGIRCd_ConfFile[0]) {
+                       Config_Error(LOG_ALERT,
+                                    "Can't read specified configuration file \"%s\": %s",
+                                    ptr, strerror(errno));
+                       if (IsStarting) {
+                               Config_Error(LOG_ALERT,
+                                            "%s exiting due to fatal errors!",
+                                            PACKAGE_NAME);
+                               exit(1);
+                       }
+               }
+               Config_Error(LOG_WARNING,
+                            "Can't read default configuration file \"%s\": %s - Ignored.",
+                            ptr, strerror(errno));
        }
 
        opers_free();
        Set_Defaults(IsStarting);
 
-       if (TestOnly)
+       if (TestOnly && fd)
                Config_Error(LOG_INFO,
                             "Reading configuration from \"%s\" ...",
                             NGIRCd_ConfFile );
@@ -962,16 +980,23 @@ Read_Config(bool TestOnly, bool IsStarting)
        ConfSSL_Init();
 #endif
 
-       Read_Config_File(NGIRCd_ConfFile, fd);
-       fclose(fd);
+       if (fd) {
+               Read_Config_File(NGIRCd_ConfFile, fd);
+               fclose(fd);
+       }
 
        if (Conf_IncludeDir[0]) {
+               /* Include directory was set in the main configuration file. So
+                * use it and show errors. */
                dh = opendir(Conf_IncludeDir);
                if (!dh)
                        Config_Error(LOG_ALERT,
                                     "Can't open include directory \"%s\": %s",
                                     Conf_IncludeDir, strerror(errno));
-       } else {
+       } else if (!NGIRCd_ConfFile[0]) {
+               /* No include dir set in the configuration file used (if any)
+                * but no config file explicitly specified either: so use the
+                * default include path here as well! */
                strlcpy(Conf_IncludeDir, SYSCONFDIR, sizeof(Conf_IncludeDir));
                strlcat(Conf_IncludeDir, CONFIG_DIR, sizeof(Conf_IncludeDir));
                dh = opendir(Conf_IncludeDir);
index 04462a6d1fa8b15b77c9768230b74eeb039824bb..b06103929e44e33e6dc28eb7d8dd68519bdc8ffb 100644 (file)
@@ -92,8 +92,6 @@ main(int argc, const char *argv[])
 #ifdef SNIFFER
        NGIRCd_Sniffer = false;
 #endif
-       strlcpy(NGIRCd_ConfFile, SYSCONFDIR, sizeof(NGIRCd_ConfFile));
-       strlcat(NGIRCd_ConfFile, CONFIG_FILE, sizeof(NGIRCd_ConfFile));
 
        Fill_Version();