From: Miod Vallat Date: Fri, 27 Jun 2025 05:50:28 +0000 (+0200) Subject: Move stripDomainSuffix() to its only user and make it static. X-Git-Tag: rec-5.3.0-alpha2~43^2~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2d6c1934b9da37bfa789b7111acf55055d267180;p=thirdparty%2Fpdns.git Move stripDomainSuffix() to its only user and make it static. This also moves ciEqual() and endsOn() which are only used by stripDomainSuffix(). Signed-off-by: Miod Vallat --- diff --git a/modules/bindbackend/bindbackend2.cc b/modules/bindbackend/bindbackend2.cc index f9beb39cd1..b0a54c68c9 100644 --- a/modules/bindbackend/bindbackend2.cc +++ b/modules/bindbackend/bindbackend2.cc @@ -281,6 +281,69 @@ bool Bind2Backend::abortTransaction() return true; } +static bool ciEqual(const string& lhs, const string& rhs) +{ + if (lhs.size() != rhs.size()) { + return false; + } + + string::size_type pos = 0; + const string::size_type epos = lhs.size(); + for (; pos < epos; ++pos) { + if (dns_tolower(lhs[pos]) != dns_tolower(rhs[pos])) { + return false; + } + } + return true; +} + +/** does domain end on suffix? Is smart about "wwwds9a.nl" "ds9a.nl" not matching */ +static bool endsOn(const string& domain, const string& suffix) +{ + if (suffix.empty() || ciEqual(domain, suffix)) { + return true; + } + + if (domain.size() <= suffix.size()) { + return false; + } + + string::size_type dpos = domain.size() - suffix.size() - 1; + string::size_type spos = 0; + + if (domain[dpos++] != '.') { + return false; + } + + for (; dpos < domain.size(); ++dpos, ++spos) { + if (dns_tolower(domain[dpos]) != dns_tolower(suffix[spos])) { + return false; + } + } + + return true; +} + +/** strips a domain suffix from a domain, returns true if it stripped */ +static bool stripDomainSuffix(string* qname, const string& domain) +{ + if (!endsOn(*qname, domain)) { + return false; + } + + if (toLower(*qname) == toLower(domain)) { + *qname = "@"; + } + else { + if ((*qname)[qname->size() - domain.size() - 1] != '.') { + return false; + } + + qname->resize(qname->size() - domain.size() - 1); + } + return true; +} + bool Bind2Backend::feedRecord(const DNSResourceRecord& rr, const DNSName& /* ordername */, bool /* ordernameIsNSEC3 */) { if (d_transaction_id == UnknownDomainID) { diff --git a/pdns/misc.cc b/pdns/misc.cc index a8b5694f76..913848fabf 100644 --- a/pdns/misc.cc +++ b/pdns/misc.cc @@ -308,69 +308,6 @@ string nowTime() return {buffer.data()}; } -static bool ciEqual(const string& lhs, const string& rhs) -{ - if (lhs.size() != rhs.size()) { - return false; - } - - string::size_type pos = 0; - const string::size_type epos = lhs.size(); - for (; pos < epos; ++pos) { - if (dns_tolower(lhs[pos]) != dns_tolower(rhs[pos])) { - return false; - } - } - return true; -} - -/** does domain end on suffix? Is smart about "wwwds9a.nl" "ds9a.nl" not matching */ -static bool endsOn(const string &domain, const string &suffix) -{ - if( suffix.empty() || ciEqual(domain, suffix) ) { - return true; - } - - if(domain.size() <= suffix.size()) { - return false; - } - - string::size_type dpos = domain.size() - suffix.size() - 1; - string::size_type spos = 0; - - if (domain[dpos++] != '.') { - return false; - } - - for(; dpos < domain.size(); ++dpos, ++spos) { - if (dns_tolower(domain[dpos]) != dns_tolower(suffix[spos])) { - return false; - } - } - - return true; -} - -/** strips a domain suffix from a domain, returns true if it stripped */ -bool stripDomainSuffix(string *qname, const string &domain) -{ - if (!endsOn(*qname, domain)) { - return false; - } - - if (toLower(*qname) == toLower(domain)) { - *qname="@"; - } - else { - if ((*qname)[qname->size() - domain.size() - 1] != '.') { - return false; - } - - qname->resize(qname->size() - domain.size()-1); - } - return true; -} - // returns -1 in case if error, 0 if no data is available, 1 if there is. In the first two cases, errno is set int waitForData(int fileDesc, int seconds, int useconds) { diff --git a/pdns/misc.hh b/pdns/misc.hh index 0b2d088383..5471df6cfe 100644 --- a/pdns/misc.hh +++ b/pdns/misc.hh @@ -102,7 +102,6 @@ namespace OpenSSL string nowTime(); string unquotify(const string &item); string humanDuration(time_t passed); -bool stripDomainSuffix(string *qname, const string &domain); void stripLine(string &line); std::optional getHostname(); std::string getCarbonHostName();