diff --git a/proofd/src/proofd.cxx b/proofd/src/proofd.cxx index b377d4708eafd987cc2f2847f76205d010681c60..2aa81fa9300a36ada4d01e9519ee6efef9b696ca 100644 --- a/proofd/src/proofd.cxx +++ b/proofd/src/proofd.cxx @@ -1,4 +1,4 @@ -// @(#)root/proofd:$Name: $:$Id: proofd.cxx,v 1.55 2003/11/20 23:00:46 rdm Exp $ +// @(#)root/proofd:$Name: $:$Id: proofd.cxx,v 1.56 2003/11/26 10:33:08 rdm Exp $ // Author: Fons Rademakers 02/02/97 /************************************************************************* @@ -917,9 +917,6 @@ void ProofdExec() if (gDebug > 0) ErrorInfo("ProofdExec: gGlobus: %d, gRcFile: %s", gGlobus, gRcFile); - // Init Random machinery ... - RpdInitRand(); - // Get Host name const char *OpenHost = NetRemoteHost(); strcpy(gOpenHost, OpenHost); diff --git a/rootd/src/rootd.cxx b/rootd/src/rootd.cxx index ed65abddf71a10023306e9f1464323930906e8d1..92f58c292f93238ddf2a5680ac12b1ea75c55b92 100644 --- a/rootd/src/rootd.cxx +++ b/rootd/src/rootd.cxx @@ -1,4 +1,4 @@ -// @(#)root/rootd:$Name: $:$Id: rootd.cxx,v 1.77 2004/01/19 22:42:07 rdm Exp $ +// @(#)root/rootd:$Name: $:$Id: rootd.cxx,v 1.78 2004/01/24 11:20:41 brun Exp $ // Author: Fons Rademakers 11/08/97 /************************************************************************* @@ -2045,9 +2045,6 @@ void RootdLoop() // CleanUp authentication table, if needed or required ... RpdCheckSession(); - // Init Random machinery ... - RpdInitRand(); - // Get Host name const char *OpenHost = NetRemoteHost(); strcpy(gOpenHost, OpenHost); diff --git a/rpdutils/src/rpdutils.cxx b/rpdutils/src/rpdutils.cxx index 108f1d3117763fea034ccbbf7254ca79b962c2f8..c035086a5caf780ca9ceb2fc41cecf41c9afd17b 100644 --- a/rpdutils/src/rpdutils.cxx +++ b/rpdutils/src/rpdutils.cxx @@ -1,4 +1,4 @@ -// @(#)root/rpdutils:$Name: $:$Id: rpdutils.cxx,v 1.27 2003/11/20 23:00:46 rdm Exp $ +// @(#)root/rpdutils:$Name: $:$Id: rpdutils.cxx,v 1.28 2003/12/30 21:42:27 brun Exp $ // Author: Gerardo Ganis 7/4/2003 /************************************************************************* @@ -262,6 +262,8 @@ int gShmIdCred = -1; // global, to pass the shm ID to proofserv gss_ctx_id_t GlbContextHandle = GSS_C_NO_CONTEXT; #endif +static int gRandInit = 0; + } //namespace ROOT // Masks for authentication methods @@ -3372,14 +3374,11 @@ char *RpdGetRandString(int Opt, int Len) // Allocate buffer char *Buf = new char[Len + 1]; - // Get current time as seed for rand(). - time_t curtime; - time(&curtime); - int seed = (int) curtime; - - // feed seed - if (seed) - srand(seed); + // Init Random machinery ... + if (!gRandInit) { + RpdInitRand(); + gRandInit = 1; + } // randomize int k = 0; @@ -3608,6 +3607,12 @@ int RpdGenRSAKeys() if (gDebug > 2) ErrorInfo("RpdGenRSAKeys: enter"); + // Init Random machinery ... + if (!gRandInit) { + RpdInitRand(); + gRandInit = 1; + } + // Sometimes some bunch is not decrypted correctly // That's why we make retries to make sure that encryption/decryption works as expected bool NotOk = 1; @@ -3818,24 +3823,23 @@ int RpdRecvClientRSAKey() //______________________________________________________________________________ void RpdInitRand() { - // Init random machine + // Init random machine. + + const char *randdev = "/dev/urandom"; - int seed = 1; - if (!access("/dev/random", R_OK)) { + int fd; + unsigned int seed; + if ((fd = open(randdev, O_RDONLY)) != -1) { if (gDebug > 2) - ErrorInfo("RpdInitRand: taking seed from /dev/random"); - char brnd[4]; - FILE *frnd = fopen("/dev/random","r"); - fread(brnd,1,4,frnd); - seed = *((int *)brnd); - fclose(frnd); + ErrorInfo("RpdInitRand: taking seed from %s", randdev); + read(fd, &seed, sizeof(seed)); + close(fd); } else { if (gDebug > 2) - ErrorInfo("RpdInitRand: /dev/random not available: using time()"); - seed = time(0); + ErrorInfo("RpdInitRand: %s not available: using time()", randdev); + seed = time(0); //better use times() + win32 equivalent } srand(seed); - } } // namespace ROOT