]> jfr.im git - irc/ircd-hybrid/efserv-cvs.git/commitdiff
- Fixed nickflood monitoring in efserv.
authora1kmm <a1kmm>
Sun, 2 Dec 2001 03:27:12 +0000 (03:27 +0000)
committera1kmm <a1kmm>
Sun, 2 Dec 2001 03:27:12 +0000 (03:27 +0000)
clients.c
clones.c
include/define.h
include/funcs.h

index c6dfbd56159385f236519423c17e3fdffa71d83e..f6e33f31509ebed9653689207177fe0f85aaaa34 100644 (file)
--- a/clients.c
+++ b/clients.c
@@ -16,7 +16,7 @@
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  *    MA  02111-1307  USA.
- * $Id: clients.c,v 1.11 2001/11/22 04:18:25 wcampbel Exp $
+ * $Id: clients.c,v 1.12 2001/12/02 03:27:12 a1kmm Exp $
  */
 #include <stdlib.h>
 #include <string.h>
@@ -194,10 +194,11 @@ m_nick(char *sender, int parc, char **parv)
   if (parc < 2)
    return;
   if ((usr = find_user(sender)) == NULL)
-   return;
+    return;
   remove_from_hash(HASH_USER, usr->nick);
   strncpy(usr->nick, parv[1], NICKLEN-1)[NICKLEN-1] = 0;
   add_to_hash(HASH_USER, usr->nick, usr);
+  add_nickchange(usr->user, usr->host);
  }
 }
 
index 9693c94fb1bdcf35c24a3e2a7ad1d82c2f6ec056..db5b54630fe2bf0138fd80dfc096a157c30a5b0e 100644 (file)
--- a/clones.c
+++ b/clones.c
@@ -16,7 +16,7 @@
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  *    MA  02111-1307  USA.
- * $Id: clones.c,v 1.7 2001/11/11 22:13:52 wcampbel Exp $
+ * $Id: clones.c,v 1.8 2001/12/02 03:27:12 a1kmm Exp $
  */
 #include <stdlib.h>
 #include <string.h>
@@ -34,8 +34,9 @@ cleanup_hosts(void)
   struct Host *h;
   FORLISTDEL(node,nnode,Hosts,struct Host*,h)
   {
-    h->last_recalc -= (timenow-h->last_recalc)/10*10;
-    h->rate -= (timenow-h->last_recalc)/10;
+    int rtime = h->full ? UHOST_NICKCHANGE_RATE : HOST_NICKCHANGE_RATE;
+    h->rate -= (timenow-h->last_recalc)/rtime;
+    h->last_recalc = timenow - (timenow-h->last_recalc)%rtime;
     if (h->rate < 0)
       h->rate = 0;
     if (h->count == 0 && h->rate == 0)
@@ -104,6 +105,16 @@ add_cloner(char *user, char *host)
     add_to_hash(HASH_HOST, h2->host, h2);
     add_to_list(&Hosts, h2);
   }
+  h1->rate -= (timenow-h1->last_recalc)/UHOST_NICKCHANGE_RATE;
+  h1->last_recalc = timenow -
+                    (timenow-h1->last_recalc)%UHOST_NICKCHANGE_RATE;
+  if (h1->rate < 0)
+    h1->rate = 0;
+  h2->rate -= (timenow-h2->last_recalc)/HOST_NICKCHANGE_RATE;
+  h2->last_recalc = timenow -
+                    (timenow-h2->last_recalc)%HOST_NICKCHANGE_RATE;
+  if (h2->rate < 0)
+    h2->rate = 0;
   h1->count++;
   h1->rate++;
   h2->count++;
@@ -118,12 +129,52 @@ add_cloner(char *user, char *host)
     report_cloner(h1, "CLONES");
     return;
   }
-  if (h2->rate > MAXCLONES_HOST)
+  if (h2->rate > MAXNICKRATE_HOST)
   {
     report_cloner(h2, "NICKFLOODER");
     return;
   }
-  if (h1->rate > MAXCLONES_UHOST)
+  if (h1->rate > MAXNICKRATE_UHOST)
+  {
+    report_cloner(h1, "NICKFLOODER");
+    return;
+  }
+}
+
+void
+add_nickchange(char *user, char *host)
+{
+  struct Host *h1, *h2;
+  char uah[HOSTLEN+USERLEN+1];
+
+  strncpy(uah, user, USERLEN-1)
+    [USERLEN-1] = '\0';
+
+  strcat(uah, "@");
+  strncat(uah, host, HOSTLEN-1);
+
+  if ((h1 = find_host(uah)) == NULL)
+    return;
+  if ((h2 = find_host(host)) == NULL)
+    return;
+  h1->rate -= (timenow-h1->last_recalc)/UHOST_NICKCHANGE_RATE;
+  h1->last_recalc = timenow -
+                    (timenow-h1->last_recalc)%UHOST_NICKCHANGE_RATE;
+  if (h1->rate < 0)
+    h1->rate = 0;
+  h2->rate -= (timenow-h2->last_recalc)/HOST_NICKCHANGE_RATE;
+  h2->last_recalc = timenow -
+                    (timenow-h2->last_recalc)%HOST_NICKCHANGE_RATE;
+  if (h2->rate < 0)
+    h2->rate = 0;
+  h1->rate++;
+  h2->rate++;
+  if (h2->rate > MAXNICKRATE_HOST)
+  {
+    report_cloner(h2, "NICKFLOODER");
+    return;
+  }
+  if (h1->rate > MAXNICKRATE_UHOST)
   {
     report_cloner(h1, "NICKFLOODER");
     return;
index 01baba0b95a500235fd691b6bf0bfa98d169210a..613b14e2e36e9015665d6ef6e021c8692e7f578d 100644 (file)
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  *    MA  02111-1307  USA.
- * $Id: define.h,v 1.7 2001/11/11 22:13:52 wcampbel Exp $
+ * $Id: define.h,v 1.8 2001/12/02 03:27:14 a1kmm Exp $
  */
 
+/* The maximum number of clients per user@host */
 #define MAXCLONES_UHOST 4
+/* The maximum number of clients per host */
 #define MAXCLONES_HOST 6
+
+/* The minimum average time(in seconds) between nick introductions
+ * or changes allowed. */
+#define UHOST_NICKCHANGE_RATE 10
+/* The maximum number of nick introductions/changes in excess of
+ * 1 per RATETIME_UHOST allowed.  */
+#define MAXNICKRATE_UHOST 3
+
+/* Same but for hosts not user@hosts */
+#define HOST_NICKCHANGE_RATE 10
+#define MAXNICKRATE_HOST 6
+
 #define MAX_SJOIN_DELAY 60
 
 #define JUPE_EXPIRE_TIME 45 *60
index 36ff2b0b2019df0ee869812e1320cfcf7a67baee..21cb129839088cf679000d86a6d1635d9a03ec2b 100644 (file)
@@ -12,6 +12,7 @@ char *getmd5(struct User*);
 void cleanup_channels(void);
 void cleanup_jupes(void);
 void cleanup_hosts(void);
+void add_nickchange(char *user, char *host);
 void wipe_type_from_hash(int type, void (*cdata)(void*));
 void save_channel_opdb(void);
 void load_channel_opdb(void);