]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
AlLow - for stdout, does need a tweak in the argument parser...
authorOtto <otto.moerbeek@open-xchange.com>
Mon, 15 Feb 2021 10:42:10 +0000 (11:42 +0100)
committerOtto <otto.moerbeek@open-xchange.com>
Mon, 15 Feb 2021 10:42:10 +0000 (11:42 +0100)
pdns/arguments.cc
pdns/rec_channel_rec.cc
pdns/rec_control.cc

index 4a8c69b03b156a8a8e0e9fc7e373ff43ed07ffc7..aa21f6ded6cb9beb96efca93a8c84fb67b5a182a 100644 (file)
@@ -347,7 +347,7 @@ void ArgvMap::parseOne(const string &arg, const string &parseOnly, bool lax)
     var=arg.substr(2);
     val="";
   }
-  else if(arg[0]=='-')
+  else if(arg[0]=='-' && arg.length() > 1)
   {
     var=arg.substr(1);
     val="";
index bb6ffb307eb3c0c32cdcd9bf7e7f969716ed75b4..1b7540bcf6c7ce17a4b53134f2e79636d8054a1e 100644 (file)
@@ -303,6 +303,7 @@ static uint64_t* pleaseDumpFailedServers(int fd)
   return new uint64_t(SyncRes::doDumpFailedServers(fd));
 }
 
+// Generic dump to file command
 static RecursorControlChannel::Answer doDumpToFile(int s, uint64_t* (*function)(int s), const string& name)
 {
   int fd = getfd(s);
@@ -323,13 +324,14 @@ static RecursorControlChannel::Answer doDumpToFile(int s, uint64_t* (*function)(
   catch(PDNSException& e)
   {
     close(fd);
-    return { 1, name + ": error dumping NS speeds: " + e.reason + "\n" };
+    return { 1, name + ": error dumping data: " + e.reason + "\n" };
   }
 
   close(fd);
-  return { 0, name+ ": dumped " + std::to_string(total)+" records\n" };
+  return { 0, name + ": dumped " + std::to_string(total) + " records\n" };
 }
 
+// Does not follow the generic dump to file pattern, has a more complex lambda
 static RecursorControlChannel::Answer doDumpCache(int s)
 {
   int fd = getfd(s);
@@ -347,6 +349,7 @@ static RecursorControlChannel::Answer doDumpCache(int s)
   return { 0, "dumped " + std::to_string(total) + " records\n" };
 }
 
+// Does not follow the generic dump to file pattern, has an argument
 template<typename T>
 static RecursorControlChannel::Answer doDumpRPZ(int s, T begin, T end)
 {
index 701e8824b6f2ba4204fa4455b7f3e4aef8506d3d..942058abf15b662cebf2872d6623a0c39f855d79 100644 (file)
@@ -116,21 +116,29 @@ int main(int argc, char** argv)
         command += " ";
       }
       command += commands[i];
-      if (fileCommands.count(commands[i]) > 0 && i+1 < commands.size()) {
-        // dump-rpz is different, it also has a zonename as argument
-        if (commands[i] == "dump-rpz" && i+2 < commands.size()) {
+      if (fileCommands.count(commands[i]) > 0) {
+        if (i + 1 < commands.size()) {
+          // dump-rpz is different, it also has a zonename as argument
+          if (commands[i] == "dump-rpz") {
+            if (i + 2 < commands.size()) {
+              ++i;
+              command += " " + commands[i]; // add rpzname and continue with filename
+            } else {
+              throw PDNSException("Command needs a zone and file argument");
+            }
+          }
           ++i;
-          command += " " + commands[i]; // add rpzname and continue with filename
-        }
-        ++i;
-        if (commands[i] == "stdout") {
-          fd = STDOUT_FILENO;
+          if (commands[i] == "-") {
+            fd = STDOUT_FILENO;
+          } else {
+            fd = open(commands[i].c_str(), O_CREAT | O_EXCL | O_WRONLY, 0660);
+          }
+          if (fd == -1) {
+            int err = errno;
+            throw PDNSException("Error opening dump file for writing: " + stringerror(err));
+          }
         } else {
-          fd = open(commands[i].c_str(), O_CREAT | O_EXCL | O_WRONLY, 0660);
-        }
-        if (fd == -1) {
-          int err = errno;
-          throw PDNSException("Error opening dump file for writing: " + stringerror(err));
+          throw PDNSException("Command needs a file argument");
         }
       }
       ++i;