From: Aki Tuomi Date: Wed, 15 May 2013 15:34:12 +0000 (+0300) Subject: Changed from boost::filesystem to plain C X-Git-Tag: auth-3.3-rc1~39^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8a16d7785c02f239aa1b82be47715d49ea5f298a;p=thirdparty%2Fpdns.git Changed from boost::filesystem to plain C --- diff --git a/pdns/arguments.cc b/pdns/arguments.cc index 23467de5ba..40e176d9ff 100644 --- a/pdns/arguments.cc +++ b/pdns/arguments.cc @@ -18,10 +18,13 @@ #include "arguments.hh" #include #include -#include #include #include "namespaces.hh" #include "logger.hh" +#include +#include +#include +#include const ArgvMap::param_t::const_iterator ArgvMap::begin() { @@ -400,7 +403,7 @@ bool ArgvMap::file(const char *fname, bool lax, bool included) return false; } - if (!included) // inject include-dir + if (!parmIsset("include-dir")) // inject include-dir set("include-dir","Directory to include configuration files from"); string line; @@ -432,16 +435,42 @@ bool ArgvMap::file(const char *fname, bool lax, bool included) } // handle include here (avoid re-include) - if (!included && parmIsset("include-dir")) { + if (!included && !params["include-dir"].empty()) { // rerun parser for all files - boost::filesystem::path targetDir(params["include-dir"]); - if (!boost::filesystem::exists(targetDir)) { + 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!"); } - 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); + + // 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; + } } }