about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAlexander Barton <alex@barton.de>2024-01-20 23:04:32 +0100
committerAlexander Barton <alex@barton.de>2024-01-21 01:20:46 +0100
commit3c39094b52332dc2b79ee9ae640324e312b81777 (patch)
tree157e3490ba4bd6999256780c799de673ffefacda
parent669d71f3fe4c21f27c329690d74427879d8ee35a (diff)
downloadngircd-3c39094b52332dc2b79ee9ae640324e312b81777.tar.gz
ngircd-3c39094b52332dc2b79ee9ae640324e312b81777.zip
Deduce a server name when not set in the configuration
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.
-rw-r--r--ChangeLog11
-rw-r--r--doc/sample-ngircd.conf.tmpl5
-rw-r--r--man/ngircd.conf.5.tmpl5
-rw-r--r--src/ngircd/conf.c28
4 files changed, 40 insertions, 9 deletions
diff --git a/ChangeLog b/ChangeLog
index 9256ff41..bd82b1ed 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -10,9 +10,16 @@
 
 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
diff --git a/doc/sample-ngircd.conf.tmpl b/doc/sample-ngircd.conf.tmpl
index cea23a2b..a5b61af7 100644
--- a/doc/sample-ngircd.conf.tmpl
+++ b/doc/sample-ngircd.conf.tmpl
@@ -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!
diff --git a/man/ngircd.conf.5.tmpl b/man/ngircd.conf.5.tmpl
index 124a886d..84a6baec 100644
--- a/man/ngircd.conf.5.tmpl
+++ b/man/ngircd.conf.5.tmpl
@@ -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
diff --git a/src/ngircd/conf.c b/src/ngircd/conf.c
index 2480249f..ec323837 100644
--- a/src/ngircd/conf.c
+++ b/src/ngircd/conf.c
@@ -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')!",