2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-30 14:07:59 +00:00

Clean up the implementation cleanup mechanism. Also remove ->issymmetric,

since it's easier to just do it in dst_api.c.
This commit is contained in:
Brian Wellington
2001-11-06 20:47:59 +00:00
parent 04f158ce9a
commit ba45e16a66
7 changed files with 46 additions and 76 deletions

View File

@@ -19,7 +19,7 @@
/* /*
* Principal Author: Brian Wellington * Principal Author: Brian Wellington
* $Id: dst_api.c,v 1.91 2001/11/06 18:08:07 bwelling Exp $ * $Id: dst_api.c,v 1.92 2001/11/06 20:47:52 bwelling Exp $
*/ */
#include <config.h> #include <config.h>
@@ -156,18 +156,15 @@ dst_lib_init(isc_mem_t *mctx, isc_entropy_t *ectx, unsigned int eflags) {
void void
dst_lib_destroy(void) { dst_lib_destroy(void) {
int i;
RUNTIME_CHECK(dst_initialized == ISC_TRUE); RUNTIME_CHECK(dst_initialized == ISC_TRUE);
dst_initialized = ISC_FALSE; dst_initialized = ISC_FALSE;
dst__hmacmd5_destroy(); for (i = 0; i < DST_MAX_ALGS; i++)
if (dst_t_func[i] != NULL && dst_t_func[i]->cleanup != NULL)
dst_t_func[i]->cleanup();
#ifdef OPENSSL #ifdef OPENSSL
dst__opensslrsa_destroy();
dst__openssldsa_destroy();
dst__openssldh_destroy();
dst__openssl_destroy(); dst__openssl_destroy();
#endif
#ifdef GSSAPI
dst__gssapi_destroy();
#endif #endif
if (dst_memory_pool != NULL) if (dst_memory_pool != NULL)
isc_mem_detach(&dst_memory_pool); isc_mem_detach(&dst_memory_pool);
@@ -893,6 +890,25 @@ read_public_key(const char *filename, isc_mem_t *mctx, dst_key_t **keyp) {
return (ret); return (ret);
} }
static isc_boolean_t
issymmetric(const dst_key_t *key) {
REQUIRE(dst_initialized == ISC_TRUE);
REQUIRE(VALID_KEY(key));
switch (key->key_alg) {
case DST_ALG_RSAMD5:
case DST_ALG_RSASHA1:
case DST_ALG_DSA:
case DST_ALG_DH:
return (ISC_FALSE);
case DST_ALG_HMACMD5:
case DST_ALG_GSSAPI:
return (ISC_TRUE);
default:
return (ISC_FALSE);
}
}
/* /*
* Writes a public key to disk in DNS format. * Writes a public key to disk in DNS format.
*/ */
@@ -944,7 +960,7 @@ write_public_key(const dst_key_t *key, const char *directory) {
if ((fp = fopen(filename, "w")) == NULL) if ((fp = fopen(filename, "w")) == NULL)
return (DST_R_WRITEERROR); return (DST_R_WRITEERROR);
if (key->func->issymmetric()) { if (issymmetric(key)) {
access = 0; access = 0;
isc_fsaccess_add(ISC_FSACCESS_OWNER, isc_fsaccess_add(ISC_FSACCESS_OWNER,
ISC_FSACCESS_READ | ISC_FSACCESS_WRITE, ISC_FSACCESS_READ | ISC_FSACCESS_WRITE,

View File

@@ -17,7 +17,7 @@
* PERFORMANCE OF THIS SOFTWARE. * PERFORMANCE OF THIS SOFTWARE.
*/ */
/* $Id: dst_internal.h,v 1.38 2001/08/28 03:58:25 marka Exp $ */ /* $Id: dst_internal.h,v 1.39 2001/11/06 20:47:53 bwelling Exp $ */
#ifndef DST_DST_INTERNAL_H #ifndef DST_DST_INTERNAL_H
#define DST_DST_INTERNAL_H 1 #define DST_DST_INTERNAL_H 1
@@ -86,7 +86,6 @@ struct dst_func {
const dst_key_t *key2); const dst_key_t *key2);
isc_result_t (*generate)(dst_key_t *key, int parms); isc_result_t (*generate)(dst_key_t *key, int parms);
isc_boolean_t (*isprivate)(const dst_key_t *key); isc_boolean_t (*isprivate)(const dst_key_t *key);
isc_boolean_t (*issymmetric)(void);
void (*destroy)(dst_key_t *key); void (*destroy)(dst_key_t *key);
/* conversion functions */ /* conversion functions */
@@ -94,6 +93,9 @@ struct dst_func {
isc_result_t (*fromdns)(dst_key_t *key, isc_buffer_t *data); isc_result_t (*fromdns)(dst_key_t *key, isc_buffer_t *data);
isc_result_t (*tofile)(const dst_key_t *key, const char *directory); isc_result_t (*tofile)(const dst_key_t *key, const char *directory);
isc_result_t (*fromfile)(dst_key_t *key, const char *filename); isc_result_t (*fromfile)(dst_key_t *key, const char *filename);
/* cleanup */
void (*cleanup)(void);
}; };
/* /*
@@ -112,12 +114,6 @@ isc_result_t dst__gssapi_init(struct dst_func **funcp);
*/ */
void dst__openssl_destroy(void); void dst__openssl_destroy(void);
void dst__hmacmd5_destroy(void);
void dst__opensslrsa_destroy(void);
void dst__openssldsa_destroy(void);
void dst__openssldh_destroy(void);
void dst__gssapi_destroy(void);
/* /*
* Memory allocators using the DST memory pool. * Memory allocators using the DST memory pool.
*/ */

View File

@@ -16,7 +16,7 @@
*/ */
/* /*
* $Id: gssapi_link.c,v 1.7 2001/03/21 20:45:55 bwelling Exp $ * $Id: gssapi_link.c,v 1.8 2001/11/06 20:47:54 bwelling Exp $
*/ */
#ifdef GSSAPI #ifdef GSSAPI
@@ -182,12 +182,6 @@ gssapi_isprivate(const dst_key_t *key) {
return (ISC_TRUE); return (ISC_TRUE);
} }
static isc_boolean_t
gssapi_issymmetric(const dst_key_t *key) {
UNUSED(key);
return (ISC_TRUE);
}
static void static void
gssapi_destroy(dst_key_t *key) { gssapi_destroy(dst_key_t *key) {
UNUSED(key); UNUSED(key);
@@ -205,12 +199,12 @@ static dst_func_t gssapi_functions = {
NULL, /* paramcompare */ NULL, /* paramcompare */
gssapi_generate, gssapi_generate,
gssapi_isprivate, gssapi_isprivate,
gssapi_issymmetric,
gssapi_destroy, gssapi_destroy,
NULL, /* todns */ NULL, /* todns */
NULL, /* fromdns */ NULL, /* fromdns */
NULL, /* tofile */ NULL, /* tofile */
NULL, /* fromfile */ NULL, /* fromfile */
NULL, /* cleanup */
}; };
isc_result_t isc_result_t
@@ -220,10 +214,6 @@ dst__gssapi_init(dst_func_t **funcp) {
return (ISC_R_SUCCESS); return (ISC_R_SUCCESS);
} }
void
dst__gssapi_destroy(void) {
}
#else #else
int gssapi_link_unneeded = 1; int gssapi_link_unneeded = 1;
#endif #endif

View File

@@ -19,7 +19,7 @@
/* /*
* Principal Author: Brian Wellington * Principal Author: Brian Wellington
* $Id: hmac_link.c,v 1.54 2001/09/15 00:01:52 bwelling Exp $ * $Id: hmac_link.c,v 1.55 2001/11/06 20:47:55 bwelling Exp $
*/ */
#include <config.h> #include <config.h>
@@ -156,11 +156,6 @@ hmacmd5_isprivate(const dst_key_t *key) {
return (ISC_TRUE); return (ISC_TRUE);
} }
static isc_boolean_t
hmacmd5_issymmetric(void) {
return (ISC_TRUE);
}
static void static void
hmacmd5_destroy(dst_key_t *key) { hmacmd5_destroy(dst_key_t *key) {
HMAC_Key *hkey = key->opaque; HMAC_Key *hkey = key->opaque;
@@ -272,12 +267,12 @@ static dst_func_t hmacmd5_functions = {
NULL, /* paramcompare */ NULL, /* paramcompare */
hmacmd5_generate, hmacmd5_generate,
hmacmd5_isprivate, hmacmd5_isprivate,
hmacmd5_issymmetric,
hmacmd5_destroy, hmacmd5_destroy,
hmacmd5_todns, hmacmd5_todns,
hmacmd5_fromdns, hmacmd5_fromdns,
hmacmd5_tofile, hmacmd5_tofile,
hmacmd5_fromfile, hmacmd5_fromfile,
NULL, /* cleanup */
}; };
isc_result_t isc_result_t
@@ -286,7 +281,3 @@ dst__hmacmd5_init(dst_func_t **funcp) {
*funcp = &hmacmd5_functions; *funcp = &hmacmd5_functions;
return (ISC_R_SUCCESS); return (ISC_R_SUCCESS);
} }
void
dst__hmacmd5_destroy(void) {
}

View File

@@ -19,7 +19,7 @@
/* /*
* Principal Author: Brian Wellington * Principal Author: Brian Wellington
* $Id: openssldh_link.c,v 1.39 2001/09/15 00:01:53 bwelling Exp $ * $Id: openssldh_link.c,v 1.40 2001/11/06 20:47:57 bwelling Exp $
*/ */
#ifdef OPENSSL #ifdef OPENSSL
@@ -170,11 +170,6 @@ openssldh_isprivate(const dst_key_t *key) {
return (ISC_TF(dh != NULL && dh->priv_key != NULL)); return (ISC_TF(dh != NULL && dh->priv_key != NULL));
} }
static isc_boolean_t
openssldh_issymmetric(void) {
return (ISC_FALSE);
}
static void static void
openssldh_destroy(dst_key_t *key) { openssldh_destroy(dst_key_t *key) {
DH *dh = key->opaque; DH *dh = key->opaque;
@@ -513,6 +508,13 @@ BN_fromhex(BIGNUM *b, const char *str) {
RUNTIME_CHECK(out != NULL); RUNTIME_CHECK(out != NULL);
} }
void
openssldh_cleanup(void) {
BN_free(&bn2);
BN_free(&bn768);
BN_free(&bn1024);
}
static dst_func_t openssldh_functions = { static dst_func_t openssldh_functions = {
NULL, /* createctx */ NULL, /* createctx */
NULL, /* destroyctx */ NULL, /* destroyctx */
@@ -524,12 +526,12 @@ static dst_func_t openssldh_functions = {
openssldh_paramcompare, openssldh_paramcompare,
openssldh_generate, openssldh_generate,
openssldh_isprivate, openssldh_isprivate,
openssldh_issymmetric,
openssldh_destroy, openssldh_destroy,
openssldh_todns, openssldh_todns,
openssldh_fromdns, openssldh_fromdns,
openssldh_tofile, openssldh_tofile,
openssldh_fromfile, openssldh_fromfile,
openssldh_cleanup,
}; };
isc_result_t isc_result_t
@@ -545,11 +547,4 @@ dst__openssldh_init(dst_func_t **funcp) {
return (ISC_R_SUCCESS); return (ISC_R_SUCCESS);
} }
void
dst__openssldh_destroy(void) {
BN_free(&bn2);
BN_free(&bn768);
BN_free(&bn1024);
}
#endif /* OPENSSL */ #endif /* OPENSSL */

View File

@@ -17,7 +17,7 @@
* PERFORMANCE OF THIS SOFTWARE. * PERFORMANCE OF THIS SOFTWARE.
*/ */
/* $Id: openssldsa_link.c,v 1.5 2001/09/15 00:01:54 bwelling Exp $ */ /* $Id: openssldsa_link.c,v 1.6 2001/11/06 20:47:58 bwelling Exp $ */
#ifdef OPENSSL #ifdef OPENSSL
@@ -206,11 +206,6 @@ openssldsa_isprivate(const dst_key_t *key) {
return (ISC_TF(dsa != NULL && dsa->priv_key != NULL)); return (ISC_TF(dsa != NULL && dsa->priv_key != NULL));
} }
static isc_boolean_t
openssldsa_issymmetric(void) {
return (ISC_FALSE);
}
static void static void
openssldsa_destroy(dst_key_t *key) { openssldsa_destroy(dst_key_t *key) {
DSA *dsa = key->opaque; DSA *dsa = key->opaque;
@@ -424,12 +419,12 @@ static dst_func_t openssldsa_functions = {
NULL, /* paramcompare */ NULL, /* paramcompare */
openssldsa_generate, openssldsa_generate,
openssldsa_isprivate, openssldsa_isprivate,
openssldsa_issymmetric,
openssldsa_destroy, openssldsa_destroy,
openssldsa_todns, openssldsa_todns,
openssldsa_fromdns, openssldsa_fromdns,
openssldsa_tofile, openssldsa_tofile,
openssldsa_fromfile, openssldsa_fromfile,
NULL, /* cleanup */
}; };
isc_result_t isc_result_t
@@ -439,8 +434,4 @@ dst__openssldsa_init(dst_func_t **funcp) {
return (ISC_R_SUCCESS); return (ISC_R_SUCCESS);
} }
void
dst__openssldsa_destroy(void) {
}
#endif /* OPENSSL */ #endif /* OPENSSL */

View File

@@ -17,7 +17,7 @@
/* /*
* Principal Author: Brian Wellington * Principal Author: Brian Wellington
* $Id: opensslrsa_link.c,v 1.14 2001/11/06 17:59:50 bwelling Exp $ * $Id: opensslrsa_link.c,v 1.15 2001/11/06 20:47:59 bwelling Exp $
*/ */
#ifdef OPENSSL #ifdef OPENSSL
@@ -243,11 +243,6 @@ opensslrsa_isprivate(const dst_key_t *key) {
return (ISC_TF(rsa != NULL && rsa->d != NULL)); return (ISC_TF(rsa != NULL && rsa->d != NULL));
} }
static isc_boolean_t
opensslrsa_issymmetric(void) {
return (ISC_FALSE);
}
static void static void
opensslrsa_destroy(dst_key_t *key) { opensslrsa_destroy(dst_key_t *key) {
RSA *rsa = key->opaque; RSA *rsa = key->opaque;
@@ -507,12 +502,12 @@ static dst_func_t opensslrsa_functions = {
NULL, /* paramcompare */ NULL, /* paramcompare */
opensslrsa_generate, opensslrsa_generate,
opensslrsa_isprivate, opensslrsa_isprivate,
opensslrsa_issymmetric,
opensslrsa_destroy, opensslrsa_destroy,
opensslrsa_todns, opensslrsa_todns,
opensslrsa_fromdns, opensslrsa_fromdns,
opensslrsa_tofile, opensslrsa_tofile,
opensslrsa_fromfile, opensslrsa_fromfile,
NULL, /* cleanup */
}; };
isc_result_t isc_result_t
@@ -522,8 +517,4 @@ dst__opensslrsa_init(dst_func_t **funcp) {
return (ISC_R_SUCCESS); return (ISC_R_SUCCESS);
} }
void
dst__opensslrsa_destroy(void) {
}
#endif /* OPENSSL */ #endif /* OPENSSL */