extensions/extb_extgecos: support CIDR masks in $x extbans (#414)

This allows a channel operator to set a channel ban such as
"$x:*!*@192.0.2.0/24#*web.libera.chat*" and have it function
as intended.

Closes solanum-ircd/solanum#26
This commit is contained in:
Aaron Jones 2023-07-01 18:16:27 +00:00 committed by GitHub
parent a6ad35e5d8
commit 5ca20c098a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View 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, sizeof buf, "%s!%s@%s#%s",
client_p->name, client_p->username, client_p->host, client_p->info);
const char *idx = strchr(data, '#');
return 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 (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 EXTBAN_NOMATCH;
}