mirror of
https://github.com/osmarks/ngircd.git
synced 2025-05-05 08:54:06 +00:00
Add support for arc4random
If arc4random is present it will be used over the srand/rand interface. This fixes some warnings in OpenBSD-current.
This commit is contained in:
parent
ea26fd2840
commit
17589534d0
@ -187,8 +187,9 @@ AC_CHECK_FUNCS([ \
|
|||||||
|
|
||||||
# Optional functions
|
# Optional functions
|
||||||
AC_CHECK_FUNCS_ONCE([ \
|
AC_CHECK_FUNCS_ONCE([ \
|
||||||
gai_strerror getaddrinfo getnameinfo inet_aton sigaction sigprocmask \
|
arc4random gai_strerror getaddrinfo getnameinfo inet_aton sigaction \
|
||||||
snprintf vsnprintf strdup strndup strlcpy strlcat strtok_r waitpid])
|
sigprocmask snprintf vsnprintf strdup strndup strlcpy strlcat strtok_r \
|
||||||
|
waitpid])
|
||||||
|
|
||||||
# -- Configuration options --
|
# -- Configuration options --
|
||||||
|
|
||||||
|
@ -533,7 +533,11 @@ Conf_UnsetServer( CONN_ID Idx )
|
|||||||
/* "Short" connection, enforce "ConnectRetry"
|
/* "Short" connection, enforce "ConnectRetry"
|
||||||
* but randomize it a little bit: 15 seconds. */
|
* but randomize it a little bit: 15 seconds. */
|
||||||
Conf_Server[i].lasttry =
|
Conf_Server[i].lasttry =
|
||||||
|
#ifdef HAVE_ARC4RANDOM
|
||||||
|
t + (arc4random() % 15);
|
||||||
|
#else
|
||||||
t + rand() / (RAND_MAX / 15);
|
t + rand() / (RAND_MAX / 15);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -242,7 +242,11 @@ IRC_NICK( CLIENT *Client, REQUEST *Req )
|
|||||||
|
|
||||||
#ifndef STRICT_RFC
|
#ifndef STRICT_RFC
|
||||||
if (Conf_AuthPing) {
|
if (Conf_AuthPing) {
|
||||||
|
#ifdef HAVE_ARC4RANDOM
|
||||||
|
Conn_SetAuthPing(Client_Conn(Client), arc4random());
|
||||||
|
#else
|
||||||
Conn_SetAuthPing(Client_Conn(Client), rand());
|
Conn_SetAuthPing(Client_Conn(Client), rand());
|
||||||
|
#endif
|
||||||
IRC_WriteStrClient(Client, "PING :%ld",
|
IRC_WriteStrClient(Client, "PING :%ld",
|
||||||
Conn_GetAuthPing(Client_Conn(Client)));
|
Conn_GetAuthPing(Client_Conn(Client)));
|
||||||
LogDebug("Connection %d: sent AUTH PING %ld ...",
|
LogDebug("Connection %d: sent AUTH PING %ld ...",
|
||||||
|
@ -613,6 +613,13 @@ NGIRCd_getNobodyID(uid_t *uid, gid_t *gid )
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef HAVE_ARC4RANDOM
|
||||||
|
static void
|
||||||
|
Random_Init(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
#else
|
||||||
static bool
|
static bool
|
||||||
Random_Init_Kern(const char *file)
|
Random_Init_Kern(const char *file)
|
||||||
{
|
{
|
||||||
@ -642,6 +649,7 @@ Random_Init(void)
|
|||||||
return;
|
return;
|
||||||
srand(rand() ^ (unsigned)getpid() ^ (unsigned)time(NULL));
|
srand(rand() ^ (unsigned)getpid() ^ (unsigned)time(NULL));
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -50,7 +50,9 @@ GLOBAL pid_t
|
|||||||
Proc_Fork(PROC_STAT *proc, int *pipefds, void (*cbfunc)(int, short), int timeout)
|
Proc_Fork(PROC_STAT *proc, int *pipefds, void (*cbfunc)(int, short), int timeout)
|
||||||
{
|
{
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
|
#ifndef HAVE_ARC4RANDOM
|
||||||
unsigned int seed;
|
unsigned int seed;
|
||||||
|
#endif
|
||||||
|
|
||||||
assert(proc != NULL);
|
assert(proc != NULL);
|
||||||
assert(pipefds != NULL);
|
assert(pipefds != NULL);
|
||||||
@ -62,7 +64,9 @@ Proc_Fork(PROC_STAT *proc, int *pipefds, void (*cbfunc)(int, short), int timeout
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef HAVE_ARC4RANDOM
|
||||||
seed = (unsigned int)rand();
|
seed = (unsigned int)rand();
|
||||||
|
#endif
|
||||||
pid = fork();
|
pid = fork();
|
||||||
switch (pid) {
|
switch (pid) {
|
||||||
case -1:
|
case -1:
|
||||||
@ -73,7 +77,9 @@ Proc_Fork(PROC_STAT *proc, int *pipefds, void (*cbfunc)(int, short), int timeout
|
|||||||
return -1;
|
return -1;
|
||||||
case 0:
|
case 0:
|
||||||
/* New child process: */
|
/* New child process: */
|
||||||
|
#ifndef HAVE_ARC4RANDOM
|
||||||
srand(seed ^ (unsigned int)time(NULL) ^ getpid());
|
srand(seed ^ (unsigned int)time(NULL) ^ getpid());
|
||||||
|
#endif
|
||||||
Signals_Exit();
|
Signals_Exit();
|
||||||
signal(SIGTERM, Proc_GenericSignalHandler);
|
signal(SIGTERM, Proc_GenericSignalHandler);
|
||||||
signal(SIGALRM, Proc_GenericSignalHandler);
|
signal(SIGALRM, Proc_GenericSignalHandler);
|
||||||
|
@ -144,11 +144,16 @@ ngt_RandomStr(char *String, const size_t len)
|
|||||||
assert(String != NULL);
|
assert(String != NULL);
|
||||||
|
|
||||||
gettimeofday(&t, NULL);
|
gettimeofday(&t, NULL);
|
||||||
|
#ifndef HAVE_ARC4RANDOM
|
||||||
srand((unsigned)(t.tv_usec * t.tv_sec));
|
srand((unsigned)(t.tv_usec * t.tv_sec));
|
||||||
|
|
||||||
for (i = 0; i < len; ++i) {
|
for (i = 0; i < len; ++i) {
|
||||||
String[i] = chars[rand() % (sizeof(chars) - 1)];
|
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';
|
String[len] = '\0';
|
||||||
|
|
||||||
return String;
|
return String;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user