]> granicus.if.org Git - pdns/commitdiff
add simple stubquery tool for testing the stubresolver
authorPeter van Dijk <peter.van.dijk@powerdns.com>
Fri, 13 May 2016 12:23:41 +0000 (14:23 +0200)
committerPeter van Dijk <peter.van.dijk@powerdns.com>
Fri, 13 May 2016 13:10:43 +0000 (15:10 +0200)
pdns/.gitignore
pdns/Makefile.am
pdns/stubquery.cc [new file with mode: 0644]

index c11064050ba79f3966d4d974d1c3e97c2da52cf9..7ab50604503597863ac387390b7dbd1f7e3645ca 100644 (file)
@@ -59,3 +59,4 @@ effective_tld_names.dat
 /dnsmessage.pb.h
 /pdns.service
 /pdns.conf-dist
+/stubquery
index c71cb4c40bfe97d32b1fddd4ec6b46f9606a5442..a57f69bb09bbf98087ee4c1770dec603d66a6cd0 100644 (file)
@@ -90,6 +90,7 @@ bin_PROGRAMS += \
        nproxy \
        nsec3dig \
        saxfr \
+       stubquery \
        ixplore \
        sdig
 
@@ -117,6 +118,7 @@ EXTRA_PROGRAMS = \
        nproxy \
        nsec3dig \
        saxfr \
+       stubquery \
        sdig \
        speedtest \
        testrunner \
@@ -493,6 +495,30 @@ kvresp_SOURCES = \
        unix_utility.cc \
        qtype.cc 
 
+stubquery_SOURCES = \
+       arguments.cc arguments.hh \
+       base32.cc \
+       base64.cc \
+       dns_random.cc \
+       dnslabeltext.cc \
+       dnsname.cc \
+       dnsparser.cc \
+       dnsrecords.cc \
+       dnswriter.cc \
+       logger.cc \
+       misc.cc \
+       nsecrecords.cc \
+       qtype.cc \
+       rcpgenerator.cc \
+       sillyrecords.cc \
+       statbag.cc \
+       stubresolver.cc stubresolver.hh \
+       stubquery.cc \
+       unix_utility.cc
+
+stubquery_LDADD = $(OPENSSL_LIBS)
+stubquery_LDFLAGS = $(AM_LDFLAGS) $(OPENSSL_LDFLAGS)
+
 saxfr_SOURCES = \
        base32.cc \
        base64.cc base64.hh \
diff --git a/pdns/stubquery.cc b/pdns/stubquery.cc
new file mode 100644 (file)
index 0000000..767328b
--- /dev/null
@@ -0,0 +1,68 @@
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+#include "arguments.hh"
+#include "dnsrecords.hh"
+#include "dns_random.hh"
+#include "stubresolver.hh"
+#include "statbag.hh"
+
+StatBag S;
+
+ArgvMap &arg()
+{
+  static ArgvMap theArg;
+  return theArg;
+}
+
+void usage() {
+  cerr<<"stubquery"<<endl;
+  cerr<<"Syntax: stubquery QUESTION [QUESTION-TYPE]"<<endl;
+}
+
+int main(int argc, char** argv)
+try
+{
+  DNSName qname;
+  QType qtype;
+
+  for(int i=1; i<argc; i++) {
+    if ((string) argv[i] == "--help") {
+      usage();
+      exit(EXIT_SUCCESS);
+    }
+
+    if ((string) argv[i] == "--version") {
+      cerr<<"stubquery "<<VERSION<<endl;
+      exit(EXIT_SUCCESS);
+    }
+  }
+
+  if(argc < 2) {
+    usage();
+    exit(EXIT_FAILURE);
+  }
+
+  ::arg().set("recursor","If recursion is desired, IP address of a recursing nameserver")="no"; 
+
+  reportAllTypes();
+  dns_random_init("0123456789abcdef");
+  stubParseResolveConf();
+
+  vector<DNSResourceRecord> ret;
+
+  int res=stubDoResolve(argv[1], DNSRecordContent::TypeToNumber(argv[2]), ret);
+
+  cout<<"res: "<<res<<endl;
+  for(const auto& r : ret) {
+    cout<<r.getZoneRepresentation()<<endl;
+  }
+}
+catch(std::exception &e)
+{
+  cerr<<"Fatal: "<<e.what()<<endl;
+}
+catch(PDNSException &e)
+{
+  cerr<<"Fatal: "<<e.reason<<endl;
+}