]> granicus.if.org Git - pdns/commitdiff
implement backend-cmd in pdnssec and gsqlbackend
authorPeter van Dijk <peter.van.dijk@netherlabs.nl>
Sun, 28 Jun 2015 18:29:39 +0000 (20:29 +0200)
committermind04 <mind04@monshouwer.org>
Wed, 8 Jul 2015 19:28:25 +0000 (21:28 +0200)
docs/manpages/pdnssec.1.md
docs/markdown/authoritative/dnssec.md
pdns/backends/gsql/gsqlbackend.cc
pdns/backends/gsql/gsqlbackend.hh
pdns/dnsbackend.hh
pdns/namespaces.hh
pdns/pdnssec.cc

index 414033fe02c084494c06b9d29d871938e4761d3d..6569eb83a56e0e9e8a8eebb946efbe7181f33c49 100644 (file)
@@ -192,5 +192,11 @@ test-schema *ZONE*
 unset-presigned *ZONE*
 :    Disables presigned operation for *ZONE*.
 
+## DEBUGGING TOOLS
+
+backend-cmd *BACKEND* *CMD* [*CMD..*]
+:    Send a text command to a backend for execution. GSQL backends will take SQL
+     commands, other backends may take different things. Be careful!
+
 # SEE ALSO
 pdns_server (1), pdns_control (1)
index cffa434cd0d0e6bb74ab8ddda2973deede39814c..39d610188a0e4eaa79adea604cec87236a5feb98 100644 (file)
@@ -208,6 +208,7 @@ The following pdnssec commands are available:
 
 * `activate-zone-key ZONE KEY-ID`: Activate a key with id KEY-ID within a zone called ZONE.
 * `add-zone-key ZONE [ksk|zsk] [bits] [rsasha1|rsasha256|rsasha512|gost|ecdsa256|ecdsa384]`: Create a new key for zone ZONE, and make it a KSK or a ZSK, with the specified algorithm.
+* `backend-cmd BACKEND CMD [CMD..]`: Send a text command to a backend for execution. GSQL backends will take SQL commands, other backends may take different things. Be careful!
 * `check-zone ZONE`: Check a zone for DNSSEC correctness. Main goals is to check if the auth flag is set correctly.
 * `check-all-zones`: Check all zones for DNSSEC correctness. Added in 3.1.
 * `deactivate-zone-key ZONE KEY-ID`: Deactivate a key with id KEY-ID within a zone called ZONE.
index d3f2e3f6e39d10bef05c959580c402b415d45985..0e9a43facbdf785e85bbf798efd09ecfab336193 100644 (file)
@@ -1481,6 +1481,32 @@ bool GSQLBackend::replaceComments(const uint32_t domain_id, const DNSName& qname
   return true;
 }
 
+string GSQLBackend::directBackendCmd(const string &query)
+{
+ try {
+   ostringstream out;
+
+   unique_ptr<SSqlStatement> stmt(d_db->prepare(query,0));
+
+   stmt->execute();
+
+   SSqlStatement::row_t row;
+
+   while(stmt->hasNextRow()) {
+     stmt->nextRow(row);
+     for(const auto &col: row)
+       out<<"\'"<<col<<"\'\t";
+     out<<endl;
+   }
+
+   return out.str();
+ }
+ catch (SSqlException &e) {
+   throw PDNSException("GSQLBackend unable to execute query: "+e.txtReason());
+ }
+}
+
+
 SSqlStatement::~SSqlStatement() { 
 // make sure vtable won't break 
 }
index 45cb78e88ed63301016221f503914c5fc3fe45b2..810185ed7b0f71b10898f7950aa416be9dd1a6e0 100644 (file)
@@ -215,6 +215,8 @@ public:
   bool getComment(Comment& comment);
   void feedComment(const Comment& comment);
   bool replaceComments(const uint32_t domain_id, const DNSName& qname, const QType& qt, const vector<Comment>& comments);
+  bool replaceComments(const uint32_t domain_id, const string& qname, const QType& qt, const vector<Comment>& comments);
+  string directBackendCmd(const string &query);
 
 private:
   DNSName d_qname;
index fdefa31bbc88de1759d2886f11ca95ed9101299f..13f8fac36fef1d29ffecf7f970b2855e183bb7e7 100644 (file)
@@ -365,6 +365,11 @@ public:
     return false;
   }
 
+  virtual string directBackendCmd(const string &query)
+  {
+    return "directBackendCmd not supported for this backend\n";
+  }
+
   const string& getPrefix() { return d_prefix; };
 protected:
   bool mustDo(const string &key);
index 165f47334c2665874d23415d733101b98f8ae890..84f95d44c5bc144ef78c31a545e85f968e121dc8 100644 (file)
@@ -40,6 +40,7 @@ using std::string;
 using boost::lexical_cast;
 using boost::tie;
 using std::shared_ptr;
+using std::unique_ptr;
 using boost::shared_array;
 using boost::scoped_array;
 using boost::tuple;
index a7f77420944c6b76208c59c456c386e6cd3e302c..8470c7e4fe4e1da1c0cff349c285426078742aaa 100644 (file)
@@ -1281,6 +1281,7 @@ try
     cerr<<"add-zone-key ZONE zsk|ksk [bits] [active|passive]"<<endl;
     cerr<<"             [rsasha1|rsasha256|rsasha512|gost|ecdsa256|ecdsa384]"<<endl;
     cerr<<"                                   Add a ZSK or KSK to zone and specify algo&bits"<<endl;
+    cerr<<"backend-cmd BACKEND CMD [CMD..]    Perform one or more backend commands"<<endl;
     cerr<<"b2b-migrate old new                Move all data from one backend to another"<<endl;
     cerr<<"bench-db [filename]                Bench database backend with queries, one domain per line"<<endl;
     cerr<<"check-zone ZONE                    Check a zone for correctness"<<endl;
@@ -2346,6 +2347,30 @@ try
 
     cout<<"Remember to drop the old backend and run rectify-all-zones"<<endl;
 
+    return 0;
+  } else if (cmds[0] == "backend-cmd") {
+    if (cmds.size() < 3) {
+      cerr<<"Usage: backend-cmd BACKEND CMD [CMD..]"<<endl;
+      return 1;
+    }
+
+    DNSBackend *db;
+    db = NULL;
+
+    for(DNSBackend *b : BackendMakers().all()) {
+      if (b->getPrefix() == cmds[1]) db = b;
+    }
+
+    if (!db) {
+      cerr<<"Unknown backend '"<<cmds[1]<<"'"<<endl;
+      return 1;
+    }
+
+    for(auto i=next(begin(cmds),2); i != end(cmds); ++i) {
+      cerr<<"== "<<*i<<endl;
+      cout<<db->directBackendCmd(*i);
+    }
+
     return 0;
   } else {
     cerr<<"Unknown command '"<<cmds[0] <<"'"<< endl;