about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ngircd/conf.c4
-rw-r--r--src/ngircd/irc-login.c4
-rw-r--r--src/ngircd/ngircd.c8
-rw-r--r--src/ngircd/proc.c6
-rw-r--r--src/tool/tool.c5
5 files changed, 27 insertions, 0 deletions
diff --git a/src/ngircd/conf.c b/src/ngircd/conf.c
index 9c2c912f..d337947d 100644
--- a/src/ngircd/conf.c
+++ b/src/ngircd/conf.c
@@ -533,7 +533,11 @@ Conf_UnsetServer( CONN_ID Idx )
 				/* "Short" connection, enforce "ConnectRetry"
 				 * but randomize it a little bit: 15 seconds. */
 				Conf_Server[i].lasttry =
+#ifdef HAVE_ARC4RANDOM
+					t + (arc4random() % 15);
+#else
 					t + rand() / (RAND_MAX / 15);
+#endif
 			}
 		}
 	}
diff --git a/src/ngircd/irc-login.c b/src/ngircd/irc-login.c
index af087f9d..d1b4033b 100644
--- a/src/ngircd/irc-login.c
+++ b/src/ngircd/irc-login.c
@@ -242,7 +242,11 @@ IRC_NICK( CLIENT *Client, REQUEST *Req )
 
 #ifndef STRICT_RFC
 			if (Conf_AuthPing) {
+#ifdef HAVE_ARC4RANDOM
+				Conn_SetAuthPing(Client_Conn(Client), arc4random());
+#else
 				Conn_SetAuthPing(Client_Conn(Client), rand());
+#endif
 				IRC_WriteStrClient(Client, "PING :%ld",
 					Conn_GetAuthPing(Client_Conn(Client)));
 				LogDebug("Connection %d: sent AUTH PING %ld ...",
diff --git a/src/ngircd/ngircd.c b/src/ngircd/ngircd.c
index 6af58169..da537055 100644
--- a/src/ngircd/ngircd.c
+++ b/src/ngircd/ngircd.c
@@ -613,6 +613,13 @@ NGIRCd_getNobodyID(uid_t *uid, gid_t *gid )
 #endif
 
 
+#ifdef HAVE_ARC4RANDOM
+static void
+Random_Init(void)
+{
+
+}
+#else
 static bool
 Random_Init_Kern(const char *file)
 {
@@ -642,6 +649,7 @@ Random_Init(void)
 		return;
 	srand(rand() ^ (unsigned)getpid() ^ (unsigned)time(NULL));
 }
+#endif
 
 
 /**
diff --git a/src/ngircd/proc.c b/src/ngircd/proc.c
index e062cd0b..d290f3bd 100644
--- a/src/ngircd/proc.c
+++ b/src/ngircd/proc.c
@@ -50,7 +50,9 @@ GLOBAL pid_t
 Proc_Fork(PROC_STAT *proc, int *pipefds, void (*cbfunc)(int, short), int timeout)
 {
 	pid_t pid;
+#ifndef HAVE_ARC4RANDOM
 	unsigned int seed;
+#endif
 
 	assert(proc != NULL);
 	assert(pipefds != NULL);
@@ -62,7 +64,9 @@ Proc_Fork(PROC_STAT *proc, int *pipefds, void (*cbfunc)(int, short), int timeout
 		return -1;
 	}
 
+#ifndef HAVE_ARC4RANDOM
 	seed = (unsigned int)rand();
+#endif
 	pid = fork();
 	switch (pid) {
 	case -1:
@@ -73,7 +77,9 @@ Proc_Fork(PROC_STAT *proc, int *pipefds, void (*cbfunc)(int, short), int timeout
 		return -1;
 	case 0:
 		/* New child process: */
+#ifndef HAVE_ARC4RANDOM
 		srand(seed ^ (unsigned int)time(NULL) ^ getpid());
+#endif
 		Signals_Exit();
 		signal(SIGTERM, Proc_GenericSignalHandler);
 		signal(SIGALRM, Proc_GenericSignalHandler);
diff --git a/src/tool/tool.c b/src/tool/tool.c
index 1bb3ebe6..3b9cc255 100644
--- a/src/tool/tool.c
+++ b/src/tool/tool.c
@@ -144,11 +144,16 @@ ngt_RandomStr(char *String, const size_t len)
 	assert(String != NULL);
 
 	gettimeofday(&t, NULL);
+#ifndef HAVE_ARC4RANDOM
 	srand((unsigned)(t.tv_usec * t.tv_sec));
 
 	for (i = 0; i < len; ++i) {
 		String[i] = chars[rand() % (sizeof(chars) - 1)];
 	}
+#else
+	for (i = 0; i < len; ++i)
+		String[i] = chars[arc4random() % (sizeof(chars) - 1)];
+#endif
 	String[len] = '\0';
 
 	return String;