]> arthur.barton.de Git - ngircd-alex.git/commitdiff
Auto-generate server name when not set in any config file tmp/auto-server-name
authorAlexander Barton <alex@barton.de>
Sat, 14 Dec 2019 00:19:06 +0000 (01:19 +0100)
committerAlexander Barton <alex@barton.de>
Sat, 29 Aug 2020 20:36:57 +0000 (22:36 +0200)
Try to get a sane name from the host name when no server name is set in
the configuration file. This enables running ngIRCd without a config
file at all, which can be handy for conatiners, for example.

Note: the IRC server name MUST contain at least one dot, so the plain
"node name" is not sufficient!

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

index 5892557920f669985b413218e2f90de793ad66ad..83b7c5b2078720500a4f20bb99298e2692fbc44e 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 build 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 e4446f96c6ae26e0f53933a9e097f7a23c5daac3..79dcaaf0672925b6ce133a5ac2d963ea3bd40f95 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 build 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 1c5ba624d5dd93e732b511d204dca4e8f6196244..29270875444993f38c418a8bd06cb0884820e1a9 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"
@@ -2052,6 +2053,7 @@ Validate_Config(bool Configtest, bool Rehash)
 #ifdef DEBUG
        int i, servers, servers_once;
 #endif
+       struct hostent *h;
        bool config_valid = true;
        char *ptr;
 
@@ -2076,9 +2078,30 @@ Validate_Config(bool Configtest, bool Rehash)
                break;
        } while (*(++ptr));
 
-       if (!Conf_ServerName[0] || !strchr(Conf_ServerName, '.'))
-       {
-               /* No server name configured! */
+       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));
+               h = gethostbyname(Conf_ServerName);
+               if (h && strchr(h->h_name, '.')) {
+                       /* Now we have a valid name! */
+                       strlcpy(Conf_ServerName, h->h_name,
+                               sizeof(Conf_ServerName));
+                       Config_Error(LOG_WARNING,
+                                    "No server name configured, using host name \"%s\".",
+                                    Conf_ServerName);
+               } else {
+                       /* No or no valid name, no dot! Show error message and
+                        * reset the server name, so the regular error handler
+                        * below will be triggered ... */
+                       Config_Error(LOG_ALERT,
+                                    "Failed to get a valid server name from node name \"%s\"!",
+                                    Conf_ServerName);
+                       Conf_ServerName[0] = '\0';
+               }
+       }
+       if (!Conf_ServerName[0] || !strchr(Conf_ServerName, '.')) {
                config_valid = false;
                Config_Error(LOG_ALERT,
                             "No (valid) server name configured in \"%s\" (section 'Global': 'Name')!",