From 806fd09a50a91e6b39433bbb270d755c6b66e04e Mon Sep 17 00:00:00 2001 From: Phil Carmody Date: Tue, 30 Jan 2018 14:14:42 +0200 Subject: [PATCH] lib/randgen - warn when DOVECOT_SRAND is not able to be used 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 --- src/lib/randgen.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/lib/randgen.c b/src/lib/randgen.c index 77b4422ed1..6b2f3ed20f 100644 --- a/src/lib/randgen.c +++ b/src/lib/randgen.c @@ -142,17 +142,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) -- 2.47.3