mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-08-30 21:45:37 +00:00
[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
This commit is contained in:
committed by
Tomek Mrugalski
parent
9b39ff3343
commit
ef79d382ce
@@ -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()) {
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user