]> 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)
committerPieter Lexis <pieter.lexis@powerdns.com>
Thu, 23 Feb 2017 10:08:16 +0000 (11:08 +0100)
This ensures we cannot start up if the file is unreadable.
Closes #4939

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

index 900f7abd65da7996364906d89d0a8c85f8f46d91..1776ccf15e327ecbb0da2e825be5f7509d48daae 100644 (file)
@@ -2704,7 +2704,13 @@ int serviceMain(int argc, char*argv[])
 
   g_dnssecLogBogus = ::arg().mustDo("dnssec-log-bogus");
 
-  loadRecursorLuaConfig(::arg()["lua-config-file"], ::arg().mustDo("daemon"));
+  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 f06575bd57763c71517342dd6b5fa08884d647bf..d70dd4b2e3ed4a78237c9e6a454e8acaa6227ec2 100644 (file)
@@ -68,10 +68,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"