ソースを参照

* More cookie work, now it just needs something to stop re-use

svn: 1259
Bryan Drewery 22 年 前
コミット
fb8a9c90ea
3 ファイル変更16 行追加96 行削除
  1. 5 51
      src/mod/irc.mod/irc.c
  2. 2 1
      src/mod/irc.mod/irc.h
  3. 9 44
      src/mod/irc.mod/mode.c

+ 5 - 51
src/mod/irc.mod/irc.c

@@ -139,7 +139,7 @@ checkcookie(char *chn, char *bnick, char *cookie)
 {
   char randstring[5] = "", ts[11] = "", *chname = NULL, *hash = NULL, tohash[50] = "", *p = NULL;
   time_t optime = 0;
-  int goodhash = 0, goodts = 0, goodobscure = 0;
+
   if (!salt2)
     salt2 = strdup(SALT2);
 
@@ -156,62 +156,16 @@ checkcookie(char *chn, char *bnick, char *cookie)
   if (strlen(chname) > 2)
     chname[3] = 0;
   strtoupper(chname);
-  putlog(LOG_MISC, "*", "randstring: %s ts: %s", randstring, ts);
   /* hash!rand@ts */
   sprintf(tohash, "%c%s%s%s%s%c", salt2[0], bnick, chname, &ts[4], randstring, salt2[15]);
-  putlog(LOG_MISC, "*", "tohash: %s", tohash);
   hash = MD5(tohash);
-  if (hash[8] == cookie[0] && hash[16] == cookie[1] && hash[18] == cookie[2])
-    goodhash = 1;
-  else
-    return 1;
-  putlog(LOG_MISC, "*", "slack: %d", ((now + timesync) - optime));
-  if (((now + timesync) - optime) < 300)
-    goodts = 1;
-  else
-    return 2;
-  goodobscure = 1;
-  if (goodhash && goodts && goodobscure)
-    putlog(LOG_MISC, "*", "GOOD COOKIE!");
-
+  if (!(hash[8] == cookie[0] && hash[16] == cookie[1] && hash[18] == cookie[2]))
+    return BC_HASH;
+  if (((now + timesync) - optime) > 300)
+    return BC_SLACK;
   return 0;
 }
 
-/*
-   plain cookie:
-   Last 6 digits of time
-   Last 5 chars of nick
-   Last 4 regular chars of chan
- */
-static void 
-makeplaincookie(char *chname, char *nick, char *buf)
-{
-  char work[256] = "", work2[256] = "";
-  int i, n;
-
-  sprintf(work, "%010li", (now + timesync));
-  strcpy(buf, (char *) &work[4]);
-  work[0] = 0;
-  if (strlen(nick) < 5)
-    while (strlen(work) + strlen(nick) < 5)
-      strcat(work, " ");
-  else
-    strcpy(work, (char *) &nick[strlen(nick) - 5]);
-  strcat(buf, work);
-
-  n = 3;
-  for (i = strlen(chname) - 1; (i >= 0) && (n >= 0); i--)
-    if (((unsigned char) chname[i] < 128) && ((unsigned char) chname[i] > 32)) {
-      work2[n] = tolower(chname[i]);
-      n--;
-    }
-  while (n >= 0)
-    work2[n--] = ' ';
-  work2[4] = 0;
-  strcat(buf, work2);
-}
-
-
 /*
    opreq = o #chan nick
    inreq = i #chan nick uhost 

+ 2 - 1
src/mod/irc.mod/irc.h

@@ -7,6 +7,8 @@
 #ifndef _EGG_MOD_IRC_IRC_H
 #define _EGG_MOD_IRC_IRC_H
 
+enum { BC_NOCOOKIE = 1, BC_SLACK, BC_HASH };
+
 #define REVENGE_KICK 1		/* Kicked victim	*/
 #define REVENGE_DEOP 2		/* Took op		*/
 
@@ -23,7 +25,6 @@
 static int check_bind_pubc(char *, char *, char *, struct userrec *, char *, char *);
 static char *makecookie(char *, char *);
 static int checkcookie(char *, char *, char *);
-static void makeplaincookie(char *, char *, char *);
 static int me_voice(struct chanset_t *);
 static int any_ops(struct chanset_t *);
 static char *getchanmode(struct chanset_t *);

+ 9 - 44
src/mod/irc.mod/mode.c

@@ -985,47 +985,15 @@ gotmode(char *from, char *msg)
 
               /* If no unbans or the -b is not the LAST mode, it's bad. */
               if (unbans != 1 || (strncmp(modes[modecnt - 1], "-b", 2))) {
-                isbadop = 1;
+                isbadop = BC_NOCOOKIE;
               } else {
-                char cookie[20] = "", *goodcookie = NULL;
-
-                /* -b hash!rand@time */
-                strncpyz(cookie, (char *) &(modes[modecnt - 1][3]), sizeof(cookie));
-                checkcookie(chan->dname, nick, cookie);
-
-                /*
-                 * last 6 digits of time
-                 * last 5 chars of nick
-                 * last 5 regular chars of chan
-                 */
-/*
-                makeplaincookie(chan->dname, (char *) (modes[0] + 3), goodcookie);	
-                if (strncmp((char *) &plaincookie[6], (char *) &goodcookie[6], 5))
-                  isbadop = 2;
-                else if (strncmp((char *) &plaincookie[11], (char *) &goodcookie[11], 5))
-                  isbadop = 3;
-                else {
-                  char ltmp[20] = "";
-                  time_t optime, off;
-
-                  sprintf(ltmp, "%010li", now + timesync);
-                  strncpyz((char *) &ltmp[4], plaincookie, 7);
-                  optime = atol(ltmp);
-                  off = (now + timesync - optime);
-
-                  if (chan->cookie_time_slack && (abs(off) > chan->cookie_time_slack)) {
-                    // isbadop = 4;
-                    putlog(LOG_DEBUG, "*", "%s opped with bad ts (not punishing.): %li was off by %li", nick,
-                           optime, off);
-                  }
-                }
-*/
+					                 /* hash!rand@time */
+                isbadop = checkcookie(chan->dname, nick, &(modes[modecnt - 1][3]));
               }
               if (isbadop) {
                 char trg[NICKLEN] = "";
 
-                putlog(LOG_DEBUG, "*", "%s opped in %s with bad cookie(%d): %s", nick, chan->dname, isbadop,
-                       msg);
+                putlog(LOG_WARNING, "*", "%s opped in %s with bad cookie(%d): %s", nick, chan->dname, isbadop, msg);
                 n = i = 0;
                 switch (role) {
                   case 0:
@@ -1058,8 +1026,7 @@ gotmode(char *from, char *msg)
                       if (mo) {
                         if (!(mo->flags & CHANOP)) {
                           if (!chan_sentkick(mo)) {
-                            sprintf(tmp, "KICK %s %s :%s%s\n", chan->name, trg, kickprefix,
-                                    response(RES_BADOPPED));
+                            sprintf(tmp, "KICK %s %s :%s%s\n", chan->name, trg, kickprefix, response(RES_BADOPPED));
                             tputs(serv, tmp, strlen(tmp));
                             mo->flags |= SENTKICK;
                           }
@@ -1068,13 +1035,11 @@ gotmode(char *from, char *msg)
                     }
                 }
 
-                if (isbadop == 1)
+                if (isbadop == BC_NOCOOKIE)
                   putlog(LOG_WARN, "*", "Missing cookie: %s!%s MODE %s", nick, from, msg);
-                else if (isbadop == 2)
-                  putlog(LOG_WARN, "*", "Invalid cookie (bad nick): %s!%s MODE %s", nick, from, msg);
-                else if (isbadop == 3)
-                  putlog(LOG_WARN, "*", "Invalid cookie (bad chan): %s!%s MODE %s", nick, from, msg);
-                else if (isbadop == 4)
+                else if (isbadop == BC_HASH)
+                  putlog(LOG_WARN, "*", "Invalid cookie (bad hash): %s!%s MODE %s", nick, from, msg);
+                else if (isbadop == BC_SLACK)
                   putlog(LOG_WARN, "*", "Invalid cookie (bad time): %s!%s MODE %s", nick, from, msg);
               } else
                 putlog(LOG_DEBUG, "@", "Good op: %s", msg);