]> 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 7d6f92279d14d15e016d389169f2efca03d23e86..4f6a0d7707665dd854e6a747f237c802b253622c 100644 (file)
@@ -34,15 +34,38 @@ _moddeinit(void)
 static int eb_extended(const char *data, struct Client *client_p,
                struct Channel *chptr, long mode_type)
 {
-       char buf[BUFSIZE];
-
        (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, '#');
+
+       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 (idx != NULL)
+       {
+               char buf[BUFSIZE];
+
+               // Copy the nick!user@host part of the ban
+               memcpy(buf, data, (idx - data));
+               buf[(idx - data)] = '\0';
+
+               // 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;
+       }
+
+       if (client_matches_mask(client_p, data))
+               return EXTBAN_MATCH;
 
-       return match(data, buf) ? EXTBAN_MATCH : EXTBAN_NOMATCH;
+       return EXTBAN_NOMATCH;
 }