Revert "Do not use random() while generating MD5 salt."
authorTatsuo Ishii <ishii@postgresql.org>
Wed, 14 Sep 2016 04:39:51 +0000 (13:39 +0900)
committerTatsuo Ishii <ishii@postgresql.org>
Wed, 14 Sep 2016 04:39:51 +0000 (13:39 +0900)
This reverts commit db72352a4f2ad640223022b0f59df1e600849482.

main.c
pool_auth.c

diff --git a/main.c b/main.c
index ebb07cd4e5315080531a94441d6539a537300ae0..af3fb40747ef5034d909aaaea234c94387d519ee 100644 (file)
--- a/main.c
+++ b/main.c
@@ -138,7 +138,6 @@ static struct sockaddr_un un_addr;          /* unix domain socket path */
 static struct sockaddr_un pcp_un_addr;  /* unix domain socket path for PCP */
 
 ProcessInfo *process_info;     /* Per child info table on shmem */
-struct timeval random_start_time;
 
 /*
  * Private copy of backend status
@@ -317,9 +316,6 @@ int main(int argc, char **argv)
                }
        }
 
-       /* For PostmasterRandom */
-       gettimeofday(&random_start_time, NULL);
-
 #ifdef USE_SSL
        /* global ssl init */
        SSL_library_init();
index c723e6ab92830fa78adf631cc4139d3dc2ea44b6..cbdad144ee7b1e0ce7ae7a789a28b61fe1a0caf8 100644 (file)
@@ -5,7 +5,7 @@
  * pgpool: a language independent connection pool server for PostgreSQL
  * written by Tatsuo Ishii
  *
- * Copyright (c) 2003-2016     PgPool Global Development Group
+ * Copyright (c) 2003-2013     PgPool Global Development Group
  *
  * Permission to use, copy, modify, and distribute this software and
  * its documentation for any purpose and without fee is hereby
@@ -52,8 +52,6 @@ static int read_password_packet(POOL_CONNECTION *frontend, int protoMajor,    char
 static int send_password_packet(POOL_CONNECTION *backend, int protoMajor, char *password);
 static int send_auth_ok(POOL_CONNECTION *frontend, int protoMajor);
 
-static long PostmasterRandom(void);
-
 /*
  * After sending the start up packet to the backend, do the
  * authentication against backend. if success return 0 otherwise non
@@ -1374,51 +1372,13 @@ int pool_read_int(POOL_CONNECTION_POOL *cp)
  */
 void pool_random_salt(char *md5Salt)
 {
-       long rand = PostmasterRandom();
+       long rand = random();
 
        md5Salt[0] = (rand % 255) + 1;
-       rand = PostmasterRandom();
+       rand = random();
        md5Salt[1] = (rand % 255) + 1;
-       rand = PostmasterRandom();
+       rand = random();
        md5Salt[2] = (rand % 255) + 1;
-       rand = PostmasterRandom();
+       rand = random();
        md5Salt[3] = (rand % 255) + 1;
 }
-
-/*
- * PostmasterRandom
- */
-static long
-PostmasterRandom(void)
-{
-       extern struct timeval random_start_time;
-       static unsigned int random_seed = 0;
-
-       /*
-        * Select a random seed at the time of first receiving a request.
-        */
-       if (random_seed == 0)
-       {
-               do
-               {
-                       struct timeval random_stop_time;
-
-                       gettimeofday(&random_stop_time, NULL);
-
-                       /*
-                        * We are not sure how much precision is in tv_usec, so we swap
-                        * the high and low 16 bits of 'random_stop_time' and XOR them
-                        * with 'random_start_time'. On the off chance that the result is
-                        * 0, we loop until it isn't.
-                        */
-                       random_seed = random_start_time.tv_usec ^
-                               ((random_stop_time.tv_usec << 16) |
-                                ((random_stop_time.tv_usec >> 16) & 0xffff));
-               }
-               while (random_seed == 0);
-
-               srandom(random_seed);
-       }
-
-       return random();
-}