From e919c87e296cd1486750079a274e6336cb30810b Mon Sep 17 00:00:00 2001
From: Simon Josefsson <simon@josefsson.org>
Date: Wed, 8 Mar 2006 13:40:30 +0000
Subject: [PATCH] Fix gc-random module.

---
 lib/ChangeLog   |  5 +++++
 lib/gc-gnulib.c |  3 +++
 m4/ChangeLog    |  5 +++++
 m4/gc-random.m4 | 24 +++++++++++++++---------
 4 files changed, 28 insertions(+), 9 deletions(-)

diff --git a/lib/ChangeLog b/lib/ChangeLog
index 6ab7de94d3..bda1d1cb2d 100644
--- a/lib/ChangeLog
+++ b/lib/ChangeLog
@@ -1,3 +1,8 @@
+2006-03-08  Simon Josefsson  <jas@extundo.com>
+
+	* gc-gnulib.c (randomize): Don't open files called 'no', they
+	signal that configure disabled the device.
+
 2006-03-07  Paul Eggert  <eggert@cs.ucla.edu>
 
 	* c-stack.c: Include unistd.h unconditionally, since we now assume
diff --git a/lib/gc-gnulib.c b/lib/gc-gnulib.c
index 111c4a19e4..a91a7c39a4 100644
--- a/lib/gc-gnulib.c
+++ b/lib/gc-gnulib.c
@@ -109,6 +109,9 @@ randomize (int level, char *data, size_t datalen)
       break;
     }
 
+  if (strcmp (device, "no") == 0)
+    return GC_RANDOM_ERROR;
+
   fd = open (device, O_RDONLY);
   if (fd < 0)
     return GC_RANDOM_ERROR;
diff --git a/m4/ChangeLog b/m4/ChangeLog
index f3043be793..33e4987cc6 100644
--- a/m4/ChangeLog
+++ b/m4/ChangeLog
@@ -1,3 +1,8 @@
+2006-03-08  Simon Josefsson  <jas@extundo.com>
+
+	* gc-random.m4: Permit 'no' as variable values and fix warnings,
+	suggested by Ralf Wildenhues <Ralf.Wildenhues@gmx.de>.
+
 2006-03-08  Simon Josefsson  <jas@extundo.com>
 
 	* gc-random.m4: Call AC_CANONICAL_HOST and use $host_os instead of
diff --git a/m4/gc-random.m4 b/m4/gc-random.m4
index 516646e17c..fb331384e4 100644
--- a/m4/gc-random.m4
+++ b/m4/gc-random.m4
@@ -41,30 +41,36 @@ AC_DEFUN([gl_GC_RANDOM],
   AC_ARG_ENABLE(random-device,
 	AC_HELP_STRING([--enable-random-device],
 		[device with (strong) randomness (for Nettle)]),
-	test "$enableval" != "no" && NAME_OF_RANDOM_DEVICE=$enableval)
+	NAME_OF_RANDOM_DEVICE=$enableval)
   AC_MSG_RESULT($NAME_OF_RANDOM_DEVICE)
 
   AC_MSG_CHECKING([device with pseudo random data...])
   AC_ARG_ENABLE(pseudo-random-device,
 	AC_HELP_STRING([--enable-pseudo-random-device],
 		[device with pseudo randomness (for Nettle)]),
-	test "$enableval" != "no" && NAME_OF_PSEUDO_RANDOM_DEVICE=$enableval)
+	NAME_OF_PSEUDO_RANDOM_DEVICE=$enableval)
   AC_MSG_RESULT($NAME_OF_PSEUDO_RANDOM_DEVICE)
 
   AC_MSG_CHECKING([device with unpredictable data for nonces...])
   AC_ARG_ENABLE(nonce-device,
 	AC_HELP_STRING([--enable-nonce-device],
 		[device with unpredictable nonces (for Nettle)]),
-	test "$enableval" != "no" && NAME_OF_NONCE_DEVICE=$enableval)
+	NAME_OF_NONCE_DEVICE=$enableval)
   AC_MSG_RESULT($NAME_OF_NONCE_DEVICE)
 
   if test "$cross_compiling" != yes; then
-    AC_CHECK_FILE($NAME_OF_RANDOM_DEVICE,,
-      AC_MSG_WARN([[device for (strong) random data `$NAME_OF_RANDOM_DEVICE' does not exist]]))
-    AC_CHECK_FILE($NAME_OF_PSEUDO_RANDOM_DEVICE,,
-      AC_MSG_WARN([[device for pseudo-random data `$NAME_OF_PSEUDO_RANDOM_DEVICE' does not exist]]))
-    AC_CHECK_FILE($NAME_OF_NONCE_DEVICE,,
-      AC_MSG_WARN([[device for unpredictable nonces `$NAME_OF_NONCE_DEVICE' does not exist]]))
+    if test "$NAME_OF_RANDOM_DEVICE" != "no"; then
+      AC_CHECK_FILE($NAME_OF_RANDOM_DEVICE,,
+        AC_MSG_WARN([[Device `$NAME_OF_RANDOM_DEVICE' does not exist, consider to use --enable-random-device]]))
+    fi
+    if test "$NAME_OF_PSEUDO_RANDOM_DEVICE" != "no"; then
+      AC_CHECK_FILE($NAME_OF_PSEUDO_RANDOM_DEVICE,,
+        AC_MSG_WARN([[Device `$NAME_OF_PSEUDO_RANDOM_DEVICE' does not exist, consider to use --enable-pseudo-random-device]]))
+    fi
+    if test "$NAME_OF_NONCE_RANDOM_DEVICE" != "no"; then
+      AC_CHECK_FILE($NAME_OF_NONCE_DEVICE,,
+        AC_MSG_WARN([[Device `$NAME_OF_NONCE_RANDOM_DEVICE' does not exist, consider to use --enable-nonce-device]]))
+    fi
   else
     AC_MSG_NOTICE([[Cross compiling, assuming random devices exists on the target host...]])  
   fi
-- 
2.30.2