]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
rec: Implement rec_control hash-password
authorRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 30 Mar 2021 15:57:33 +0000 (17:57 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 16 Sep 2021 12:12:27 +0000 (14:12 +0200)
pdns/rec_control.cc
pdns/recursordist/docs/manpages/rec_control.1.rst

index 9d705b85803fbeea02cb3e4ef3b69920c1b99460..77bdfe789c8865069aaffbdcb3416d295994300f 100644 (file)
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
-#include "rec_channel.hh"
+
 #include <iostream>
 #include <fcntl.h>
+
 #include "pdnsexception.hh"
 #include "arguments.hh"
-
+#include "credentials.hh"
 #include "namespaces.hh"
+#include "rec_channel.hh"
 
 ArgvMap &arg()
 {
@@ -95,7 +97,6 @@ int main(int argc, char** argv)
   };
   try {
     initArguments(argc, argv);
-    RecursorControlChannel rccS;
     string sockname="pdns_recursor";
 
     if (arg()["config-name"] != "")
@@ -106,10 +107,9 @@ int main(int argc, char** argv)
 
     sockname.append(".controlsocket");
 
-    rccS.connect(arg()["socket-dir"], sockname);
-
     const vector<string>&commands=arg().getCommands();
     string command;
+    string password;
     int fd = -1;
     unsigned int i = 0;
     while (i < commands.size()) {
@@ -142,10 +142,26 @@ int main(int argc, char** argv)
           throw PDNSException("Command needs a file argument");
         }
       }
+      else if (commands.at(i) == "hash-password") {
+        if (commands.size() > (i + 1)) {
+          ++i;
+          password = commands.at(i);
+        }
+        else {
+          throw PDNSException("Command needs a password argument");
+        }
+      }
       ++i;
     }
 
+    if (!password.empty()) {
+      cout << hashPassword(password) << endl;
+      return 0;
+    }
+
     auto timeout = arg().asNum("timeout");
+    RecursorControlChannel rccS;
+    rccS.connect(arg()["socket-dir"], sockname);
     rccS.send({0, command}, nullptr, timeout, fd);
 
     auto receive = rccS.recv(0, timeout);
index 42c1607498b27aa9b764d8768fbfe76ffc2c8c08..f690b6650c47ef4f869ad684f222244d600e9a5c 100644 (file)
@@ -152,6 +152,11 @@ get-parameter *KEY* [*KEY*]...
 get-qtypelist
     Retrieves QType statistics. Queries from cache aren't being counted yet.
 
+hash-password
+    Hash and salt the given password, to use as a webserver password or
+    API key. This command does not contact the recursor but does the
+    hashing inside rec_control.
+
 help
     Shows a list of supported commands understood by the running
     :program:`pdns_recursor`