Skip to content

Commit

Permalink
lib/randgen - warn when DOVECOT_SRAND is not able to be used
Browse files Browse the repository at this point in the history
As suggested by Jeff, it's friendly to warn if we're unable to act
upon the request for reproduceable random numbers because we're not
built for that.

Note, this deliberately permits a blank string, so that you can
silence the warning by prefixing a command with an empty
  DOVECOT_SRAND=
which is taken as an explicit attempt to disable use of the feature.

Signed-off-by: Phil Carmody <phil@dovecot.fi>
  • Loading branch information
Phil Carmody authored and cmouse committed Feb 14, 2019
1 parent 00a3985 commit 8463321
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/lib/randgen.c
Expand Up @@ -141,17 +141,21 @@ void random_fill(void *buf, size_t size)
void random_init(void)
{
unsigned int seed;
const char *env_seed;

if (init_refcount++ > 0)
return;

env_seed = getenv("DOVECOT_SRAND");
#ifdef DEBUG
const char *env_seed = getenv("DOVECOT_SRAND");
if (env_seed != NULL && str_to_uint(env_seed, &seed) >= 0) {
kiss_init(seed);
/* getrandom_present = FALSE; not needed, only used in random_read() */
goto normal_exit;
}
#else
if (env_seed != NULL && *env_seed != '\0')
i_warning("DOVECOT_SRAND is not available in non-debug builds");
#endif /* DEBUG */

#if defined(USE_RANDOM_DEV)
Expand Down

0 comments on commit 8463321

Please sign in to comment.