Commit c9c630ee authored by Brian Wellington's avatar Brian Wellington
Browse files

If signing a zone fails, remove the partial file. [RT #1131]

parent bb74e8ce
......@@ -17,7 +17,7 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: dnssec-signzone.c,v 1.135 2001/03/31 01:46:13 bwelling Exp $ */
/* $Id: dnssec-signzone.c,v 1.136 2001/03/31 02:12:23 bwelling Exp $ */
#include <config.h>
......@@ -99,6 +99,7 @@ static isc_mem_t *mctx = NULL;
static isc_entropy_t *ectx = NULL;
static dns_ttl_t zonettl;
static FILE *fp;
static char *tempfile = NULL;
static const dns_master_style_t *masterstyle = &dns_master_style_explicitttl;
static unsigned int nsigned = 0, nretained = 0, ndropped = 0;
static unsigned int nverified = 0, nverifyfailed = 0;
......@@ -116,6 +117,7 @@ static unsigned int ntasks = 0;
static isc_boolean_t shuttingdown = ISC_FALSE, finished = ISC_FALSE;
static unsigned int assigned = 0, completed = 0;
static isc_boolean_t nokeys = ISC_FALSE;
static isc_boolean_t removefile = ISC_FALSE;
#define INCSTAT(counter) \
if (printstats) { \
......@@ -1486,12 +1488,17 @@ usage(void) {
exit(0);
}
static void
removetempfile(void) {
if (removefile)
isc_file_remove(tempfile);
}
int
main(int argc, char *argv[]) {
int i, ch;
char *startstr = NULL, *endstr = NULL, *classname = NULL;
char *origin = NULL, *file = NULL, *output = NULL;
char *tempfile = NULL;
char *randomfile = NULL;
char *endp;
isc_time_t timer_start, timer_finish;
......@@ -1726,6 +1733,9 @@ main(int argc, char *argv[]) {
if (result != ISC_R_SUCCESS)
fatal("failed to open temporary output file: %s",
isc_result_totext(result));
removefile = ISC_TRUE;
setfatalcallback(&removetempfile);
print_time(fp);
print_version(fp);
......@@ -1771,6 +1781,7 @@ main(int argc, char *argv[]) {
result = isc_stdio_close(fp);
check_result(result, "isc_stdio_close");
removefile = ISC_FALSE;
result = isc_file_rename(tempfile, output);
if (result != ISC_R_SUCCESS)
......
......@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: dnssectool.c,v 1.27 2001/01/09 21:39:27 bwelling Exp $ */
/* $Id: dnssectool.c,v 1.28 2001/03/31 02:12:24 bwelling Exp $ */
#include <config.h>
......@@ -45,6 +45,7 @@ extern const char *program;
static isc_entropysource_t *source = NULL;
static isc_keyboard_t kbd;
static isc_boolean_t wantkeyboard = ISC_FALSE;
static fatalcallback_t *fatalcallback = NULL;
void
fatal(const char *format, ...) {
......@@ -55,9 +56,16 @@ fatal(const char *format, ...) {
vfprintf(stderr, format, args);
va_end(args);
fprintf(stderr, "\n");
if (fatalcallback != NULL)
(*fatalcallback)();
exit(1);
}
void
setfatalcallback(fatalcallback_t *callback) {
fatalcallback = callback;
}
void
check_result(isc_result_t result, const char *message) {
if (result != ISC_R_SUCCESS) {
......
......@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: dnssectool.h,v 1.13 2001/01/09 21:39:28 bwelling Exp $ */
/* $Id: dnssectool.h,v 1.14 2001/03/31 02:12:26 bwelling Exp $ */
#ifndef DNSSECTOOL_H
#define DNSSECTOOL_H 1
......@@ -25,9 +25,14 @@
#include <dns/rdatastruct.h>
#include <dst/dst.h>
typedef void (fatalcallback_t)(void);
void
fatal(const char *format, ...) ISC_FORMAT_PRINTF(1, 2);
void
setfatalcallback(fatalcallback_t *callback);
void
check_result(isc_result_t result, const char *message);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment