From 3c39094b52332dc2b79ee9ae640324e312b81777 Mon Sep 17 00:00:00 2001 From: Alexander Barton Date: Sat, 20 Jan 2024 23:04:32 +0100 Subject: [PATCH] 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. --- ChangeLog | 11 +++++++++-- doc/sample-ngircd.conf.tmpl | 5 +++-- man/ngircd.conf.5.tmpl | 5 +++-- src/ngircd/conf.c | 28 +++++++++++++++++++++++++--- 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 #include #include +#include #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')!", -- 2.39.2