From 0e0cd6bf17704300cf3a1f69563219ce263da913 Mon Sep 17 00:00:00 2001
From: Mark Andrews <marka@isc.org>
Date: Thu, 23 Dec 2021 17:54:53 +1100
Subject: [PATCH] Report duplicate dnssec-policy names

Duplicate dnssec-policy names were detected as an error condition
but were not logged.

(cherry picked from commit b8845454c8c67c5c5650e597936f6303708bdd7d)
Conflict: NA
Reference: https://gitlab.isc.org/isc-projects/bind9/-/commit/0e0cd6bf17704300cf3a1f69563219ce263da913
---
 bin/tests/system/checkconf/bad-kasp-duplicate.conf | 13 +++++++++++++
 lib/isccfg/kaspconf.c                              |  4 ++++
 2 files changed, 17 insertions(+)
 create mode 100644 bin/tests/system/checkconf/bad-kasp-duplicate.conf

diff --git a/bin/tests/system/checkconf/bad-kasp-duplicate.conf b/bin/tests/system/checkconf/bad-kasp-duplicate.conf
new file mode 100644
index 0000000000..8ecc670e0b
--- /dev/null
+++ b/bin/tests/system/checkconf/bad-kasp-duplicate.conf
@@ -0,0 +1,13 @@
+/*
+ * Copyright (C) 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
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * See the COPYRIGHT file distributed with this work for additional
+ * information regarding copyright ownership.
+ */
+
+dnssec-policy a { };
+dnssec-policy a { };
diff --git a/lib/isccfg/kaspconf.c b/lib/isccfg/kaspconf.c
index 15433d9f90..f6f1bc3a10 100644
--- a/lib/isccfg/kaspconf.c
+++ b/lib/isccfg/kaspconf.c
@@ -272,6 +272,10 @@ cfg_kasp_fromconfig(const cfg_obj_t *config, const char *name, isc_mem_t *mctx,
 	result = dns_kasplist_find(kasplist, kaspname, &kasp);
 
 	if (result == ISC_R_SUCCESS) {
+		cfg_obj_log(
+			config, logctx, ISC_LOG_ERROR,
+			"dnssec-policy: duplicately named policy found '%s'",
+			kaspname);
 		dns_kasp_detach(&kasp);
 		return (ISC_R_EXISTS);
 	}
-- 
2.23.0

