]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
[master] comment nzf files
authorEvan Hunt <each@isc.org>
Thu, 19 Sep 2013 22:37:09 +0000 (15:37 -0700)
committerEvan Hunt <each@isc.org>
Thu, 19 Sep 2013 22:37:09 +0000 (15:37 -0700)
3649. [cleanup] Include a comment in .nzf files, giving the name of
the associated view. [RT #34765]

CHANGES
bin/named/server.c
bin/tests/system/addzone/tests.sh

diff --git a/CHANGES b/CHANGES
index 507d990e2f5f99e3ca399a88bedcb7a0e14d1eed..22ee43634c49d18a7e3711c5bc4ef40db069ca8d 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,6 @@
+3649.  [cleanup]       Include a comment in .nzf files, giving the name of
+                       the associated view. [RT #34765]
+
 3648.  [test]          Updated the ATF test framework to version 0.17.
                        [RT #25627]
 
index 12ddde28c3e5d490eb30a83cbe6854866722850a..da4f62541ba06a141d3bf1093f9daa274402f459 100644 (file)
@@ -391,6 +391,9 @@ end_reserved_dispatches(ns_server_t *server, isc_boolean_t all);
 static void
 newzone_cfgctx_destroy(void **cfgp);
 
+isc_result_t
+add_comment(FILE *fp, const char *viewname);
+
 /*%
  * Configure a single view ACL at '*aclp'.  Get its configuration from
  * 'vconfig' (for per-view configuration) and maybe from 'config'
@@ -8486,6 +8489,23 @@ ns_smf_add_message(isc_buffer_t *text) {
 }
 #endif /* HAVE_LIBSCF */
 
+/*
+ * Emit a comment at the top of the nzf file containing the viewname
+ * Expects the fp to already be open for writing
+ */
+#define HEADER1 "# New zone file for view: "
+#define HEADER2 "\n# This file contains configuration for zones added by\n" \
+               "# the 'rndc addzone' command. DO NOT EDIT BY HAND.\n"
+isc_result_t
+add_comment(FILE *fp, const char *viewname) {
+       isc_result_t result;
+       CHECK(isc_stdio_write(HEADER1, sizeof(HEADER1) - 1, 1, fp, NULL));
+       CHECK(isc_stdio_write(viewname, strlen(viewname), 1, fp, NULL));
+       CHECK(isc_stdio_write(HEADER2, sizeof(HEADER2) - 1, 1, fp, NULL));
+ cleanup:
+       return (result);
+}
+
 /*
  * Act on an "addzone" command from the command channel.
  */
@@ -8514,6 +8534,7 @@ ns_server_add_zone(ns_server_t *server, char *args) {
        FILE                *fp = NULL;
        struct cfg_context  *cfg = NULL;
        char                namebuf[DNS_NAME_FORMATSIZE];
+       off_t               offset;
 
        /* Try to parse the argument string */
        arglen = strlen(args);
@@ -8587,6 +8608,9 @@ ns_server_add_zone(ns_server_t *server, char *args) {
 
        /* Open save file for write configuration */
        CHECK(isc_stdio_open(view->new_zone_file, "a", &fp));
+       CHECK(isc_stdio_tell(fp, &offset));
+       if (offset == 0)
+               CHECK(add_comment(fp, view->name));
 
        /* Mark view unfrozen so that zone can be added */
        result = isc_task_beginexclusive(server->task);
@@ -8720,6 +8744,7 @@ ns_server_del_zone(ns_server_t *server, char *args, isc_buffer_t *text) {
        FILE *ifp = NULL, *ofp = NULL;
        isc_boolean_t exclusive = ISC_FALSE;
        isc_boolean_t cleanup = ISC_FALSE;
+       isc_boolean_t inheader = ISC_TRUE;
        const char *file, *arg;
 
        /* Parse parameters */
@@ -8777,28 +8802,44 @@ ns_server_del_zone(ns_server_t *server, char *args, isc_buffer_t *text) {
                        goto cleanup;
                }
                CHECK(isc_stdio_open(tmpname, "w", &ofp));
+               CHECK(add_comment(ofp, view->name));
 
                /* Look for the entry for that zone */
                while (fgets(buf, 1024, ifp)) {
-                       /* A 'zone' line */
-                       if (strncasecmp(buf, "zone", 4)) {
+                       /* Skip initial comment, if any */
+                       if (inheader && *buf == '#')
+                               continue;
+                       if (*buf != '#')
+                               inheader = ISC_FALSE;
+
+                       /*
+                        * Any other lines not starting with zone, copy
+                        * them out and continue.
+                        */
+                       if (strncasecmp(buf, "zone", 4) != 0) {
                                fputs(buf, ofp);
                                continue;
                        }
                        p = buf+4;
 
-                       /* Locate a name */
+                       /* This is a zone; find its name. */
                        while (*p &&
                               ((*p == '"') || isspace((unsigned char)*p)))
                                p++;
 
-                       /* Is that the zone we're looking for */
-                       if (strncasecmp(p, zonename, znamelen)) {
+                       /*
+                        * If it's not the zone we're looking for, copy
+                        * it out and continue
+                        */
+                       if (strncasecmp(p, zonename, znamelen) != 0) {
                                fputs(buf, ofp);
                                continue;
                        }
 
-                       /* And nothing else? */
+                       /* 
+                        * But if it is the zone we want, skip over it
+                        * so it will be omitted from the new file
+                        */
                        p += znamelen;
                        if (isspace((unsigned char)*p) ||
                            *p == '"' || *p == '{') {
@@ -8807,7 +8848,7 @@ ns_server_del_zone(ns_server_t *server, char *args, isc_buffer_t *text) {
                                break;
                        }
 
-                       /* Spit it out, keep looking */
+                       /* Copy the rest of the buffer out and continue */
                        fputs(buf, ofp);
                }
 
index c7c22ec97d57cc56f31329ff6b42fd3522f37f74..a57e202b09d2ad5246d441bb886d0922ad1c6364 100755 (executable)
@@ -84,6 +84,14 @@ n=`expr $n + 1`
 if [ $ret != 0 ]; then echo "I:failed"; fi
 status=`expr $status + $ret`
 
+echo "I:verifying no comments in nzf file ($n)"
+ret=0
+hcount=`grep "^# New zone file for view: _default" ns2/3bf305731dd26307.nzf | wc -l`
+[ $hcount -eq 0 ] || ret=1
+n=`expr $n + 1`
+if [ $ret != 0 ]; then echo "I:failed"; fi
+status=`expr $status + $ret`
+
 echo "I:deleting previously added zone ($n)"
 ret=0
 $RNDC -c ../common/rndc.conf -s 10.53.0.2 -p 9953 delzone previous.example 2>&1 | sed 's/^/I:ns2 /'
@@ -94,6 +102,14 @@ n=`expr $n + 1`
 if [ $ret != 0 ]; then echo "I:failed"; fi
 status=`expr $status + $ret`
 
+echo "I:checking nzf file now has comment ($n)"
+ret=0
+hcount=`grep "^# New zone file for view: _default" ns2/3bf305731dd26307.nzf | wc -l`
+[ $hcount -eq 1 ] || ret=1
+n=`expr $n + 1`
+if [ $ret != 0 ]; then echo "I:failed"; fi
+status=`expr $status + $ret`
+
 echo "I:deleting newly added zone ($n)"
 ret=0
 $RNDC -c ../common/rndc.conf -s 10.53.0.2 -p 9953 delzone added.example 2>&1 | sed 's/^/I:ns2 /'
@@ -243,6 +259,15 @@ n=`expr $n + 1`
 if [ $ret != 0 ]; then echo "I:failed"; fi
 status=`expr $status + $ret`
 
+echo "I:checking new nzf file has comment ($n)"
+ret=0
+hcount=`grep "^# New zone file for view: external" ns2/3c4623849a49a539.nzf | wc -l`
+[ $hcount -eq 1 ] || ret=1
+n=`expr $n + 1`
+if [ $ret != 0 ]; then echo "I:failed"; fi
+status=`expr $status + $ret`
+
+
 echo "I:deleting newly added zone ($n)"
 ret=0
 $RNDC -c ../common/rndc.conf -s 10.53.0.2 -p 9953 delzone 'added.example in external' 2>&1 | sed 's/^/I:ns2 /'