From: Aki Tuomi Date: Wed, 15 May 2013 14:05:01 +0000 (+0300) Subject: Support for include-dir directive X-Git-Tag: auth-3.3-rc1~39^2~4 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=4f6ef75fa951250e10bd056bd31acf6970b4fd9b;p=thirdparty%2Fpdns.git Support for include-dir directive --- diff --git a/pdns/arguments.cc b/pdns/arguments.cc index b9f2fece43..23467de5ba 100644 --- a/pdns/arguments.cc +++ b/pdns/arguments.cc @@ -17,7 +17,11 @@ */ #include "arguments.hh" #include +#include +#include +#include #include "namespaces.hh" +#include "logger.hh" const ArgvMap::param_t::const_iterator ArgvMap::begin() { @@ -384,14 +388,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 (!included) // inject include-dir + set("include-dir","Directory to include configuration files from"); + string line; string pline; string::size_type pos; @@ -420,5 +431,19 @@ bool ArgvMap::file(const char *fname, bool lax) line=""; } + // handle include here (avoid re-include) + if (!included && parmIsset("include-dir")) { + // rerun parser for all files + boost::filesystem::path targetDir(params["include-dir"]); + if (!boost::filesystem::exists(targetDir)) { + L << Logger::Error << params["include-dir"] << " does not exist!" << std::endl; + throw ArgException(params["include-dir"] + " does not exist!"); + } + boost::filesystem::directory_iterator bfd_it(targetDir), eod; + BOOST_FOREACH(boost::filesystem::path const &p, std::make_pair(bfd_it, eod)) { + if (boost::ends_with(p.native(),".conf") && is_regular_file(p)) file(p.c_str(), lax, true); + } + } + return true; } diff --git a/pdns/arguments.hh b/pdns/arguments.hh index 9f196a686a..865239337c 100644 --- a/pdns/arguments.hh +++ b/pdns/arguments.hh @@ -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);