From 8f0502e922120f27207fbf6b6dda18f1112e486c Mon Sep 17 00:00:00 2001 From: Evan Hunt Date: Sat, 24 Oct 2009 00:00:06 +0000 Subject: [PATCH] 2728. [bug] dnssec-keygen, dnssec-keyfromlabel and dnssec-signzone now warn immediately if asked to write into a nonexistent directory. [RT #20278] --- CHANGES | 4 ++++ bin/dnssec/dnssec-keyfromlabel.c | 6 +++++- bin/dnssec/dnssec-keygen.c | 10 ++++++---- bin/dnssec/dnssec-signzone.c | 6 +++++- bin/dnssec/dnssectool.c | 16 +++++++++++++++- bin/dnssec/dnssectool.h | 4 +++- 6 files changed, 38 insertions(+), 8 deletions(-) diff --git a/CHANGES b/CHANGES index 073154d949..2150496a03 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,7 @@ +2728. [bug] dnssec-keygen, dnssec-keyfromlabel and + dnssec-signzone now warn immediately if asked to + write into a nonexistent directory. [RT #20278] + 2727. [func] The 'key-directory' option can now specify a relative path. [RT #20154] diff --git a/bin/dnssec/dnssec-keyfromlabel.c b/bin/dnssec/dnssec-keyfromlabel.c index d51efbd449..58eb349aaa 100644 --- a/bin/dnssec/dnssec-keyfromlabel.c +++ b/bin/dnssec/dnssec-keyfromlabel.c @@ -14,7 +14,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: dnssec-keyfromlabel.c,v 1.23 2009/10/22 02:21:30 each Exp $ */ +/* $Id: dnssec-keyfromlabel.c,v 1.24 2009/10/24 00:00:06 each Exp $ */ /*! \file */ @@ -188,6 +188,10 @@ main(int argc, char **argv) { break; case 'K': directory = isc_commandline_argument; + ret = try_dir(directory); + if (ret != ISC_R_SUCCESS) + fatal("Cannot write to directory %s: %s", + directory, isc_result_totext(ret)); break; case 'k': options |= DST_TYPE_KEY; diff --git a/bin/dnssec/dnssec-keygen.c b/bin/dnssec/dnssec-keygen.c index 1d19297467..0631af15b7 100644 --- a/bin/dnssec/dnssec-keygen.c +++ b/bin/dnssec/dnssec-keygen.c @@ -29,7 +29,7 @@ * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: dnssec-keygen.c,v 1.102 2009/10/22 02:21:30 each Exp $ */ +/* $Id: dnssec-keygen.c,v 1.103 2009/10/24 00:00:06 each Exp $ */ /*! \file */ @@ -281,6 +281,10 @@ main(int argc, char **argv) { break; case 'K': directory = isc_commandline_argument; + ret = try_dir(directory); + if (ret != ISC_R_SUCCESS) + fatal("cannot write to directory %s: %s", + directory, isc_result_totext(ret)); break; case 'k': fatal("The -k option has been deprecated.\n" @@ -773,8 +777,7 @@ main(int argc, char **argv) { if (conflict == ISC_TRUE) { if (verbose > 0) { isc_buffer_clear(&buf); - ret = dst_key_buildfilename(key, 0, directory, - &buf); + dst_key_buildfilename(key, 0, directory, &buf); fprintf(stderr, "%s: %s already exists, " "generating a new key\n", @@ -782,7 +785,6 @@ main(int argc, char **argv) { } dst_key_free(&key); } - } while (conflict == ISC_TRUE); if (conflict) diff --git a/bin/dnssec/dnssec-signzone.c b/bin/dnssec/dnssec-signzone.c index 4739dfc290..2f3da0f990 100644 --- a/bin/dnssec/dnssec-signzone.c +++ b/bin/dnssec/dnssec-signzone.c @@ -29,7 +29,7 @@ * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: dnssec-signzone.c,v 1.247 2009/10/13 23:48:12 tbox Exp $ */ +/* $Id: dnssec-signzone.c,v 1.248 2009/10/24 00:00:06 each Exp $ */ /*! \file */ @@ -3274,6 +3274,10 @@ main(int argc, char *argv[]) { dsdir = isc_commandline_argument; if (strlen(dsdir) == 0U) fatal("DS directory must be non-empty string"); + result = try_dir(dsdir); + if (result != ISC_R_SUCCESS) + fatal("Cannot write to directory %s: %s", + dsdir, isc_result_totext(result)); break; case 'E': diff --git a/bin/dnssec/dnssectool.c b/bin/dnssec/dnssectool.c index 38ab8c2006..541dda0b12 100644 --- a/bin/dnssec/dnssectool.c +++ b/bin/dnssec/dnssectool.c @@ -15,7 +15,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: dnssectool.c,v 1.55 2009/10/12 20:48:11 each Exp $ */ +/* $Id: dnssectool.c,v 1.56 2009/10/24 00:00:06 each Exp $ */ /*! \file */ @@ -28,6 +28,7 @@ #include #include +#include #include #include #include @@ -348,3 +349,16 @@ strtoclass(const char *str) { fatal("unknown class %s", str); return (rdclass); } + +isc_result_t +try_dir(const char *dirname) { + isc_result_t result; + isc_dir_t d; + + isc_dir_init(&d); + result = isc_dir_open(&d, dirname); + if (result == ISC_R_SUCCESS) { + isc_dir_close(&d); + } + return (result); +} diff --git a/bin/dnssec/dnssectool.h b/bin/dnssec/dnssectool.h index 82e1d62fef..c1a0ee1767 100644 --- a/bin/dnssec/dnssectool.h +++ b/bin/dnssec/dnssectool.h @@ -15,7 +15,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: dnssectool.h,v 1.27 2009/10/12 20:48:11 each Exp $ */ +/* $Id: dnssectool.h,v 1.28 2009/10/24 00:00:06 each Exp $ */ #ifndef DNSSECTOOL_H #define DNSSECTOOL_H 1 @@ -68,4 +68,6 @@ strtotime(const char *str, isc_int64_t now, isc_int64_t base); dns_rdataclass_t strtoclass(const char *str); +isc_result_t +try_dir(const char *dirname); #endif /* DNSSEC_DNSSECTOOL_H */