Permalink
Browse files

Merge pull request #812 from cmouse/config-include-support

Config include support
  • Loading branch information...
2 parents 27f1edc + 140617b commit 7796a3b5e7c7ae970b6902c9591853a92859e28c @Habbie Habbie committed May 17, 2013
Showing with 62 additions and 7 deletions.
  1. +0 −1 configure.ac
  2. +1 −2 pdns/Makefile.am
  3. +55 −1 pdns/arguments.cc
  4. +1 −0 pdns/arguments.hh
  5. +3 −3 pdns/backends/bind/Makefile.am
  6. +2 −0 pdns/common_startup.cc
View
@@ -28,7 +28,6 @@ AM_CONDITIONAL([RELEASE_BUILD], [test "$PACKAGE_VERSION" != "git"])
BOOST_REQUIRE([1.34])
BOOST_FOREACH
-#BOOST_FILESYSTEM([mt])
BOOST_PROGRAM_OPTIONS([mt])
BOOST_SERIALIZATION([mt])
AC_ARG_ENABLE(unit-tests, AC_HELP_STRING([--enable-unit-tests],[enable unit test building]), [enable_unit_tests=yes],[enable_unit_tests=no])
View
@@ -5,7 +5,6 @@ AM_CXXFLAGS=-DSYSCONFDIR=\"@sysconfdir@\" -DLIBDIR=\"@libdir@\" -DLOCALSTATEDIR=
endif
AM_CPPFLAGS=-Ibackends/bind $(BOOST_CPPFLAGS) @THREADFLAGS@ $(LIBCURL_CFLAGS)
-
if BOTAN110
AM_CPPFLAGS += $(BOTAN110_CFLAGS)
endif
@@ -112,7 +111,7 @@ pdnssec_SOURCES=pdnssec.cc dbdnsseckeeper.cc sstuff.hh dnsparser.cc dnsparser.hh
aes/aestab.c aes/aestab.h aes/brg_endian.h aes/brg_types.h aes/dns_random.cc json.cc
-pdnssec_LDFLAGS=@moduleobjects@ @modulelibs@ @DYNLINKFLAGS@ @LIBDL@ @THREADFLAGS@ $(BOOST_PROGRAM_OPTIONS_LDFLAGS) $(BOOST_SERIALIZATION_LDFLAGS)
+pdnssec_LDFLAGS=@moduleobjects@ @modulelibs@ @DYNLINKFLAGS@ @LIBDL@ @THREADFLAGS@ $(BOOST_PROGRAM_OPTIONS_LDFLAGS) $(BOOST_SERIALIZATION_LDFLAGS)
pdnssec_LDADD= ext/polarssl-1.1.2/library/libpolarssl.a $(BOOST_PROGRAM_OPTIONS_LIBS) $(BOOST_SERIALIZATION_LIBS) $(SQLITE3_LIBS) $(LIBCURL_LIBS) $(MYSQL_lib)
if BOTAN110
View
@@ -17,7 +17,14 @@
*/
#include "arguments.hh"
#include <boost/algorithm/string.hpp>
+#include <boost/algorithm/string/predicate.hpp>
+#include <boost/foreach.hpp>
#include "namespaces.hh"
+#include "logger.hh"
+#include <sys/types.h>
+#include <dirent.h>
+#include <sys/stat.h>
+#include <unistd.h>
const ArgvMap::param_t::const_iterator ArgvMap::begin()
{
@@ -384,14 +391,21 @@ bool ArgvMap::preParseFile(const char *fname, const string &arg, const string& t
return true;
}
-
bool ArgvMap::file(const char *fname, bool lax)
{
+ return file(fname,lax,false);
+}
+
+bool ArgvMap::file(const char *fname, bool lax, bool included)
+{
ifstream f(fname);
if(!f) {
return false;
}
+ if (!parmIsset("include-dir")) // inject include-dir
+ set("include-dir","Directory to include configuration files from");
+
string line;
string pline;
string::size_type pos;
@@ -420,5 +434,45 @@ bool ArgvMap::file(const char *fname, bool lax)
line="";
}
+ // handle include here (avoid re-include)
+ if (!included && !params["include-dir"].empty()) {
+ // rerun parser for all files
+ struct stat st;
+ DIR *dir;
+ struct dirent *ent;
+ char namebuf[PATH_MAX] = {0};
+
+ // stat
+ if (stat(params["include-dir"].c_str(), &st)) {
+ L << Logger::Error << params["include-dir"] << " does not exist!" << std::endl;
+ throw ArgException(params["include-dir"] + " does not exist!");
+ }
+
+ // wonder if it's accessible directory
+ if (!S_ISDIR(st.st_mode)) {
+ L << Logger::Error << params["include-dir"] << " is not a directory" << std::endl;
+ throw ArgException(params["include-dir"] + " is not a directory");
+ }
+
+ if (!(dir = opendir(params["include-dir"].c_str()))) {
+ L << Logger::Error << params["include-dir"] << " is not accessible" << std::endl;
+ throw ArgException(params["include-dir"] + " is not accessible");
+ }
+
+ while((ent = readdir(dir)) != NULL) {
+ if (ent->d_name[0] == '.') continue; // skip any dots
+ if (boost::ends_with(ent->d_name, ".conf")) {
+ // ensure it's readable file
+ snprintf(namebuf, sizeof namebuf, "%s/%s", params["include-dir"].c_str(), ent->d_name);
+ if (stat(namebuf, &st) || !S_ISREG(st.st_mode)) {
+ L << Logger::Error << namebuf << " is not a file" << std::endl;
+ throw ArgException(std::string(namebuf) + " does not exist!");
+ }
+ if (!file(namebuf, lax, true))
+ L << Logger::Warning << namebuf << " could not be read - skipping" << std::endl;
+ }
+ }
+ }
+
return true;
}
View
@@ -85,6 +85,7 @@ public:
bool preParseFile(const char *fname, const string &arg, const string& theDefault=""); //!< use this to preparse a single var in configuration
bool file(const char *fname, bool lax=false); //!< Parses a file with parameters
+ bool file(const char *fname, bool lax, bool included);
bool laxFile(const char *fname)
{
return file(fname,true);
@@ -42,14 +42,14 @@ zone2ldap_SOURCES=bindparser.yy bindlexer.l bind-dnssec.schema.sqlite3.sql.h \
../../aes/aescpp.h ../../aes/aescrypt.c ../../aes/aes.h ../../aes/aeskey.c ../../aes/aes_modes.c ../../aes/aesopt.h \
../../aes/aestab.c ../../aes/aestab.h ../../aes/brg_endian.h ../../aes/brg_types.h # ../../dbdnsseckeeper.cc
-zone2ldap_LDFLAGS=@THREADFLAGS@
+zone2ldap_LDFLAGS=@THREADFLAGS@
if HAVE_LIBPOLARSSL
zone2ldap_LDADD=
else
zone2ldap_LDADD= ../../ext/polarssl-1.1.2/library/libpolarssl.a
endif
-zone2sql_LDFLAGS=@THREADFLAGS@
+zone2sql_LDFLAGS=@THREADFLAGS@
if HAVE_LIBPOLARSSL
zone2sql_LDADD=
else
@@ -70,4 +70,4 @@ dnslabeltext.cc: ../../dnslabeltext.rl
ragel ../../dnslabeltext.rl -o dnslabeltext.cc
.hh.h:
- cp $< $@
+ cp $< $@
@@ -142,6 +142,8 @@ void declareArguments()
::arg().set("default-ksk-size","Default KSK size (0 means default)")="0";
::arg().set("default-zsk-algorithms","Default ZSK algorithms")="rsasha256";
::arg().set("default-zsk-size","Default KSK size (0 means default)")="0";
+
+ ::arg().set("include-dir","Include *.conf files from this directory");
}
void declareStats(void)

0 comments on commit 7796a3b

Please sign in to comment.