]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Fix recursor lua addRecord function's impl in C++
authorSasha Kabenin <28066869+kabenin@users.noreply.github.com>
Fri, 27 Mar 2026 23:05:16 +0000 (16:05 -0700)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Mon, 20 Apr 2026 07:54:28 +0000 (09:54 +0200)
name argiment must be DNSName, not string

Signed-off-by: Sasha Kabenin <28066869+kabenin@users.noreply.github.com>
pdns/recursordist/lua-recursor4.cc
pdns/recursordist/lua-recursor4.hh
regression-tests.recursor-dnssec/test_Lua.py

index a80989250b0065c0048e1273483ab0fadfd8ff48..230daeb2a201055dfb62f3c5ccc12349e65ed0b1 100644 (file)
@@ -132,10 +132,10 @@ void RecursorLua4::DNSQuestion::setRecords(const vector<pair<int, DNSRecord>>& a
   }
 }
 
-void RecursorLua4::DNSQuestion::addRecord(uint16_t type, const std::string& content, DNSResourceRecord::Place place, std::optional<int> ttl, std::optional<string> name)
+void RecursorLua4::DNSQuestion::addRecord(uint16_t type, const std::string& content, DNSResourceRecord::Place place, std::optional<int> ttl, std::optional<DNSName> name)
 {
   DNSRecord dnsRecord;
-  dnsRecord.d_name = name ? DNSName(*name) : qname;
+  dnsRecord.d_name = name.value_or(qname);
   dnsRecord.d_ttl = ttl.value_or(3600);
   dnsRecord.d_type = type;
   dnsRecord.d_place = place;
@@ -143,7 +143,7 @@ void RecursorLua4::DNSQuestion::addRecord(uint16_t type, const std::string& cont
   records.push_back(std::move(dnsRecord));
 }
 
-void RecursorLua4::DNSQuestion::addAnswer(uint16_t type, const std::string& content, std::optional<int> ttl, std::optional<string> name)
+void RecursorLua4::DNSQuestion::addAnswer(uint16_t type, const std::string& content, std::optional<int> ttl, std::optional<DNSName> name)
 {
   addRecord(type, content, DNSResourceRecord::ANSWER, ttl, std::move(name));
 }
index 9fd3e4957e9d713915c07f45fda21120f466c5d2..f60fb49da11f6d892a08cbb37a5c3e2cdd0ded30 100644 (file)
@@ -136,8 +136,8 @@ public:
     bool isTcp;
     vState validationState{vState::Indeterminate};
 
-    void addAnswer(uint16_t type, const std::string& content, std::optional<int> ttl, std::optional<string> name);
-    void addRecord(uint16_t type, const std::string& content, DNSResourceRecord::Place place, std::optional<int> ttl, std::optional<string> name);
+    void addAnswer(uint16_t type, const std::string& content, std::optional<int> ttl, std::optional<DNSName> name);
+    void addRecord(uint16_t type, const std::string& content, DNSResourceRecord::Place place, std::optional<int> ttl, std::optional<DNSName> name);
     [[nodiscard]] vector<pair<int, DNSRecord>> getRecords() const;
     [[nodiscard]] std::optional<dnsheader> getDH() const;
     [[nodiscard]] vector<pair<uint16_t, string>> getEDNSOptions() const;
index 78ed03f362474d0b3d1dd842a0b83e5c55b2a94c..a71365f9b395f858f1f9da7155759f6972f4757f 100644 (file)
@@ -1089,3 +1089,46 @@ end
         self.assertEqual(len(res.authority), 0)
         self.assertEqual(len(res.additional), 0)
         self.assertEqual(res.answer, expectedAnswerRecords)
+
+
+class AddRecordRecusrorTest(RecursorTest):
+    """Test addRecord can add SOA to authority section.
+    """
+
+    _confdir = "AddRecordRecusror"
+    _soa = "ns1.example. admin.example. 2026033101 3600 1200 604800 60"
+    _config_template = """
+    """
+    _lua_dns_script_file = f"""
+    local PLACE_AUTHORITY = 2
+
+    function preresolve(dq)
+      if dq.qname == newDN("nxd-addrecord.example.") then
+        dq.rcode = pdns.NXDOMAIN
+        dq:addRecord(
+          pdns.SOA,
+          "{_soa}",
+          PLACE_AUTHORITY,
+          3600,
+          newDN("example.")
+        )
+        return true
+      end
+      return false
+    end
+    """
+
+    def testAddRecord4AuthSeection(self):
+        """addRecord: NXDOMAIN response with SOA in authority section"""
+        expectedAuthority = dns.rrset.from_text(
+            "example.", 3600, dns.rdataclass.IN, "SOA", AddRecordRecusrorTest._soa
+        )
+        query = dns.message.make_query("nxd-addrecord.example.", "A")
+
+        for method in ("sendUDPQuery", "sendTCPQuery"):
+            sender = getattr(self, method)
+            res = sender(query)
+            self.assertRcodeEqual(res, dns.rcode.NXDOMAIN)
+            self.assertEqual(len(res.answer), 0)
+            self.assertEqual(len(res.authority), 1)
+            self.assertEqual(res.authority[0], expectedAuthority)