0b18b1
From 31612e4f76eeb07d0fffa33814ce5edef04b286a Mon Sep 17 00:00:00 2001
6e9104
From: Evan Hunt <each@isc.org>
6e9104
Date: Tue, 12 Sep 2017 19:05:46 -0700
6e9104
Subject: [PATCH] rebased rt31459c
6e9104
6e9104
[rt31459d] update the newer tools
6e9104
6e9104
[rt31459d] setup entropy in dns_lib_init()
6e9104
6e9104
[rt31459d] silence compiler warning
6e9104
6e9104
DNS_OPENSSL_LIBS -> DST_OPENSSL_LIBS
6e9104
6e9104
Include new unit test
6e9104
---
0b18b1
 bin/tests/system/pipelined/pipequeries.c |  1 +
0b18b1
 bin/tests/system/pipelined/tests.sh      |  4 +-
0b18b1
 bin/tests/system/tkey/keycreate.c        |  1 +
0b18b1
 bin/tests/system/tkey/keydelete.c        |  1 +
0b18b1
 bin/tests/system/tkey/tests.sh           |  8 +-
0b18b1
 configure                                | 97 ++++++++++--------------
0b18b1
 lib/dns/include/dst/dst.h                |  8 ++
0b18b1
 lib/dns/lib.c                            |  1 +
0b18b1
 lib/dns/tests/Makefile.in                |  5 ++
0b18b1
 lib/isc/include/isc/types.h              |  2 +
0b18b1
 win32utils/Configure                     |  4 +-
0b18b1
 11 files changed, 66 insertions(+), 66 deletions(-)
6e9104
6e9104
diff --git a/bin/tests/system/pipelined/pipequeries.c b/bin/tests/system/pipelined/pipequeries.c
0b18b1
index 74de833..4fac3cb 100644
6e9104
--- a/bin/tests/system/pipelined/pipequeries.c
6e9104
+++ b/bin/tests/system/pipelined/pipequeries.c
0b18b1
@@ -205,6 +205,7 @@ sendqueries(isc_task_t *task, isc_event_t *event) {
6e9104
 
6e9104
 int
6e9104
 main(int argc, char *argv[]) {
6e9104
+	char *randomfile = NULL;
6e9104
 	isc_sockaddr_t bind_any;
6e9104
 	struct in_addr inaddr;
6e9104
 	isc_result_t result;
6e9104
diff --git a/bin/tests/system/pipelined/tests.sh b/bin/tests/system/pipelined/tests.sh
1e4169
index 61f1ff7..ed1302a 100644
6e9104
--- a/bin/tests/system/pipelined/tests.sh
6e9104
+++ b/bin/tests/system/pipelined/tests.sh
6e9104
@@ -19,7 +19,7 @@ status=0
6e9104
 
6e9104
 echo_i "check pipelined TCP queries"
6e9104
 ret=0
6e9104
-$PIPEQUERIES -p ${PORT} < input > raw || ret=1
6e9104
+$PIPEQUERIES -p ${PORT} -r $RANDFILE < input > raw || ret=1
6e9104
 awk '{ print $1 " " $5 }' < raw > output
6e9104
 sort < output > output-sorted
1e4169
 $DIFF ref output-sorted || { ret=1 ; echo_i "diff sorted failed"; }
6e9104
@@ -43,7 +43,7 @@ status=`expr $status + $ret`
6e9104
 
6e9104
 echo_i "check keep-response-order"
6e9104
 ret=0
6e9104
-$PIPEQUERIES -p ${PORT} ++ < inputb > rawb || ret=1
6e9104
+$PIPEQUERIES -p ${PORT} -r $RANDFILE ++ < inputb > rawb || ret=1
6e9104
 awk '{ print $1 " " $5 }' < rawb > outputb
1e4169
 $DIFF refb outputb || ret=1
6e9104
 if [ $ret != 0 ]; then echo_i "failed"; fi
6e9104
diff --git a/bin/tests/system/tkey/keycreate.c b/bin/tests/system/tkey/keycreate.c
0b18b1
index c39f6a4..b29a3cb 100644
6e9104
--- a/bin/tests/system/tkey/keycreate.c
6e9104
+++ b/bin/tests/system/tkey/keycreate.c
0b18b1
@@ -195,6 +195,7 @@ sendquery(isc_task_t *task, isc_event_t *event) {
6e9104
 int
6e9104
 main(int argc, char *argv[]) {
6e9104
 	char *ourkeyname;
6e9104
+	char *randomfile;
6e9104
 	isc_taskmgr_t *taskmgr;
6e9104
 	isc_timermgr_t *timermgr;
6e9104
 	isc_socketmgr_t *socketmgr;
6e9104
diff --git a/bin/tests/system/tkey/keydelete.c b/bin/tests/system/tkey/keydelete.c
0b18b1
index 547e8d0..efcea1d 100644
6e9104
--- a/bin/tests/system/tkey/keydelete.c
6e9104
+++ b/bin/tests/system/tkey/keydelete.c
6e9104
@@ -136,6 +136,7 @@ sendquery(isc_task_t *task, isc_event_t *event) {
6e9104
 int
6e9104
 main(int argc, char **argv) {
6e9104
 	char *keyname;
6e9104
+	char *randomfile;
6e9104
 	isc_taskmgr_t *taskmgr;
6e9104
 	isc_timermgr_t *timermgr;
6e9104
 	isc_socketmgr_t *socketmgr;
6e9104
diff --git a/bin/tests/system/tkey/tests.sh b/bin/tests/system/tkey/tests.sh
0b18b1
index a293d32..51ed2cb 100644
6e9104
--- a/bin/tests/system/tkey/tests.sh
6e9104
+++ b/bin/tests/system/tkey/tests.sh
0b18b1
@@ -31,7 +31,7 @@ for owner in . foo.example.
6e9104
 do
6e9104
 	echo "I:creating new key using owner name \"$owner\""
6e9104
 	ret=0
6e9104
-	keyname=`$KEYCREATE $dhkeyname $owner` || ret=1
6e9104
+	keyname=`$KEYCREATE -r $RANDFILE $dhkeyname $owner` || ret=1
6e9104
 	if [ $ret != 0 ]; then
6e9104
 		echo "I:failed"
6e9104
 		status=`expr $status + $ret`
0b18b1
@@ -53,7 +53,7 @@ do
6e9104
 
6e9104
 	echo "I:deleting new key"
6e9104
 	ret=0
6e9104
-	$KEYDELETE $keyname || ret=1
6e9104
+	$KEYDELETE -r $RANDFILE $keyname || ret=1
6e9104
 	if [ $ret != 0 ]; then
6e9104
 		echo "I:failed"
6e9104
 	fi
0b18b1
@@ -73,7 +73,7 @@ done
6e9104
 
6e9104
 echo "I:creating new key using owner name bar.example."
6e9104
 ret=0
6e9104
-keyname=`$KEYCREATE $dhkeyname bar.example.` || ret=1
6e9104
+keyname=`$KEYCREATE -r $RANDFILE $dhkeyname bar.example.` || ret=1
6e9104
 if [ $ret != 0 ]; then
6e9104
         echo "I:failed"
6e9104
 	status=`expr $status + $ret`
0b18b1
@@ -114,7 +114,7 @@ status=`expr $status + $ret`
6e9104
 
6e9104
 echo "I:recreating the bar.example. key"
6e9104
 ret=0
6e9104
-keyname=`$KEYCREATE $dhkeyname bar.example.` || ret=1
6e9104
+keyname=`$KEYCREATE -r $RANDFILE $dhkeyname bar.example.` || ret=1
6e9104
 if [ $ret != 0 ]; then
6e9104
         echo "I:failed"
6e9104
 	status=`expr $status + $ret`
6e9104
diff --git a/configure b/configure
0b18b1
index 4c97c8c..1e047bd 100755
6e9104
--- a/configure
6e9104
+++ b/configure
0b18b1
@@ -632,6 +632,7 @@ ac_includes_default="\
6e9104
 
6e9104
 ac_subst_vars='LTLIBOBJS
6e9104
 LIBOBJS
6e9104
+LIBDIR_SUFFIX
6e9104
 BUILD_LIBS
6e9104
 BUILD_LDFLAGS
6e9104
 BUILD_CPPFLAGS
0b18b1
@@ -20509,6 +20510,30 @@ fi
6e9104
 #
6e9104
 dlzdir='${DLZ_DRIVER_DIR}'
6e9104
 
6e9104
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for target libdir" >&5
6e9104
+$as_echo_n "checking for target libdir... " >&6; }
6e9104
+if test "$cross_compiling" = yes; then :
6e9104
+  { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
6e9104
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
6e9104
+as_fn_error $? "cannot run test program while cross compiling
6e9104
+See \`config.log' for more details" "$LINENO" 5; }
6e9104
+else
6e9104
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
6e9104
+/* end confdefs.h.  */
6e9104
+int main(void) {exit((sizeof(void *) == 8) ? 0 : 1);}
6e9104
+_ACEOF
6e9104
+if ac_fn_c_try_run "$LINENO"; then :
6e9104
+  target_lib=lib64
6e9104
+else
6e9104
+  target_lib=lib
6e9104
+fi
6e9104
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
6e9104
+  conftest.$ac_objext conftest.beam conftest.$ac_ext
6e9104
+fi
6e9104
+
6e9104
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: \"$target_lib\"" >&5
6e9104
+$as_echo "\"$target_lib\"" >&6; }
6e9104
+
6e9104
 #
6e9104
 # Private autoconf macro to simplify configuring drivers:
6e9104
 #
0b18b1
@@ -20839,11 +20864,11 @@ $as_echo "no" >&6; }
6e9104
 $as_echo "using mysql with libs ${mysql_lib} and includes ${mysql_include}" >&6; }
6e9104
 		;;
6e9104
 	*)
6e9104
-		if test -d "$use_dlz_mysql/lib/mysql"
6e9104
+		if test -d $use_dlz_mysql/${target_lib}/mysql
6e9104
 		then
6e9104
-			mysql_lib="$use_dlz_mysql/lib/mysql"
6e9104
+			mysql_lib=$use_dlz_mysql/${target_lib}/mysql
6e9104
 		else
6e9104
-			mysql_lib="$use_dlz_mysql/lib"
6e9104
+			mysql_lib=$use_dlz_mysql/${target_lib}
6e9104
 		fi
6e9104
 
6e9104
 	CONTRIB_DLZ="$CONTRIB_DLZ -DDLZ_MYSQL"
0b18b1
@@ -20928,7 +20953,7 @@ $as_echo "" >&6; }
6e9104
 			# Check other locations for includes.
6e9104
 			# Order is important (sigh).
6e9104
 
6e9104
-			bdb_incdirs="/db53 /db51 /db48 /db47 /db46 /db45 /db44 /db43 /db42 /db41 /db4 /db"
6e9104
+			bdb_incdirs="/db53 /db51 /db48 /db47 /db46 /db45 /db44 /db43 /db42 /db41 /db4 /libdb /db"
6e9104
 			# include a blank element first
6e9104
 			for d in "" $bdb_incdirs
6e9104
 			do
0b18b1
@@ -20953,57 +20978,9 @@ $as_echo "" >&6; }
6e9104
 			bdb_libnames="db53 db-5.3 db51 db-5.1 db48 db-4.8 db47 db-4.7 db46 db-4.6 db45 db-4.5 db44 db-4.4 db43 db-4.3 db42 db-4.2 db41 db-4.1 db"
6e9104
 			for d in $bdb_libnames
6e9104
 			do
6e9104
-				if test "$dd" = "/usr"
ad7b3b
-				then
6e9104
-					as_ac_Lib=`$as_echo "ac_cv_lib_$d''_db_create" | $as_tr_sh`
6e9104
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for db_create in -l$d" >&5
6e9104
-$as_echo_n "checking for db_create in -l$d... " >&6; }
6e9104
-if eval \${$as_ac_Lib+:} false; then :
6e9104
-  $as_echo_n "(cached) " >&6
6e9104
-else
6e9104
-  ac_check_lib_save_LIBS=$LIBS
6e9104
-LIBS="-l$d  $LIBS"
6e9104
-cat confdefs.h - <<_ACEOF >conftest.$ac_ext
6e9104
-/* end confdefs.h.  */
6e9104
-
6e9104
-/* Override any GCC internal prototype to avoid an error.
6e9104
-   Use char because int might match the return type of a GCC
6e9104
-   builtin and then its argument prototype would still apply.  */
6e9104
-#ifdef __cplusplus
6e9104
-extern "C"
6e9104
-#endif
6e9104
-char db_create ();
6e9104
-int
6e9104
-main ()
6e9104
-{
6e9104
-return db_create ();
6e9104
-  ;
6e9104
-  return 0;
6e9104
-}
6e9104
-_ACEOF
6e9104
-if ac_fn_c_try_link "$LINENO"; then :
6e9104
-  eval "$as_ac_Lib=yes"
6e9104
-else
6e9104
-  eval "$as_ac_Lib=no"
6e9104
-fi
6e9104
-rm -f core conftest.err conftest.$ac_objext \
6e9104
-    conftest$ac_exeext conftest.$ac_ext
6e9104
-LIBS=$ac_check_lib_save_LIBS
6e9104
-fi
6e9104
-eval ac_res=\$$as_ac_Lib
6e9104
-	       { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
6e9104
-$as_echo "$ac_res" >&6; }
6e9104
-if eval test \"x\$"$as_ac_Lib"\" = x"yes"; then :
6e9104
-  dlz_bdb_libs="-l${d}"
6e9104
-fi
6e9104
-
6e9104
-					if test $dlz_bdb_libs != "yes"
6e9104
-					then
6e9104
-						break
6e9104
-					fi
6e9104
-				elif test -f "$dd/lib/lib${d}.so"
ad7b3b
+				if test -f "$dd/${target_lib}/lib${d}.so"
ad7b3b
 				then
6e9104
-					dlz_bdb_libs="-L${dd}/lib -l${d}"
6e9104
+					dlz_bdb_libs="-L${dd}/${target_lib}/libdb -l${d}"
6e9104
 					break
6e9104
 				fi
6e9104
 			done
0b18b1
@@ -21162,10 +21139,10 @@ $as_echo "no" >&6; }
6e9104
 		DLZ_DRIVER_INCLUDES="$DLZ_DRIVER_INCLUDES -I$use_dlz_ldap/include"
6e9104
 		DLZ_DRIVER_LDAP_INCLUDES="-I$use_dlz_ldap/include"
6e9104
 	fi
6e9104
-	if test -n "-L$use_dlz_ldap/lib -lldap -llber"
6e9104
+	if test -n "-L$use_dlz_ldap/${target_lib} -lldap -llber"
6e9104
 	then
6e9104
-		DLZ_DRIVER_LIBS="$DLZ_DRIVER_LIBS -L$use_dlz_ldap/lib -lldap -llber"
6e9104
-		DLZ_DRIVER_LDAP_LIBS="-L$use_dlz_ldap/lib -lldap -llber"
6e9104
+		DLZ_DRIVER_LIBS="$DLZ_DRIVER_LIBS -L$use_dlz_ldap/${target_lib} -lldap -llber"
6e9104
+		DLZ_DRIVER_LDAP_LIBS="-L$use_dlz_ldap/${target_lib} -lldap -llber"
6e9104
 	fi
6e9104
 
6e9104
 
0b18b1
@@ -21251,11 +21228,11 @@ fi
6e9104
 		odbcdirs="/usr /usr/local /usr/pkg"
6e9104
 		for d in $odbcdirs
6e9104
 		do
6e9104
-			if test -f $d/include/sql.h -a -f $d/lib/libodbc.a
6e9104
+			if test -f $d/include/sql.h -a -f $d/${target_lib}/libodbc.a
6e9104
 			then
6e9104
 				use_dlz_odbc=$d
6e9104
 				dlz_odbc_include="-I$use_dlz_odbc/include"
6e9104
-				dlz_odbc_libs="-L$use_dlz_odbc/lib -lodbc"
6e9104
+				dlz_odbc_libs="-L$use_dlz_odbc/${target_lib} -lodbc"
6e9104
 				break
6e9104
 			fi
6e9104
 		done
0b18b1
@@ -21530,6 +21507,8 @@ DNS_CRYPTO_LIBS="$NEWFLAGS"
6e9104
 
6e9104
 
6e9104
 
6e9104
+
6e9104
+
6e9104
 #
6e9104
 # Commands to run at the end of config.status.
6e9104
 # Don't just put these into configure, it won't work right if somebody
6e9104
diff --git a/lib/dns/include/dst/dst.h b/lib/dns/include/dst/dst.h
0b18b1
index 3146d88..3f7ac4d 100644
6e9104
--- a/lib/dns/include/dst/dst.h
6e9104
+++ b/lib/dns/include/dst/dst.h
0b18b1
@@ -153,6 +153,14 @@ dst_lib_destroy(void);
6e9104
  * Releases all resources allocated by DST.
6e9104
  */
6e9104
 
6e9104
+isc_result_t
6e9104
+dst_random_getdata(void *data, unsigned int length,
6e9104
+		   unsigned int *returned, unsigned int flags);
6e9104
+/*%<
6e9104
+ * \brief Return data from the crypto random generator.
6e9104
+ * Specialization of isc_entropy_getdata().
6e9104
+ */
6e9104
+
ad7b3b
 bool
6e9104
 dst_algorithm_supported(unsigned int alg);
6e9104
 /*%<
6e9104
diff --git a/lib/dns/lib.c b/lib/dns/lib.c
0b18b1
index 5fccb57..1f627c4 100644
6e9104
--- a/lib/dns/lib.c
6e9104
+++ b/lib/dns/lib.c
0b18b1
@@ -51,6 +51,7 @@ static unsigned int references = 0;
6e9104
 static void
6e9104
 initialize(void) {
6e9104
 	isc_result_t result;
6e9104
+	isc_entropy_t *ectx = NULL;
6e9104
 
ad7b3b
 	REQUIRE(initialize_done == false);
6e9104
 
6e9104
diff --git a/lib/dns/tests/Makefile.in b/lib/dns/tests/Makefile.in
0b18b1
index 7b35b93..c5befff 100644
6e9104
--- a/lib/dns/tests/Makefile.in
6e9104
+++ b/lib/dns/tests/Makefile.in
0b18b1
@@ -259,6 +259,11 @@ zt_test@EXEEXT@: zt_test.@O@ dnstest.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
1e4169
 		${LDFLAGS} -o $@ zt_test.@O@ dnstest.@O@ \
1e4169
 		${DNSLIBS} ${ISCLIBS} ${LIBS}
6e9104
 
6e9104
+dstrandom_test@EXEEXT@: dstrandom_test.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
6e9104
+	${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
6e9104
+			dstrandom_test.@O@ ${DNSLIBS} \
6e9104
+			${ISCLIBS} ${ISCPK11LIBS} ${LIBS}
6e9104
+
6e9104
 unit::
6e9104
 	sh ${top_builddir}/unit/unittest.sh
6e9104
 
6e9104
diff --git a/lib/isc/include/isc/types.h b/lib/isc/include/isc/types.h
0b18b1
index f8e5ae6..d0dc9b5 100644
6e9104
--- a/lib/isc/include/isc/types.h
6e9104
+++ b/lib/isc/include/isc/types.h
0b18b1
@@ -82,6 +82,8 @@ typedef struct isc_time			isc_time_t;		/*%< Time */
6e9104
 typedef struct isc_timer		isc_timer_t;		/*%< Timer */
6e9104
 typedef struct isc_timermgr		isc_timermgr_t;		/*%< Timer Manager */
6e9104
 
6e9104
+typedef isc_result_t (*isc_entropy_getdata_t)(void *, unsigned int,
6e9104
+					      unsigned int *, unsigned int);
6e9104
 typedef void (*isc_taskaction_t)(isc_task_t *, isc_event_t *);
6e9104
 typedef int (*isc_sockfdwatch_t)(isc_task_t *, isc_socket_t *, void *, int);
6e9104
 
6e9104
diff --git a/win32utils/Configure b/win32utils/Configure
0b18b1
index 9731b0c..0b7bc6e 100644
6e9104
--- a/win32utils/Configure
6e9104
+++ b/win32utils/Configure
0b18b1
@@ -353,7 +353,8 @@ my @allcond = (@substcond, "NOTYET", "NOLONGER");
6e9104
 
6e9104
 # enable-xxx/disable-xxx
6e9104
 
6e9104
-my @enablelist = ("developer",
6e9104
+my @enablelist = ("crypto-rand",
6e9104
+                  "developer",
6e9104
                   "fixed-rrset",
6e9104
                   "intrinsics",
6e9104
                   "isc-spnego",
0b18b1
@@ -2929,6 +2930,7 @@ exit 0;
6e9104
 #  --enable-developer partially supported
6e9104
 #  --enable-newstats (9.9/9.9sub only)
6e9104
 #  --enable-native-pkcs11 supported
6e9104
+#  --enable-crypto-rand supported
6e9104
 #  --enable-openssl-version-check included without a way to disable it
6e9104
 #  --enable-openssl-hash supported
6e9104
 #  --enable-threads included without a way to disable it
6e9104
-- 
0b18b1
2.20.1
6e9104