]> jfr.im git - solanum.git/blobdiff - extensions/extb_extgecos.c
extensions/extb_extgecos: support CIDR masks in $x extbans (#414)
[solanum.git] / extensions / extb_extgecos.c
index 6060044e7015e772bc05f693d682396f32ef4d64..4f6a0d7707665dd854e6a747f237c802b253622c 100644 (file)
@@ -2,8 +2,6 @@
  * Extended extban type: bans all users with matching nick!user@host#gecos.
  * Requested by Lockwood.
  *  - nenolod
- *
- * $Id: extb_realname.c 1339 2006-05-17 00:45:40Z nenolod $
  */
 
 #include "stdinc.h"
 #include "client.h"
 #include "ircd.h"
 
+static const char extb_desc[] = "Extended mask ($x) extban type";
+
 static int _modinit(void);
 static void _moddeinit(void);
 static int eb_extended(const char *data, struct Client *client_p, struct Channel *chptr, long mode_type);
 
-DECLARE_MODULE_AV1(extb_extended, _modinit, _moddeinit, NULL, NULL, NULL, "$Revision: 1339 $");
+DECLARE_MODULE_AV2(extb_extended, _modinit, _moddeinit, NULL, NULL, NULL, NULL, NULL, extb_desc);
 
 static int
 _modinit(void)
@@ -34,26 +34,38 @@ _moddeinit(void)
 static int eb_extended(const char *data, struct Client *client_p,
                struct Channel *chptr, long mode_type)
 {
-       char buf[BUFSIZE];
-       int ret;
-
        (void)chptr;
 
        if (data == NULL)
                return EXTBAN_INVALID;
 
-       snprintf(buf, BUFSIZE, "%s!%s@%s#%s",
-               client_p->name, client_p->username, client_p->host, client_p->info);
+       const char *idx = strchr(data, '#');
 
-       ret = match(data, buf) ? EXTBAN_MATCH : EXTBAN_NOMATCH;
+       if (idx != NULL && idx[1] == '\0')
+               /* Users cannot have empty realnames,
+                * so don't let a ban be set matching one
+                */
+               return EXTBAN_INVALID;
 
-       if (ret == EXTBAN_NOMATCH && IsDynSpoof(client_p))
+       if (idx != NULL)
        {
-               snprintf(buf, BUFSIZE, "%s!%s@%s#%s",
-                       client_p->name, client_p->username, client_p->orighost, client_p->info);
+               char buf[BUFSIZE];
+
+               // Copy the nick!user@host part of the ban
+               memcpy(buf, data, (idx - data));
+               buf[(idx - data)] = '\0';
 
-               ret = match(data, buf) ? EXTBAN_MATCH : EXTBAN_NOMATCH;
+               // Advance to the realname part of the ban
+               idx++;
+
+               if (client_matches_mask(client_p, buf) && match(idx, client_p->info))
+                       return EXTBAN_MATCH;
+
+               return EXTBAN_NOMATCH;
        }
 
-       return ret;
+       if (client_matches_mask(client_p, data))
+               return EXTBAN_MATCH;
+
+       return EXTBAN_NOMATCH;
 }