Committer  : entrope
CVSROOT    : /cvsroot/undernet-ircu
Module     : ircu2.10
Commit time: 2006-07-17 22:52:22 UTC

Modified files:
     ChangeLog doc/example.conf doc/readme.features include/channel.h
     include/client.h include/ircd_features.h ircd/channel.c
     ircd/ircd_features.c ircd/m_join.c ircd/m_part.c

Log message:

Add local spambot detection code.

---------------------- diff included ----------------------
Index: ircu2.10/ChangeLog
diff -u ircu2.10/ChangeLog:1.798 ircu2.10/ChangeLog:1.799
--- ircu2.10/ChangeLog:1.798    Fri Jul 14 17:09:09 2006
+++ ircu2.10/ChangeLog  Mon Jul 17 15:52:11 2006
@@ -1,5 +1,40 @@
 2006-07-14  Michael Poole <[EMAIL PROTECTED]>
 
+       * doc/example.conf (Features): Show the four added features.
+
+       * doc/readme.features (USER_GLIST): Fix indentation of headers.
+       (SPAM_OPER_COUNTDOWN): Document new feature.
+       (SPAM_EXPIRE_TIME): Likewise.
+       (SPAM_JOINED_TIME): Likewise.
+       (SPAM_FJP_COUNT): Likewise.
+
+       * include/channel.h (Ban): Fix typo in comment.
+       (check_spambot_warning): Declare new function.
+
+       * include/client.h (Connection): New fields for spambot detection.
+       (cli_last_join): New helper macro.
+       (cli_last_part): New helper macro.
+       (cli_join_part_count): New helper macro.
+       (cli_warn_countdown): New helper macro.
+
+       * include/ircd_features.h (FEAT_SPAM_OPER_COUNTDOWN): New feature.
+       (FEAT_SPAM_EXPIRE_TIME): Likewise.
+       (FEAT_SPAM_JOINED_TIME): Likewise.
+       (FEAT_SPAM_FJP_COUNT): Likewise.
+
+       * ircd/channel.c (check_spambot_warning): New function.
+
+       * ircd/ircd_features.c (SPAM_OPER_COUNTDOWN): Define new feature.
+       (SPAM_EXPIRE_TIME): Likewise.
+       (SPAM_JOINED_TIME): Likewise.
+       (SPAM_FJP_COUNT): Likewise.
+
+       * ircd/m_join.c (m_join): Update last-join time at each join.
+
+       * ircd/m_part.c (m_part): Check spambot behavior at each part.
+
+2006-07-14  Michael Poole <[EMAIL PROTECTED]>
+
        * include/ircd_snprintf.h: Escape %, #, < and > with \.
 
        * ircd/ircd_events.c (sigInfo): Name the struct type.
Index: ircu2.10/doc/example.conf
diff -u ircu2.10/doc/example.conf:1.72 ircu2.10/doc/example.conf:1.73
--- ircu2.10/doc/example.conf:1.72      Wed Jun 28 17:52:40 2006
+++ ircu2.10/doc/example.conf   Mon Jul 17 15:52:11 2006
@@ -885,6 +885,10 @@
 #  "HIS_SERVERNAME" = "*.undernet.org";
 #  "HIS_SERVERINFO" = "The Undernet Underworld";
 #  "HIS_URLSERVERS" = "http://www.undernet.org/servers.php";;
+#  "SPAM_OPER_COUNTDOWN" = "5";
+#  "SPAM_EXPIRE_TIME" = "120";
+#  "SPAM_JOINED_TIME" = "60";
+#  "SPAM_FJP_COUNT" = "5";
 };
 
 # Well, you have now reached the end of this sample configuration
Index: ircu2.10/doc/readme.features
diff -u ircu2.10/doc/readme.features:1.25 ircu2.10/doc/readme.features:1.26
--- ircu2.10/doc/readme.features:1.25   Mon Jun 26 17:11:17 2006
+++ ircu2.10/doc/readme.features        Mon Jul 17 15:52:11 2006
@@ -882,8 +882,36 @@
 TRUE whenever the OPLEVELS features is TRUE.
 
 USER_GLIST
-* Type: boolean
-* Default: FALSE
+ * Type: boolean
+ * Default: FALSE
 
 Optionally removes the ability to list glines by users
 (ie /GLINE [EMAIL PROTECTED], shows reason, expiry time etc)
+
+SPAM_OPER_COUNTDOWN
+ * Type: integer
+ * Default: 5
+
+Number of times a user may continue to join in a spambot-like fashion
+between snotices.
+
+SPAM_EXPIRE_TIME
+ * Type: integer
+ * Default: 120
+
+Number of seconds before a spambot-like join is "forgotten".
+
+SPAM_JOINED_TIME
+ * Type: integer
+ * Default: 60
+
+Number of seconds a client must stay in channels before a join/part
+sequence is not considered spambot-like.  This can be set to zero to
+disable spambot warnings.
+
+SPAM_FJP_COUNT
+ * Type: integer
+ * Default: 5
+
+Number of fast join-part sequences before a client is judged to look
+like a spambot.
Index: ircu2.10/include/channel.h
diff -u ircu2.10/include/channel.h:1.59 ircu2.10/include/channel.h:1.60
--- ircu2.10/include/channel.h:1.59     Mon Jun 26 19:39:59 2006
+++ ircu2.10/include/channel.h  Mon Jul 17 15:52:11 2006
@@ -19,7 +19,7 @@
  */
 /** @file
  * @brief Channel management and maintenance.
- * @version $Id: channel.h,v 1.59 2006/06/27 02:39:59 entrope Exp $
+ * @version $Id: channel.h,v 1.60 2006/07/17 22:52:11 entrope Exp $
  */
 #ifndef INCLUDED_channel_h
 #define INCLUDED_channel_h
@@ -241,7 +241,7 @@
 /** A single ban for a channel. */
 struct Ban {
   struct Ban* next;           /**< next ban in the channel */
-  struct irc_in_addr address; /**< addres for BAN_IPMASK bans */
+  struct irc_in_addr address; /**< address for BAN_IPMASK bans */
   time_t when;                /**< timestamp when ban was added */
   unsigned short flags;       /**< modifier flags for the ban */
   unsigned char nu_len;       /**< length of nick!user part of banstr */
@@ -390,6 +390,7 @@
 extern char *pretty_mask(char *mask);
 extern void del_invite(struct Client *cptr, struct Channel *chptr);
 extern void list_set_default(void); /* this belongs elsewhere! */
+extern void check_spambot_warning(struct Client *cptr);
 
 extern void modebuf_init(struct ModeBuf *mbuf, struct Client *source,
                         struct Client *connect, struct Channel *chan,
Index: ircu2.10/include/client.h
diff -u ircu2.10/include/client.h:1.50 ircu2.10/include/client.h:1.51
--- ircu2.10/include/client.h:1.50      Mon Jun 26 19:39:59 2006
+++ ircu2.10/include/client.h   Mon Jul 17 15:52:11 2006
@@ -19,7 +19,7 @@
  */
 /** @file
  * @brief Structures and functions for handling local clients.
- * @version $Id: client.h,v 1.50 2006/06/27 02:39:59 entrope Exp $
+ * @version $Id: client.h,v 1.51 2006/07/17 22:52:11 entrope Exp $
  */
 #ifndef INCLUDED_client_h
 #define INCLUDED_client_h
@@ -196,6 +196,10 @@
   time_t              con_nexttarget;/**< Next time a target change is allowed 
*/
   time_t              con_lasttime;  /**< Last time data read from socket */
   time_t              con_since;     /**< Last time we accepted a command */
+  time_t              con_last_join; /**< Last time this client joined a 
channel */
+  time_t              con_last_part; /**< Last time this client left a channel 
*/
+  int                 con_join_part_count; /**< Count of fast join/parts */
+  int                 con_warn_countdown; /**< Counter for spambot warnings */
   struct MsgQ         con_sendQ;     /**< Outgoing message queue */
   struct DBuf         con_recvQ;     /**< Incoming data yet to be parsed */
   unsigned int        con_sendM;     /**< Stats: protocol messages sent */
@@ -316,6 +320,14 @@
 #define cli_username(cli)      ((cli)->cli_username)
 /** Get client realname (information field). */
 #define cli_info(cli)          ((cli)->cli_info)
+/** Get client's last channel join time. */
+#define cli_last_join(cli)      (cli_connect(cli)->con_last_join)
+/** Get client's last channel part time. */
+#define cli_last_part(cli)      (cli_connect(cli)->con_last_part)
+/** Get client's fast join/part count. */
+#define cli_join_part_count(cli) (cli_connect(cli)->con_join_part_count)
+/** Get client's warning countdown value. */
+#define cli_warn_countdown(cli) (cli_connect(cli)->con_warn_countdown)
 
 /** Get number of incoming bytes queued for client. */
 #define cli_count(cli)         con_count(cli_connect(cli))
Index: ircu2.10/include/ircd_features.h
diff -u ircu2.10/include/ircd_features.h:1.43 
ircu2.10/include/ircd_features.h:1.44
--- ircu2.10/include/ircd_features.h:1.43       Thu Jun  1 08:59:19 2006
+++ ircu2.10/include/ircd_features.h    Mon Jul 17 15:52:11 2006
@@ -20,7 +20,7 @@
  */
 /** @file
  * @brief Public interfaces and declarations for dealing with configurable 
features.
- * @version $Id: ircd_features.h,v 1.43 2006/06/01 15:59:19 klmitch Exp $
+ * @version $Id: ircd_features.h,v 1.44 2006/07/17 22:52:11 entrope Exp $
  */
 
 struct Client;
@@ -181,6 +181,10 @@
   /* Misc. random stuff */
   FEAT_NETWORK,
   FEAT_URL_CLIENTS,
+  FEAT_SPAM_OPER_COUNTDOWN,
+  FEAT_SPAM_EXPIRE_TIME,
+  FEAT_SPAM_JOINED_TIME,
+  FEAT_SPAM_FJP_COUNT,
 
   FEAT_LAST_F
 };
Index: ircu2.10/ircd/channel.c
diff -u ircu2.10/ircd/channel.c:1.170 ircu2.10/ircd/channel.c:1.171
--- ircu2.10/ircd/channel.c:1.170       Mon Jun 26 19:39:59 2006
+++ ircu2.10/ircd/channel.c     Mon Jul 17 15:52:11 2006
@@ -19,7 +19,7 @@
  */
 /** @file
  * @brief Channel management and maintenance
- * @version $Id: channel.c,v 1.170 2006/06/27 02:39:59 entrope Exp $
+ * @version $Id: channel.c,v 1.171 2006/07/17 22:52:11 entrope Exp $
  */
 #include "config.h"
 
@@ -3467,3 +3467,52 @@
   return 0;
 }
 
+/** Check whether \a sptr is acting like a spambot when it leaves a
+ * channel.
+ * Side effects: Updates \a sptr's join_part_count, last_part and
+ * warn_countdown fields; may warn operators.
+ * Based on code by Dianora.
+ *
+ * @param[in] sptr Client to check
+ * @param[in] name Channel being joined (or NULL if a part).
+ */
+void
+check_spambot_warning(struct Client *sptr)
+{
+  int decrement_count;
+
+  if (!MyUser(sptr))
+  {
+    /* This client's behavior is someone else's problem. */
+  }
+  else if (cli_join_part_count(sptr) >= feature_int(FEAT_SPAM_FJP_COUNT))
+  {
+    if (cli_warn_countdown(sptr) > 0)
+      cli_warn_countdown(sptr)--;
+
+    if (cli_warn_countdown(sptr) == 0)
+    {
+      /* Its already known as a possible spambot */
+      sendto_opmask_butone(0, SNO_OLDSNO,
+                           "User %s ([EMAIL PROTECTED]) is a possible spambot",
+                           cli_name(sptr), cli_username(sptr),
+                           cli_sockhost(sptr));
+      cli_warn_countdown(sptr) = feature_int(FEAT_SPAM_OPER_COUNTDOWN);
+    }
+  }
+  else if ((decrement_count = (CurrentTime - cli_last_part(sptr))
+            / feature_int(FEAT_SPAM_EXPIRE_TIME)) > 0)
+  {
+    if (decrement_count > cli_join_part_count(sptr))
+      cli_join_part_count(sptr) = 0;
+    else
+      cli_join_part_count(sptr) -= decrement_count;
+  }
+  else if ((CurrentTime - (cli_last_join(sptr))) < 
feature_int(FEAT_SPAM_JOINED_TIME))
+  {
+    /* oh, its a possible spambot */
+    cli_join_part_count(sptr)++;
+  }
+
+  cli_last_part(sptr) = CurrentTime;
+}
Index: ircu2.10/ircd/ircd_features.c
diff -u ircu2.10/ircd/ircd_features.c:1.58 ircu2.10/ircd/ircd_features.c:1.59
--- ircu2.10/ircd/ircd_features.c:1.58  Mon Jun 26 19:05:20 2006
+++ ircu2.10/ircd/ircd_features.c       Mon Jul 17 15:52:11 2006
@@ -18,7 +18,7 @@
  */
 /** @file
  * @brief Implementation of configurable feature support.
- * @version $Id: ircd_features.c,v 1.58 2006/06/27 02:05:20 entrope Exp $
+ * @version $Id: ircd_features.c,v 1.59 2006/07/17 22:52:11 entrope Exp $
  */
 #include "config.h"
 
@@ -495,6 +495,10 @@
   /* Misc. random stuff */
   F_S(NETWORK, 0, "UnderNet", set_isupport_network),
   F_S(URL_CLIENTS, 0, "ftp://ftp.undernet.org/pub/irc/clients";, 0),
+  F_I(SPAM_OPER_COUNTDOWN, 0, 5, 0),
+  F_I(SPAM_EXPIRE_TIME, 0, 120, 0),
+  F_I(SPAM_JOINED_TIME, 0, 60, 0),
+  F_I(SPAM_FJP_COUNT, 0, 5, 0),
 
 #undef F_S
 #undef F_B
Index: ircu2.10/ircd/m_join.c
diff -u ircu2.10/ircd/m_join.c:1.45 ircu2.10/ircd/m_join.c:1.46
--- ircu2.10/ircd/m_join.c:1.45 Mon Jun 26 19:39:59 2006
+++ ircu2.10/ircd/m_join.c      Mon Jul 17 15:52:11 2006
@@ -20,7 +20,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: m_join.c,v 1.45 2006/06/27 02:39:59 entrope Exp $
+ * $Id: m_join.c,v 1.46 2006/07/17 22:52:11 entrope Exp $
  */
 
 #include "config.h"
@@ -243,6 +243,7 @@
       }
 
       joinbuf_join(&join, chptr, flags);
+      cli_last_join(sptr) = CurrentTime;
       if (flags & CHFL_CHANOP) {
         struct ModeBuf mbuf;
        /* Always let the server op him: this is needed on a net with older 
servers
Index: ircu2.10/ircd/m_part.c
diff -u ircu2.10/ircd/m_part.c:1.12 ircu2.10/ircd/m_part.c:1.13
--- ircu2.10/ircd/m_part.c:1.12 Tue Jul  4 13:37:32 2006
+++ ircu2.10/ircd/m_part.c      Mon Jul 17 15:52:11 2006
@@ -20,7 +20,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: m_part.c,v 1.12 2006/07/04 20:37:32 entrope Exp $
+ * $Id: m_part.c,v 1.13 2006/07/17 22:52:11 entrope Exp $
  */
 
 #include "config.h"
@@ -98,6 +98,7 @@
       flags |= CHFL_DELAYED;
 
     joinbuf_join(&parts, chptr, flags); /* part client from channel */
+    check_spambot_warning(sptr);
   }
 
   return joinbuf_flush(&parts); /* flush channel parts */
----------------------- End of diff -----------------------
_______________________________________________
Patches mailing list
[email protected]
http://undernet.sbg.org/mailman/listinfo/patches

Reply via email to