summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/bahamut.c2
-rw-r--r--src/config.c69
-rw-r--r--src/dreamforge.c2
-rw-r--r--src/hybrid.c6
-rw-r--r--src/init.c4
-rw-r--r--src/misc.c119
-rw-r--r--src/mysql.c23
-rw-r--r--src/nickserv.c5
-rw-r--r--src/process.c4
-rw-r--r--src/rageircd.c2
-rw-r--r--src/rdb.c4
-rw-r--r--src/ultimate2.c2
-rw-r--r--src/ultimate3.c2
-rw-r--r--src/unreal31.c2
-rw-r--r--src/unreal32.c2
-rw-r--r--src/viagra.c2
16 files changed, 226 insertions, 24 deletions
diff --git a/src/bahamut.c b/src/bahamut.c
index 49dce62dd..309d5ecb4 100644
--- a/src/bahamut.c
+++ b/src/bahamut.c
@@ -1399,7 +1399,7 @@ void anope_cmd_nc_change(User * u)
/* SVSMODE +d */
void anope_cmd_svid_umode2(User * u, char *ts)
{
- // not used by bahamut ircds
+ /* not used by bahamut ircds */
}
diff --git a/src/config.c b/src/config.c
index 99fd6b677..4c3af8292 100644
--- a/src/config.c
+++ b/src/config.c
@@ -316,6 +316,10 @@ char *DefConOffMessage;
char *DefconMessage;
char *DefConAkillReason;
+unsigned int UserKey1;
+unsigned int UserKey2;
+unsigned int UserKey3;
+
/*************************************************************************/
/* Deprecated directive (dep_) and value checking (chk_) functions: */
@@ -333,14 +337,21 @@ static void dep_ListOpersOnly(void)
/* Configuration directives */
typedef struct {
+ int type;
+ int flags;
+ void *ptr;
+} ConfParam;
+
+typedef struct {
char *name;
- struct {
- int type; /* PARAM_* below */
- int flags; /* Same */
- void *ptr; /* Pointer to where to store the value */
- } params[MAXPARAMS];
+ ConfParam params[MAXPARAMS];
} Directive;
+typedef struct {
+ char *name;
+ int (*func) (int line, int argc, char **argv);
+} ConfCB;
+
#define PARAM_NONE 0
#define PARAM_INT 1
#define PARAM_POSINT 2 /* Positive integer only */
@@ -358,6 +369,11 @@ typedef struct {
#define PARAM_FULLONLY 0x02 /* Directive only allowed if !STREAMLINED */
#define PARAM_RELOAD 0x04 /* Directive is reloadable */
+int doAddOper(int line, int argc, char **argv);
+
+ConfCB confroutines[] = {
+ {"Oper", &doAddOper}
+};
Directive directives[] = {
{"AkillOnAdd", {{PARAM_SET, PARAM_RELOAD, &AkillOnAdd}}},
{"AutokillDB", {{PARAM_STRING, PARAM_RELOAD, &AutokillDBName}}},
@@ -612,6 +628,9 @@ Directive directives[] = {
{"UpdateTimeout", {{PARAM_TIME, PARAM_RELOAD, &UpdateTimeout}}},
{"UseMail", {{PARAM_SET, PARAM_RELOAD, &UseMail}}},
{"UsePrivmsg", {{PARAM_SET, PARAM_RELOAD, &UsePrivmsg}}},
+ {"UserKey1", {{PARAM_POSINT, PARAM_RELOAD, &UserKey1}}},
+ {"UserKey2", {{PARAM_POSINT, PARAM_RELOAD, &UserKey2}}},
+ {"UserKey3", {{PARAM_POSINT, PARAM_RELOAD, &UserKey3}}},
{"UseSVSHOLD", {{PARAM_SET, PARAM_RELOAD, &UseSVSHOLD}}},
{"WallAkillExpire", {{PARAM_SET, PARAM_RELOAD, &WallAkillExpire}}},
{"WallBadOS", {{PARAM_SET, PARAM_RELOAD, &WallBadOS}}},
@@ -675,6 +694,22 @@ void error(int linenum, char *message, ...)
/*************************************************************************/
+int doAddOper(int line, int argc, char **argv)
+{
+ char *name;
+ int i, operflags;
+ if (argc < 2) {
+ error(line, "Oper: Missing Arguments");
+ return 0;
+ }
+
+ name = argv[0];
+ operflags = atoi(argv[1]);
+ error(line, "Added Oper %s with flags %d", name, operflags);
+
+ return 1;
+}
+
/* Parse a configuration line. Return 1 on success; otherwise, print an
* appropriate error message and return 0. Destroys the buffer by side
* effect.
@@ -727,6 +762,13 @@ int parse(char *buf, int linenum, int reload)
if (!dir)
return 1;
+ for (n = 0; n < lenof(confroutines); n++) {
+ ConfCB *cb = &confroutines[n];
+ if (stricmp(dir, cb->name) != 0)
+ continue;
+ return cb->func(linenum, ac, av);
+ }
+
for (n = 0; n < lenof(directives); n++) {
Directive *d = &directives[n];
if (stricmp(dir, d->name) != 0)
@@ -1261,6 +1303,23 @@ int read_config(int reload)
}
}
+ /* Check the user keys */
+ CHECK(UserKey1);
+ CHECK(UserKey2);
+ CHECK(UserKey3);
+ if ((UserKey1 == UserKey2) || (UserKey1 == UserKey3)
+ || (UserKey3 == UserKey2)) {
+ error(0,
+ "Every UserKey must be different. It's for YOUR safety! Remember that!");
+ retval = 0;
+ }
+ if ((UserKey1 == 9866235) || (UserKey2 == 5216332)
+ || (UserKey3 == 9651291)) {
+ error(0,
+ "You don't want your network secure? You are supposed to set NEW UserKey values!!!");
+ retval = 0;
+ }
+
/**
* Check all DEFCON dependiencies...
**/
diff --git a/src/dreamforge.c b/src/dreamforge.c
index fd82391ce..93f696e93 100644
--- a/src/dreamforge.c
+++ b/src/dreamforge.c
@@ -1232,7 +1232,7 @@ void anope_cmd_svid_umode2(User * u, char *ts)
void anope_cmd_svid_umode3(User * u, char *ts)
{
- // not used
+ /* not used */
}
/* NICK <newnick> */
diff --git a/src/hybrid.c b/src/hybrid.c
index 3f974898d..c7da4df56 100644
--- a/src/hybrid.c
+++ b/src/hybrid.c
@@ -1272,19 +1272,19 @@ void anope_cmd_svid_umode(char *nick, time_t ts)
/* nc_change was = 1, and there is no na->status */
void anope_cmd_nc_change(User * u)
{
- // not used
+ /* not used */
}
/* SVSMODE +d */
void anope_cmd_svid_umode2(User * u, char *ts)
{
- // not used
+ /* not used */
}
void anope_cmd_svid_umode3(User * u, char *ts)
{
- // not used
+ /* not used */
}
/* NICK <newnick> */
diff --git a/src/init.c b/src/init.c
index 3ceca3c3f..2ff23d437 100644
--- a/src/init.c
+++ b/src/init.c
@@ -589,6 +589,10 @@ int init(int ac, char **av)
/* load any custom modules */
modules_init();
+ /* Initialize random number generator */
+ rand_init();
+ add_entropy_userkeys();
+
#ifdef USE_CONVERTER
/* Convert the databases NOW! */
# ifdef IS44_CONVERTER
diff --git a/src/misc.c b/src/misc.c
index 6b3369341..be34f3bf6 100644
--- a/src/misc.c
+++ b/src/misc.c
@@ -19,6 +19,12 @@
/* Cheaper than isspace() or isblank() */
#define issp(c) ((c) == 32)
+struct arc4_stream {
+ u_int8_t i;
+ u_int8_t j;
+ u_int8_t s[256];
+} rs;
+
/*************************************************************************/
/* toupper/tolower: Like the ANSI functions, but make sure we return an
@@ -642,7 +648,7 @@ void doCleanBuffer(char *str)
break;
*out++ = ' ';
}
- *out = ch; // == '\0'
+ *out = ch; /* == '\0' */
}
void EnforceQlinedNick(char *nick, char *killer)
@@ -714,4 +720,115 @@ int nickIsServices(char *nick)
return found;
}
+static void arc4_init(void)
+{
+ int n;
+ for (n = 0; n < 256; n++)
+ rs.s[n] = n;
+ rs.i = 0;
+ rs.j = 0;
+}
+
+static inline void arc4_addrandom(void *dat, int datlen)
+{
+ int n;
+ u_int8_t si;
+
+ rs.i--;
+ for (n = 0; n < 256; n++) {
+ rs.i = (rs.i + 1);
+ si = rs.s[rs.i];
+ rs.j = (rs.j + si + ((unsigned char *) dat)[n % datlen]);
+ rs.s[rs.i] = rs.s[rs.j];
+ rs.s[rs.j] = si;
+ }
+}
+
+void rand_init(void)
+{
+ int n;
+#ifndef _WIN32
+ int fd;
+#endif
+ struct {
+#ifdef USE_MYSQL
+ int sqlrand;
+#endif
+#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 "random" MYSQL data */
+#ifdef USE_MYSQL
+ rdat.sqlrand = mysql_rand();
+#endif
+
+ /* Grab OS specific "random" data */
+#ifndef _WIN32
+ /* unix/bsd: time */
+ gettimeofday(&rdat.nowt, NULL);
+ /* unix/bsd: /dev/urandom */
+ fd = open("/dev/urandom", "r");
+ if (fd) {
+ n = 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));
+}
+
+void add_entropy_userkeys(void)
+{
+ arc4_addrandom(&UserKey1, sizeof(UserKey1));
+ arc4_addrandom(&UserKey2, sizeof(UserKey2));
+ arc4_addrandom(&UserKey3, sizeof(UserKey3));
+ /* UserKey3 is also used in mysql_rand() */
+}
+
+u_char getrandom8(void)
+{
+ u_char si, sj;
+
+ rs.i = (rs.i + 1);
+ si = rs.s[rs.i];
+ rs.j = (rs.j + si);
+ sj = rs.s[rs.j];
+ rs.s[rs.i] = sj;
+ rs.s[rs.j] = si;
+ return (rs.s[(si + sj) & 0xff]);
+}
+
+u_int16_t getrandom16(void)
+{
+ u_int16_t val;
+
+ val = getrandom8() << 8;
+ val |= getrandom8();
+ return val;
+}
+
+u_int32_t getrandom32(void)
+{
+ u_int32_t val;
+
+ val = getrandom8() << 24;
+ val |= getrandom8() << 16;
+ val |= getrandom8() << 8;
+ val |= getrandom8();
+ return val;
+}
+
diff --git a/src/mysql.c b/src/mysql.c
index 932b6a5db..7be2b5d40 100644
--- a/src/mysql.c
+++ b/src/mysql.c
@@ -1611,4 +1611,27 @@ void db_mysql_load_ns_dbase(void)
}
}
+/* get random mysql number for the generator */
+unsigned int mysql_rand(void)
+{
+ char sqlcmd[MAX_SQL_BUF];
+ unsigned int num = 0;
+ if (!do_mysql)
+ return 0;
+ snprintf(sqlcmd, MAX_SQL_BUF, "SELECT RAND()");
+ if (db_mysql_query(sqlcmd)) {
+ log_perror("Can't create sql query: %s", sqlcmd);
+ db_mysql_error(MYSQL_WARNING, "query");
+ }
+ mysql_res = mysql_store_result(mysql);
+ if (mysql_num_rows(mysql_res) == 0) {
+ mysql_free_result(mysql_res);
+ return 0;
+ }
+ mysql_row = mysql_fetch_row(mysql_res);
+ num = (atoi(mysql_row[0]) * UserKey3);
+ mysql_free_result(mysql_res);
+ return num;
+}
+
diff --git a/src/nickserv.c b/src/nickserv.c
index e9fff9fce..0c00df3e8 100644
--- a/src/nickserv.c
+++ b/src/nickserv.c
@@ -2010,12 +2010,11 @@ static int do_register(User * u)
notice_lang(s_NickServ, u, PASSWORD_TRUNCATED, PASSMAX - 1);
}
#endif
- srand((unsigned) time(NULL));
for (idx = 0; idx < 9; idx++) {
passcode[idx] =
chars[(1 +
- (int) (((float) (max - min)) * rand() /
- (RAND_MAX + 1.0)) + min)];
+ (int) (((float) (max - min)) * getrandom16() /
+ (65535 + 1.0)) + min)];
} passcode[idx] = '\0';
nr = makerequest(u->nick);
nr->passcode = sstrdup(passcode);
diff --git a/src/process.c b/src/process.c
index c917c9785..c4ae9b6d7 100644
--- a/src/process.c
+++ b/src/process.c
@@ -75,8 +75,8 @@ IgnoreData *get_ignore(const char *nick)
IgnoreData **whichlist = &ignore[tolower(nick[0])];
User *u = finduser(nick);
IgnoreData **whichlist2 = NULL;
- // Bleah, this doesn't work. I need a way to get the first char of u->username.
- //if (u) whichlist2 = &ignore[tolower(u->username[0])];
+ /* Bleah, this doesn't work. I need a way to get the first char of u->username.
+ /if (u) whichlist2 = &ignore[tolower(u->username[0])]; */
IgnoreData **whichlistast = &ignore[42]; /* * */
IgnoreData **whichlistqst = &ignore[63]; /* ? */
int finished = 0;
diff --git a/src/rageircd.c b/src/rageircd.c
index bc8f3ae3c..7d643ccdd 100644
--- a/src/rageircd.c
+++ b/src/rageircd.c
@@ -1369,7 +1369,7 @@ void anope_cmd_nc_change(User * u)
/* SVSMODE +d */
void anope_cmd_svid_umode2(User * u, char *ts)
{
- // not used by bahamut ircds
+ /* not used by bahamut ircds */
}
void anope_cmd_svid_umode3(User * u, char *ts)
diff --git a/src/rdb.c b/src/rdb.c
index 5876273dd..fd57b6058 100644
--- a/src/rdb.c
+++ b/src/rdb.c
@@ -30,7 +30,7 @@ int rdb_open()
{
#ifdef USE_MYSQL
- return do_mysql; // db_mysql_open();
+ return do_mysql; /* db_mysql_open(); */
#endif
}
@@ -41,7 +41,7 @@ int rdb_close()
{
#ifdef USE_MYSQL
- return 1; // db_mysql_close();
+ return 1; /* db_mysql_close(); */
#endif
}
diff --git a/src/ultimate2.c b/src/ultimate2.c
index b6856925c..7a6e0db31 100644
--- a/src/ultimate2.c
+++ b/src/ultimate2.c
@@ -1424,7 +1424,7 @@ void anope_cmd_svid_umode2(User * u, char *ts)
void anope_cmd_svid_umode3(User * u, char *ts)
{
- // not used
+ /* not used */
}
int anope_event_notice(char *source, int ac, char **av)
diff --git a/src/ultimate3.c b/src/ultimate3.c
index 95de6121c..f942ae856 100644
--- a/src/ultimate3.c
+++ b/src/ultimate3.c
@@ -1530,7 +1530,7 @@ void anope_cmd_nc_change(User * u)
/* SVSMODE +d */
void anope_cmd_svid_umode2(User * u, char *ts)
{
- // not used by bahamut ircds
+ /* not used by bahamut ircds */
}
void anope_cmd_svid_umode3(User * u, char *ts)
diff --git a/src/unreal31.c b/src/unreal31.c
index 0ead65d5a..42d3a5135 100644
--- a/src/unreal31.c
+++ b/src/unreal31.c
@@ -1452,7 +1452,7 @@ void anope_cmd_svid_umode2(User * u, char *ts)
void anope_cmd_svid_umode3(User * u, char *ts)
{
- // not used
+ /* not used */
}
#endif
diff --git a/src/unreal32.c b/src/unreal32.c
index 3c83fe854..55dafcd57 100644
--- a/src/unreal32.c
+++ b/src/unreal32.c
@@ -1545,7 +1545,7 @@ void anope_cmd_svid_umode2(User * u, char *ts)
void anope_cmd_svid_umode3(User * u, char *ts)
{
- // not used
+ /* not used */
}
int anope_event_error(char *source, int ac, char **av)
diff --git a/src/viagra.c b/src/viagra.c
index b96751f39..a4a324c44 100644
--- a/src/viagra.c
+++ b/src/viagra.c
@@ -1452,7 +1452,7 @@ void anope_cmd_nc_change(User * u)
/* SVSMODE +d */
void anope_cmd_svid_umode2(User * u, char *ts)
{
- // not used by bahamut ircds
+ /* not used by bahamut ircds */
}
void anope_cmd_svid_umode3(User * u, char *ts)