Commit Diff


commit - ea26fd2840f6c7f286407e86f832d6ec5e93eeeb
commit + 17589534d0ccff05463910d1f0ba673d7d1630fd
blob - faf3086b6b87b2d5d3d964e9024f4f067d8c056e
blob + 16f970f8dc982d21d96e9f1bdf2de8deba1736f8
--- configure.ng
+++ configure.ng
@@ -187,8 +187,9 @@ AC_CHECK_FUNCS([ \
 
 # Optional functions
 AC_CHECK_FUNCS_ONCE([ \
-	gai_strerror getaddrinfo getnameinfo inet_aton sigaction sigprocmask \
-	snprintf vsnprintf strdup strndup strlcpy strlcat strtok_r waitpid])
+	arc4random gai_strerror getaddrinfo getnameinfo inet_aton sigaction \
+	sigprocmask snprintf vsnprintf strdup strndup strlcpy strlcat strtok_r \
+	waitpid])
 
 # -- Configuration options --
 
blob - 9c2c912f1d126ee2282653c7ad85d9b2e9f1f91c
blob + d337947d9104eac1a9ef2a7da45b9132aef06f22
--- src/ngircd/conf.c
+++ 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
 			}
 		}
 	}
blob - af087f9dcdd7d01907e749745e0111896aa46a7a
blob + d1b4033b3a54d70ef83bab9e729eeafd5123f177
--- src/ngircd/irc-login.c
+++ 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 ...",
blob - 6af58169e48f6382056e7af68536eaceeb1e9fae
blob + da537055ffdd742960a425a067ddfd3a62540f98
--- src/ngircd/ngircd.c
+++ src/ngircd/ngircd.c
@@ -611,8 +611,15 @@ NGIRCd_getNobodyID(uid_t *uid, gid_t *gid )
 } /* NGIRCd_getNobodyID */
 
 #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
 
 
 /**
blob - e062cd0b7c702494a3992e8bfe1beab2a348113a
blob + d290f3bd100faed3cc17d8d24cd6396443a41131
--- src/ngircd/proc.c
+++ 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
 		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
 		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);
blob - 1bb3ebe698b0a6f106e09f5d1b85fea51e9f654b
blob + 3b9cc255aed18141c38d6548804798bf396ff125
--- src/tool/tool.c
+++ 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;