mirror of
https://github.com/isc-projects/bind9.git
synced 2026-06-10 06:30:00 -04:00
[9.20] fix: usr: Fix a crash triggered by rndc modzone on zone that already existed in NZF file
Calling `rndc modzone` didn't work properly for a zone hat was configured in the configuration file. It could crash if BIND 9 was built without LMDB or if there was already an NZF file for the zone. In addition, `rndc modzone` failed in subsequent attempts. These problems are now fixed. Closes #5826 Merge branch '5826-fix-modzone-issues-ytatuya' into 'bind-9.20' See merge request isc-projects/bind9!11743
This commit is contained in:
commit
46dbcd7c9a
2 changed files with 69 additions and 22 deletions
|
|
@ -14113,6 +14113,7 @@ do_modzone(named_server_t *server, ns_cfgctx_t *cfg, dns_view_t *view,
|
|||
dns_zone_t *zone = NULL;
|
||||
bool added;
|
||||
bool locked = false;
|
||||
const cfg_obj_t *options = NULL;
|
||||
#ifndef HAVE_LMDB
|
||||
FILE *fp = NULL;
|
||||
cfg_obj_t *z;
|
||||
|
|
@ -14220,17 +14221,13 @@ do_modzone(named_server_t *server, ns_cfgctx_t *cfg, dns_view_t *view,
|
|||
|
||||
if (!added) {
|
||||
if (cfg->vconfig == NULL) {
|
||||
result = delete_zoneconf(
|
||||
view, cfg->conf_parser, cfg->config,
|
||||
dns_zone_getorigin(zone), NULL, locked);
|
||||
options = cfg->config;
|
||||
} else {
|
||||
const cfg_obj_t *voptions = cfg_tuple_get(cfg->vconfig,
|
||||
"options");
|
||||
result = delete_zoneconf(
|
||||
view, cfg->conf_parser, voptions,
|
||||
dns_zone_getorigin(zone), NULL, locked);
|
||||
options = cfg_tuple_get(cfg->vconfig, "options");
|
||||
}
|
||||
|
||||
result = delete_zoneconf(view, cfg->conf_parser, options,
|
||||
dns_zone_getorigin(zone), NULL,
|
||||
locked);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
TCHECK(putstr(text, "former zone configuration "
|
||||
"not deleted: "));
|
||||
|
|
@ -14277,8 +14274,11 @@ do_modzone(named_server_t *server, ns_cfgctx_t *cfg, dns_view_t *view,
|
|||
|
||||
#ifndef HAVE_LMDB
|
||||
/* Store the new zone configuration; also in NZF if applicable */
|
||||
z = UNCONST(zoneobj);
|
||||
CHECK(cfg_parser_mapadd(cfg->add_parser, cfg->nzf_config, z, "zone"));
|
||||
if (cfg->nzf_config != NULL) {
|
||||
z = UNCONST(zoneobj);
|
||||
CHECK(cfg_parser_mapadd(cfg->add_parser, cfg->nzf_config, z,
|
||||
"zone"));
|
||||
}
|
||||
#endif /* HAVE_LMDB */
|
||||
|
||||
if (added) {
|
||||
|
|
@ -14298,17 +14298,8 @@ do_modzone(named_server_t *server, ns_cfgctx_t *cfg, dns_view_t *view,
|
|||
TCHECK(putstr(text, zname));
|
||||
TCHECK(putstr(text, "' reconfigured."));
|
||||
} else {
|
||||
#ifdef HAVE_LMDB
|
||||
CHECK(nzd_open(view, 0, &txn, &dbi));
|
||||
CHECK(nzd_save(&txn, dbi, zone, zoneobj));
|
||||
#else /* ifdef HAVE_LMDB */
|
||||
result = nzf_append(view, zoneobj);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
TCHECK(putstr(text, "\nNew zone config not saved: "));
|
||||
TCHECK(putstr(text, isc_result_totext(result)));
|
||||
goto cleanup;
|
||||
}
|
||||
#endif /* HAVE_LMDB */
|
||||
CHECK(cfg_parser_mapadd(cfg->conf_parser, UNCONST(options),
|
||||
UNCONST(zoneobj), "zone"));
|
||||
|
||||
TCHECK(putstr(text, "zone '"));
|
||||
TCHECK(putstr(text, zname));
|
||||
|
|
|
|||
56
bin/tests/system/addzone/tests_rndc_modzone_without_add.py
Normal file
56
bin/tests/system/addzone/tests_rndc_modzone_without_add.py
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
||||
#
|
||||
# SPDX-License-Identifier: MPL-2.0
|
||||
#
|
||||
# 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
|
||||
# file, you can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
#
|
||||
# See the COPYRIGHT file distributed with this work for additional
|
||||
# information regarding copyright ownership.
|
||||
|
||||
import pytest
|
||||
|
||||
pytestmark = pytest.mark.extra_artifacts(
|
||||
[
|
||||
"ns*/*.nzf*",
|
||||
"ns*/*.nzd*",
|
||||
"ns1/redirect.db",
|
||||
"ns2/new-zones",
|
||||
"ns2/redirect.db",
|
||||
"ns3/redirect.db",
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
def test_rndc_modzone_without_add(ns3):
|
||||
"""
|
||||
Confirm "rndc modzone" works for a zone that was not added by "addzone".
|
||||
"""
|
||||
# We begin with a zone that has a normal configuration, and then modify it
|
||||
# by rndc modzone. This should succeed and shouldn't cause any disruption.
|
||||
# Previously, it triggered an assertion failure unless LMDB was enabled.
|
||||
cmd = ns3.rndc(
|
||||
'modzone . {type primary; file "redirect.db"; allow-query {none;};};',
|
||||
raise_on_exception=False,
|
||||
)
|
||||
assert cmd.rc == 0
|
||||
|
||||
# Confirm that the modzone took effect in 'rndc showzone'.
|
||||
cmd = ns3.rndc("showzone .", raise_on_exception=False)
|
||||
assert cmd.rc == 0
|
||||
assert 'allow-query { "none"; }' in cmd.out
|
||||
|
||||
# Confirm that 'rndc modzone' still works after the first modzone.
|
||||
# This was not the case before as the zone config was incorrectly
|
||||
# removed in-memory after the first modzone.
|
||||
cmd = ns3.rndc(
|
||||
'modzone . {type primary; file "redirect.db"; allow-query {any;};};',
|
||||
raise_on_exception=False,
|
||||
)
|
||||
assert cmd.rc == 0
|
||||
|
||||
# Confirm that the second modzone took effect in 'rndc showzone'.
|
||||
cmd = ns3.rndc("showzone .", raise_on_exception=False)
|
||||
assert cmd.rc == 0
|
||||
assert 'allow-query { "any"; }' in cmd.out
|
||||
Loading…
Reference in a new issue