From: Art Cancro Date: Wed, 12 Jan 2022 21:04:12 +0000 (-0500) Subject: Seed the random number generator before the config system is initialized. X-Git-Tag: v950~49 X-Git-Url: https://code.citadel.org/?a=commitdiff_plain;ds=sidebyside;h=d3a76479a895c71eb734d2c39a116e0f4f31537d;p=citadel.git Seed the random number generator before the config system is initialized. --- diff --git a/citadel/citserver.c b/citadel/citserver.c index f12543acc..2d829f1dd 100644 --- a/citadel/citserver.c +++ b/citadel/citserver.c @@ -29,13 +29,32 @@ int panic_fd; int openid_level_supported = 0; -// Various things that need to be initialized at startup -void master_startup(void) { +// We need pseudo-random numbers for a few things. Seed generously. +void seed_random_number_generator(void) { + FILE *urandom; struct timeval tv; unsigned int seed; - FILE *urandom; + + syslog(LOG_INFO, "Seeding the pseudo-random number generator..."); + urandom = fopen("/dev/urandom", "r"); + if (urandom != NULL) { + if (fread(&seed, sizeof seed, 1, urandom) == -1) { + syslog(LOG_ERR, "citserver: failed to read random seed: %m"); + } + fclose(urandom); + } + else { + gettimeofday(&tv, NULL); + seed = tv.tv_usec; + } + srand(seed); + srandom(seed); +} + + +// Various things that need to be initialized at startup +void master_startup(void) { struct ctdlroom qrbuf; - int rv; struct passwd *pw; gid_t gid; @@ -58,6 +77,7 @@ void master_startup(void) { open_databases(); // Load site-specific configuration + seed_random_number_generator(); // must be done before config system syslog(LOG_INFO, "Initializing configuration system"); initialize_config_system(); validate_config(); @@ -91,22 +111,6 @@ void master_startup(void) { CtdlPutRoomLock(&qrbuf); } - syslog(LOG_INFO, "Seeding the pseudo-random number generator..."); - urandom = fopen("/dev/urandom", "r"); - if (urandom != NULL) { - rv = fread(&seed, sizeof seed, 1, urandom); - if (rv == -1) { - syslog(LOG_ERR, "citserver: failed to read random seed: %m"); - } - fclose(urandom); - } - else { - gettimeofday(&tv, NULL); - seed = tv.tv_usec; - } - srand(seed); - srandom(seed); - syslog(LOG_DEBUG, "master_startup() finished"); }