1
0
mirror of https://github.com/osmarks/ngircd.git synced 2024-10-28 04:46:17 +00:00

IncludeDir: default to "$SYSCONFDIR/ngircd.conf.d"

Now "IncludeDir" defaults to "$SYSCONFDIR/ngircd.conf.d" instead
of no directory, but a missing directory is only reported as an
error if it has explicitely configured in the main configuration
file and simply ignored otherwise.

Therefore it is now possible not to touch the default (sample)
configuration file at all, and set all distribution and/or system
specific configuration options in "*.conf" files stored in
"$SYSCONFDIF/ngircd.conf.d/".

Thanks to "Elmasloco" for the idea!
This commit is contained in:
Alexander Barton 2013-05-25 00:25:38 +02:00
parent 891dbd2acc
commit 7ea3864a93
4 changed files with 35 additions and 24 deletions

View File

@ -947,33 +947,39 @@ Read_Config(bool TestOnly, bool IsStarting)
fclose(fd); fclose(fd);
if (Conf_IncludeDir[0]) { if (Conf_IncludeDir[0]) {
/* Include further configuration files, if any */
dh = opendir(Conf_IncludeDir); dh = opendir(Conf_IncludeDir);
if (dh) { if (!dh)
while ((entry = readdir(dh)) != NULL) {
ptr = strrchr(entry->d_name, '.');
if (!ptr || strcasecmp(ptr, ".conf") != 0)
continue;
snprintf(file, sizeof(file), "%s/%s",
Conf_IncludeDir, entry->d_name);
if (TestOnly)
Config_Error(LOG_INFO,
"Reading configuration from \"%s\" ...",
file);
fd = fopen(file, "r");
if (fd) {
Read_Config_File(file, fd);
fclose(fd);
} else
Config_Error(LOG_ALERT,
"Can't read configuration \"%s\": %s",
file, strerror(errno));
}
closedir(dh);
} else
Config_Error(LOG_ALERT, Config_Error(LOG_ALERT,
"Can't open include directory \"%s\": %s", "Can't open include directory \"%s\": %s",
Conf_IncludeDir, strerror(errno)); Conf_IncludeDir, strerror(errno));
} else {
strlcpy(Conf_IncludeDir, SYSCONFDIR, sizeof(Conf_IncludeDir));
strlcat(Conf_IncludeDir, CONFIG_DIR, sizeof(Conf_IncludeDir));
dh = opendir(Conf_IncludeDir);
}
/* Include further configuration files, if IncludeDir is available */
if (dh) {
while ((entry = readdir(dh)) != NULL) {
ptr = strrchr(entry->d_name, '.');
if (!ptr || strcasecmp(ptr, ".conf") != 0)
continue;
snprintf(file, sizeof(file), "%s/%s",
Conf_IncludeDir, entry->d_name);
if (TestOnly)
Config_Error(LOG_INFO,
"Reading configuration from \"%s\" ...",
file);
fd = fopen(file, "r");
if (fd) {
Read_Config_File(file, fd);
fclose(fd);
} else
Config_Error(LOG_ALERT,
"Can't read configuration \"%s\": %s",
file, strerror(errno));
}
closedir(dh);
} }
/* Check if there is still a server to add */ /* Check if there is still a server to add */

View File

@ -1,6 +1,6 @@
/* /*
* ngIRCd -- The Next Generation IRC Daemon * ngIRCd -- The Next Generation IRC Daemon
* Copyright (c)2001-2012 Alexander Barton (alex@barton.de) and Contributors. * Copyright (c)2001-2013 Alexander Barton (alex@barton.de) and Contributors.
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -73,6 +73,9 @@
/** Configuration file name. */ /** Configuration file name. */
#define CONFIG_FILE "/ngircd.conf" #define CONFIG_FILE "/ngircd.conf"
/** Directory containing optional configuration snippets. */
#define CONFIG_DIR "/ngircd.conf.d"
/** Name of the MOTD file. */ /** Name of the MOTD file. */
#define MOTD_FILE "/ngircd.motd" #define MOTD_FILE "/ngircd.motd"

View File

@ -16,6 +16,7 @@
[Options] [Options]
OperCanUseMode = yes OperCanUseMode = yes
Ident = no Ident = no
IncludeDir = /var/empty
PAM = no PAM = no
[Operator] [Operator]

View File

@ -16,6 +16,7 @@
[Options] [Options]
OperCanUseMode = yes OperCanUseMode = yes
Ident = no Ident = no
IncludeDir = /var/empty
PAM = no PAM = no
[Operator] [Operator]