]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
auth LUA: (optionally) drop whitespace on join 14021/head
authorPeter van Dijk <peter.van.dijk@powerdns.com>
Tue, 2 Apr 2024 14:00:07 +0000 (16:00 +0200)
committerPeter van Dijk <peter.van.dijk@powerdns.com>
Mon, 8 Apr 2024 11:06:10 +0000 (13:06 +0200)
fixes #14002

docs/settings.rst
docs/upgrading.rst
pdns/auth-main.cc
pdns/auth-main.hh
pdns/dnsrecords.cc
regression-tests.auth-py/test_LuaRecords.py

index f129896806520b2130d26852ef71857c5d13c95d..597603e87cec74ba341ca4432cb6c33e62343dbd 100644 (file)
@@ -1084,7 +1084,7 @@ guaranteed to be stable, and is in fact likely to change.
 .. _setting-lua-records-exec-limit:
 
 ``lua-records-exec-limit``
------------------------------
+--------------------------
 
 -  Integer
 -  Default: 1000
@@ -1092,6 +1092,18 @@ guaranteed to be stable, and is in fact likely to change.
 Limit LUA records scripts to ``lua-records-exec-limit`` instructions.
 Setting this to any value less than or equal to 0 will set no limit.
 
+.. _setting-lua-records-insert-whitespace:
+
+``lua-records-insert-whitespace``
+---------------------------------
+
+- Boolean
+- Default: no in 5.0, yes before that
+
+.. versionadded:: 4.9.1
+
+When combining the ``"`` delimited chunks of a LUA record, whether to insert whitespace between each chunk.
+
 .. _setting-master:
 
 ``master``
index b0713eee9c5debefd2e879a04cc6dd86461b9f6e..683ac23c9bbf72ed646d4161c9a6287ad54ed94f 100644 (file)
@@ -11,6 +11,11 @@ upgrade notes if your version is older than 3.4.2.
 4.9.0 to 5.0.0/master
 --------------
 
+LUA records whitespace insertion
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+:ref:`setting-lua-records-insert-whitespace`, introduced in 4.9.1 with the default value (``yes``) set to maintain the old behaviour of inserting whitespace, is set to ``no`` in 5.0.
+
 ixfrdist IPv6 support
 ^^^^^^^^^^^^^^^^^^^^^
 
index 98ccfc03ae43a7fb687e2ea44f6cd8593dd033d7..fc42d07db8f951fe8f57afe02debadb2b5bcafbd 100644 (file)
@@ -309,6 +309,7 @@ static void declareArguments()
   ::arg().setSwitch("8bit-dns", "Allow 8bit dns queries") = "no";
 #ifdef HAVE_LUA_RECORDS
   ::arg().setSwitch("enable-lua-records", "Process LUA records for all zones (metadata overrides this)") = "no";
+  ::arg().setSwitch("lua-records-insert-whitespace", "Insert whitespace when combining LUA chunks") = "no";
   ::arg().set("lua-records-exec-limit", "LUA records scripts execution limit (instructions count). Values <= 0 mean no limit") = "1000";
   ::arg().set("lua-health-checks-expire-delay", "Stops doing health checks after the record hasn't been used for that delay (in seconds)") = "3600";
   ::arg().set("lua-health-checks-interval", "LUA records health checks monitoring interval in seconds") = "5";
@@ -704,6 +705,7 @@ static void mainthread()
   g_doLuaRecord = ::arg().mustDo("enable-lua-records");
   g_LuaRecordSharedState = (::arg()["enable-lua-records"] == "shared");
   g_luaRecordExecLimit = ::arg().asNum("lua-records-exec-limit");
+  g_luaRecordInsertWhitespace = ::arg().mustDo("lua-records-insert-whitespace");
   g_luaHealthChecksInterval = ::arg().asNum("lua-health-checks-interval");
   g_luaConsistentHashesExpireDelay = ::arg().asNum("lua-consistent-hashes-expire-delay");
   g_luaConsistentHashesCleanupInterval = ::arg().asNum("lua-consistent-hashes-cleanup-interval");
index b96a61c681870a6060b20544d8c64d9d927d2636..bc3d90c0d77d344fa01ea8fe4274ef96db916338 100644 (file)
@@ -50,6 +50,7 @@ extern size_t g_proxyProtocolMaximumSize;
 #ifdef HAVE_LUA_RECORDS
 extern bool g_doLuaRecord;
 extern bool g_LuaRecordSharedState;
+extern bool g_luaRecordInsertWhitespace;
 extern time_t g_luaHealthChecksInterval;
 extern time_t g_luaHealthChecksExpireDelay;
 extern time_t g_luaConsistentHashesExpireDelay;
index 6b0079247ebc6682d6e5f42babaf6319ae12a7b6..a7c752be1fa95ab184a284596cc75598032f7c05 100644 (file)
@@ -167,15 +167,27 @@ boilerplate_conv(OPT,
                  );
 
 #ifdef HAVE_LUA_RECORDS
+
+bool g_luaRecordInsertWhitespace;
+
 string LUARecordContent::getCode() const
 {
   // in d_code, series of "part1" "part2"
   vector<string> parts;
   stringtok(parts, d_code, "\"");
   string ret;
-  for(const auto& p : parts) {
-    ret += p;
-    ret.append(1, ' ');
+  if (g_luaRecordInsertWhitespace) { // default before 5.0
+    for(const auto& part : parts) {
+      ret += part;
+      ret.append(1, ' ');
+    }
+  }
+  else { // default since 5.0
+    for(const auto& part : parts) {
+      if (part != " ") {
+        ret += part;
+      }
+    }
   }
   return ret;
 }
index 3d6d91a4bc8f9a0a4a296625ef66c66890f2d683..973d98568c87e9e752ea9526771b87b83e331f9c 100644 (file)
@@ -43,6 +43,7 @@ edns-subnet-processing=yes
 launch=bind geoip
 any-to-tcp=no
 enable-lua-records
+lua-records-insert-whitespace=yes
 lua-health-checks-interval=1
 """
 
@@ -157,6 +158,8 @@ counter          IN    LUA    TXT  ";counter = counter or 0 counter=counter+1 re
 
 lookmeup         IN           A  192.0.2.5
 dblookup         IN    LUA    A  "dblookup('lookmeup.example.org', pdns.A)[1]"
+
+whitespace       IN    LUA    TXT "'foo" "bar'"
         """,
         'createforward6.example.org': """
 createforward6.example.org.                 3600 IN SOA  {soa}
@@ -1090,6 +1093,22 @@ createforward6.example.org.                 3600 IN NS   ns2.example.org.
         self.assertRcodeEqual(res, dns.rcode.NOERROR)
         self.assertEqual(self.sortRRsets(res.answer), self.sortRRsets(response.answer))
 
+    def testWhitespace(self, expectws=True):
+        """
+        Test TXT query for whitespace
+        """
+        name = 'whitespace.example.org.'
+
+        query = dns.message.make_query(name, 'TXT')
+
+        response = dns.message.make_response(query)
+
+        response.answer.append(dns.rrset.from_text(name, 0, dns.rdataclass.IN, dns.rdatatype.TXT, '"foo   bar"' if expectws else '"foobar"'))
+
+        res = self.sendUDPQuery(query)
+        self.assertRcodeEqual(res, dns.rcode.NOERROR)
+        self.assertEqual(res.answer, response.answer)
+
 
 class TestLuaRecordsShared(TestLuaRecords):
     _config_template = """
@@ -1098,6 +1117,7 @@ edns-subnet-processing=yes
 launch=bind geoip
 any-to-tcp=no
 enable-lua-records=shared
+lua-records-insert-whitespace=yes
 lua-health-checks-interval=1
 """
 
@@ -1112,6 +1132,20 @@ lua-health-checks-interval=1
         self.assertEqual(len(resUDP), 50)
         self.assertEqual(len(resTCP), 50)
 
+class TestLuaRecordsNoWhiteSpace(TestLuaRecords):
+    _config_template = """
+geoip-database-files=../modules/geoipbackend/regression-tests/GeoLiteCity.mmdb
+edns-subnet-processing=yes
+launch=bind geoip
+any-to-tcp=no
+enable-lua-records
+lua-records-insert-whitespace=no
+lua-health-checks-interval=1
+"""
+
+    def testWhitespace(self):
+        return TestLuaRecords.testWhitespace(self, False)
+
 if __name__ == '__main__':
     unittest.main()
     exit(0)