]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib/randgen - warn when DOVECOT_SRAND is not able to be used
authorPhil Carmody <phil@dovecot.fi>
Tue, 30 Jan 2018 12:14:42 +0000 (14:14 +0200)
committerAki Tuomi <aki.tuomi@open-xchange.com>
Thu, 14 Feb 2019 09:38:07 +0000 (11:38 +0200)
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>
src/lib/randgen.c

index 6808a8432c2a750c0abd0ef9d496e96ecf8f5e52..ffb9c79b21bafbf8611571c67a0d4b183319e0be 100644 (file)
@@ -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)