From f72c687fa2de625a3ba743bf9246ee71140cca00 Mon Sep 17 00:00:00 2001 From: Tony Finch Date: Fri, 11 Jan 2019 15:17:04 +0000 Subject: [PATCH 1/3] Fix a few cosmetic issues with `rndc managed-keys` The handling of class and view arguments was broken, because the code didn't realise that next_token() would overwrite the class name when it parsed the view name. The code was trying to implement a syntax like `refresh [[class] view]`, but it was documented to have a syntax like `refresh [class [view]]`. The latter is consistent with other rndc commands, so that is how I have fixed it. Before: $ rndc managed-keys refresh in rec rndc: 'managed-keys' failed: unknown class/type unknown class 'rec' After: $ rndc managed-keys refresh in rec refreshing managed keys for 'rec' There were missing newlines in the output from `rndc managed-keys refresh` and `rndc managed-keys destroy`. Before: $ rndc managed-keys refresh refreshing managed keys for 'rec'refreshing managed keys for 'auth' After: $ rndc managed-keys refresh refreshing managed keys for 'rec' refreshing managed keys for 'auth' (cherry picked from commit 6a3b851f72929802fc10a51f17b170db54988021) (cherry picked from commit bc984ace12ef57ddbcb8ec6a87dd541b58c80f63) --- bin/named/server.c | 56 +++++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/bin/named/server.c b/bin/named/server.c index 7a00ac629b..11a9dbe053 100644 --- a/bin/named/server.c +++ b/bin/named/server.c @@ -14214,21 +14214,23 @@ ns_server_mkeys(ns_server_t *server, isc_lex_t *lex, isc_buffer_t **text) { /* Skip rndc command name */ cmd = next_token(lex, text); - if (cmd == NULL) + if (cmd == NULL) { return (ISC_R_UNEXPECTEDEND); + } /* Get managed-keys subcommand */ cmd = next_token(lex, text); - if (cmd == NULL) + if (cmd == NULL) { return (ISC_R_UNEXPECTEDEND); + } - if (strcasecmp(cmd, "status") == 0) + if (strcasecmp(cmd, "status") == 0) { opt = STATUS; - else if (strcasecmp(cmd, "refresh") == 0) + } else if (strcasecmp(cmd, "refresh") == 0) { opt = REFRESH; - else if (strcasecmp(cmd, "sync") == 0) + } else if (strcasecmp(cmd, "sync") == 0) { opt = SYNC; - else { + } else { snprintf(msg, sizeof(msg), "unknown command '%s'", cmd); (void) putstr(text, msg); result = ISC_R_UNEXPECTED; @@ -14238,29 +14240,17 @@ ns_server_mkeys(ns_server_t *server, isc_lex_t *lex, isc_buffer_t **text) { /* Look for the optional class name. */ classtxt = next_token(lex, text); if (classtxt != NULL) { - /* Look for the optional view name. */ - viewtxt = next_token(lex, text); - } - - if (classtxt == NULL) { - rdclass = dns_rdataclass_in; - } else { isc_textregion_t r; r.base = classtxt; r.length = strlen(classtxt); result = dns_rdataclass_fromtext(&rdclass, &r); if (result != ISC_R_SUCCESS) { - if (viewtxt == NULL) { - rdclass = dns_rdataclass_in; - viewtxt = classtxt; - result = ISC_R_SUCCESS; - } else { - snprintf(msg, sizeof(msg), - "unknown class '%s'", classtxt); - (void) putstr(text, msg); - goto cleanup; - } + snprintf(msg, sizeof(msg), + "unknown class '%s'", classtxt); + (void) putstr(text, msg); + goto cleanup; } + viewtxt = next_token(lex, text); } for (view = ISC_LIST_HEAD(server->viewlist); @@ -14270,7 +14260,9 @@ ns_server_mkeys(ns_server_t *server, isc_lex_t *lex, isc_buffer_t **text) { if (viewtxt != NULL && (rdclass != view->rdclass || strcmp(view->name, viewtxt) != 0)) + { continue; + } if (view->managed_keys == NULL) { if (viewtxt != NULL) { @@ -14278,21 +14270,25 @@ ns_server_mkeys(ns_server_t *server, isc_lex_t *lex, isc_buffer_t **text) { "view '%s': no managed keys", viewtxt); CHECK(putstr(text, msg)); goto cleanup; - } else + } else { continue; + } } found = true; switch (opt) { case REFRESH: + if (!first) { + CHECK(putstr(text, "\n")); + } CHECK(mkey_refresh(view, text)); break; case STATUS: - if (!first) + if (!first) { CHECK(putstr(text, "\n\n")); + } CHECK(mkey_status(view, text)); - first = false; break; case SYNC: CHECK(dns_zone_flush(view->managed_keys)); @@ -14302,12 +14298,16 @@ ns_server_mkeys(ns_server_t *server, isc_lex_t *lex, isc_buffer_t **text) { ISC_UNREACHABLE(); } - if (viewtxt != NULL) + if (viewtxt != NULL) { break; + } + + first = false; } - if (!found) + if (!found) { CHECK(putstr(text, "no views with managed keys")); + } cleanup: if (isc_buffer_usedlength(*text) > 0) From fb255668fa3cb71e79ea40680e910d48bdb61f64 Mon Sep 17 00:00:00 2001 From: Mark Andrews Date: Mon, 14 Jan 2019 16:09:36 +1100 Subject: [PATCH 2/3] add CHANGES note (cherry picked from commit 2d3f1597079b6814a3edbd10af381b46a3818ad1) --- CHANGES | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGES b/CHANGES index 6fddb1f493..43730c6463 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,7 @@ +5133. [bug] 'rndc managed-keys' didn't handle class and view + correctly and failed to add new lines between each + view. [GL !1327] + 5128. [bug] Refreshkeytime was not being updated for managed keys zones. [GL #784] From 06eb0a43675abdea66ed31cec222aa8ee34a8379 Mon Sep 17 00:00:00 2001 From: Mark Andrews Date: Mon, 14 Jan 2019 16:40:00 +1100 Subject: [PATCH 3/3] add multi-view server and tests (cherry picked from commit 7122b5786db12b0811f868977740e12e540488a0) (cherry picked from commit 22b77f45b739a211c9524ce2528a2b41a809f19e) --- bin/tests/system/mkeys/clean.sh | 3 +- bin/tests/system/mkeys/ns6/named.conf.in | 50 ++++++++++++++++++++++++ bin/tests/system/mkeys/setup.sh | 1 + bin/tests/system/mkeys/tests.sh | 17 +++++++- util/copyrights | 1 + 5 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 bin/tests/system/mkeys/ns6/named.conf.in diff --git a/bin/tests/system/mkeys/clean.sh b/bin/tests/system/mkeys/clean.sh index 17bd50f273..8a70488737 100644 --- a/bin/tests/system/mkeys/clean.sh +++ b/bin/tests/system/mkeys/clean.sh @@ -16,6 +16,7 @@ rm -f */managed-keys.bind* */named.secroots rm -f */managed.conf ns1/managed.key ns1/managed.key.id rm -f */named.memstats */named.run */named.run.prev rm -f dig.out* delv.out* rndc.out* signer.out* -rm -f ns1/named.secroots ns1/root.db.signed* ns1/root.db.tmp +rm -f ns1/root.db.signed* ns1/root.db.tmp rm -f */named.conf rm -f ns5/named.args +rm -f ns6/view1.mkeys ns6/view2.mkeys diff --git a/bin/tests/system/mkeys/ns6/named.conf.in b/bin/tests/system/mkeys/ns6/named.conf.in new file mode 100644 index 0000000000..37ddaa16ec --- /dev/null +++ b/bin/tests/system/mkeys/ns6/named.conf.in @@ -0,0 +1,50 @@ +/* + * 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. + */ + +// NS6 + +options { + query-source address 10.53.0.6; + notify-source 10.53.0.6; + transfer-source 10.53.0.6; + port @PORT@; + pid-file "named.pid"; + listen-on { 10.53.0.6; }; + listen-on-v6 { none; }; + recursion yes; + notify no; + dnssec-enable yes; + dnssec-validation auto; + bindkeys-file "managed.conf"; +}; + +key rndc_key { + secret "1234abcd8765"; + algorithm hmac-sha256; +}; + +controls { + inet 10.53.0.6 port @CONTROLPORT@ allow { any; } keys { rndc_key; }; +}; + +view view1 { + zone "." { + type hint; + file "../../common/root.hint"; + }; +}; + +view view2 { + zone "." { + type hint; + file "../../common/root.hint"; + }; +}; diff --git a/bin/tests/system/mkeys/setup.sh b/bin/tests/system/mkeys/setup.sh index 202ddeb3ee..a8b6be46d0 100644 --- a/bin/tests/system/mkeys/setup.sh +++ b/bin/tests/system/mkeys/setup.sh @@ -21,6 +21,7 @@ copy_setports ns1/named1.conf.in ns1/named.conf copy_setports ns2/named.conf.in ns2/named.conf copy_setports ns3/named.conf.in ns3/named.conf copy_setports ns5/named.conf.in ns5/named.conf +copy_setports ns6/named.conf.in ns6/named.conf cp ns5/named1.args ns5/named.args diff --git a/bin/tests/system/mkeys/tests.sh b/bin/tests/system/mkeys/tests.sh index 1e9097a5de..18facbf195 100644 --- a/bin/tests/system/mkeys/tests.sh +++ b/bin/tests/system/mkeys/tests.sh @@ -297,7 +297,7 @@ if [ $ret != 0 ]; then echo_i "failed"; fi status=`expr $status + $ret` echo_i "reinitialize trust anchors" -$PERL $SYSTEMTESTTOP/stop.pl --use-rndc mkeys ns2 +$PERL $SYSTEMTESTTOP/stop.pl --use-rndc --port ${CONTROLPORT} mkeys ns2 rm -f ns2/managed-keys.bind* nextpart ns2/named.run > /dev/null $PERL $SYSTEMTESTTOP/start.pl --noclean --restart --port ${PORT} mkeys ns2 @@ -710,5 +710,20 @@ grep "status: NOERROR" dig.out.ns5.b.test$n > /dev/null || ret=1 if [ $ret != 0 ]; then echo_i "failed"; fi status=`expr $status + $ret` +n=`expr $n + 1` +echo_i "check 'rndc managed-keys' and views ($n)" +ret=0 +$RNDCCMD 10.53.0.6 managed-keys refresh in view1 > rndc.out.ns6.view1.test$n || ret=1 +grep "refreshing managed keys for 'view1'" rndc.out.ns6.view1.test$n > /dev/null || ret=1 +lines=`wc -l < rndc.out.ns6.view1.test$n` +[ $lines -eq 1 ] || ret=1 +$RNDCCMD 10.53.0.6 managed-keys refresh > rndc.out.ns6.view2.test$n || ret=1 +lines=`wc -l < rndc.out.ns6.view2.test$n` +grep "refreshing managed keys for 'view1'" rndc.out.ns6.view2.test$n > /dev/null || ret=1 +grep "refreshing managed keys for 'view2'" rndc.out.ns6.view2.test$n > /dev/null || ret=1 +[ $lines -eq 2 ] || ret=1 +if [ $ret != 0 ]; then echo_i "failed"; fi +status=`expr $status + $ret` + echo_i "exit status: $status" [ $status -eq 0 ] || exit 1 diff --git a/util/copyrights b/util/copyrights index 8ad1988441..2d1bbe867a 100644 --- a/util/copyrights +++ b/util/copyrights @@ -1678,6 +1678,7 @@ ./bin/tests/system/mkeys/ns5/named.conf.in CONF-C 2018,2019 ./bin/tests/system/mkeys/ns5/named1.args X 2017,2018,2019 ./bin/tests/system/mkeys/ns5/named2.args X 2017,2018,2019 +./bin/tests/system/mkeys/ns6/named.conf.in CONF-C 2019 ./bin/tests/system/mkeys/prereq.sh SH 2015,2016,2018,2019 ./bin/tests/system/mkeys/setup.sh SH 2015,2016,2017,2018,2019 ./bin/tests/system/mkeys/tests.sh SH 2015,2016,2017,2018,2019