]> granicus.if.org Git - pdns/commitdiff
improve kv-example script, make sure we honor variable in there
authorbert hubert <bert.hubert@netherlabs.nl>
Fri, 22 Jan 2016 11:45:53 +0000 (12:45 +0100)
committerbert hubert <bert.hubert@netherlabs.nl>
Fri, 22 Jan 2016 11:45:53 +0000 (12:45 +0100)
pdns/kv-example-script.lua
pdns/lua-recursor4.cc

index ae39cddb9417db37a2fae4f29b9a82f85e00080d..18b4df547dd716511b27b7a459e05da779d7fe3f 100644 (file)
@@ -15,40 +15,41 @@ To test, use the 'kvresp' example program provided.
 function preresolve (dq)
        print ("prereesolve handler called for: "..dq.remoteaddr:toString().. ", local: ".. dq.localaddr:toString()..", ".. dq.qname:toString()..", ".. dq.qtype)
        dq.followupFunction="udpQueryResponse"
-       dq.udpCallback="gotipdetails"
+       dq.udpCallback="gotdomaindetails"
        dq.udpQueryDest=newCA("127.0.0.1:5555")
-       dq.udpQuery = "IP "..dq.remoteaddr:toString()
-        dq.variable = true;
+       dq.udpQuery = "DOMAIN "..dq.qname:toString()
        return true;
 end
 
-function gotipdetails(dq)
-       print("gotipdetails called, got: "..dq.udpAnswer)
-        if(dq.udpAnswer ~= "1") 
+function gotdomaindetails(dq)
+       print("gotdomaindetails called, got: "..dq.udpAnswer)
+        if(dq.udpAnswer == "0") 
         then
-                print("IP address wants no filtering, not looking up this domain")
+                print("This domain needs no filtering, not looking up this domain")
                 dq.followupFunction=""   
                 return false
         end
+        print("Domain might need filtering for some users")
+        dq.variable = true -- disable packet cache
        local data={}
-       data["ipdetails"]= dq.udpAnswer
+       data["domaindetails"]= dq.udpAnswer
        dq.data=data 
-       dq.udpQuery="DOMAIN "..dq.qname:toString()
-       dq.udpCallback="gotdomaindetails"
+       dq.udpQuery="IP "..dq.remoteaddr:toString()
+       dq.udpCallback="gotipdetails"
        print("returning true in gotipdetails")
        return true
 end
 
-function gotdomaindetails(dq)
+function gotipdetails(dq)
         dq.followupFunction=""
-       print("So status of domain is "..dq.udpAnswer.." and status of IP is "..dq.data.ipdetails)
-       if(dq.data.ipdetails=="1" and dq.udpAnswer=="1")
+       print("So status of IP is "..dq.udpAnswer.." and status of domain is "..dq.data.domaindetails)
+       if(dq.data.domaindetails=="1" and dq.udpAnswer=="1")
        then
                print("IP wants filtering and domain is of the filtered kind")
                dq:addAnswer(pdns.CNAME, "blocked.powerdns.com")
                return true
        else
-                print("Returning false (normal resolution should proceed)")
+                print("Returning false (normal resolution should proceed, for this user)")
                return false
        end
 end
index fc87af208329d23336b889b6845d2d5adeb3b5ef..2e1102e8229825bd8b47a36d611c1ef6181cd8c2 100644 (file)
@@ -391,28 +391,31 @@ bool RecursorLua4::genhook(luacall_t& func, const ComboAddress& remote,const Com
   if(handled) {
     ret=dq->rcode;
   loop:;
+    
     if(!dq->followupFunction.empty()) {
       if(dq->followupFunction=="followCNAMERecords") {
-       ret = followCNAMERecords(dq->records, qtype);
+        ret = followCNAMERecords(dq->records, qtype);
       }
       else if(dq->followupFunction=="getFakeAAAARecords") {
-       ret=getFakeAAAARecords(dq->followupName, dq->followupPrefix, dq->records);
+        ret=getFakeAAAARecords(dq->followupName, dq->followupPrefix, dq->records);
       }
       else if(dq->followupFunction=="getFakePTRRecords") {
-       ret=getFakePTRRecords(dq->followupName, dq->followupPrefix, dq->records);
+        ret=getFakePTRRecords(dq->followupName, dq->followupPrefix, dq->records);
       }
       else if(dq->followupFunction=="udpQueryResponse") {
-       dq->udpAnswer = GenUDPQueryResponse(dq->udpQueryDest, dq->udpQuery);
-       auto func = d_lw->readVariable<boost::optional<luacall_t>>(dq->udpCallback).get_value_or(0);
-       if(!func) {
-         theL()<<Logger::Error<<"Attempted callback for Lua UDP Query/Response which could not be found"<<endl;
-         return false;
-       }
-        if(!func(dq))
+        dq->udpAnswer = GenUDPQueryResponse(dq->udpQueryDest, dq->udpQuery);
+        auto func = d_lw->readVariable<boost::optional<luacall_t>>(dq->udpCallback).get_value_or(0);
+        if(!func) {
+          theL()<<Logger::Error<<"Attempted callback for Lua UDP Query/Response which could not be found"<<endl;
           return false;
-       goto loop;
+        }
+        bool res=func(dq);
+        if(variable) *variable |= dq->variable; // could still be set to indicate this *name* is variable
+        if(!res) {
+          return false;
+        }
+        goto loop;
       }
-      
     }
     res=dq->records;
   }