summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2012-02-13 00:10:45 -0500
committerAdam <Adam@anope.org>2012-02-13 00:10:45 -0500
commit086790d6331357022f4da17c76b26b9fc6e2ad90 (patch)
treee82d9e0b67cfc5ad0251d8bdcd2490207a875fc6 /src
parent1bc8e2ab82db9ce00faaa44887338873a2cd9210 (diff)
Removed our RNG and just use the systems, it's not very widely used. Also made DNS query ids not random as they don't need to be.
Diffstat (limited to 'src')
-rw-r--r--src/config.cpp7
-rw-r--r--src/dns.cpp15
-rw-r--r--src/init.cpp3
-rw-r--r--src/misc.cpp143
-rw-r--r--src/operserv.cpp2
-rw-r--r--src/users.cpp2
6 files changed, 12 insertions, 160 deletions
diff --git a/src/config.cpp b/src/config.cpp
index 952da263c..d35399896 100644
--- a/src/config.cpp
+++ b/src/config.cpp
@@ -154,10 +154,6 @@ ServerConfig::ServerConfig() : config_data(), NSDefFlags(NickCoreFlagStrings), C
this->SessionAutoKillExpiry = 1800; /* 30 minutes */
}
- /* Check the user keys */
- if (this->UserKey1 == this->UserKey2 || this->UserKey1 == this->UserKey3 || this->UserKey3 == this->UserKey2)
- Log() << "Every UserKey must be different. It's for YOUR safety! Remember that!";
-
SetDefaultMLock(this);
if (IsFile(this->NameServer))
@@ -1132,9 +1128,6 @@ ConfigItems::ConfigItems(ServerConfig *conf)
{"networkinfo", "userlen", "10", new ValueContainerUInt(&conf->UserLen), DT_UINTEGER | DT_NORELOAD, NoValidation},
{"networkinfo", "hostlen", "64", new ValueContainerUInt(&conf->HostLen), DT_UINTEGER | DT_NORELOAD, NoValidation},
{"options", "passlen", "32", new ValueContainerUInt(&conf->PassLen), DT_UINTEGER | DT_NORELOAD, NoValidation},
- {"options", "userkey1", "0", new ValueContainerLUInt(&conf->UserKey1), DT_LUINTEGER, NoValidation},
- {"options", "userkey2", "0", new ValueContainerLUInt(&conf->UserKey2), DT_LUINTEGER, NoValidation},
- {"options", "userkey3", "0", new ValueContainerLUInt(&conf->UserKey3), DT_LUINTEGER, NoValidation},
{"options", "nobackupokay", "no", new ValueContainerBool(&conf->NoBackupOkay), DT_BOOLEAN, NoValidation},
{"options", "strictpasswords", "no", new ValueContainerBool(&conf->StrictPasswords), DT_BOOLEAN, NoValidation},
{"options", "badpasslimit", "0", new ValueContainerUInt(&conf->BadPassLimit), DT_UINTEGER, NoValidation},
diff --git a/src/dns.cpp b/src/dns.cpp
index 02df2aea4..fc1ab37df 100644
--- a/src/dns.cpp
+++ b/src/dns.cpp
@@ -52,8 +52,11 @@ DNSRequest::DNSRequest(const Anope::string &addr, QueryType qt, bool cache, Modu
throw SocketException("DNS queue full");
do
- this->id = getrandom16();
- while (!this->id || DNSEngine->requests.count(this->id));
+ {
+ static unsigned short cur_id = 0;
+ this->id = cur_id++;
+ }
+ while (DNSEngine->requests.count(this->id));
DNSEngine->requests[this->id] = this;
}
@@ -457,7 +460,7 @@ DNSManager::~DNSManager()
delete this->packets[i - 1];
this->packets.clear();
- for (std::map<short, DNSRequest *>::iterator it = this->requests.begin(), it_end = this->requests.end(); it != it_end; ++it)
+ for (std::map<unsigned short, DNSRequest *>::iterator it = this->requests.begin(), it_end = this->requests.end(); it != it_end; ++it)
{
DNSRequest *request = it->second;
@@ -504,7 +507,7 @@ bool DNSManager::ProcessRead()
return true;
}
- std::map<short, DNSRequest *>::iterator it = DNSEngine->requests.find(recv_packet.id);
+ std::map<unsigned short, DNSRequest *>::iterator it = DNSEngine->requests.find(recv_packet.id);
if (it == DNSEngine->requests.end())
{
Log(LOG_DEBUG_2) << "Resolver: Received an answer for something we didn't request";
@@ -652,9 +655,9 @@ void DNSManager::Tick(time_t now)
void DNSManager::Cleanup(Module *mod)
{
- for (std::map<short, DNSRequest *>::iterator it = this->requests.begin(), it_end = this->requests.end(); it != it_end;)
+ for (std::map<unsigned short, DNSRequest *>::iterator it = this->requests.begin(), it_end = this->requests.end(); it != it_end;)
{
- short id = it->first;
+ unsigned short id = it->first;
DNSRequest *req = it->second;
++it;
diff --git a/src/init.cpp b/src/init.cpp
index a9cbcc03a..2a87ade9c 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -459,8 +459,7 @@ void Init(int ac, char **av)
InitLanguages();
/* Initialize random number generator */
- rand_init();
- add_entropy_userkeys();
+ srand(time(NULL));
/* load modules */
Log() << "Loading modules...";
diff --git a/src/misc.cpp b/src/misc.cpp
index 02b886d75..524095d88 100644
--- a/src/misc.cpp
+++ b/src/misc.cpp
@@ -27,13 +27,6 @@ void ExtensibleItem::OnDelete()
delete this;
}
-struct arc4_stream
-{
- uint8_t i;
- uint8_t j;
- uint8_t s[256];
-} rs;
-
/*************************************************************************/
/** Check if a file exists
@@ -520,142 +513,6 @@ bool nickIsServices(const Anope::string &tempnick, bool bot)
/*************************************************************************/
/**
- * arc4 init
- * @return void
- */
-static void arc4_init()
-{
- for (int n = 0; n < 256; ++n)
- rs.s[n] = n;
- rs.i = 0;
- rs.j = 0;
-}
-
-/*************************************************************************/
-
-/**
- * arc4 addrandom
- * @param data
- * @param dalen Data Length
- * @return void
- */
-static void arc4_addrandom(void *dat, int datlen)
-{
- --rs.i;
- for (int n = 0; n < 256; ++n)
- {
- ++rs.i;
- uint8_t si = rs.s[rs.i];
- rs.j = rs.j + si + (static_cast<unsigned char *>(dat))[n % datlen];
- rs.s[rs.i] = rs.s[rs.j];
- rs.s[rs.j] = si;
- }
-}
-
-/*************************************************************************/
-
-/**
- * random init
- * @return void
- */
-void rand_init()
-{
- struct
- {
-#ifndef _WIN32
- struct timeval nowt; /* time */
- char rnd[32]; /* /dev/urandom */
-#else
- MEMORYSTATUS mstat; /* memory status */
- struct _timeb nowt; /* time */
-#endif
- } rdat;
-
- arc4_init();
-
- /* Grab OS specific "random" data */
-#ifndef _WIN32
- /* unix/bsd: time */
- gettimeofday(&rdat.nowt, NULL);
- /* unix/bsd: /dev/urandom */
- int fd = open("/dev/urandom", O_RDONLY);
- if (fd)
- {
- read(fd, &rdat.rnd, sizeof(rdat.rnd));
- close(fd);
- }
-#else
- /* win32: time */
- _ftime(&rdat.nowt);
- /* win32: memory status */
- GlobalMemoryStatus(&rdat.mstat);
-#endif
-
- arc4_addrandom(&rdat, sizeof(rdat));
-}
-
-/*************************************************************************/
-
-/**
- * Setup the random numbers
- * @return void
- */
-void add_entropy_userkeys()
-{
- arc4_addrandom(&Config->UserKey1, sizeof(Config->UserKey1));
- arc4_addrandom(&Config->UserKey2, sizeof(Config->UserKey2));
- arc4_addrandom(&Config->UserKey3, sizeof(Config->UserKey3));
- /* UserKey3 is also used in mysql_rand() */
-}
-
-/*************************************************************************/
-
-/**
- * Get the random numbers 8 byte deep
- * @return char
- */
-unsigned char getrandom8()
-{
- ++rs.i;
- unsigned char si = rs.s[rs.i];
- rs.j += si;
- unsigned char sj = rs.s[rs.j];
- rs.s[rs.i] = sj;
- rs.s[rs.j] = si;
- return rs.s[(si + sj) & 0xff];
-}
-
-/*************************************************************************/
-
-/**
- * Get the random numbers 16 byte deep
- * @return char
- */
-uint16_t getrandom16()
-{
- uint16_t val = getrandom8() << 8;
- val |= getrandom8();
- return val;
-}
-
-/*************************************************************************/
-
-/**
- * Get the random numbers 32 byte deep
- * @return char
- */
-uint32_t getrandom32()
-{
- uint32_t val = getrandom8() << 24;
- val |= getrandom8() << 16;
- val |= getrandom8() << 8;
- val |= getrandom8();
- return val;
-}
-
-/*************************************************************************/
-
-/**
* Number of tokens in a string
* @param str String
* @param dilim Dilimiter
diff --git a/src/operserv.cpp b/src/operserv.cpp
index 6793581e0..e32937797 100644
--- a/src/operserv.cpp
+++ b/src/operserv.cpp
@@ -162,7 +162,7 @@ Anope::string XLineManager::GenerateUID()
{
char c;
do
- c = getrandom8();
+ c = (random() % 75) + 48;
while (!isupper(c) && !isdigit(c));
id += c;
}
diff --git a/src/users.cpp b/src/users.cpp
index c5f8351a4..f15754b28 100644
--- a/src/users.cpp
+++ b/src/users.cpp
@@ -321,7 +321,7 @@ void User::Collide(NickAlias *na)
int i = 0;
do
{
- guestnick = Config->NSGuestNickPrefix + stringify(getrandom16());
+ guestnick = Config->NSGuestNickPrefix + stringify(static_cast<uint16_t>(rand()));
} while (finduser(guestnick) && i++ < 10);
if (i == 11)