} 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()) {
#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>
"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."
}
};
"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."
}
};
}
}
-
} // end of anonymous namespace