]> granicus.if.org Git - sudo/commitdiff
Use getentropy() in mkstemp/mkdtemp replacement.
authorTodd C. Miller <Todd.Miller@courtesan.com>
Fri, 30 Jun 2017 00:11:30 +0000 (18:11 -0600)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Fri, 30 Jun 2017 00:11:30 +0000 (18:11 -0600)
config.h.in
configure
configure.ac
lib/util/mktemp.c

index 0283f24c81e62d6087e57a3795b21fdbafd35ad1..cfa9108e173fe34f3bb34c893d4caee82924d679 100644 (file)
 /* Define to 1 if you have the `getdomainname' function. */
 #undef HAVE_GETDOMAINNAME
 
+/* Define to 1 if you have the `getentropy' function. */
+#undef HAVE_GETENTROPY
+
 /* Define to 1 if you have the `getgrouplist' function. */
 #undef HAVE_GETGROUPLIST
 
index 3631e71d7f75386b8d4f6bd2fdf4d84e0946f209..4cc93c00b2c88a8ed485b90bfb6d26fe9f17cb98 100755 (executable)
--- a/configure
+++ b/configure
@@ -20446,6 +20446,19 @@ _ACEOF
 fi
 done
 
+    if test X"$ac_cv_func_arc4random" != X"yes"; then
+       for ac_func in getentropy
+do :
+  ac_fn_c_check_func "$LINENO" "getentropy" "ac_cv_func_getentropy"
+if test "x$ac_cv_func_getentropy" = xyes; then :
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_GETENTROPY 1
+_ACEOF
+
+fi
+done
+
+    fi
     case " $LIBOBJS " in
   *" mktemp.$ac_objext "* ) ;;
   *) LIBOBJS="$LIBOBJS mktemp.$ac_objext"
index c94af6724105e87cbfcf0b287eb3e6ab9c46cdc7..07d794a56795b605fb0f03b895b4fd2d29e2b1b0 100644 (file)
@@ -2689,6 +2689,9 @@ AC_CHECK_FUNCS([closefrom], [], [AC_LIBOBJ(closefrom)
 AC_CHECK_FUNCS([mkstemps mkdtemp], [], [break])
 if test X"$ac_cv_func_mkstemps$ac_cv_func_mkdtemp" != X"yesyes"; then
     AC_CHECK_FUNCS([arc4random random lrand48], [break])
+    if test X"$ac_cv_func_arc4random" != X"yes"; then
+       AC_CHECK_FUNCS([getentropy])
+    fi
     AC_LIBOBJ(mktemp)
     # If either mkdtemp() or mkstemps() is missing, replace both.
     SUDO_APPEND_COMPAT_EXP(sudo_mkdtemp sudo_mkstemps)
index f5280bd29646e9fb8416507d6fdee1f0bfc48184..bd5e0d4b65fc724dd8251d3fb913d9c2c8119da1 100644 (file)
@@ -81,6 +81,10 @@ seed_random(void)
        SEED_T seed;
        int fd;
 
+# ifdef HAVE_GETENTROPY
+       /* Not really an fd, just has to be -1 on error. */
+       fd = getentropy(&seed, sizeof(seed));
+# else
        /*
         * Seed from /dev/urandom if possible.
         */
@@ -95,7 +99,7 @@ seed_random(void)
            if (nread != (ssize_t)sizeof(seed))
                fd = -1;
        }
-
+# endif /* HAVE_GETENTROPY */
        /*
         * If no /dev/urandom, seed from time of day and process id
         * multiplied by small primes.