Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEgor Duda <deo@logos-m.ru>2001-05-04 20:30:18 +0400
committerEgor Duda <deo@logos-m.ru>2001-05-04 20:30:18 +0400
commit69b218bf24d1374876fa900dc75c14532ec1c040 (patch)
tree715322a8f196bc890f4cea4dc63004441eac52ac /winsup/cygwin/fhandler_socket.cc
parenta1ad23671c779500df5b61c824d79612d61abc6e (diff)
* fhandler_socket.cc (set_connect_secret): Use /dev/urandom to
generate secret cookie.
Diffstat (limited to 'winsup/cygwin/fhandler_socket.cc')
-rw-r--r--winsup/cygwin/fhandler_socket.cc22
1 files changed, 20 insertions, 2 deletions
diff --git a/winsup/cygwin/fhandler_socket.cc b/winsup/cygwin/fhandler_socket.cc
index f4428639a..eb6f36a2e 100644
--- a/winsup/cygwin/fhandler_socket.cc
+++ b/winsup/cygwin/fhandler_socket.cc
@@ -28,6 +28,10 @@
#include "sigproc.h"
#define SECRET_EVENT_NAME "cygwin.local_socket.secret.%d.%08x-%08x-%08x-%08x"
+#define ENTROPY_SOURCE_NAME "/dev/urandom"
+#define ENTROPY_SOURCE_DEV_UNIT 9
+
+fhandler_dev_random* entropy_source = NULL;
/**********************************************************************/
/* fhandler_socket */
@@ -50,8 +54,22 @@ fhandler_socket::~fhandler_socket ()
void
fhandler_socket::set_connect_secret ()
{
- for (int i = 0; i < 4; i++)
- connect_secret [i] = random ();
+ if (!entropy_source)
+ {
+ void *buf = malloc (sizeof (fhandler_dev_random));
+ entropy_source = new (buf) fhandler_dev_random (ENTROPY_SOURCE_NAME,
+ ENTROPY_SOURCE_DEV_UNIT);
+ }
+ if (entropy_source &&
+ !entropy_source->open (ENTROPY_SOURCE_NAME, O_RDONLY))
+ {
+ delete entropy_source;
+ entropy_source = NULL;
+ }
+ if (!entropy_source ||
+ (entropy_source->read (connect_secret, sizeof (connect_secret)) !=
+ sizeof (connect_secret)))
+ bzero ((char*) connect_secret, sizeof (connect_secret));
}
void