summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHeiko Schlichting <heiko@fu-berlin.de>2021-02-19 11:16:10 +0000
committerJeremy Harris <jgh146exb@wizmail.org>2021-02-19 11:55:56 +0000
commit213da388e7834c078ed5fd2e0063c951db0d8080 (patch)
tree9975c0e0e4109bf4f9ded08a24ff649655e9ff01 /src
parent83811e3c1b8189c0a725ec53df699730e7767263 (diff)
Use random_number rather than random, for external server distribution. Bug 2694
Diffstat (limited to 'src')
-rw-r--r--src/src/spam.c12
-rw-r--r--src/src/transports/smtp_socks.c12
2 files changed, 2 insertions, 22 deletions
diff --git a/src/src/spam.c b/src/src/spam.c
index b0e24b368..286038678 100644
--- a/src/src/spam.c
+++ b/src/src/spam.c
@@ -139,21 +139,11 @@ unsigned int i;
spamd_address_container * sd;
long weights;
unsigned pri;
-static BOOL srandomed = FALSE;
/* speedup, if we have only 1 server */
if (num_servers == 1)
return (spamds[0]->is_failed ? -1 : 0);
-/* init ranmod */
-if (!srandomed)
- {
- struct timeval tv;
- gettimeofday(&tv, NULL);
- srandom((unsigned int)(tv.tv_usec/1000));
- srandomed = TRUE;
- }
-
/* scan for highest pri */
for (pri = 0, i = 0; i < num_servers; i++)
{
@@ -170,7 +160,7 @@ for (weights = 0, i = 0; i < num_servers; i++)
if (weights == 0) /* all servers failed */
return -1;
-for (long rnd = random() % weights, i = 0; i < num_servers; i++)
+for (long rnd = random_number(weights), i = 0; i < num_servers; i++)
{
sd = spamds[i];
if (!sd->is_failed && sd->priority == pri)
diff --git a/src/src/transports/smtp_socks.c b/src/src/transports/smtp_socks.c
index cd8ed3e6d..22cfbecb4 100644
--- a/src/src/transports/smtp_socks.c
+++ b/src/src/transports/smtp_socks.c
@@ -160,20 +160,10 @@ socks_opts * sd;
socks_opts * lim = &proxies[nproxies];
long rnd, weights;
unsigned pri;
-static BOOL srandomed = FALSE;
if (nproxies == 1) /* shortcut, if we have only 1 server */
return (proxies[0].is_failed ? -1 : 0);
-/* init random */
-if (!srandomed)
- {
- struct timeval tv;
- gettimeofday(&tv, NULL);
- srandom((unsigned int)(tv.tv_usec/1000));
- srandomed = TRUE;
- }
-
/* scan for highest pri */
for (pri = 0, sd = proxies; sd < lim; sd++)
if (!sd->is_failed && sd->priority > pri)
@@ -186,7 +176,7 @@ for (weights = 0, sd = proxies; sd < lim; sd++)
if (weights == 0) /* all servers failed */
return -1;
-for (rnd = random() % weights, i = 0; i < nproxies; i++)
+for (rnd = random_number(weights), i = 0; i < nproxies; i++)
{
sd = &proxies[i];
if (!sd->is_failed && sd->priority == pri)