]> granicus.if.org Git - pdns/commitdiff
Throw an error when lua-conf-file can't be loaded
authorPieter Lexis <pieter.lexis@powerdns.com>
Thu, 23 Feb 2017 10:08:16 +0000 (11:08 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 13 Nov 2017 14:47:34 +0000 (15:47 +0100)
This ensures we cannot start up if the file is unreadable.
Closes #4939

(cherry picked from commit 0f5785a6c441b043564f3ba26a39145aee74b1c2)

pdns/pdns_recursor.cc
pdns/rec-lua-conf.cc

index 4efc81e486900f28c492d55f906ba1527c27390b..3d86a0770b3d0249639d1eb11cc5d9f4575140d2 100644 (file)
@@ -2640,7 +2640,31 @@ int serviceMain(int argc, char*argv[])
     exit(99);
   }
 
-  loadRecursorLuaConfig(::arg()["lua-config-file"], ::arg().mustDo("daemon"));
+  // keep this ABOVE loadRecursorLuaConfig!
+  if(::arg()["dnssec"]=="off")
+    g_dnssecmode=DNSSECMode::Off;
+  else if(::arg()["dnssec"]=="process-no-validate")
+    g_dnssecmode=DNSSECMode::ProcessNoValidate;
+  else if(::arg()["dnssec"]=="process")
+    g_dnssecmode=DNSSECMode::Process;
+  else if(::arg()["dnssec"]=="validate")
+    g_dnssecmode=DNSSECMode::ValidateAll;
+  else if(::arg()["dnssec"]=="log-fail")
+    g_dnssecmode=DNSSECMode::ValidateForLog;
+  else {
+    L<<Logger::Error<<"Unknown DNSSEC mode "<<::arg()["dnssec"]<<endl;
+    exit(1);
+  }
+
+  g_dnssecLogBogus = ::arg().mustDo("dnssec-log-bogus");
+
+  try {
+    loadRecursorLuaConfig(::arg()["lua-config-file"], ::arg().mustDo("daemon"));
+  }
+  catch (PDNSException &e) {
+    L<<Logger::Error<<"Cannot load Lua configuration: "<<e.reason<<endl;
+    exit(1);
+  }
 
   parseACLs();
   sortPublicSuffixList();
index a97a61b38fe2a9fb30786e54779b9eb9cb4b8c34..4e84686483faf096b95509d3d7e609f5bdba0b21 100644 (file)
@@ -67,10 +67,9 @@ void loadRecursorLuaConfig(const std::string& fname, bool checkOnly)
   if(fname.empty())
     return;
   ifstream ifs(fname);
-  if(!ifs) {
-    theL()<<"Unable to read configuration file from '"<<fname<<"': "<<strerror(errno)<<endl;
-    return;
-  }
+  if(!ifs)
+    throw PDNSException("Cannot open file '"+fname+"': "+strerror(errno));
+
   Lua.writeFunction("clearSortlist", [&lci]() { lci.sortlist.clear(); });
   
   /* we can get: "1.2.3.4"