From a663216c0e63bcbf90dc5142f9914bb02edac144 Mon Sep 17 00:00:00 2001
From: Aram Sargsyan <aram@isc.org>
Date: Tue, 28 Dec 2021 12:08:48 +0000
Subject: [PATCH] Improve the zones' view reverting logic when a zone is a
 catalog zone

When a zone is being configured with a new view, the catalog zones
structure will also be linked to that view. Later on, in case of some
error, should the zone be reverted to the previous view, the link
between the catalog zones structure and the view won't be reverted.

Change the dns_zone_setviewrevert() function so it calls
dns_zone_catz_enable() during a zone revert, which will reset the
link between `catzs` and view.

(cherry picked from commit 2fd967136ad014f6d7456c1e19e185803f7d99ac)
Conflict: NA
Reference: https://gitlab.isc.org/isc-projects/bind9/-/commit/a663216c0e63bcbf90dc5142f9914bb02edac144
---
 lib/dns/zone.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/lib/dns/zone.c b/lib/dns/zone.c
index 9205271574..74ecace4a5 100644
--- a/lib/dns/zone.c
+++ b/lib/dns/zone.c
@@ -1674,6 +1674,9 @@ dns_zone_setviewrevert(dns_zone_t *zone) {
 		dns_zone_setview_helper(zone, zone->prev_view);
 		dns_view_weakdetach(&zone->prev_view);
 	}
+	if (zone->catzs != NULL) {
+		zone_catz_enable(zone, zone->catzs);
+	}
 	if (inline_secure(zone)) {
 		dns_zone_setviewrevert(zone->raw);
 	}
-- 
2.23.0

