diff --git a/bin/dnssec/dnssectool.c b/bin/dnssec/dnssectool.c index 2912b14a65..9f6e1a187b 100644 --- a/bin/dnssec/dnssectool.c +++ b/bin/dnssec/dnssectool.c @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: dnssectool.c,v 1.31 2001/07/22 06:09:42 mayer Exp $ */ +/* $Id: dnssectool.c,v 1.32 2001/09/05 22:32:05 bwelling Exp $ */ #include @@ -23,7 +23,6 @@ #include #include -#include #include #include #include @@ -202,13 +201,23 @@ cleanup_logging(isc_log_t **logp) { void setup_entropy(isc_mem_t *mctx, const char *randomfile, isc_entropy_t **ectx) { isc_result_t result; + int usekeyboard = ISC_ENTROPY_KEYBOARDMAYBE; - result = isc_entropy_create(mctx, ectx); - if (result != ISC_R_SUCCESS) - fatal("could not create entropy object"); + REQUIRE(ectx != NULL); + + if (*ectx == NULL) { + result = isc_entropy_create(mctx, ectx); + if (result != ISC_R_SUCCESS) + fatal("could not create entropy object"); + } + + if (randomfile != NULL && strcmp(randomfile, "keyboard") == 0) { + usekeyboard = ISC_ENTROPY_KEYBOARDYES; + randomfile = NULL; + } result = isc_entropy_usebestsource(*ectx, &source, randomfile, - ISC_ENTROPY_KEYBOARDMAYBE); + usekeyboard); if (result != ISC_R_SUCCESS) fatal("could not initialize entropy source: %s", diff --git a/bin/rndc/rndc-confgen.c b/bin/rndc/rndc-confgen.c index 276f7a4d12..3decc90233 100644 --- a/bin/rndc/rndc-confgen.c +++ b/bin/rndc/rndc-confgen.c @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: rndc-confgen.c,v 1.9 2001/08/27 23:55:16 gson Exp $ */ +/* $Id: rndc-confgen.c,v 1.10 2001/09/05 22:32:06 bwelling Exp $ */ #include @@ -230,6 +230,10 @@ main(int argc, char **argv) { DO("create entropy context", isc_entropy_create(mctx, &ectx)); + if (randomfile != NULL && strcmp(randomfile, "keyboard") == 0) { + randomfile = NULL; + open_keyboard = ISC_ENTROPY_KEYBOARDYES; + } DO("start entropy source", isc_entropy_usebestsource(ectx, &entropy_source, randomfile, diff --git a/lib/isc/entropy.c b/lib/isc/entropy.c index 89c2c4ce6b..2c87ea264f 100644 --- a/lib/isc/entropy.c +++ b/lib/isc/entropy.c @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: entropy.c,v 1.4 2001/09/01 00:46:04 gson Exp $ */ +/* $Id: entropy.c,v 1.5 2001/09/05 22:32:08 bwelling Exp $ */ /* * This is the system independent part of the entropy module. It is @@ -1201,6 +1201,7 @@ isc_entropy_usebestsource(isc_entropy_t *ectx, isc_entropysource_t **source, { isc_result_t result; isc_result_t final_result = ISC_R_NOENTROPY; + isc_boolean_t userfile = ISC_TRUE; REQUIRE(VALID_ENTROPY(ectx)); REQUIRE(source != NULL && *source == NULL); @@ -1209,15 +1210,19 @@ isc_entropy_usebestsource(isc_entropy_t *ectx, isc_entropysource_t **source, use_keyboard == ISC_ENTROPY_KEYBOARDMAYBE); #ifdef PATH_RANDOMDEV - if (randomfile == NULL) + if (randomfile == NULL) { randomfile = PATH_RANDOMDEV; + userfile = ISC_FALSE; + } #endif - if (randomfile != NULL) { + if (randomfile != NULL && use_keyboard != ISC_ENTROPY_KEYBOARDYES) { result = isc_entropy_createfilesource(ectx, randomfile); if (result == ISC_R_SUCCESS && use_keyboard == ISC_ENTROPY_KEYBOARDMAYBE) use_keyboard = ISC_ENTROPY_KEYBOARDNO; + if (result != ISC_R_SUCCESS && userfile) + return (result); final_result = result; } diff --git a/lib/isc/include/isc/entropy.h b/lib/isc/include/isc/entropy.h index 6e5688f555..c2081220a2 100644 --- a/lib/isc/include/isc/entropy.h +++ b/lib/isc/include/isc/entropy.h @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: entropy.h,v 1.23 2001/06/22 17:05:53 tale Exp $ */ +/* $Id: entropy.h,v 1.24 2001/09/05 22:32:09 bwelling Exp $ */ #ifndef ISC_ENTROPY_H #define ISC_ENTROPY_H 1 @@ -112,12 +112,12 @@ typedef void (*isc_entropystop_t)(isc_entropysource_t *source, void *arg); * For use with isc_entropy_usebestsource(). * * _KEYBOARDYES - * Always use the keyboard as an entropy source. + * Use the keyboard as the only entropy source. * _KEYBOARDNO * Never use the keyboard as an entropy source. * _KEYBOARDMAYBE * Use the keyboard as an entropy source only if opening the - * random device or supplied filename fails. + * random device fails. */ #define ISC_ENTROPY_KEYBOARDYES 1 #define ISC_ENTROPY_KEYBOARDNO 2