diff options
| author | Alexander Barton <alex@barton.de> | 2024-01-20 23:04:32 +0100 |
|---|---|---|
| committer | Alexander Barton <alex@barton.de> | 2024-01-21 01:20:46 +0100 |
| commit | 3c39094b52332dc2b79ee9ae640324e312b81777 (patch) | |
| tree | 157e3490ba4bd6999256780c799de673ffefacda /src | |
| parent | 669d71f3fe4c21f27c329690d74427879d8ee35a (diff) | |
| download | ngircd-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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ngircd/conf.c | 28 |
1 files changed, 25 insertions, 3 deletions
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')!", |