diff options
author | Thomas Markwalder <tmark@isc.org> | 2021-07-30 17:09:40 +0200 |
---|---|---|
committer | Thomas Markwalder <tmark@isc.org> | 2021-08-05 19:16:44 +0200 |
commit | a8f61ee95daea74a70b7281cd518703225cba556 (patch) | |
tree | 7fbb39bb204046a708a1383513dde3039d103cf7 /src/lib/dhcpsrv/d2_client_mgr.cc | |
parent | [#1993] hammer.py: support for NETCONF (diff) | |
download | kea-a8f61ee95daea74a70b7281cd518703225cba556.tar.xz kea-a8f61ee95daea74a70b7281cd518703225cba556.zip |
[#1529] Avoid duplicating qualifying suffix
src/lib/dhcpsrv/d2_client_mgr.*
D2ClientMgr::qualifyName() - modified to only add the qualifying
suffix if the input name does not already end with it.
src/lib/dhcpsrv/tests/d2_client_unittest.cc
TEST_F(D2ClientMgrParamsTest, qualifyNameWithoutDuplicatingSuffix) -
new test
Diffstat (limited to 'src/lib/dhcpsrv/d2_client_mgr.cc')
-rw-r--r-- | src/lib/dhcpsrv/d2_client_mgr.cc | 43 |
1 files changed, 38 insertions, 5 deletions
diff --git a/src/lib/dhcpsrv/d2_client_mgr.cc b/src/lib/dhcpsrv/d2_client_mgr.cc index 6671471309..3ba12d172c 100644 --- a/src/lib/dhcpsrv/d2_client_mgr.cc +++ b/src/lib/dhcpsrv/d2_client_mgr.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2020 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2014-2021 Internet Systems Consortium, Inc. ("ISC") // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -186,14 +186,47 @@ D2ClientMgr::qualifyName(const std::string& partial_name, gen_name << partial_name; std::string suffix = ddns_params.getQualifyingSuffix(); + bool suffix_present = true; if (!suffix.empty()) { std::string str = gen_name.str(); - size_t len = str.length(); - if ((len > 0) && (str[len - 1] != '.')) { - gen_name << "."; + auto suffix_rit = suffix.rbegin(); + if (*suffix_rit == '.') { + ++suffix_rit; + } + + auto gen_rit = str.rbegin(); + if (*gen_rit == '.') { + ++gen_rit; } - gen_name << suffix; + while (suffix_rit != suffix.rend()) { + if ((gen_rit == str.rend()) || + (*suffix_rit != *gen_rit)) { + // They don't match. + suffix_present = false; + break; + } + + ++suffix_rit; + ++gen_rit; + } + + // Catch the case where name has suffix embedded. + // input: foo.barexample.com suffix: example.com + if ((suffix_present) && (suffix_rit == suffix.rend())) { + if (*gen_rit != '.') { + suffix_present = false; + } + } + + if (!suffix_present) { + size_t len = str.length(); + if ((len > 0) && (str[len - 1] != '.')) { + gen_name << "."; + } + + gen_name << suffix; + } } std::string str = gen_name.str(); |