|
@@ -330,20 +330,20 @@ static void cache_invite(struct chanset_t *chan, char *nick, char *host, char *h
|
|
|
dprintf(DP_SERVER, "INVITE %s %s\n", nick, chan->name);
|
|
dprintf(DP_SERVER, "INVITE %s %s\n", nick, chan->name);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-const char * cookie_hash(const char* chname, const memberlist* opper, const memberlist* opped, const char* ts, const char* salt, const char* key) {
|
|
|
|
|
|
|
+static inline const char * cookie_hash(const char* chname, const memberlist* opper, const memberlist* opped, const char* ts, const char* randstring, const char* key) {
|
|
|
char tohash[201] = "";
|
|
char tohash[201] = "";
|
|
|
const char salt2[] = SALT2;
|
|
const char salt2[] = SALT2;
|
|
|
|
|
|
|
|
simple_snprintf(tohash, sizeof(tohash), STR("%c%s%c%c%c\n%c%c%s%s%s"),
|
|
simple_snprintf(tohash, sizeof(tohash), STR("%c%s%c%c%c\n%c%c%s%s%s"),
|
|
|
salt2[0],
|
|
salt2[0],
|
|
|
ts,
|
|
ts,
|
|
|
- salt[0], salt[1], salt[2], salt[3],
|
|
|
|
|
|
|
+ randstring[0], randstring[1], randstring[2], randstring[3],
|
|
|
salt2[15],
|
|
salt2[15],
|
|
|
opped->nick,
|
|
opped->nick,
|
|
|
opped->userhost,
|
|
opped->userhost,
|
|
|
key);
|
|
key);
|
|
|
#ifdef DEBUG
|
|
#ifdef DEBUG
|
|
|
-sdprintf("chname: %s ts: %s salt: %c%c%c%c", chname, ts, salt[0], salt[1], salt[2], salt[3]);
|
|
|
|
|
|
|
+sdprintf("chname: %s ts: %s randstring: %c%c%c%c", chname, ts, randstring[0], randstring[1], randstring[2], randstring[3]);
|
|
|
sdprintf("tohash: %s", tohash);
|
|
sdprintf("tohash: %s", tohash);
|
|
|
#endif
|
|
#endif
|
|
|
const char* md5 = MD5(tohash);
|
|
const char* md5 = MD5(tohash);
|
|
@@ -351,27 +351,10 @@ sdprintf("tohash: %s", tohash);
|
|
|
return md5;
|
|
return md5;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-#define HASH_INDEX1(_x) (8 + (_x))
|
|
|
|
|
-#define HASH_INDEX2(_x) (16 + (_x))
|
|
|
|
|
-#define HASH_INDEX3(_x) (18 + (_x))
|
|
|
|
|
-
|
|
|
|
|
-void makecookie(char *out, size_t len, const char *chname, const memberlist* opper, const memberlist* m1, const memberlist* m2, const memberlist* m3) {
|
|
|
|
|
- char randstring[5] = "", ts[11] = "";
|
|
|
|
|
-
|
|
|
|
|
- make_rand_str(randstring, 4);
|
|
|
|
|
- /* &ts[4] is now last 6 digits of time */
|
|
|
|
|
- simple_snprintf(ts, sizeof(ts), "%010li", (long) (now + timesync));
|
|
|
|
|
-
|
|
|
|
|
- char cookie_clear[101] = "";
|
|
|
|
|
-
|
|
|
|
|
- //Increase my counter
|
|
|
|
|
- ++my_counter;
|
|
|
|
|
- simple_snprintf2(cookie_clear, sizeof(cookie_clear), STR("%s%s%D"), randstring, &ts[3], my_counter);
|
|
|
|
|
-
|
|
|
|
|
- char key[150] = "";
|
|
|
|
|
|
|
+static inline void cookie_key(char *key, size_t key_len, const char* randstring, const memberlist *opper, const char *chname) {
|
|
|
const char salt1[] = SALT1;
|
|
const char salt1[] = SALT1;
|
|
|
const char salt2[] = SALT2;
|
|
const char salt2[] = SALT2;
|
|
|
- simple_snprintf2(key, sizeof(key), STR("%c%c%c%s%c%c%c%c%c%c%^s%c%c%c%c%c%c%c%s"),
|
|
|
|
|
|
|
+ simple_snprintf2(key, key_len, STR("%c%c%c%s%c%c%c%c%c%c%^s%c%c%c%c%c%c%c%s"),
|
|
|
randstring[0],
|
|
randstring[0],
|
|
|
salt1[5],
|
|
salt1[5],
|
|
|
randstring[3],
|
|
randstring[3],
|
|
@@ -392,6 +375,28 @@ void makecookie(char *out, size_t len, const char *chname, const memberlist* opp
|
|
|
salt2[1],
|
|
salt2[1],
|
|
|
opper->userhost
|
|
opper->userhost
|
|
|
);
|
|
);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+#define HASH_INDEX1(_x) (8 + (_x))
|
|
|
|
|
+#define HASH_INDEX2(_x) (16 + (_x))
|
|
|
|
|
+#define HASH_INDEX3(_x) (18 + (_x))
|
|
|
|
|
+
|
|
|
|
|
+void makecookie(char *out, size_t len, const char *chname, const memberlist* opper, const memberlist* m1, const memberlist* m2, const memberlist* m3) {
|
|
|
|
|
+ char randstring[5] = "", ts[11] = "";
|
|
|
|
|
+
|
|
|
|
|
+ make_rand_str(randstring, 4);
|
|
|
|
|
+ /* &ts[4] is now last 6 digits of time */
|
|
|
|
|
+ simple_snprintf(ts, sizeof(ts), "%010li", (long) (now + timesync));
|
|
|
|
|
+
|
|
|
|
|
+ char cookie_clear[101] = "";
|
|
|
|
|
+
|
|
|
|
|
+ //Increase my counter
|
|
|
|
|
+ ++my_counter;
|
|
|
|
|
+ simple_snprintf2(cookie_clear, sizeof(cookie_clear), STR("%s%s%D"), randstring, &ts[3], my_counter);
|
|
|
|
|
+
|
|
|
|
|
+ char key[150] = "";
|
|
|
|
|
+ cookie_key(key, sizeof(key), randstring, opper, chname);
|
|
|
|
|
+
|
|
|
const char* hash1 = cookie_hash(chname, opper, m1, &ts[4], randstring, key);
|
|
const char* hash1 = cookie_hash(chname, opper, m1, &ts[4], randstring, key);
|
|
|
const char* hash2 = m2 ? cookie_hash(chname, opper, m2, &ts[4], randstring, key) : NULL;
|
|
const char* hash2 = m2 ? cookie_hash(chname, opper, m2, &ts[4], randstring, key) : NULL;
|
|
|
const char* hash3 = m3 ? cookie_hash(chname, opper, m3, &ts[4], randstring, key) : NULL;
|
|
const char* hash3 = m3 ? cookie_hash(chname, opper, m3, &ts[4], randstring, key) : NULL;
|
|
@@ -446,36 +451,17 @@ void counter_clear(struct userrec *u) {
|
|
|
hash_table_insert(bot_counters, u->handle, (void *)(counter));
|
|
hash_table_insert(bot_counters, u->handle, (void *)(counter));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-static int checkcookie(const char *chname, const memberlist* opper, const memberlist* opped, const char *cookie, int indexHint) {
|
|
|
|
|
|
|
+static inline int checkcookie(const char *chname, const memberlist* opper, const memberlist* opped, const char *cookie, int indexHint) {
|
|
|
#define HOST(_x) (6 + (_x) + ((hashes << 1) + hashes)) /* x + (hashes * 3) */
|
|
#define HOST(_x) (6 + (_x) + ((hashes << 1) + hashes)) /* x + (hashes * 3) */
|
|
|
#define SALT(_x) (1 + (_x) + ((hashes << 1) + hashes)) /* x + (hashes * 3) */
|
|
#define SALT(_x) (1 + (_x) + ((hashes << 1) + hashes)) /* x + (hashes * 3) */
|
|
|
/* How many hashes are in the cookie? */
|
|
/* How many hashes are in the cookie? */
|
|
|
const size_t hashes = cookie[3] == '!' ? 1 : (cookie[6] == '!' ? 2 : 3);
|
|
const size_t hashes = cookie[3] == '!' ? 1 : (cookie[6] == '!' ? 2 : 3);
|
|
|
|
|
|
|
|
char key[150] = "";
|
|
char key[150] = "";
|
|
|
- const char salt1[] = SALT1;
|
|
|
|
|
- const char salt2[] = SALT2;
|
|
|
|
|
- simple_snprintf2(key, sizeof(key), STR("%c%c%c%s%c%c%c%c%c%c%^s%c%c%c%c%c%c%c%s"),
|
|
|
|
|
- cookie[SALT(0)],
|
|
|
|
|
- salt1[5],
|
|
|
|
|
- cookie[SALT(3)],
|
|
|
|
|
- opper->user->handle,
|
|
|
|
|
- cookie[SALT(2)],
|
|
|
|
|
- salt1[4],
|
|
|
|
|
- salt1[0],
|
|
|
|
|
- salt1[1],
|
|
|
|
|
- salt1[3],
|
|
|
|
|
- salt1[6],
|
|
|
|
|
- chname,
|
|
|
|
|
- salt1[10],
|
|
|
|
|
- cookie[SALT(1)],
|
|
|
|
|
- salt2[15],
|
|
|
|
|
- salt2[13],
|
|
|
|
|
- salt1[10],
|
|
|
|
|
- salt2[3],
|
|
|
|
|
- salt2[1],
|
|
|
|
|
- opper->userhost
|
|
|
|
|
- );
|
|
|
|
|
|
|
+ const char *randstring = &cookie[SALT(0)];
|
|
|
|
|
+
|
|
|
|
|
+ cookie_key(key, sizeof(key), randstring, opper, chname);
|
|
|
|
|
+
|
|
|
char* cleartext = decrypt_string(MD5(key), (char*) &cookie[HOST(0)]);
|
|
char* cleartext = decrypt_string(MD5(key), (char*) &cookie[HOST(0)]);
|
|
|
char ts[8] = "";
|
|
char ts[8] = "";
|
|
|
strlcpy(ts, cleartext + 4, sizeof(ts));
|
|
strlcpy(ts, cleartext + 4, sizeof(ts));
|
|
@@ -513,8 +499,7 @@ if (indexHint == 0) {
|
|
|
hash_table_insert(bot_counters, opper->user->handle, (void *)(counter));
|
|
hash_table_insert(bot_counters, opper->user->handle, (void *)(counter));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- const char *salt = &cookie[SALT(0)];
|
|
|
|
|
- const char *hash = cookie_hash(chname, opper, opped, &ts[1], salt, key);
|
|
|
|
|
|
|
+ const char *hash = cookie_hash(chname, opper, opped, &ts[1], randstring, key);
|
|
|
#ifdef DEBUG
|
|
#ifdef DEBUG
|
|
|
sdprintf("hash: %s", hash);
|
|
sdprintf("hash: %s", hash);
|
|
|
#endif
|
|
#endif
|