commit - d61fbfc6e3a0a85ced036d8c1fa161fab0d9ba3d
commit + 5acb90fafc9dea012967751fb6a5c7847da1820a
blob - 74a998800f364376a87efb290cd2d0dc030a2ab4
blob + 4cac909d8f02e3f4d60593693ee6855b49e7f338
--- src/ngircd/ngircd.c
+++ src/ngircd/ngircd.c
static void Pidfile_Delete PARAMS(( void ));
static void Fill_Version PARAMS(( void ));
+
+static void Random_Init PARAMS(( void ));
static void Setup_FDStreams PARAMS(( int fd ));
NGIRCd_SignalRestart = false;
NGIRCd_SignalQuit = false;
+ Random_Init();
+
/* Initialize modules, part I */
Log_Init( ! NGIRCd_NoDaemon );
Conf_Init( );
exit(1);
}
- srandom(getpid());
-
/* Create protocol and server identification. The syntax
* used by ngIRCd in PASS commands and the known "extended
* flags" are described in doc/Protocol.txt. */
} /* NGIRCd_getNobodyID */
+static bool
+Random_Init_Kern(const char *file)
+{
+ unsigned int seed;
+ bool ret = false;
+ int fd = open(file, O_RDONLY);
+ if (fd >= 0) {
+ if (read(fd, &seed, sizeof(seed)) == sizeof(seed))
+ ret = true;
+ close(fd);
+ srandom(seed);
+ }
+ return ret;
+}
+
/**
+ * Initialize libc random(3) number generator
+ */
+static void
+Random_Init(void)
+{
+ if (Random_Init_Kern("/dev/urandom"))
+ return;
+ if (Random_Init_Kern("/dev/random"))
+ return;
+ if (Random_Init_Kern("/dev/arandom"))
+ return;
+ srandom(random() ^ getpid() ^ time(NULL));
+}
+
+
+/**
* Initialize ngIRCd daemon.
*
* @param NGIRCd_NoDaemon Set to true if ngIRCd should run in the
blob - aace8053c00c2cca27f2a24ed0490f1271137f0e
blob + 557543c26c2385941b3c0ce8f75031398d66f0e8
--- src/ngircd/proc.c
+++ src/ngircd/proc.c
Proc_Fork(PROC_STAT *proc, int *pipefds, void (*cbfunc)(int, short), int timeout)
{
pid_t pid;
+ unsigned int seed;
assert(proc != NULL);
assert(pipefds != NULL);
return -1;
}
+ seed = random();
pid = fork();
switch (pid) {
case -1:
return -1;
case 0:
/* New child process: */
+ srandom(seed ^ time(NULL) ^ getpid());
Signals_Exit();
signal(SIGTERM, Proc_GenericSignalHandler);
signal(SIGALRM, Proc_GenericSignalHandler);