Make realname Kill blocks more predictable, and add username="x" field.
authorMichael Poole <mdpoole@troilus.org>
Sun, 17 Apr 2005 02:57:57 +0000 (02:57 +0000)
committerMichael Poole <mdpoole@troilus.org>
Sun, 17 Apr 2005 02:57:57 +0000 (02:57 +0000)
git-svn-id: file:///home/klmitch/undernet-ircu/undernet-ircu-svn/ircu2/trunk@1365 c9e4aea6-c8fd-4c43-8297-357d70d61c8c

ChangeLog
doc/example.conf
include/s_conf.h
ircd/ircd_parser.y
ircd/s_conf.c
ircd/s_err.c
ircd/s_stats.c

index a67dd1d609a3f5e6939fbfd0d23a10c64d5b3d58..532e6e2f7f3b13ac0dca3e3a1b514609b4854271 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,24 @@
+2005-04-16  Michael Poole <mdpoole@troilus.org>
+
+       * doc/example.conf (Kill): Document newly supported syntax.
+
+       * include/s_conf.h (DenyConf): Split realname mask into its own
+       field.  Remove the unused DENY_FLAGS_{IP,REALNAME}.
+
+       * ircd/ircd_parser.y (Kill): Only require one of usermask,
+       hostmask, realmask to be set for a valid block.
+       (killitem): Add new production killusername.
+
+       * ircd/s_conf.c (conf_erase_deny_list): Free realmask field.
+       (find_kill): Rearrange slightly to clarify control flow.
+
+       * ircd/s_err.c (RPL_STATSKLINE): Stick usermask before hostmask,
+       so the old usermask field can be adopted for realname mask.  Add
+       double quotes around the realmask field.
+
+       * ircd/s_stats.c (report_deny_list): Do so.
+       (stats_klines): Likewise.
+
 2005-04-17  Perry Lorier <isomer@undernet.org>
        
        * tools/convert-conf.py: Fix lots of conversion problems with
index 28796d6b0e621c976f200d26a04ecb1e0292c6d3..5b81cf4f143897594d994eeb81815b3f3550d9ad 100644 (file)
@@ -483,8 +483,12 @@ Jupe {
 Kill { host = "*.au"; reason = "Please use a nearer server"; };
 Kill { host = "*.edu"; reason = "Please use a nearer server"; };
 
+# You can also kill based on username.
+Kill { username = "sub7"; realname = "s*7*"; reason = "You are infected with a Trojan";
+
 # The file can contain for example, a reason, a link to the
-# server rules and a contact address.
+# server rules and a contact address.  Note the combination
+# of username and host in the host field.
 Kill
 {
  host = "*luser@unixbox.flooder.co.uk";
index 377542701c4e076cda91db10018b17e932ed6b17..8860e0b46a7ffd8b106b15fdd830a993e6f96a6d 100644 (file)
@@ -80,17 +80,16 @@ struct qline
 /** Local K-line structure. */
 struct DenyConf {
   struct DenyConf*    next;     /**< Next DenyConf in #denyConfList. */
-  char*               hostmask; /**< Mask for realname, IP or hostname. */
+  char*               hostmask; /**< Mask for  IP or hostname. */
   char*               message;  /**< Message to send to denied users. */
   char*               usermask; /**< Mask for client's username. */
+  char*               realmask; /**< Mask for realname. */
   struct irc_in_addr  address;  /**< Address for IP-based denies. */
   unsigned int        flags;    /**< Interpretation flags for the above.  */
   unsigned char       bits;     /**< Number of bits for ipkills */
 };
 
 #define DENY_FLAGS_FILE     0x0001 /**< Comment is a filename */
-#define DENY_FLAGS_IP       0x0002 /**< K-line by IP address */
-#define DENY_FLAGS_REALNAME 0x0004 /**< K-line by real name */
 
 /** Local server configuration. */
 struct LocalConf {
index c132991e376b1a5765f29d641b67dda0f09743d7..1c65d657078901718ed293b2a0d315c2c23564cf 100644 (file)
@@ -732,16 +732,15 @@ killblock: KILL
   dconf = (struct DenyConf*) MyCalloc(1, sizeof(*dconf));
 } '{' killitems '}'
 {
-  if (dconf->hostmask != NULL)
-  {
-    if (dconf->usermask == NULL)
-      DupString(dconf->usermask, "*");
+  if (dconf->usermask || dconf->hostmask ||dconf->realmask) {
     dconf->next = denyConfList;
     denyConfList = dconf;
   }
   else
   {
+    MyFree(dconf->usermask);
     MyFree(dconf->hostmask);
+    MyFree(dconf->realmask);
     MyFree(dconf->message);
     MyFree(dconf);
     parse_error("Bad kill block");
@@ -749,11 +748,10 @@ killblock: KILL
   dconf = NULL;
 } ';';
 killitems: killitem killitems | killitem;
-killitem: killuhost | killreal | killreasonfile | killreason | error;
+killitem: killuhost | killreal | killusername | killreasonfile | killreason | error;
 killuhost: HOST '=' QSTRING ';'
 {
   char *u, *h;
-  dconf->flags &= ~DENY_FLAGS_REALNAME;
   MyFree(dconf->hostmask);
   MyFree(dconf->usermask);
   if ((h = strchr($3, '@')) == NULL)
@@ -771,13 +769,16 @@ killuhost: HOST '=' QSTRING ';'
   ipmask_parse(dconf->hostmask, &dconf->address, &dconf->bits);
 };
 
+killusername: USERNAME '=' QSTRING ';'
+{
+  MyFree(dconf->usermask);
+  DupString(dconf->usermask, $3);
+};
+
 killreal: REAL '=' QSTRING ';'
 {
- dconf->flags &= ~DENY_FLAGS_IP;
- dconf->flags |= DENY_FLAGS_REALNAME;
- MyFree(dconf->hostmask);
- /* Leave usermask so you can specify user and real... */
- DupString(dconf->hostmask, $3);
+ MyFree(dconf->realmask);
+ DupString(dconf->realmask, $3);
 };
 
 killreason: REASON '=' QSTRING ';'
index 536087b605dea442f5eea1dbe04c432e656ba7cf..51c0971cafda3d0c6aa76c32e3ff7ff3bafa8b9f 100644 (file)
@@ -756,6 +756,7 @@ void conf_erase_deny_list(void)
     MyFree(p->hostmask);
     MyFree(p->usermask);
     MyFree(p->message);
+    MyFree(p->realmask);
     MyFree(p);
   }
   denyConfList = 0;
@@ -1016,28 +1017,16 @@ int find_kill(struct Client *cptr)
    *             -- Isomer
    */
   for (deny = denyConfList; deny; deny = deny->next) {
-    if (0 != match(deny->usermask, name))
+    if (deny->usermask && match(deny->usermask, name))
+      continue;
+    if (deny->realmask && match(deny->realmask, realname))
+      continue;
+    if (deny->bits > 0) {
+      if (!ipmask_check(&cli_ip(cptr), &deny->address, deny->bits))
+        continue;
+    } else if (deny->hostmask && match(deny->hostmask, host))
       continue;
 
-    if (EmptyString(deny->hostmask))
-      break;
-
-    if (deny->flags & DENY_FLAGS_REALNAME) { /* K: by real name */
-      if (0 == match(deny->hostmask, realname))
-       break;
-    } else if (deny->flags & DENY_FLAGS_IP) { /* k: by IP */
-#ifdef DEBUGMODE
-      char tbuf1[SOCKIPLEN], tbuf2[SOCKIPLEN];
-      Debug((DEBUG_DEBUG, "ip: %s network: %s/%u",
-             ircd_ntoa_r(tbuf1, &cli_ip(cptr)), ircd_ntoa_r(tbuf2, &deny->address), deny->bits));
-#endif
-      if (ipmask_check(&cli_ip(cptr), &deny->address, deny->bits))
-        break;
-    }
-    else if (0 == match(deny->hostmask, host))
-      break;
-  }
-  if (deny) {
     if (EmptyString(deny->message))
       send_reply(cptr, SND_EXPLICIT | ERR_YOUREBANNEDCREEP,
                  ":Connection from your host is refused on this server.");
@@ -1047,19 +1036,17 @@ int find_kill(struct Client *cptr)
       else
         send_reply(cptr, SND_EXPLICIT | ERR_YOUREBANNEDCREEP, ":%s.", deny->message);
     }
+    return -1;
   }
-  else if ((agline = gline_lookup(cptr, 0))) {
+
+  if ((agline = gline_lookup(cptr, 0))) {
     /*
      * find active glines
      * added a check against the user's IP address to find_gline() -Kev
      */
     send_reply(cptr, SND_EXPLICIT | ERR_YOUREBANNEDCREEP, ":%s.", GlineReason(agline));
-  }
-
-  if (deny)
-    return -1;
-  if (agline)
     return -2;
+  }
 
   return 0;
 }
index 45a34daaff53f99b5eec2b01fc52f78a112e74fc..4b03b3ddffd5b75262f40900aeee929dc0da8ae1 100644 (file)
@@ -464,7 +464,7 @@ static Numeric replyTable[] = {
 /* 215 */
   { RPL_STATSILINE, "I %s %d %s%s %d %s", "215" },
 /* 216 */
-  { RPL_STATSKLINE, "%c %s \"%s\" %s 0 0", "216" },
+  { RPL_STATSKLINE, "%c %s@%s \"%s\" \"%s\" 0 0", "216" },
 /* 217 */
   { RPL_STATSPLINE, "P %d %d %s %s", "217" },
 /* 218 */
index 355537626a86747736a0b452614908310f6c0828..9714157616944cec13960e3df27ca664e79f2bb7 100644 (file)
@@ -194,8 +194,11 @@ report_deny_list(struct Client* to)
 {
   const struct DenyConf* p = conf_get_deny_list();
   for ( ; p; p = p->next)
-    send_reply(to, RPL_STATSKLINE, (p->flags & DENY_FLAGS_IP) ? 'k' : 'K',
-               p->hostmask, p->message, p->usermask);
+    send_reply(to, RPL_STATSKLINE, p->bits > 0 ? 'k' : 'K',
+               p->usermask ? p->usermask : "*",
+               p->hostmask ? p->hostmask : "*",
+               p->message ? p->message : "(none)",
+               p->realmask ? p->realmask : "*");
 }
 
 /** Report K/k-lines to a user.
@@ -246,9 +249,11 @@ stats_klines(struct Client *sptr, const struct StatDesc *sd, char *mask)
         (wilds && !mmatch(host, conf->hostmask) &&
          (!user || !mmatch(user, conf->usermask))))
     {
-      send_reply(sptr, RPL_STATSKLINE,
-                 (conf->flags & DENY_FLAGS_IP) ? 'k' : 'K',
-                 conf->hostmask, conf->message, conf->usermask);
+      send_reply(sptr, RPL_STATSKLINE, conf->bits > 0 ? 'k' : 'K',
+                 conf->usermask ? conf->usermask : "*",
+                 conf->hostmask ? conf->hostmask : "*",
+                 conf->message ? conf->message : "(none)",
+                 conf->realmask ? conf->realmask : "*");
       if (--count == 0)
         return;
     }