mirror of
https://github.com/asterisk/asterisk.git
synced 2025-10-12 07:35:18 +00:00
Add support for using /dev/urandom to get random numbers on systems that support it.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@76296 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
40
configure
vendored
40
configure
vendored
@@ -1,5 +1,5 @@
|
|||||||
#! /bin/sh
|
#! /bin/sh
|
||||||
# From configure.ac Revision: 74575 .
|
# From configure.ac Revision: 75259 .
|
||||||
# Guess values for system-dependent variables and create Makefiles.
|
# Guess values for system-dependent variables and create Makefiles.
|
||||||
# Generated by GNU Autoconf 2.61.
|
# Generated by GNU Autoconf 2.61.
|
||||||
#
|
#
|
||||||
@@ -12127,11 +12127,13 @@ _ACEOF
|
|||||||
cat confdefs.h >>conftest.$ac_ext
|
cat confdefs.h >>conftest.$ac_ext
|
||||||
cat >>conftest.$ac_ext <<_ACEOF
|
cat >>conftest.$ac_ext <<_ACEOF
|
||||||
/* end confdefs.h. */
|
/* end confdefs.h. */
|
||||||
#include <stdio.h>
|
#include <sys/types.h> /* for off_t */
|
||||||
|
#include <stdio.h>
|
||||||
int
|
int
|
||||||
main ()
|
main ()
|
||||||
{
|
{
|
||||||
return fseeko (stdin, 0, 0) && (fseeko) (stdin, 0, 0);
|
int (*fp) (FILE *, off_t, int) = fseeko;
|
||||||
|
return fseeko (stdin, 0, 0) && fp (stdin, 0, 0);
|
||||||
;
|
;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -12171,11 +12173,13 @@ cat confdefs.h >>conftest.$ac_ext
|
|||||||
cat >>conftest.$ac_ext <<_ACEOF
|
cat >>conftest.$ac_ext <<_ACEOF
|
||||||
/* end confdefs.h. */
|
/* end confdefs.h. */
|
||||||
#define _LARGEFILE_SOURCE 1
|
#define _LARGEFILE_SOURCE 1
|
||||||
#include <stdio.h>
|
#include <sys/types.h> /* for off_t */
|
||||||
|
#include <stdio.h>
|
||||||
int
|
int
|
||||||
main ()
|
main ()
|
||||||
{
|
{
|
||||||
return fseeko (stdin, 0, 0) && (fseeko) (stdin, 0, 0);
|
int (*fp) (FILE *, off_t, int) = fseeko;
|
||||||
|
return fseeko (stdin, 0, 0) && fp (stdin, 0, 0);
|
||||||
;
|
;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -15110,6 +15114,32 @@ fi
|
|||||||
done
|
done
|
||||||
|
|
||||||
|
|
||||||
|
{ echo "$as_me:$LINENO: checking for /dev/urandom" >&5
|
||||||
|
echo $ECHO_N "checking for /dev/urandom... $ECHO_C" >&6; }
|
||||||
|
if test "${ac_cv_file__dev_urandom+set}" = set; then
|
||||||
|
echo $ECHO_N "(cached) $ECHO_C" >&6
|
||||||
|
else
|
||||||
|
test "$cross_compiling" = yes &&
|
||||||
|
{ { echo "$as_me:$LINENO: error: cannot check for file existence when cross compiling" >&5
|
||||||
|
echo "$as_me: error: cannot check for file existence when cross compiling" >&2;}
|
||||||
|
{ (exit 1); exit 1; }; }
|
||||||
|
if test -r "/dev/urandom"; then
|
||||||
|
ac_cv_file__dev_urandom=yes
|
||||||
|
else
|
||||||
|
ac_cv_file__dev_urandom=no
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
{ echo "$as_me:$LINENO: result: $ac_cv_file__dev_urandom" >&5
|
||||||
|
echo "${ECHO_T}$ac_cv_file__dev_urandom" >&6; }
|
||||||
|
if test $ac_cv_file__dev_urandom = yes; then
|
||||||
|
|
||||||
|
cat >>confdefs.h <<\_ACEOF
|
||||||
|
#define HAVE_DEV_URANDOM 1
|
||||||
|
_ACEOF
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if test "x${PBX_PTHREAD_RWLOCK_INITIALIZER}" != "x1" -a "${USE_PTHREAD_RWLOCK_INITIALIZER}" != "no"; then
|
if test "x${PBX_PTHREAD_RWLOCK_INITIALIZER}" != "x1" -a "${USE_PTHREAD_RWLOCK_INITIALIZER}" != "no"; then
|
||||||
{ echo "$as_me:$LINENO: checking for PTHREAD_RWLOCK_INITIALIZER in pthread.h" >&5
|
{ echo "$as_me:$LINENO: checking for PTHREAD_RWLOCK_INITIALIZER in pthread.h" >&5
|
||||||
|
@@ -286,6 +286,8 @@ AC_CHECK_FUNCS([funopen fopencookie])
|
|||||||
# some systems already have gethostbyname_r so we don't need to build ours in main/utils.c
|
# some systems already have gethostbyname_r so we don't need to build ours in main/utils.c
|
||||||
AC_CHECK_FUNCS([gethostbyname_r])
|
AC_CHECK_FUNCS([gethostbyname_r])
|
||||||
|
|
||||||
|
AC_CHECK_FILE(/dev/urandom, AC_DEFINE([HAVE_DEV_URANDOM], 1, [Define to 1 if your system has /dev/urandom.]))
|
||||||
|
|
||||||
AST_C_DEFINE_CHECK([PTHREAD_RWLOCK_INITIALIZER], [PTHREAD_RWLOCK_INITIALIZER], [pthread.h])
|
AST_C_DEFINE_CHECK([PTHREAD_RWLOCK_INITIALIZER], [PTHREAD_RWLOCK_INITIALIZER], [pthread.h])
|
||||||
AST_C_DEFINE_CHECK([PTHREAD_RWLOCK_PREFER_WRITER_NP], [PTHREAD_RWLOCK_PREFER_WRITER_NP], [pthread.h])
|
AST_C_DEFINE_CHECK([PTHREAD_RWLOCK_PREFER_WRITER_NP], [PTHREAD_RWLOCK_PREFER_WRITER_NP], [pthread.h])
|
||||||
|
|
||||||
|
@@ -95,6 +95,9 @@
|
|||||||
/* Define to indicate the ${CURSES_DESCRIP} library version */
|
/* Define to indicate the ${CURSES_DESCRIP} library version */
|
||||||
#undef HAVE_CURSES_VERSION
|
#undef HAVE_CURSES_VERSION
|
||||||
|
|
||||||
|
/* Define to 1 if your system has /dev/urandom. */
|
||||||
|
#undef HAVE_DEV_URANDOM
|
||||||
|
|
||||||
/* Define to 1 if you have the <dirent.h> header file, and it defines `DIR'.
|
/* Define to 1 if you have the <dirent.h> header file, and it defines `DIR'.
|
||||||
*/
|
*/
|
||||||
#undef HAVE_DIRENT_H
|
#undef HAVE_DIRENT_H
|
||||||
|
@@ -393,11 +393,7 @@ int ast_pthread_create_detached_stack(pthread_t *thread, pthread_attr_t *attr, v
|
|||||||
*/
|
*/
|
||||||
char *ast_process_quotes_and_slashes(char *start, char find, char replace_with);
|
char *ast_process_quotes_and_slashes(char *start, char find, char replace_with);
|
||||||
|
|
||||||
#ifdef linux
|
|
||||||
#define ast_random random
|
|
||||||
#else
|
|
||||||
long int ast_random(void);
|
long int ast_random(void);
|
||||||
#endif
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief free() wrapper
|
* \brief free() wrapper
|
||||||
|
26
main/utils.c
26
main/utils.c
@@ -40,6 +40,10 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
|
|||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
|
|
||||||
|
#ifdef HAVE_DEV_URANDOM
|
||||||
|
#include <fcntl.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#define AST_API_MODULE /* ensure that inlinable API functions will be built in lock.h if required */
|
#define AST_API_MODULE /* ensure that inlinable API functions will be built in lock.h if required */
|
||||||
#include "asterisk/lock.h"
|
#include "asterisk/lock.h"
|
||||||
#include "asterisk/io.h"
|
#include "asterisk/io.h"
|
||||||
@@ -501,8 +505,15 @@ const char *ast_inet_ntoa(struct in_addr ia)
|
|||||||
return inet_ntop(AF_INET, &ia, buf, INET_ADDRSTRLEN);
|
return inet_ntop(AF_INET, &ia, buf, INET_ADDRSTRLEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef HAVE_DEV_URANDOM
|
||||||
|
static int dev_urandom_fd;
|
||||||
|
#endif
|
||||||
|
|
||||||
int ast_utils_init(void)
|
int ast_utils_init(void)
|
||||||
{
|
{
|
||||||
|
#ifdef HAVE_DEV_URANDOM
|
||||||
|
dev_urandom_fd = open("/dev/urandom", O_RDONLY);
|
||||||
|
#endif
|
||||||
base64_init();
|
base64_init();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -807,19 +818,30 @@ struct timeval ast_tvsub(struct timeval a, struct timeval b)
|
|||||||
|
|
||||||
/*! \brief glibc puts a lock inside random(3), so that the results are thread-safe.
|
/*! \brief glibc puts a lock inside random(3), so that the results are thread-safe.
|
||||||
* BSD libc (and others) do not. */
|
* BSD libc (and others) do not. */
|
||||||
#ifndef linux
|
|
||||||
|
|
||||||
|
#ifndef linux
|
||||||
AST_MUTEX_DEFINE_STATIC(randomlock);
|
AST_MUTEX_DEFINE_STATIC(randomlock);
|
||||||
|
#endif
|
||||||
|
|
||||||
long int ast_random(void)
|
long int ast_random(void)
|
||||||
{
|
{
|
||||||
long int res;
|
long int res;
|
||||||
|
#ifdef HAVE_DEV_URANDOM
|
||||||
|
if (dev_urandom_fd >= 0) {
|
||||||
|
int read_res = read(dev_urandom_fd, &res, sizeof(res));
|
||||||
|
if (read_res > 0)
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#ifdef linux
|
||||||
|
res = random();
|
||||||
|
#else
|
||||||
ast_mutex_lock(&randomlock);
|
ast_mutex_lock(&randomlock);
|
||||||
res = random();
|
res = random();
|
||||||
ast_mutex_unlock(&randomlock);
|
ast_mutex_unlock(&randomlock);
|
||||||
|
#endif
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
char *ast_process_quotes_and_slashes(char *start, char find, char replace_with)
|
char *ast_process_quotes_and_slashes(char *start, char find, char replace_with)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user