]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[5680] Use raw text from dns::Name to cope with escape sequences
authorThomas Markwalder <tmark@isc.org>
Fri, 20 Jul 2018 16:11:00 +0000 (12:11 -0400)
committerTomek Mrugalski <tomasz@isc.org>
Fri, 27 Jul 2018 11:54:10 +0000 (13:54 +0200)
src/lib/dhcpsrv/d2_client_mgr.h
    D2ClientMgr::adjustDomainName() - modified to start with
    raw text domain name, this allows us to cope with escape
    sequences

src/lib/dhcpsrv/tests/d2_client_unittest.cc
    Updated unit tests

src/lib/dhcpsrv/d2_client_mgr.h
src/lib/dhcpsrv/tests/d2_client_unittest.cc

index c4b4c67b31a1aef54a2b793157ce9b5b2ce4b2de..ca2d1db339127f66c7d77d920bc9e375e890bd3b 100644 (file)
@@ -472,13 +472,18 @@ D2ClientMgr::adjustDomainName(const T& fqdn, T& fqdn_resp) {
     } else {
         // Sanitize the name the client sent us, if we're configured to do so.
         std::string client_name = fqdn.getDomainName();
+
         if (d2_client_config_->getHostnameSanitizer()) {
+            // We need the raw text form, so we can replace escaped chars
+            dns::Name tmp(client_name);
+            std::string raw_name = tmp.toRawText();
+
             // We do not know if the sanitizer's regexp preserves dots, so
             // we'll scrub it label by label. Yeah, lucky us.
             // Using boost::split is simpler than using dns::Name::split() as
             // that returns Names which have trailing dots etc.
             std::vector<std::string> labels;
-            boost::algorithm::split(labels, client_name, boost::is_any_of("."));
+            boost::algorithm::split(labels, raw_name, boost::is_any_of("."));
             std::stringstream ss;
             for (auto label = labels.begin(); label != labels.end(); ++label ) {
                 if (label != labels.begin()) {
index 9087e770d54f2c1d8fb89f65ea1ce9bdeb6de563..13cf020ac053fca43f15954d9e19f895a9a95736 100644 (file)
@@ -10,6 +10,7 @@
 #include <dhcpsrv/d2_client_mgr.h>
 #include <testutils/test_to_element.h>
 #include <exceptions/exceptions.h>
+#include <util/strutil.h>
 
 #include <boost/algorithm/string.hpp>
 #include <gtest/gtest.h>
@@ -1178,15 +1179,16 @@ TEST(D2ClientMgr, sanitizeFqdnV4) {
         "One.1x2x3.suffix.com."
         },
         {
-        // Some chars, like parens, get escaped by lib::dns::Name
-        // when output via Name::getDomainName().  This means they'll
-        // get replaced by TWO replacment chars, if the backslash "\"
-        // is an invalid character per hostname-char-set.
-        "full FQDN, scrubbed with escaped char",
-        "One.123.exa(mple.com.",
+        "full FQDN with characters that get escaped",
+        "O n e.123.exa(m)ple.com.",
         Option4ClientFqdn::FULL,
-        // expect the ( to be replaced by two x's
-        "One.123.exaxxmple.com."
+        "Oxnxe.123.exaxmxple.com."
+        },
+        {
+        "full FQDN with escape sequences",
+        "O\032n\032e.123.example.com.",
+        Option4ClientFqdn::FULL,
+        "Oxnxe.123.example.com."
         }
     };
 
@@ -1261,15 +1263,16 @@ TEST(D2ClientMgr, sanitizeFqdnV6) {
         "one.1x2x3.suffix.com."
         },
         {
-        // Some chars, like parens, get escaped by lib::dns::Name
-        // when output via Name::getDomainName().  This means they'll
-        // get replaced by TWO replacment chars, if the backslash "\"
-        // is an invalid character per hostname-char-set.
-        "full FQDN, scrubbed with escaped char",
-        "One.123.exa(mple.com.",
+        "full FQDN with characters that get escaped",
+        "O n e.123.exa(m)ple.com.",
         Option6ClientFqdn::FULL,
-        // expect the ( to be replaced by two x's
-        "one.123.exaxxmple.com."
+        "oxnxe.123.exaxmxple.com."
+        },
+        {
+        "full FQDN with escape sequences",
+        "O\032n\032e.123.example.com.",
+        Option6ClientFqdn::FULL,
+        "oxnxe.123.example.com."
         }
     };
 
@@ -1289,5 +1292,4 @@ TEST(D2ClientMgr, sanitizeFqdnV6) {
     }
 }
 
-
 } // end of anonymous namespace