From: Thomas Markwalder Date: Fri, 20 Jul 2018 16:11:00 +0000 (-0400) Subject: [5680] Use raw text from dns::Name to cope with escape sequences X-Git-Tag: ha_phase2~29 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ef79d382cec738e4e0e8b8a93575b5876b7f04b1;p=thirdparty%2Fkea.git [5680] Use raw text from dns::Name to cope with escape sequences 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 --- diff --git a/src/lib/dhcpsrv/d2_client_mgr.h b/src/lib/dhcpsrv/d2_client_mgr.h index c4b4c67b31..ca2d1db339 100644 --- a/src/lib/dhcpsrv/d2_client_mgr.h +++ b/src/lib/dhcpsrv/d2_client_mgr.h @@ -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 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()) { diff --git a/src/lib/dhcpsrv/tests/d2_client_unittest.cc b/src/lib/dhcpsrv/tests/d2_client_unittest.cc index 9087e770d5..13cf020ac0 100644 --- a/src/lib/dhcpsrv/tests/d2_client_unittest.cc +++ b/src/lib/dhcpsrv/tests/d2_client_unittest.cc @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -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