dovecot-2.0: If /dev/arandom exists (OpenBSD), use it instead of...

dovecot at dovecot.org dovecot at dovecot.org
Mon May 4 05:05:09 EEST 2009


details:   http://hg.dovecot.org/dovecot-2.0/rev/1849c4269ad8
changeset: 9204:1849c4269ad8
user:      Timo Sirainen <tss at iki.fi>
date:      Sun May 03 22:04:39 2009 -0400
description:
If /dev/arandom exists (OpenBSD), use it instead of /dev/urandom.

diffstat:

2 files changed, 20 insertions(+), 12 deletions(-)
configure.in      |   18 ++++++++++++++----
src/lib/randgen.c |   14 ++++++--------

diffs (75 lines):

diff -r a035febf39d4 -r 1849c4269ad8 configure.in
--- a/configure.in	Sun May 03 21:35:28 2009 -0400
+++ b/configure.in	Sun May 03 22:04:39 2009 -0400
@@ -853,14 +853,24 @@ AC_DEFINE_UNQUOTED(MEM_ALIGN_SIZE, $mem_
 AC_DEFINE_UNQUOTED(MEM_ALIGN_SIZE, $mem_align, Required memory alignment)
 
 dnl * find random source
-AC_MSG_CHECKING([for /dev/urandom])
-if test -c /dev/urandom || test -s /dev/urandom; then
+AC_MSG_CHECKING([for OpenBSD /dev/arandom])
+if test -c /dev/arandom; then
   AC_MSG_RESULT(yes)
-  AC_DEFINE(HAVE_DEV_URANDOM,, Define if you have /dev/urandom)
+  AC_DEFINE(DEV_URANDOM_PATH, "/dev/arandom", Path to /dev/urandom)
   have_random_source=yes
 else
   AC_MSG_RESULT(no)
-
+  AC_MSG_CHECKING([for /dev/urandom])
+  if test -c /dev/urandom || test -s /dev/urandom; then
+    AC_MSG_RESULT(yes)
+    AC_DEFINE(DEV_URANDOM_PATH, "/dev/urandom", Path to /dev/urandom)
+    have_random_source=yes
+  else
+    AC_MSG_RESULT(no)
+  fi
+fi
+
+if test "$have_random_source" != "yes"; then
   AC_CHECK_HEADER(openssl/rand.h, [
     AC_DEFINE(HAVE_OPENSSL_RAND_H,, Define if you have openssl/rand.h)
     LIBS="$LIBS -lcrypto"
diff -r a035febf39d4 -r 1849c4269ad8 src/lib/randgen.c
--- a/src/lib/randgen.c	Sun May 03 21:35:28 2009 -0400
+++ b/src/lib/randgen.c	Sun May 03 22:04:39 2009 -0400
@@ -5,9 +5,7 @@
 
 #include <stdlib.h>
 
-#ifdef HAVE_DEV_URANDOM
-
-#define URANDOM_PATH "/dev/urandom"
+#ifdef DEV_URANDOM_PATH
 
 #include "fd-close-on-exec.h"
 #include <unistd.h>
@@ -28,9 +26,9 @@ void random_fill(void *buf, size_t size)
 		ret = read(urandom_fd, (char *) buf + pos, size - pos);
 		if (unlikely(ret <= 0)) {
 			if (ret == 0)
-				i_fatal("EOF when reading from "URANDOM_PATH);
+				i_fatal("EOF when reading from "DEV_URANDOM_PATH);
 			else if (errno != EINTR)
-				i_fatal("read("URANDOM_PATH") failed: %m");
+				i_fatal("read("DEV_URANDOM_PATH") failed: %m");
 		} else {
 			pos += ret;
 		}
@@ -44,13 +42,13 @@ void random_init(void)
 	if (init_refcount++ > 0)
 		return;
 
-	urandom_fd = open(URANDOM_PATH, O_RDONLY);
+	urandom_fd = open(DEV_URANDOM_PATH, O_RDONLY);
 	if (urandom_fd == -1) {
 		if (errno == ENOENT) {
-			i_fatal(URANDOM_PATH" doesn't exist, "
+			i_fatal(DEV_URANDOM_PATH" doesn't exist, "
 				"currently we require it");
 		} else {
-			i_fatal("Can't open "URANDOM_PATH": %m");
+			i_fatal("Can't open "DEV_URANDOM_PATH": %m");
 		}
 	}
 


More information about the dovecot-cvs mailing list