Commit 747abb49 authored by Evan Hunt's avatar Evan Hunt

2658. [bug] dnssec-settime and dnssec-revoke didn't process

			key file paths correctly. [RT #20078]
parent 85eb2c76
2658. [bug] dnssec-settime and dnssec-revoke didn't process
key file paths correctly. [RT #20078]
2657. [cleanup] Lower "journal file <path> does not exist, creating it"
log level to debug 1. [RT #20058]
......
......@@ -14,7 +14,7 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: dnssec-revoke.c,v 1.6 2009/07/19 05:26:05 each Exp $ */
/* $Id: dnssec-revoke.c,v 1.7 2009/08/28 03:13:08 each Exp $ */
/*! \file */
......@@ -27,6 +27,7 @@
#include <isc/buffer.h>
#include <isc/commandline.h>
#include <isc/entropy.h>
#include <isc/file.h>
#include <isc/hash.h>
#include <isc/mem.h>
#include <isc/print.h>
......@@ -66,7 +67,7 @@ usage(void) {
int
main(int argc, char **argv) {
isc_result_t result;
char *filename = NULL, *dir= NULL;
char *filename = NULL, *dir = NULL;
char newname[1024], oldname[1024];
char keystr[KEY_FORMATSIZE];
char *endp;
......@@ -126,30 +127,11 @@ main(int argc, char **argv) {
if (argc > isc_commandline_index + 1)
fatal("Extraneous arguments");
if (dir == NULL) {
char *slash;
#ifdef _WIN32
char *backslash;
#endif
dir = strdup(argv[isc_commandline_index]);
filename = dir;
/* Figure out the directory name from the key name */
slash = strrchr(dir, '/');
#ifdef _WIN32
backslash = strrchr(dir, '\\');
if ((slash != NULL && backslash != NULL && backslash > slash) ||
(slash == NULL && backslash != NULL))
slash = backslash;
#endif
if (slash != NULL) {
*slash++ = '\0';
filename = slash;
} else {
free(dir);
dir = strdup(".");
}
if (dir != NULL) {
filename = argv[isc_commandline_index];
} else {
isc_file_splitpath(mctx, argv[isc_commandline_index],
&dir, &filename);
}
if (ectx == NULL)
......@@ -232,6 +214,7 @@ cleanup:
cleanup_entropy(&ectx);
if (verbose > 10)
isc_mem_stats(mctx, stdout);
isc_mem_free(mctx, dir);
isc_mem_destroy(&mctx);
return (0);
......
......@@ -14,7 +14,7 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: dnssec-settime.c,v 1.6 2009/07/21 02:57:39 jinmei Exp $ */
/* $Id: dnssec-settime.c,v 1.7 2009/08/28 03:13:08 each Exp $ */
/*! \file */
......@@ -29,6 +29,7 @@
#include <isc/buffer.h>
#include <isc/commandline.h>
#include <isc/entropy.h>
#include <isc/file.h>
#include <isc/hash.h>
#include <isc/mem.h>
#include <isc/print.h>
......@@ -188,39 +189,12 @@ main(int argc, char **argv) {
if (argc > isc_commandline_index + 1)
fatal("Extraneous arguments");
if (directory == NULL) {
char *slash;
#ifdef _WIN32
char *backslash;
#endif
directory = isc_mem_strdup(mctx, argv[isc_commandline_index]);
if (directory == NULL)
fatal("Failed to memory allocation for directory");
filename = directory;
/* Figure out the directory name from the key name */
slash = strrchr(directory, '/');
#ifdef _WIN32
backslash = strrchr(directory, '\\');
if ((slash != NULL && backslash != NULL && backslash > slash) ||
(slash == NULL && backslash != NULL))
slash = backslash;
#endif
if (slash != NULL) {
*slash++ = '\0';
filename = slash;
} else {
isc_mem_free(mctx, directory);
/* strdup could be skipped (see above) */
directory = isc_mem_strdup(mctx, ".");
if (directory == NULL) {
fatal("Failed to memory allocation "
"for directory");
}
}
} else
if (directory != NULL) {
filename = argv[isc_commandline_index];
} else {
isc_file_splitpath(mctx, argv[isc_commandline_index],
&directory, &filename);
}
if (ectx == NULL)
setup_entropy(mctx, NULL, &ectx);
......
......@@ -15,7 +15,7 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: file.h,v 1.36 2009/06/10 00:27:22 each Exp $ */
/* $Id: file.h,v 1.37 2009/08/28 03:13:08 each Exp $ */
#ifndef ISC_FILE_H
#define ISC_FILE_H 1
......@@ -259,6 +259,21 @@ isc_file_safecreate(const char *filename, FILE **fp);
* that only the owner can read/write it.
*/
isc_result_t
isc_file_splitpath(isc_mem_t *mctx, char *path,
char **dirname, char **basename);
/*%<
* Split a path into dirname and basename. If 'path' contains no slash
* (or, on windows, backslash), then '*dirname' is set to ".".
*
* Allocates memory for '*dirname', which can be freed with isc_mem_free().
*
* Returns:
* - ISC_R_SUCCESS on success
* - ISC_R_INVALIDFILE if 'path' is empty or ends with '/'
* - ISC_R_NOMEMORY if unable to allocate memory
*/
ISC_LANG_ENDDECLS
#endif /* ISC_FILE_H */
......@@ -48,7 +48,7 @@
* SUCH DAMAGE.
*/
/* $Id: file.c,v 1.54 2009/06/10 00:27:22 each Exp $ */
/* $Id: file.c,v 1.55 2009/08/28 03:13:08 each Exp $ */
/*! \file */
......@@ -68,6 +68,7 @@
#include <isc/dir.h>
#include <isc/file.h>
#include <isc/log.h>
#include <isc/mem.h>
#include <isc/random.h>
#include <isc/string.h>
#include <isc/time.h>
......@@ -478,3 +479,37 @@ isc_file_safecreate(const char *filename, FILE **fp) {
*fp = f;
return (ISC_R_SUCCESS);
}
isc_result_t
isc_file_splitpath(isc_mem_t *mctx, char *path, char **dirname, char **basename)
{
char *dir, *file, *slash;
slash = strrchr(path, '/');
if (slash == path) {
file = ++slash;
dir = isc_mem_strdup(mctx, "/");
} else if (slash != NULL) {
file = ++slash;
dir = isc_mem_allocate(mctx, slash - path);
if (dir != NULL)
strlcpy(dir, path, slash - path);
} else {
file = path;
dir = isc_mem_strdup(mctx, ".");
}
if (dir == NULL)
return (ISC_R_NOMEMORY);
if (*file == '\0') {
isc_mem_free(mctx, dir);
return (ISC_R_INVALIDFILE);
}
*dirname = dir;
*basename = file;
return (ISC_R_SUCCESS);
}
......@@ -15,7 +15,7 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: file.c,v 1.33 2009/06/11 23:47:55 tbox Exp $ */
/* $Id: file.c,v 1.34 2009/08/28 03:13:08 each Exp $ */
#include <config.h>
......@@ -31,6 +31,7 @@
#include <sys/utime.h>
#include <isc/file.h>
#include <isc/mem.h>
#include <isc/result.h>
#include <isc/time.h>
#include <isc/util.h>
......@@ -541,3 +542,43 @@ isc_file_safecreate(const char *filename, FILE **fp) {
*fp = f;
return (ISC_R_SUCCESS);
}
isc_result_t
isc_file_splitpath(isc_mem_t *mctx, char *path, char **dirname, char **basename)
{
char *dir, *file, *slash;
char *backslash;
slash = strrchr(path, '/');
backslash = strrchr(path, '\\');
if ((slash != NULL && backslash != NULL && backslash > slash) ||
(slash == NULL && backslash != NULL))
slash = backslash;
if (slash == path) {
file = ++slash;
dir = isc_mem_strdup(mctx, "/");
} else if (slash != NULL) {
file = ++slash;
dir = isc_mem_allocate(mctx, slash - path);
if (dir != NULL)
strlcpy(dir, path, slash - path);
} else {
file = path;
dir = isc_mem_strdup(mctx, ".");
}
if (dir == NULL)
return (ISC_R_NOMEMORY);
if (*file == '\0') {
isc_mem_free(mctx, dir);
return (ISC_R_INVALIDFILE);
}
*dirname = dir;
*basename = file;
return (ISC_R_SUCCESS);
}
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