From b5ce93bcac62a49f6bb975d50fe5e862a362fbd6 Mon Sep 17 00:00:00 2001 From: Jamie Cameron Date: Sat, 18 Jun 2022 12:47:11 -0700 Subject: [PATCH] Add flag to force key re-generation https://github.com/virtualmin/virtualmin-gpl/issues/406 --- bind8/bind8-lib.pl | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/bind8/bind8-lib.pl b/bind8/bind8-lib.pl index 6ddc07575..b4231a246 100755 --- a/bind8/bind8-lib.pl +++ b/bind8/bind8-lib.pl @@ -3288,12 +3288,13 @@ else { } } -# create_dnssec_key(&zone|&zone-name, algorithm, size, single-key) +# create_dnssec_key(&zone|&zone-name, algorithm, size, single-key, +# [force-regen]) # Creates a new DNSSEC key for some zone, and places it in the same directory # as the zone file. Returns undef on success or an error message on failure. sub create_dnssec_key { -my ($z, $alg, $size, $single) = @_; +my ($z, $alg, $size, $single, $force) = @_; my $fn = &get_keys_dir($z); $fn || return "Could not work keys directory!"; my $dom = $z->{'members'} ? $z->{'values'}->[0] : $z->{'name'}; @@ -3329,6 +3330,17 @@ else { # Check if there are saved keys, and if so use them my @savedkeys = grep { $_->{'saved'} } &get_dnssec_key($z, 1); my $out; +if (@savedkeys && $force) { + # Delete any saved keys, to force re-generation + foreach my $key (@savedkeys) { + foreach my $f ('publicfile', 'privatefile') { + if (ref($key) && $key->{$f} && $key->{'saved'}) { + &unlink_file($key->{$f}); + } + } + } + @savedkeys = ( ); + } if (@savedkeys) { # Rename back the saved key files foreach my $key (@savedkeys) {