mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-31 14:35:26 +00:00
[master] comment nzf files
3649. [cleanup] Include a comment in .nzf files, giving the name of the associated view. [RT #34765]
This commit is contained in:
3
CHANGES
3
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.
|
3648. [test] Updated the ATF test framework to version 0.17.
|
||||||
[RT #25627]
|
[RT #25627]
|
||||||
|
|
||||||
|
@@ -391,6 +391,9 @@ end_reserved_dispatches(ns_server_t *server, isc_boolean_t all);
|
|||||||
static void
|
static void
|
||||||
newzone_cfgctx_destroy(void **cfgp);
|
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
|
* Configure a single view ACL at '*aclp'. Get its configuration from
|
||||||
* 'vconfig' (for per-view configuration) and maybe from 'config'
|
* 'vconfig' (for per-view configuration) and maybe from 'config'
|
||||||
@@ -8486,6 +8489,23 @@ ns_smf_add_message(isc_buffer_t *text) {
|
|||||||
}
|
}
|
||||||
#endif /* HAVE_LIBSCF */
|
#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.
|
* 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;
|
FILE *fp = NULL;
|
||||||
struct cfg_context *cfg = NULL;
|
struct cfg_context *cfg = NULL;
|
||||||
char namebuf[DNS_NAME_FORMATSIZE];
|
char namebuf[DNS_NAME_FORMATSIZE];
|
||||||
|
off_t offset;
|
||||||
|
|
||||||
/* Try to parse the argument string */
|
/* Try to parse the argument string */
|
||||||
arglen = strlen(args);
|
arglen = strlen(args);
|
||||||
@@ -8587,6 +8608,9 @@ ns_server_add_zone(ns_server_t *server, char *args) {
|
|||||||
|
|
||||||
/* Open save file for write configuration */
|
/* Open save file for write configuration */
|
||||||
CHECK(isc_stdio_open(view->new_zone_file, "a", &fp));
|
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 */
|
/* Mark view unfrozen so that zone can be added */
|
||||||
result = isc_task_beginexclusive(server->task);
|
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;
|
FILE *ifp = NULL, *ofp = NULL;
|
||||||
isc_boolean_t exclusive = ISC_FALSE;
|
isc_boolean_t exclusive = ISC_FALSE;
|
||||||
isc_boolean_t cleanup = ISC_FALSE;
|
isc_boolean_t cleanup = ISC_FALSE;
|
||||||
|
isc_boolean_t inheader = ISC_TRUE;
|
||||||
const char *file, *arg;
|
const char *file, *arg;
|
||||||
|
|
||||||
/* Parse parameters */
|
/* Parse parameters */
|
||||||
@@ -8777,28 +8802,44 @@ ns_server_del_zone(ns_server_t *server, char *args, isc_buffer_t *text) {
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
CHECK(isc_stdio_open(tmpname, "w", &ofp));
|
CHECK(isc_stdio_open(tmpname, "w", &ofp));
|
||||||
|
CHECK(add_comment(ofp, view->name));
|
||||||
|
|
||||||
/* Look for the entry for that zone */
|
/* Look for the entry for that zone */
|
||||||
while (fgets(buf, 1024, ifp)) {
|
while (fgets(buf, 1024, ifp)) {
|
||||||
/* A 'zone' line */
|
/* Skip initial comment, if any */
|
||||||
if (strncasecmp(buf, "zone", 4)) {
|
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);
|
fputs(buf, ofp);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
p = buf+4;
|
p = buf+4;
|
||||||
|
|
||||||
/* Locate a name */
|
/* This is a zone; find its name. */
|
||||||
while (*p &&
|
while (*p &&
|
||||||
((*p == '"') || isspace((unsigned char)*p)))
|
((*p == '"') || isspace((unsigned char)*p)))
|
||||||
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);
|
fputs(buf, ofp);
|
||||||
continue;
|
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;
|
p += znamelen;
|
||||||
if (isspace((unsigned char)*p) ||
|
if (isspace((unsigned char)*p) ||
|
||||||
*p == '"' || *p == '{') {
|
*p == '"' || *p == '{') {
|
||||||
@@ -8807,7 +8848,7 @@ ns_server_del_zone(ns_server_t *server, char *args, isc_buffer_t *text) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Spit it out, keep looking */
|
/* Copy the rest of the buffer out and continue */
|
||||||
fputs(buf, ofp);
|
fputs(buf, ofp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -84,6 +84,14 @@ n=`expr $n + 1`
|
|||||||
if [ $ret != 0 ]; then echo "I:failed"; fi
|
if [ $ret != 0 ]; then echo "I:failed"; fi
|
||||||
status=`expr $status + $ret`
|
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)"
|
echo "I:deleting previously added zone ($n)"
|
||||||
ret=0
|
ret=0
|
||||||
$RNDC -c ../common/rndc.conf -s 10.53.0.2 -p 9953 delzone previous.example 2>&1 | sed 's/^/I:ns2 /'
|
$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
|
if [ $ret != 0 ]; then echo "I:failed"; fi
|
||||||
status=`expr $status + $ret`
|
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)"
|
echo "I:deleting newly added zone ($n)"
|
||||||
ret=0
|
ret=0
|
||||||
$RNDC -c ../common/rndc.conf -s 10.53.0.2 -p 9953 delzone added.example 2>&1 | sed 's/^/I:ns2 /'
|
$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
|
if [ $ret != 0 ]; then echo "I:failed"; fi
|
||||||
status=`expr $status + $ret`
|
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)"
|
echo "I:deleting newly added zone ($n)"
|
||||||
ret=0
|
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 /'
|
$RNDC -c ../common/rndc.conf -s 10.53.0.2 -p 9953 delzone 'added.example in external' 2>&1 | sed 's/^/I:ns2 /'
|
||||||
|
Reference in New Issue
Block a user