From 9dcb6b314373b9aa882ba700c0bbf3a70c7a6d47 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sun, 4 Apr 2021 06:15:50 +0300 Subject: [PATCH 52/52] Enable /dev/urandom support when possible Add configure check to enable support for using /dev/urandom as entropy source for randseed. For cross-compiling the default is to disable support, but you can override that by setting ac_cv_dev_urandom=yes See osdn #41918 Signed-off-by: Marko Lindqvist --- configure.ac | 12 ++++++++++-- utility/randseed.c | 4 ++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/configure.ac b/configure.ac index 7768fb5f9b..9dafba5df0 100644 --- a/configure.ac +++ b/configure.ac @@ -1445,8 +1445,16 @@ AC_CHECK_LIB([bcrypt], [BCryptGenRandom], [ UTILITY_LIBS="${UTILITY_LIBS} -lbcrypt" ]) AC_CHECK_FUNCS([getentropy clock_gettime]) -dnl TODO: Reimplement this check, in a cross-compiling friendly way -dnl AC_CHECK_FILES([/dev/urandom]) +AC_CACHE_CHECK([for /dev/urandom], [ac_cv_dev_urandom], + [if test "x$cross_compiling" != "xyes" ; then + AC_CHECK_FILES([/dev/urandom], [ac_cv_dev_urandom=yes], [ac_cv_dev_urandom=no]) + else + dnl Pessimistic default when cross-compiling + ac_cv_dev_urandom=no + fi]) +if test "x${ac_cv_dev_urandom}" = "xyes" ; then + AC_DEFINE([HAVE_USABLE_URANDOM], [1], [Build in /dev/urandom support]) +fi AC_CHECK_FUNCS([_mkdir]) diff --git a/utility/randseed.c b/utility/randseed.c index be25c46490..3b7ad7d855 100644 --- a/utility/randseed.c +++ b/utility/randseed.c @@ -97,7 +97,7 @@ static bool generate_seed_bcryptgenrandom(randseed *ret) **************************************************************************/ static bool generate_seed_urandom(randseed *ret) { -#if HAVE__DEV_URANDOM /* the first slash turns to an extra underline */ +#if HAVE_USABLE_URANDOM /* * /dev/urandom should be available on most Unixen. The Wikipedia page * mentions Linux, FreeBSD, OpenBSD, macOS as well as Solaris, NetBSD, @@ -135,7 +135,7 @@ static bool generate_seed_urandom(randseed *ret) return TRUE; } -#endif /* HAVE__DEV_URANDOM */ +#endif /* HAVE_USABLE_URANDOM */ return FALSE; } -- 2.30.2