ntdll: Fall back to reading /dev/urandom if getrandom() is not supported.

Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=50168
Signed-off-by: Hans Leidekker <hans@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
(cherry picked from commit e6407c39ba)
Signed-off-by: Michael Stefaniuc <mstefani@winehq.org>
This commit is contained in:
Hans Leidekker 2021-03-16 09:46:48 +01:00 committed by Michael Stefaniuc
parent b9eb1a9327
commit 0b33385f11
1 changed files with 19 additions and 12 deletions

View File

@ -2056,6 +2056,22 @@ static void get_timezone_info( RTL_DYNAMIC_TIME_ZONE_INFORMATION *tzi )
}
static void read_dev_urandom( void *buf, ULONG len )
{
int fd = open( "/dev/urandom", O_RDONLY );
if (fd != -1)
{
int ret;
do
{
ret = read( fd, buf, len );
}
while (ret == -1 && errno == EINTR);
close( fd );
}
else WARN( "can't open /dev/urandom\n" );
}
/******************************************************************************
* NtQuerySystemInformation (NTDLL.@)
*/
@ -2541,19 +2557,10 @@ NTSTATUS WINAPI NtQuerySystemInformation( SYSTEM_INFORMATION_CLASS class,
ret = getrandom( info, len, 0 );
}
while (ret == -1 && errno == EINTR);
if (ret == -1 && errno == ENOSYS) read_dev_urandom( info, len );
#else
int fd = open( "/dev/urandom", O_RDONLY );
if (fd != -1)
{
int ret;
do
{
ret = read( fd, info, len );
}
while (ret == -1 && errno == EINTR);
close( fd );
}
else WARN( "can't open /dev/urandom\n" );
read_dev_urandom( info, len );
#endif
}
}