mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-31 14:35:26 +00:00
consolidated duplicated code for filename mangling, removed sanity checks that
weren't.
This commit is contained in:
@@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Principal Author: Brian Wellington
|
* Principal Author: Brian Wellington
|
||||||
* $Id: dst_api.c,v 1.78 2001/05/04 17:57:33 gson Exp $
|
* $Id: dst_api.c,v 1.79 2001/05/09 23:04:47 bwelling Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
@@ -33,6 +33,7 @@
|
|||||||
#include <isc/lex.h>
|
#include <isc/lex.h>
|
||||||
#include <isc/mem.h>
|
#include <isc/mem.h>
|
||||||
#include <isc/once.h>
|
#include <isc/once.h>
|
||||||
|
#include <isc/print.h>
|
||||||
#include <isc/random.h>
|
#include <isc/random.h>
|
||||||
#include <isc/string.h>
|
#include <isc/string.h>
|
||||||
#include <isc/time.h>
|
#include <isc/time.h>
|
||||||
@@ -791,23 +792,17 @@ read_public_key(const char *filename, isc_mem_t *mctx, dst_key_t **keyp) {
|
|||||||
dns_rdata_t rdata = DNS_RDATA_INIT;
|
dns_rdata_t rdata = DNS_RDATA_INIT;
|
||||||
unsigned int opt = ISC_LEXOPT_DNSMULTILINE;
|
unsigned int opt = ISC_LEXOPT_DNSMULTILINE;
|
||||||
char *newfilename;
|
char *newfilename;
|
||||||
|
unsigned int newfilenamelen;
|
||||||
isc_textregion_t r;
|
isc_textregion_t r;
|
||||||
dns_rdataclass_t rdclass = dns_rdataclass_in;
|
dns_rdataclass_t rdclass = dns_rdataclass_in;
|
||||||
|
|
||||||
if (strlen(filename) < 8)
|
newfilenamelen = strlen(filename) + 5;
|
||||||
return (DST_R_INVALIDPUBLICKEY);
|
newfilename = isc_mem_get(mctx, newfilenamelen);
|
||||||
|
|
||||||
newfilename = isc_mem_get(mctx, strlen(filename) + 5);
|
|
||||||
if (newfilename == NULL)
|
if (newfilename == NULL)
|
||||||
return (ISC_R_NOMEMORY);
|
return (ISC_R_NOMEMORY);
|
||||||
strcpy(newfilename, filename);
|
ret = dst__file_addsuffix(newfilename, newfilenamelen, filename,
|
||||||
|
".key");
|
||||||
if (strcmp(filename + strlen(filename) - 8, ".private") == 0)
|
INSIST(ret == ISC_R_SUCCESS);
|
||||||
sprintf(newfilename + strlen(filename) - 8, ".key");
|
|
||||||
else if (strcmp(filename + strlen(filename) - 1, ".") == 0)
|
|
||||||
sprintf(newfilename + strlen(filename), "key");
|
|
||||||
else if (strcmp(filename + strlen(filename) - 4, ".key") != 0)
|
|
||||||
sprintf(newfilename + strlen(filename), ".key");
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Open the file and read its formatted contents
|
* Open the file and read its formatted contents
|
||||||
@@ -886,7 +881,7 @@ read_public_key(const char *filename, isc_mem_t *mctx, dst_key_t **keyp) {
|
|||||||
isc_lex_close(lex);
|
isc_lex_close(lex);
|
||||||
isc_lex_destroy(&lex);
|
isc_lex_destroy(&lex);
|
||||||
}
|
}
|
||||||
isc_mem_put(mctx, newfilename, strlen(filename) + 5);
|
isc_mem_put(mctx, newfilename, newfilenamelen);
|
||||||
|
|
||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
@@ -1057,6 +1052,26 @@ frombuffer(dns_name_t *name, const unsigned int alg, const unsigned int flags,
|
|||||||
return (ISC_R_SUCCESS);
|
return (ISC_R_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isc_result_t
|
||||||
|
dst__file_addsuffix(char *filename, unsigned int len,
|
||||||
|
const char *ofilename, const char *suffix)
|
||||||
|
{
|
||||||
|
unsigned int olen = strlen(ofilename);
|
||||||
|
int n;
|
||||||
|
|
||||||
|
if (olen > 1 && ofilename[olen - 1] == '.')
|
||||||
|
olen -= 1;
|
||||||
|
else if (olen > 8 && strcmp(ofilename + olen - 8, ".private") == 0)
|
||||||
|
olen -= 8;
|
||||||
|
else if (olen > 4 && strcmp(ofilename + olen - 8, ".key") == 0)
|
||||||
|
olen -= 4;
|
||||||
|
|
||||||
|
n = snprintf(filename, len, "%.*s%s", olen, ofilename, suffix);
|
||||||
|
if (n < 0)
|
||||||
|
return (ISC_R_NOSPACE);
|
||||||
|
return (ISC_R_SUCCESS);
|
||||||
|
}
|
||||||
|
|
||||||
void *
|
void *
|
||||||
dst__mem_alloc(size_t size) {
|
dst__mem_alloc(size_t size) {
|
||||||
INSIST(dst_memory_pool != NULL);
|
INSIST(dst_memory_pool != NULL);
|
||||||
|
@@ -17,7 +17,7 @@
|
|||||||
* PERFORMANCE OF THIS SOFTWARE.
|
* PERFORMANCE OF THIS SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* $Id: dst_internal.h,v 1.34 2001/01/24 02:22:53 bwelling Exp $ */
|
/* $Id: dst_internal.h,v 1.35 2001/05/09 23:04:49 bwelling Exp $ */
|
||||||
|
|
||||||
#ifndef DST_DST_INTERNAL_H
|
#ifndef DST_DST_INTERNAL_H
|
||||||
#define DST_DST_INTERNAL_H 1
|
#define DST_DST_INTERNAL_H 1
|
||||||
@@ -133,6 +133,13 @@ void * dst__mem_realloc(void *ptr, size_t size);
|
|||||||
isc_result_t dst__entropy_getdata(void *buf, unsigned int len,
|
isc_result_t dst__entropy_getdata(void *buf, unsigned int len,
|
||||||
isc_boolean_t pseudo);
|
isc_boolean_t pseudo);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Generic helper functions.
|
||||||
|
*/
|
||||||
|
isc_result_t
|
||||||
|
dst__file_addsuffix(char *filename, unsigned int len,
|
||||||
|
const char *ofilename, const char *suffix);
|
||||||
|
|
||||||
ISC_LANG_ENDDECLS
|
ISC_LANG_ENDDECLS
|
||||||
|
|
||||||
#endif /* DST_DST_INTERNAL_H */
|
#endif /* DST_DST_INTERNAL_H */
|
||||||
|
@@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Principal Author: Brian Wellington
|
* Principal Author: Brian Wellington
|
||||||
* $Id: dst_parse.c,v 1.28 2001/01/24 02:22:54 bwelling Exp $
|
* $Id: dst_parse.c,v 1.29 2001/05/09 23:04:50 bwelling Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
@@ -195,24 +195,18 @@ dst__privstruct_parsefile(dst_key_t *key, const dns_keytag_t id,
|
|||||||
isc_token_t token;
|
isc_token_t token;
|
||||||
unsigned int opt = ISC_LEXOPT_EOL;
|
unsigned int opt = ISC_LEXOPT_EOL;
|
||||||
char *newfilename;
|
char *newfilename;
|
||||||
|
int newfilenamelen;
|
||||||
isc_result_t ret;
|
isc_result_t ret;
|
||||||
|
|
||||||
REQUIRE(priv != NULL);
|
REQUIRE(priv != NULL);
|
||||||
|
|
||||||
if (strlen(filename) < 8)
|
newfilenamelen = strlen(filename) + 9;
|
||||||
return (DST_R_INVALIDPRIVATEKEY);
|
newfilename = isc_mem_get(mctx, newfilenamelen);
|
||||||
|
|
||||||
newfilename = isc_mem_get(mctx, strlen(filename) + 9);
|
|
||||||
if (newfilename == NULL)
|
if (newfilename == NULL)
|
||||||
return (ISC_R_NOMEMORY);
|
return (ISC_R_NOMEMORY);
|
||||||
strcpy(newfilename, filename);
|
ret = dst__file_addsuffix(newfilename, newfilenamelen, filename,
|
||||||
|
".private");
|
||||||
if (strcmp(filename + strlen(filename) - 4, ".key") == 0)
|
INSIST(ret == ISC_R_SUCCESS);
|
||||||
sprintf(newfilename + strlen(filename) - 4, ".private");
|
|
||||||
else if (strcmp(filename + strlen(filename) - 1, ".") == 0)
|
|
||||||
sprintf(newfilename + strlen(filename), "private");
|
|
||||||
else if (strcmp(filename + strlen(filename) - 8, ".private") != 0)
|
|
||||||
sprintf(newfilename + strlen(filename), ".private");
|
|
||||||
|
|
||||||
priv->nelements = 0;
|
priv->nelements = 0;
|
||||||
|
|
||||||
@@ -338,7 +332,7 @@ dst__privstruct_parsefile(dst_key_t *key, const dns_keytag_t id,
|
|||||||
|
|
||||||
isc_lex_close(lex);
|
isc_lex_close(lex);
|
||||||
isc_lex_destroy(&lex);
|
isc_lex_destroy(&lex);
|
||||||
isc_mem_put(mctx, newfilename, strlen(filename) + 9);
|
isc_mem_put(mctx, newfilename, newfilenamelen);
|
||||||
|
|
||||||
return (ISC_R_SUCCESS);
|
return (ISC_R_SUCCESS);
|
||||||
|
|
||||||
@@ -347,7 +341,7 @@ fail:
|
|||||||
isc_lex_close(lex);
|
isc_lex_close(lex);
|
||||||
isc_lex_destroy(&lex);
|
isc_lex_destroy(&lex);
|
||||||
}
|
}
|
||||||
isc_mem_put(mctx, newfilename, strlen(filename) + 9);
|
isc_mem_put(mctx, newfilename, newfilenamelen);
|
||||||
|
|
||||||
priv->nelements = n;
|
priv->nelements = n;
|
||||||
dst__privstruct_free(priv, mctx);
|
dst__privstruct_free(priv, mctx);
|
||||||
|
Reference in New Issue
Block a user