* devices.in (dev_storage): Map /dev/random and /dev/urandom to

\Device\Null.
	* devices.cc: Regenerate.
	* fhandler.h (fhandler_dev_random::open): Drop declaration.
	(fhandler_dev_random::close): Ditto.
	(fhandler_dev_random::crypt_gen_random): Convert to static method.
	* fhandler_random.cc (fhandler_dev_random::open): Remove so that default
	fhandler_base::open is used to open \Device\Null.
	(fhandler_dev_random::close): Ditto.
	* fhandler_socket.cc (entropy_source): Delete.
	(fhandler_socket::af_local_set_secret): Remove entropy_source code and
	call fhandler_dev_random::crypt_gen_random directly instead.
This commit is contained in:
Corinna Vinschen 2013-10-25 12:21:59 +00:00
parent 8ef76ab6f9
commit 494c626414
7 changed files with 27 additions and 46 deletions

View File

@ -1,3 +1,18 @@
2013-10-25 Corinna Vinschen <corinna@vinschen.de>
* devices.in (dev_storage): Map /dev/random and /dev/urandom to
\Device\Null.
* devices.cc: Regenerate.
* fhandler.h (fhandler_dev_random::open): Drop declaration.
(fhandler_dev_random::close): Ditto.
(fhandler_dev_random::crypt_gen_random): Convert to static method.
* fhandler_random.cc (fhandler_dev_random::open): Remove so that default
fhandler_base::open is used to open \Device\Null.
(fhandler_dev_random::close): Ditto.
* fhandler_socket.cc (entropy_source): Delete.
(fhandler_socket::af_local_set_secret): Remove entropy_source code and
call fhandler_dev_random::crypt_gen_random directly instead.
2013-10-24 Corinna Vinschen <corinna@vinschen.de>
* fhandler.h (fhandler_dev_zero::lseek): Convert to inline method.

View File

@ -439,7 +439,7 @@ const _RDATA device dev_storage[] =
{"/dev/pty61", BRACK(FHDEV(DEV_PTYS_MAJOR, 61)), "/dev/pty61", exists_pty, S_IFCHR, true},
{"/dev/pty62", BRACK(FHDEV(DEV_PTYS_MAJOR, 62)), "/dev/pty62", exists_pty, S_IFCHR, true},
{"/dev/pty63", BRACK(FHDEV(DEV_PTYS_MAJOR, 63)), "/dev/pty63", exists_pty, S_IFCHR, true},
{"/dev/random", BRACK(FH_RANDOM), "/dev/random", exists, S_IFCHR, true},
{"/dev/random", BRACK(FH_RANDOM), "\\Device\\Null", exists_ntdev, S_IFCHR, true},
{"/dev/scd0", BRACK(FHDEV(DEV_CDROM_MAJOR, 0)), "\\Device\\CdRom0", exists_ntdev, S_IFBLK, true},
{"/dev/scd1", BRACK(FHDEV(DEV_CDROM_MAJOR, 1)), "\\Device\\CdRom1", exists_ntdev, S_IFBLK, true},
{"/dev/scd2", BRACK(FHDEV(DEV_CDROM_MAJOR, 2)), "\\Device\\CdRom2", exists_ntdev, S_IFBLK, true},
@ -2713,7 +2713,7 @@ const _RDATA device dev_storage[] =
{"/dev/ttyS61", BRACK(FHDEV(DEV_SERIAL_MAJOR, 61)), "\\??\\COM62", exists_ntdev, S_IFCHR, true},
{"/dev/ttyS62", BRACK(FHDEV(DEV_SERIAL_MAJOR, 62)), "\\??\\COM63", exists_ntdev, S_IFCHR, true},
{"/dev/ttyS63", BRACK(FHDEV(DEV_SERIAL_MAJOR, 63)), "\\??\\COM64", exists_ntdev, S_IFCHR, true},
{"/dev/urandom", BRACK(FH_URANDOM), "/dev/urandom", exists, S_IFCHR, true},
{"/dev/urandom", BRACK(FH_URANDOM), "\\Device\\Null", exists_ntdev, S_IFCHR, true},
{"/dev/windows", BRACK(FH_WINDOWS), "/dev/windows", exists, S_IFCHR, true},
{"/dev/zero", BRACK(FH_ZERO), "\\Device\\Null", exists_ntdev, S_IFCHR, true},
{":fifo", BRACK(FH_FIFO), "/dev/fifo", exists_internal, S_IFCHR, false},

View File

@ -154,8 +154,8 @@ const device dev_error_storage =
"/dev/null", BRACK(FH_NULL), "\\Device\\Null", exists_ntdev, S_IFCHR
"/dev/zero", BRACK(FH_ZERO), "\\Device\\Null", exists_ntdev, S_IFCHR
"/dev/full", BRACK(FH_FULL), "\\Device\\Null", exists_ntdev, S_IFCHR
"/dev/random", BRACK(FH_RANDOM), "/dev/random", exists, S_IFCHR
"/dev/urandom", BRACK(FH_URANDOM), "/dev/urandom", exists, S_IFCHR, =urandom_dev
"/dev/random", BRACK(FH_RANDOM), "\\Device\\Null", exists_ntdev, S_IFCHR
"/dev/urandom", BRACK(FH_URANDOM), "\\Device\\Null", exists_ntdev, S_IFCHR, =urandom_dev
"/dev/clipboard", BRACK(FH_CLIPBOARD), "/dev/clipboard", exists, S_IFCHR
"/dev/com%(1-16)d", BRACK(FHDEV(DEV_SERIAL_MAJOR, {$1 - 1})), "\\??\\COM{$1}", exists_ntdev_silent, S_IFCHR
"/dev/ttyS%(0-63)d", BRACK(FHDEV(DEV_SERIAL_MAJOR, {$1})), "\\??\\COM{$1 + 1}", exists_ntdev, S_IFCHR

View File

@ -1654,16 +1654,15 @@ class fhandler_dev_random: public fhandler_base
protected:
uint32_t pseudo;
bool crypt_gen_random (void *ptr, size_t len);
int pseudo_write (const void *ptr, size_t len);
int pseudo_read (void *ptr, size_t len);
public:
int open (int flags, mode_t mode = 0);
ssize_t __stdcall write (const void *ptr, size_t len);
void __reg3 read (void *ptr, size_t& len);
off_t lseek (off_t, int) { return 0; }
int close ();
static bool crypt_gen_random (void *ptr, size_t len);
fhandler_dev_random () : fhandler_base () {}
fhandler_dev_random (void *) {}

View File

@ -28,15 +28,6 @@ details. */
#define PSEUDO_MULTIPLIER (6364136223846793005LL)
#define PSEUDO_SHIFTVAL (21)
int
fhandler_dev_random::open (int flags, mode_t)
{
set_flags ((flags & ~O_TEXT) | O_BINARY);
nohandle (true);
set_open_status ();
return 1;
}
/* There's a bug in ntsecapi.h (Mingw as well as MSFT). SystemFunction036
is, in fact, a WINAPI function, but it's not defined as such. Therefore
we have to do it correctly here. */
@ -149,9 +140,3 @@ fhandler_dev_random::read (void *ptr, size_t& len)
else if (!crypt_gen_random (ptr, len))
len = pseudo_read (ptr, len);
}
int
fhandler_dev_random::close ()
{
return 0;
}

View File

@ -48,8 +48,6 @@ extern "C" {
int sscanf (const char *, const char *, ...);
} /* End of "C" section */
fhandler_dev_random* entropy_source;
static inline mode_t
adjust_socket_file_mode (mode_t mode)
{
@ -445,25 +443,9 @@ fhandler_socket::af_local_copy (fhandler_socket *sock)
void
fhandler_socket::af_local_set_secret (char *buf)
{
if (!entropy_source)
{
void *buf = malloc (sizeof (fhandler_dev_random));
entropy_source = new (buf) fhandler_dev_random ();
entropy_source->dev () = *urandom_dev;
}
if (entropy_source &&
!entropy_source->open (O_RDONLY))
{
delete entropy_source;
entropy_source = NULL;
}
if (entropy_source)
{
size_t len = sizeof (connect_secret);
entropy_source->read (connect_secret, len);
if (len != sizeof (connect_secret))
bzero ((char*) connect_secret, sizeof (connect_secret));
}
if (!fhandler_dev_random::crypt_gen_random (connect_secret,
sizeof (connect_secret)))
bzero ((char*) connect_secret, sizeof (connect_secret));
__small_sprintf (buf, "%08x-%08x-%08x-%08x",
connect_secret [0], connect_secret [1],
connect_secret [2], connect_secret [3]);

View File

@ -7,9 +7,9 @@ What changed:
- Slightly improve randomness of /dev/random emulation.
- Allow to use advisory locking on any device which is backed by an OS handle.
Right now this excludes /dev/clipboard, /dev/dsp, /dev/random, /dev/urandom,
as well as almost all virtual files under /proc.
- Allow to use advisory locking on any device which is backed by an OS
handle. Right now this excludes /dev/clipboard, /dev/dsp, as well as
almost all virtual files under /proc.
Bug fixes: