Index: b/pdns/arguments.cc
===================================================================
--- a/pdns/arguments.cc
+++ b/pdns/arguments.cc
@@ -312,9 +312,12 @@
if(pos && pos!=string::npos)
val=val.substr(pos);
- if(parmIsset(var))
+ if(parmIsset(var)) {
params[var]=val;
- else
+ if (var == "include") { // include directory
+ preParseDir(val, arg, lax);
+ }
+ } else
if(!lax)
throw ArgException("Trying to set unexisting parameter '"+var+"'");
}
@@ -341,6 +344,31 @@
}
}
+bool ArgvMap::preParseDir(const string dir, const string &arg, bool lax)
+{
+ DIR *dir_p;
+ string filename;
+ struct dirent *dir_entry_p;
+
+ if (dir_p = opendir(dir.c_str())) {
+ while((dir_entry_p = readdir(dir_p)))
+ {
+ if (strcmp(dir_entry_p->d_name, ".") == 0 ||
+ strcmp(dir_entry_p->d_name, "..") == 0)
+ continue;
+
+ filename = dir + "/" + dir_entry_p->d_name;
+ file(filename.c_str(), lax);
+ }
+ closedir(dir_p);
+ } else {
+ // Could be a file.
+ file(dir.c_str(), lax);
+ }
+
+ return true;
+}
+
bool ArgvMap::preParseFile(const char *fname, const string &arg)
{
params[arg].clear();
Index: b/pdns/arguments.hh
===================================================================
--- a/pdns/arguments.hh
+++ b/pdns/arguments.hh
@@ -24,6 +24,7 @@
#include <vector>
#include <fstream>
#include <iostream>
+#include <dirent.h>
#include "misc.hh"
#include "ahuexception.hh"
#ifndef WIN32
@@ -83,6 +84,7 @@
}
void preParse(int &argc, char **argv, const string &arg); //!< use this to preparse a single var
bool preParseFile(const char *fname, const string &arg); //!< use this to preparse a single var in configuration
+ bool preParseDir(const string dir, const string &arg, bool lax); //!< use this to include a directory
bool file(const char *fname, bool lax=false); //!< Parses a file with parameters
bool laxFile(const char *fname)
Index: b/pdns/common_startup.cc
===================================================================
--- a/pdns/common_startup.cc
+++ b/pdns/common_startup.cc
@@ -61,6 +61,7 @@
::arg().set("fancy-records","Process URL and MBOXFW records")="no";
::arg().set("wildcard-url","Process URL and MBOXFW records")="no";
::arg().set("wildcards","Honor wildcards in the database")="";
+ ::arg().set("include", "Directory with config files to include")="/etc/powerdns/pdns.d"; // Add directory with config files
::arg().set("loglevel","Amount of logging. Higher is more. Do not set below 3")="4";
::arg().set("default-soa-name","name to insert in the SOA record if none set in the backend")="a.misconfigured.powerdns.server";
::arg().set("distributor-threads","Default number of Distributor (backend) threads to start")="3";
Index: b/pdns/docs/pdns.sgml
===================================================================
--- a/pdns/docs/pdns.sgml
+++ b/pdns/docs/pdns.sgml
@@ -9549,6 +9549,10 @@
<listitem><para>
Provide a helpful message
</para></listitem></varlistentry>
+ <varlistentry><term>include</term>
+ <listitem><para>
+ Include a directory with configuration files. This adds support for pdns.d or config.d constructions.
+ </para></listitem></varlistentry>
<varlistentry><term>launch=...</term>
<listitem><para>
Which backends to launch and order to query them in. See <xref linkend="modules">.