1
0
mirror of https://github.com/osmarks/ngircd.git synced 2025-01-05 21:30:29 +00:00

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.
This commit is contained in:
Alexander Barton 2024-01-20 23:04:32 +01:00
parent 669d71f3fe
commit 3c39094b52
4 changed files with 40 additions and 9 deletions

View File

@ -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

View 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!

View 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

View 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')!",