From ece19205b7e90facbe906bef9a6830676ea08176 Mon Sep 17 00:00:00 2001 From: Mukund Sivaraman Date: Fri, 16 Jan 2015 15:33:50 +0530 Subject: [PATCH] Close FILEs before overwriting NZF file (#38332) Based on a patch sent in by Tony Finch . (cherry picked from commit 1721fb782c4a6f4ad0f3b21ce65879fa9c8afa20) Conflicts: CHANGES bin/named/server.c --- CHANGES | 4 ++++ bin/named/server.c | 16 +++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/CHANGES b/CHANGES index 798b81316c..931e5d9580 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,7 @@ +4035. [bug] Close temporary and NZF FILE pointers before moving + the former into the latter's place, as required on + Windows. [RT #38332] + 4032. [bug] Built-in "empty" zones did not correctly inherit the "allow-transfer" ACL from the options or view. [RT #38310] diff --git a/bin/named/server.c b/bin/named/server.c index 2d54deba15..5b46496585 100644 --- a/bin/named/server.c +++ b/bin/named/server.c @@ -8581,6 +8581,16 @@ ns_server_del_zone(ns_server_t *server, char *args, isc_buffer_t *text) { result = isc_stdio_read(buf, 1, 1024, ifp, &n); } + /* + * Close files before overwriting the nzfile + * with the temporary file as it's necessary on + * some platforms (win32). + */ + (void) isc_stdio_close(ifp); + ifp = NULL; + (void) isc_stdio_close(ofp); + ofp = NULL; + /* Move temporary into place */ CHECK(isc_file_rename(tmpname, view->new_zone_file)); } else { @@ -8611,12 +8621,12 @@ ns_server_del_zone(ns_server_t *server, char *args, isc_buffer_t *text) { putnull(text); if (ifp != NULL) isc_stdio_close(ifp); - if (ofp != NULL) { + if (ofp != NULL) isc_stdio_close(ofp); + if (tmpname != NULL) { isc_file_remove(tmpname); - } - if (tmpname != NULL) isc_mem_free(server->mctx, tmpname); + } if (zone != NULL) dns_zone_detach(&zone);