]> granicus.if.org Git - pdns/commitdiff
initial hookup of lua
authorbert hubert <bert.hubert@powerdns.com>
Mon, 31 Oct 2016 16:09:41 +0000 (17:09 +0100)
committerbert hubert <bert.hubert@netherlabs.nl>
Sun, 19 Nov 2017 19:48:19 +0000 (20:48 +0100)
pdns/dnsrecords.cc
pdns/dnsrecords.hh
pdns/lua-auth4.cc
pdns/lua-auth4.hh
pdns/packethandler.cc
pdns/qtype.hh

index 3b3d569c15e7e13d6e8100708f02c5b5e305258a..fbd05a83563f938797d900d28c8f438a1a63be22 100644 (file)
@@ -141,6 +141,7 @@ boilerplate_conv(DNAME, QType::DNAME, conv.xfrName(d_content));
 boilerplate_conv(MR, QType::MR, conv.xfrName(d_alias, true));
 boilerplate_conv(MINFO, QType::MINFO, conv.xfrName(d_rmailbx, true); conv.xfrName(d_emailbx, true));
 boilerplate_conv(TXT, QType::TXT, conv.xfrText(d_text, true));
+boilerplate_conv(LUA, QType::LUA, conv.xfrText(d_code, true));
 boilerplate_conv(ENT, 0, );
 boilerplate_conv(SPF, 99, conv.xfrText(d_text, true));
 boilerplate_conv(HINFO, QType::HINFO,  conv.xfrText(d_cpu);   conv.xfrText(d_host));
@@ -581,6 +582,7 @@ void reportBasicTypes()
   PTRRecordContent::report();
   DNSRecordContent::regist(QClass::CHAOS, QType::TXT, &TXTRecordContent::make, &TXTRecordContent::make, "TXT");
   TXTRecordContent::report();
+  LUARecordContent::report();
   DNSRecordContent::regist(QClass::IN, QType::ANY, 0, 0, "ANY");
   DNSRecordContent::regist(QClass::IN, QType::AXFR, 0, 0, "AXFR");
   DNSRecordContent::regist(QClass::IN, QType::IXFR, 0, 0, "IXFR");
index 55afedbf2d40f91fd44fa60ea96ec303b67df8e7..fbaff717da5ef2e1cd6aedcd49006af1b264adf6 100644 (file)
@@ -185,6 +185,15 @@ public:
   string d_text;
 };
 
+class LUARecordContent : public DNSRecordContent
+{
+public:
+  includeboilerplate(LUA)
+
+  string d_code;
+};
+
+
 class ENTRecordContent : public DNSRecordContent
 {
 public:
index 773d71090d8c73995f6ef6ce5ff4513e4130b7f5..56d05389bc4575f9668cd8a212ce7cede8151725 100644 (file)
@@ -282,4 +282,19 @@ bool AuthLua4::updatePolicy(const DNSName &qname, QType qtype, const DNSName &zo
 
 AuthLua4::~AuthLua4() { }
 
+
+
+std::vector<shared_ptr<DNSRecordContent>> luaSynth(const std::string& code, uint16_t qtype) 
+{
+  std::vector<shared_ptr<DNSRecordContent>> ret;
+  cout<<"Code: "<<code<<endl;
+  string strip=code.c_str()+1;
+  strip.resize(strip.size()-1);
+  
+  LuaContext lua;
+  ret.push_back(std::shared_ptr<DNSRecordContent>(DNSRecordContent::mastermake(qtype, 1, lua.executeCode<string>("return "+strip))));
+
+  return ret;
+}
+
 #endif
index 3bad3541f7c79ab300a2fb7f25dbc7870bf13eef..fcdd545f80afcf042a7b4c7126ea696e32511be4 100644 (file)
@@ -42,3 +42,4 @@ private:
   luacall_update_policy_t d_update_policy;
   luacall_axfr_filter_t d_axfr_filter;
 };
+std::vector<shared_ptr<DNSRecordContent>> luaSynth(const std::string& code, uint16_t qtype);
index 3b3bcbd161d6ce7772d49e14fd8610944cb4df36..e50247d2578247264ba46a02e092409b5245cf20 100644 (file)
@@ -1283,6 +1283,19 @@ DNSPacket *PacketHandler::doQuestion(DNSPacket *p)
     weDone = weRedirected = weHaveUnauth =  false;
     
     while(B.get(rr)) {
+      if(rr.dr.d_type == QType::LUA) {
+        cerr<<"We got LUA: "<<endl;
+        auto recvec=luaSynth(getRR<LUARecordContent>(rr.dr)->d_code, p->qtype.getCode());
+        if(!recvec.empty()) {
+          cerr<<"We got answers from Lua"<<endl;
+          for(const auto& r : recvec) {
+            rr.dr.d_type = p->qtype.getCode();
+            rr.dr.d_content = r;
+            rrset.push_back(rr);
+          }
+          weDone = 1;
+        }
+      }
       //cerr<<"got content: ["<<rr.content<<"]"<<endl;
       if (p->qtype.getCode() == QType::ANY && !p->d_dnssecOk && (rr.dr.d_type == QType:: DNSKEY || rr.dr.d_type == QType::NSEC3PARAM))
         continue; // Don't send dnssec info to non validating resolvers.
index 5d3577fcfda5ebe33771ce83f61c2f1740c8a0f5..33cf98d17d653c0bc7e38897b37da42518642a96 100644 (file)
@@ -125,7 +125,8 @@ public:
     CAA=257,
     DLV=32769,
     ADDR=65400,
-    ALIAS=65401
+    ALIAS=65401,
+    LUA=65402
   };
 
   typedef pair<string,uint16_t> namenum;