]> arthur.barton.de Git - ngircd.git/commitdiff
Deduce a server name when not set in the configuration
authorAlexander Barton <alex@barton.de>
Sat, 20 Jan 2024 22:04:32 +0000 (23:04 +0100)
committerAlexander Barton <alex@barton.de>
Sun, 21 Jan 2024 00:20:46 +0000 (01:20 +0100)
The server "Name" in the "[Global]" section of the configuration file is
optional now: When not set (or empty), ngIRCd now tries to deduce a
valid IRC server name from the local host name ("node name"), possibly
adding a ".host" extension when the host name does not contain a dot
(".") which is required in an IRC server name ("ID").

This new behaviour, with all configuration parameters now being
optional, allows running ngIRCd without any configuration file at all.

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

index 9256ff41d7302c876a47aec0546d84750dea549f..bd82b1edcb573b995750f28c1ca29ab5944430af 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
 
 ngIRCd 27
 
-  - autogen.sh: Prefere automake 1.11 over other releases because this is the
+  - 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"),
+    possibly adding a ".host" extension when the host name does not contain a
+    dot (".") which is required in an IRC server name ("ID").
+    This new behaviour, with all configuration parameters now being optional,
+    allows running ngIRCd without any configuration file at all.
+  - autogen.sh: Prefer automake 1.11 over other releases because this is the
     last release supporting "de-ANSI-fication" using the included ansi2knr tool.
-    And becuase we _want_ to support old K&R platforms, we try hard to use this
+    And because we _want_ to support old K&R platforms, we try hard to use this
     release of automake when available to generate our build system.
     Note: This is only relevant for you if you are building from Git sources.
   - Autodetect support for IPv6 by default: Until now, IPv6 support was disabled
index cea23a2bd39508a60582478b256dc8dd700aa241..a5b61af7eadb9d22f8f803a837139e95d3291870 100644 (file)
@@ -24,8 +24,9 @@
        # make sure that they correspond to your installation and setup!
 
        # Server name in the IRC network, must contain at least one dot
-       # (".") and be unique in the IRC network. Required!
-       Name = irc.example.net
+       # (".") and be unique in the IRC network. When not set, ngIRCd tries
+       # to deduce a valid IRC server name from the local host name.
+       ;Name = irc.example.net
 
        # Information about the server and the administrator, used by the
        # ADMIN command. Not required by server but by RFC!
index 124a886d11ad1d404e009b0309466052a7f9dfd8..84a6baece9b3f4b3e5f6726dee11e4387207b866 100644 (file)
@@ -93,10 +93,11 @@ like the server name and the ports on which the server should be listening.
 These settings depend on your personal preferences, so you should make sure
 that they correspond to your installation and setup!
 .TP
-\fBName\fR (string; required)
+\fBName\fR (string)
 Server name in the IRC network. This is an individual name of the IRC
 server, it is not related to the DNS host name. It must be unique in the
-IRC network and must contain at least one dot (".") character.
+IRC network and must contain at least one dot (".") character. When not set,
+ngIRCd tries to deduce a valid IRC server name from the local host name.
 .TP
 \fBAdminInfo1\fR, \fBAdminInfo2\fR, \fBAdminEMail\fR (string)
 Information about the server and the administrator, used by the ADMIN
index 2480249fcbce875115e494655e072977c6c2f38d..ec3238373084c79140357e7cd5a646e408c362c3 100644 (file)
@@ -33,6 +33,7 @@
 #include <grp.h>
 #include <sys/types.h>
 #include <dirent.h>
+#include <netdb.h>
 
 #include "ngircd.h"
 #include "conn.h"
@@ -2053,6 +2054,7 @@ Validate_Config(bool Configtest, bool Rehash)
        /* Validate configuration settings. */
 
        int i, servers, servers_once;
+       struct hostent *h;
        bool config_valid = true;
        char *ptr;
 
@@ -2063,6 +2065,28 @@ Validate_Config(bool Configtest, bool Rehash)
                        NGIRCd_ConfFile);
        }
 
+       if (!Conf_ServerName[0]) {
+               /* No server name configured, try to get a sane name from the
+                * host name. Note: the IRC server name MUST contain
+                * at least one dot, so the "node name" is not sufficient! */
+               gethostname(Conf_ServerName, sizeof(Conf_ServerName));
+               if (Conf_DNS) {
+                       /* Try to get a proper host name ... */
+                       h = gethostbyname(Conf_ServerName);
+                       if (h)
+                               strlcpy(Conf_ServerName, h->h_name,
+                                       sizeof(Conf_ServerName));
+               }
+               if (!strchr(Conf_ServerName, '.')) {
+                       /* (Still) No dot in the name! */
+                       strlcat(Conf_ServerName, ".host",
+                               sizeof(Conf_ServerName));
+               }
+               Config_Error(LOG_WARNING,
+                            "No server name configured, using host name \"%s\".",
+                            Conf_ServerName);
+       }
+
        /* Validate configured server name, see RFC 2812 section 2.3.1 */
        ptr = Conf_ServerName;
        do {
@@ -2077,9 +2101,7 @@ Validate_Config(bool Configtest, bool Rehash)
                break;
        } while (*(++ptr));
 
-       if (!Conf_ServerName[0] || !strchr(Conf_ServerName, '.'))
-       {
-               /* No server name configured! */
+       if (!Conf_ServerName[0] || !strchr(Conf_ServerName, '.')) {
                config_valid = false;
                Config_Error(LOG_ALERT,
                             "No (valid) server name configured in \"%s\" (section 'Global': 'Name')!",