]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
[master] add "-clean" option to "rndc delzone"
authorEvan Hunt <each@isc.org>
Wed, 5 Jun 2013 04:26:29 +0000 (21:26 -0700)
committerEvan Hunt <each@isc.org>
Wed, 5 Jun 2013 04:26:29 +0000 (21:26 -0700)
3585. [func] "rndc delzone -clean" option removes zone files
when deleting a zone. [RT #33570]

CHANGES
bin/named/server.c
bin/rndc/rndc.c
bin/tests/system/addzone/tests.sh
doc/arm/Bv9ARM-book.xml

diff --git a/CHANGES b/CHANGES
index f22abfe05e3eb65f06053ead43e39eec234701c5..cf53b7b0cafaa7e02c86f8e79a0d5eb2697f1005 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,6 @@
+3585.  [func]          "rndc delzone -clean" option removes zone files
+                       when deleting a zone. [RT #33570]
+
 3584.  [security]      Caching data from an incompletely signed zone could
                        trigger an assertion failure in resolver.c [RT #33690]
 
index 2a705fba667ea681de3fffe4d98dff76f0a76360..5828827e3aa36dd9e75519d3d292c5eff2ff6939 100644 (file)
@@ -8479,22 +8479,32 @@ inuse(const char* file, isc_boolean_t first, isc_buffer_t *text) {
  */
 isc_result_t
 ns_server_del_zone(ns_server_t *server, char *args, isc_buffer_t *text) {
-       isc_result_t           result;
-       dns_zone_t            *zone = NULL;
-       dns_zone_t            *raw = NULL;
-       dns_zone_t            *mayberaw;
-       dns_view_t            *view = NULL;
-       dns_db_t              *dbp = NULL;
-       const char            *filename = NULL;
-       char                  *tmpname = NULL;
-       char                   buf[1024];
-       const char            *zonename = NULL;
-       size_t                 znamelen = 0;
-       FILE                  *ifp = NULL, *ofp = NULL;
-       isc_boolean_t          exclusive = ISC_FALSE;
+       isc_result_t result;
+       dns_zone_t *zone = NULL;
+       dns_zone_t *raw = NULL;
+       dns_zone_t *mayberaw;
+       dns_view_t *view = NULL;
+       dns_db_t *dbp = NULL;
+       const char *filename = NULL;
+       char *tmpname = NULL;
+       char buf[1024];
+       const char *zonename = NULL;
+       size_t znamelen = 0;
+       FILE *ifp = NULL, *ofp = NULL;
+       isc_boolean_t exclusive = ISC_FALSE;
+       isc_boolean_t cleanup = ISC_FALSE;
+       const char *file, *arg;
 
        /* Parse parameters */
-       CHECK(zone_from_args(server, args, NULL, &zone, &zonename, ISC_TRUE));
+       (void) next_token(&args, " \t");
+       arg = next_token(&args, " \t");
+       if (arg != NULL &&
+           (strcmp(arg, "-clean") == 0 || strcmp(arg, "-clear") == 0)) {
+               cleanup = ISC_TRUE;
+               arg = next_token(&args, " \t");
+       }
+
+       CHECK(zone_from_args(server, args, arg, &zone, &zonename, ISC_FALSE));
 
        if (zone == NULL) {
                result = ISC_R_UNEXPECTEDEND;
@@ -8620,9 +8630,30 @@ ns_server_del_zone(ns_server_t *server, char *args, isc_buffer_t *text) {
        /* Clean up stub / slave zone files */
        dns_zone_getraw(zone, &raw);
        mayberaw = (raw != NULL) ? raw : zone;
-       if (dns_zone_gettype(mayberaw) == dns_zone_slave ||
-           dns_zone_gettype(mayberaw) == dns_zone_stub) {
-               const char *file;
+       if (cleanup) {
+               file = dns_zone_getfile(mayberaw);
+               if (isc_file_exists(file))
+                       isc_file_remove(file);
+
+               file = dns_zone_getjournal(mayberaw);
+               if (isc_file_exists(file))
+                       isc_file_remove(file);
+
+               if (zone != mayberaw) {
+                       file = dns_zone_getfile(zone);
+                       if (isc_file_exists(file))
+                               isc_file_remove(file);
+
+                       file = dns_zone_getjournal(zone);
+                       if (isc_file_exists(file))
+                               isc_file_remove(file);
+               }
+               isc_buffer_putstr(text, "zone ");
+               isc_buffer_putstr(text, zonename);
+               isc_buffer_putstr(text, " and associated files deleted");
+       } else if (dns_zone_gettype(mayberaw) == dns_zone_slave ||
+                  dns_zone_gettype(mayberaw) == dns_zone_stub)
+       {
                isc_boolean_t first;
 
                file = dns_zone_getfile(mayberaw);
index 0f69f5fcea05ea4eb9c6cd47f67419d6fd675b4e..036b3544c7fcb7c66da9d2f1d294f1491d07a3ed 100644 (file)
@@ -159,9 +159,9 @@ command is one of the following:\n\
                Delete a TKEY-negotiated TSIG key.\n\
   validation newstate [view]\n\
                Enable / disable DNSSEC validation.\n\
-  addzone [\"file\"] zone [class [view]] { zone-options }\n\
+  addzone zone [class [view]] { zone-options }\n\
                Add zone to given view. Requires new-zone-file option.\n\
-  delzone [\"file\"] zone [class [view]]\n\
+  delzone [-clean] zone [class [view]]\n\
                Removes zone from given view. Requires new-zone-file option.\n\
   signing -list zone [class [view]]\n\
                List the private records showing the state of DNSSEC\n\
index 28e9c6571008316e3f67c7e9ff0b8553e640241b..c7c22ec97d57cc56f31329ff6b42fd3522f37f74 100755 (executable)
@@ -182,6 +182,39 @@ grep '^inlineslave.bk.signed$' rndc.out2.test$n > /dev/null || {
 n=`expr $n + 1`
 status=`expr $status + $ret`
 
+echo "I:restoring slave zone with inline signing ($n)"
+$RNDC -c ../common/rndc.conf -s 10.53.0.2 -p 9953 addzone 'inlineslave.example { type slave; masters { 10.53.0.1; }; file "inlineslave.bk"; inline-signing yes; };' 2>&1 | sed 's/^/I:ns2 /'
+for i in 1 2 3 4 5
+do
+ret=0
+$DIG $DIGOPTS @10.53.0.2 a.inlineslave.example a > dig.out.ns2.$n || ret=1
+grep 'status: NOERROR' dig.out.ns2.$n > /dev/null || ret=1
+grep '^a.inlineslave.example' dig.out.ns2.$n > /dev/null || ret=1
+[ $ret = 0 ] && break
+sleep 1
+done
+n=`expr $n + 1`
+if [ $ret != 0 ]; then echo "I:failed"; fi
+status=`expr $status + $ret`
+
+echo "I:deleting slave zone with automatic zone file removal ($n)"
+ret=0
+for i in 0 1 2 3 4 5 6 7 8 9
+do
+       test -f ns2/inlineslave.bk.signed -a -f ns2/inlineslave.bk && break
+       sleep 1
+done
+$RNDC -c ../common/rndc.conf -s 10.53.0.2 -p 9953 delzone -clean inlineslave.example 2>&1 > /dev/null
+for i in 0 1 2 3 4 5 6 7 8 9
+do
+        ret=0
+       test -f ns2/inlineslave.bk.signed -a -f ns2/inlineslave.bk && ret=1
+        [ $ret = 0 ] && break
+       sleep 1
+done
+n=`expr $n + 1`
+status=`expr $status + $ret`
+
 echo "I:reconfiguring server with multiple views"
 rm -f ns2/named.conf 
 cp -f ns2/named2.conf ns2/named.conf
index 0213beb150cd73cfe67405c0090fe889b5a8200c..7c06fbca61bd6526d5c6fe6ef6b6be8214685d90 100644 (file)
@@ -1597,6 +1597,7 @@ zone "eng.example.com" {
 
                   <varlistentry>
                     <term><userinput>delzone
+                        <optional>-clean</optional>
                         <replaceable>zone</replaceable>
                         <optional><replaceable>class</replaceable>
                         <optional><replaceable>view</replaceable></optional></optional>
@@ -1606,7 +1607,17 @@ zone "eng.example.com" {
                         Delete a zone while the server is running.
                         Only zones that were originally added via
                         <command>rndc addzone</command> can be deleted
-                        in this matter.
+                        in this matter. 
+                      </para>
+                      <para>
+                        If the <option>-clean</option> is specified,
+                        the zone's master file (and journal file, if any)
+                        will be deleted along with the zone.  Without the
+                        <option>-clean</option> option, zone files must
+                        be cleaned up by hand.  (If the zone is of
+                        type "slave" or "stub", the files needing to
+                        be cleaned up will be reported in the output
+                        of the <command>rndc delzone</command> command.)
                       </para>
                     </listitem>
                   </varlistentry>