mirror of
https://github.com/unrealircd/unrealircd.git
synced 2026-07-07 19:43:13 +02:00
Changes to BanContext struct (extended ban API):
* Now ban_check_types (previously checktype): this is one or more of BANCHK_* OR'd together, eg BANCHK_JOIN, BANCHK_MSG.. * Now ban_type (previously what2): this is the type of the ban, eg EXBTYPE_BAN, EXBTYPE_EXCEPT, etc. * Now is_ok_check (previously is_ok_checktype) this is one of EXBCHK_* for is_ok, eg EXBCHK_PARAM to check parameter.
This commit is contained in:
+3
-3
@@ -405,13 +405,13 @@ typedef struct {
|
||||
Client *client; /**< Client to check, can be a remote client */
|
||||
Channel *channel; /**< Channel to check */
|
||||
const char *banstr; /**< Mask string (ban) */
|
||||
ExtbanCheck checktype; /**< Check type, one of BANCHK_* */
|
||||
int ban_check_types; /**< Ban types to check for, one or more of BANCHK_* OR'd together */
|
||||
const char *msg; /**< Message, only for some BANCHK_* types (for censoring text) */
|
||||
const char *error_msg; /**< Error message, can be NULL */
|
||||
int no_extbans; /**< Set to 1 to disable extended bans checking - only nick!user@host allowed */
|
||||
int what; /**< MODE_ADD or MODE_DEL (for is_ok) */
|
||||
ExtbanType what2; /**< EXBTYPE_BAN or EXBTYPE_EXCEPT (for is_ok) */
|
||||
int is_ok_checktype; /**< One of EXBCHK_* (for is_ok) */
|
||||
ExtbanType ban_type; /**< EXBTYPE_BAN or EXBTYPE_EXCEPT (for is_ok) */
|
||||
ExtbanCheck is_ok_check;/**< One of EXBCHK_* (for is_ok) */
|
||||
int conv_options; /**< One of BCTX_CONV_OPTION_* (for conv_param) */
|
||||
} BanContext;
|
||||
|
||||
|
||||
+1
-1
@@ -198,7 +198,7 @@ int extban_is_ok_nuh_extban(BanContext *b)
|
||||
if (extban_is_ok_recursion)
|
||||
return 0; /* Rule #1 violation (more than one stacked extban) */
|
||||
|
||||
if ((b->is_ok_checktype == EXBCHK_PARAM) && RESTRICT_EXTENDEDBANS && !ValidatePermissionsForPath("immune:restrict-extendedbans",b->client,NULL,b->channel,NULL))
|
||||
if ((b->is_ok_check == EXBCHK_PARAM) && RESTRICT_EXTENDEDBANS && !ValidatePermissionsForPath("immune:restrict-extendedbans",b->client,NULL,b->channel,NULL))
|
||||
{
|
||||
/* Test if this specific extban has been disabled.
|
||||
* (We can be sure RESTRICT_EXTENDEDBANS is not *. Else this extended ban wouldn't be happening at all.)
|
||||
|
||||
+3
-3
@@ -385,7 +385,7 @@ inline int ban_check_mask(BanContext *b)
|
||||
/* Is an extended ban. */
|
||||
const char *nextbanstr;
|
||||
Extban *extban = findmod_by_bantype(b->banstr, &nextbanstr);
|
||||
if (!extban || !(extban->is_banned_events & b->checktype))
|
||||
if (!extban || !(extban->is_banned_events & b->ban_check_types))
|
||||
{
|
||||
return 0;
|
||||
} else {
|
||||
@@ -435,7 +435,7 @@ Ban *is_banned_with_nick(Client *client, Channel *channel, int type, const char
|
||||
|
||||
b->client = client;
|
||||
b->channel = channel;
|
||||
b->checktype = type;
|
||||
b->ban_check_types = type;
|
||||
if (msg)
|
||||
b->msg = *msg;
|
||||
|
||||
@@ -820,7 +820,7 @@ int find_invex(Channel *channel, Client *client)
|
||||
|
||||
b->client = client;
|
||||
b->channel = channel;
|
||||
b->checktype = BANCHK_JOIN;
|
||||
b->ban_check_types = BANCHK_JOIN;
|
||||
|
||||
for (inv = channel->invexlist; inv; inv = inv->next)
|
||||
{
|
||||
|
||||
@@ -229,9 +229,9 @@ int extban_link_is_ok(BanContext *b)
|
||||
if (b->what == MODE_DEL)
|
||||
return 1;
|
||||
|
||||
if (b->what2 != EXBTYPE_BAN)
|
||||
if (b->ban_type != EXBTYPE_BAN)
|
||||
{
|
||||
if (b->is_ok_checktype == EXBCHK_PARAM)
|
||||
if (b->is_ok_check == EXBCHK_PARAM)
|
||||
sendnotice(b->client, "Ban type ~f only works with bans (+b) and not with exceptions or invex (+e/+I)");
|
||||
return 0; // Reject
|
||||
}
|
||||
@@ -240,15 +240,15 @@ int extban_link_is_ok(BanContext *b)
|
||||
chan = paramtmp;
|
||||
matchby = strchr(paramtmp, ':');
|
||||
if (!matchby || !matchby[1])
|
||||
return extban_link_syntax(b->client, b->is_ok_checktype, "Invalid syntax");
|
||||
return extban_link_syntax(b->client, b->is_ok_check, "Invalid syntax");
|
||||
*matchby++ = '\0';
|
||||
|
||||
if (*chan != '#' || strchr(b->banstr, ','))
|
||||
return extban_link_syntax(b->client, b->is_ok_checktype, "Invalid channel");
|
||||
return extban_link_syntax(b->client, b->is_ok_check, "Invalid channel");
|
||||
|
||||
b->banstr = matchby;
|
||||
if (extban_is_ok_nuh_extban(b) == 0)
|
||||
return extban_link_syntax(b->client, b->is_ok_checktype, "Invalid matcher");
|
||||
return extban_link_syntax(b->client, b->is_ok_check, "Invalid matcher");
|
||||
|
||||
return 1; // Is ok
|
||||
}
|
||||
@@ -360,7 +360,7 @@ int link_pre_localjoin_cb(Client *client, Channel *channel, const char *key)
|
||||
|
||||
b->client = client;
|
||||
b->channel = channel;
|
||||
b->checktype = BANCHK_JOIN;
|
||||
b->ban_check_types = BANCHK_JOIN;
|
||||
|
||||
for (ban = channel->banlist; ban; ban = ban->next)
|
||||
{
|
||||
|
||||
@@ -79,7 +79,7 @@ int extban_certfp_usage(Client *client)
|
||||
|
||||
int extban_certfp_is_ok(BanContext *b)
|
||||
{
|
||||
if (b->is_ok_checktype == EXCHK_PARAM)
|
||||
if (b->is_ok_check == EXCHK_PARAM)
|
||||
{
|
||||
const char *p;
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@ int extban_country_usage(Client *client)
|
||||
|
||||
int extban_country_is_ok(BanContext *b)
|
||||
{
|
||||
if (b->is_ok_checktype == EXCHK_PARAM)
|
||||
if (b->is_ok_check == EXCHK_PARAM)
|
||||
{
|
||||
const char *p;
|
||||
|
||||
|
||||
@@ -99,7 +99,7 @@ int extban_inchannel_is_ok(BanContext *b)
|
||||
{
|
||||
const char *p = b->banstr;
|
||||
|
||||
if ((b->is_ok_checktype == EXBCHK_PARAM) && MyUser(b->client) && (b->what == MODE_ADD) && (strlen(b->banstr) > 3))
|
||||
if ((b->is_ok_check == EXBCHK_PARAM) && MyUser(b->client) && (b->what == MODE_ADD) && (strlen(b->banstr) > 3))
|
||||
{
|
||||
if ((*p == '+') || (*p == '%') || (*p == '%') ||
|
||||
(*p == '@') || (*p == '&') || (*p == '~'))
|
||||
|
||||
@@ -76,7 +76,7 @@ int msgbypass_can_bypass(Client *client, Channel *channel, BypassChannelMessageR
|
||||
|
||||
b->client = client;
|
||||
b->channel = channel;
|
||||
b->checktype = BANCHK_MSG;
|
||||
b->ban_check_types = BANCHK_MSG;
|
||||
|
||||
for (ban = channel->exlist; ban; ban=ban->next)
|
||||
{
|
||||
@@ -187,9 +187,9 @@ int msgbypass_extban_is_ok(BanContext *b)
|
||||
if (b->what == MODE_DEL)
|
||||
return 1;
|
||||
|
||||
if (b->what2 != EXBTYPE_EXCEPT)
|
||||
if (b->ban_type != EXBTYPE_EXCEPT)
|
||||
{
|
||||
if (b->is_ok_checktype == EXBCHK_PARAM)
|
||||
if (b->is_ok_check == EXBCHK_PARAM)
|
||||
sendnotice(b->client, "Ban type ~m only works with exceptions (+e) and not with bans or invex (+b/+I)");
|
||||
return 0; /* reject */
|
||||
}
|
||||
@@ -203,11 +203,11 @@ int msgbypass_extban_is_ok(BanContext *b)
|
||||
type = para;
|
||||
matchby = strchr(para, ':');
|
||||
if (!matchby || !matchby[1])
|
||||
return msgbypass_extban_syntax(b->client, b->is_ok_checktype, "Invalid syntax");
|
||||
return msgbypass_extban_syntax(b->client, b->is_ok_check, "Invalid syntax");
|
||||
*matchby++ = '\0';
|
||||
|
||||
if (!msgbypass_extban_type_ok(type))
|
||||
return msgbypass_extban_syntax(b->client, b->is_ok_checktype, "Unknown type");
|
||||
return msgbypass_extban_syntax(b->client, b->is_ok_check, "Unknown type");
|
||||
|
||||
b->banstr = matchby;
|
||||
if (extban_is_ok_nuh_extban(b) == 0)
|
||||
@@ -216,7 +216,7 @@ int msgbypass_extban_is_ok(BanContext *b)
|
||||
* invalid n!u@h syntax, unknown (sub)extbantype,
|
||||
* disabled extban type in conf, too much recursion, etc.
|
||||
*/
|
||||
return msgbypass_extban_syntax(b->client, b->is_ok_checktype, "Invalid matcher");
|
||||
return msgbypass_extban_syntax(b->client, b->is_ok_check, "Invalid matcher");
|
||||
}
|
||||
|
||||
return 1; /* OK */
|
||||
|
||||
@@ -95,7 +95,7 @@ int extban_securitygroup_generic(char *mask, int strict)
|
||||
|
||||
int extban_securitygroup_is_ok(BanContext *b)
|
||||
{
|
||||
if (MyUser(b->client) && (b->what == MODE_ADD) && (b->is_ok_checktype == EXBCHK_PARAM))
|
||||
if (MyUser(b->client) && (b->what == MODE_ADD) && (b->is_ok_check == EXBCHK_PARAM))
|
||||
{
|
||||
char banbuf[SECURITYGROUPLEN+8];
|
||||
strlcpy(banbuf, b->banstr, sizeof(banbuf));
|
||||
|
||||
@@ -256,11 +256,11 @@ int extban_modeT_is_ok(BanContext *b)
|
||||
{
|
||||
int n;
|
||||
|
||||
if ((b->what == MODE_ADD) && (b->what2 == EXBTYPE_EXCEPT) && MyUser(b->client))
|
||||
if ((b->what == MODE_ADD) && (b->ban_type == EXBTYPE_EXCEPT) && MyUser(b->client))
|
||||
return 0; /* except is not supported */
|
||||
|
||||
/* We check the # of bans in the channel, may not exceed MAX_EXTBANT_PER_CHAN */
|
||||
if ((b->what == MODE_ADD) && (b->is_ok_checktype == EXBCHK_PARAM) &&
|
||||
if ((b->what == MODE_ADD) && (b->is_ok_check == EXBCHK_PARAM) &&
|
||||
MyUser(b->client) && !IsOper(b->client) &&
|
||||
((n = counttextbans(b->channel)) >= MAX_EXTBANT_PER_CHAN))
|
||||
{
|
||||
|
||||
@@ -255,13 +255,13 @@ int generic_ban_is_ok(BanContext *b)
|
||||
{
|
||||
if (!strcmp(RESTRICT_EXTENDEDBANS, "*"))
|
||||
{
|
||||
if (b->is_ok_checktype == EXBCHK_ACCESS_ERR)
|
||||
if (b->is_ok_check == EXBCHK_ACCESS_ERR)
|
||||
sendnotice(b->client, "Setting/removing of extended bans has been disabled");
|
||||
return 0; /* REJECT */
|
||||
}
|
||||
if (strchr(RESTRICT_EXTENDEDBANS, b->banstr[1]))
|
||||
{
|
||||
if (b->is_ok_checktype == EXBCHK_ACCESS_ERR)
|
||||
if (b->is_ok_check == EXBCHK_ACCESS_ERR)
|
||||
sendnotice(b->client, "Setting/removing of extended bantypes '%s' has been disabled", RESTRICT_EXTENDEDBANS);
|
||||
return 0; /* REJECT */
|
||||
}
|
||||
@@ -271,7 +271,7 @@ int generic_ban_is_ok(BanContext *b)
|
||||
if (extban && extban->is_ok)
|
||||
{
|
||||
b->banstr = nextbanstr;
|
||||
if ((b->is_ok_checktype == EXBCHK_ACCESS) || (b->is_ok_checktype == EXBCHK_ACCESS_ERR))
|
||||
if ((b->is_ok_check == EXBCHK_ACCESS) || (b->is_ok_check == EXBCHK_ACCESS_ERR))
|
||||
{
|
||||
if (!extban->is_ok(b) &&
|
||||
!ValidatePermissionsForPath("channel:override:mode:extban",b->client,NULL,b->channel,NULL))
|
||||
@@ -279,7 +279,7 @@ int generic_ban_is_ok(BanContext *b)
|
||||
return 0; /* REJECT */
|
||||
}
|
||||
} else
|
||||
if (b->is_ok_checktype == EXBCHK_PARAM)
|
||||
if (b->is_ok_check == EXBCHK_PARAM)
|
||||
{
|
||||
if (!extban->is_ok(b))
|
||||
{
|
||||
@@ -326,17 +326,17 @@ int timedban_extban_is_ok(BanContext *b)
|
||||
durationstr = para;
|
||||
matchby = strchr(para, ':');
|
||||
if (!matchby || !matchby[1])
|
||||
return timedban_extban_syntax(b->client, b->is_ok_checktype, "Invalid syntax");
|
||||
return timedban_extban_syntax(b->client, b->is_ok_check, "Invalid syntax");
|
||||
*matchby++ = '\0';
|
||||
|
||||
duration = atoi(durationstr);
|
||||
|
||||
if ((duration <= 0) || (duration > TIMEDBAN_MAX_TIME))
|
||||
return timedban_extban_syntax(b->client, b->is_ok_checktype, "Invalid duration time");
|
||||
return timedban_extban_syntax(b->client, b->is_ok_check, "Invalid duration time");
|
||||
|
||||
strlcpy(tmpmask, matchby, sizeof(tmpmask));
|
||||
timedban_extban_is_ok_recursion++;
|
||||
//res = extban_is_ok_nuh_extban(b->client, b->channel, tmpmask, b->is_ok_checktype, b->what, b->what2);
|
||||
//res = extban_is_ok_nuh_extban(b->client, b->channel, tmpmask, b->is_ok_check, b->what, b->ban_type);
|
||||
b->banstr = tmpmask;
|
||||
res = generic_ban_is_ok(b);
|
||||
timedban_extban_is_ok_recursion--;
|
||||
@@ -346,7 +346,7 @@ int timedban_extban_is_ok(BanContext *b)
|
||||
* invalid n!u@h syntax, unknown (sub)extbantype,
|
||||
* disabled extban type in conf, too much recursion, etc.
|
||||
*/
|
||||
return timedban_extban_syntax(b->client, b->is_ok_checktype, "Invalid matcher");
|
||||
return timedban_extban_syntax(b->client, b->is_ok_check, "Invalid matcher");
|
||||
}
|
||||
|
||||
return 1; /* OK */
|
||||
|
||||
+6
-6
@@ -551,9 +551,9 @@ const char *mode_ban_handler(Client *client, Channel *channel, const char *param
|
||||
b->client = client;
|
||||
b->channel = channel;
|
||||
b->banstr = nextbanstr;
|
||||
b->is_ok_checktype = EXBCHK_PARAM;
|
||||
b->is_ok_check = EXBCHK_PARAM;
|
||||
b->what = what;
|
||||
b->what2 = extbtype;
|
||||
b->ban_type = extbtype;
|
||||
if (extban && extban->is_ok)
|
||||
extban->is_ok(b);
|
||||
safe_free(b);
|
||||
@@ -576,9 +576,9 @@ const char *mode_ban_handler(Client *client, Channel *channel, const char *param
|
||||
b->client = client;
|
||||
b->channel = channel;
|
||||
b->what = what;
|
||||
b->what2 = extbtype;
|
||||
b->ban_type = extbtype;
|
||||
|
||||
b->is_ok_checktype = EXBCHK_ACCESS;
|
||||
b->is_ok_check = EXBCHK_ACCESS;
|
||||
b->banstr = nextbanstr;
|
||||
if (!extban->is_ok(b))
|
||||
{
|
||||
@@ -587,14 +587,14 @@ const char *mode_ban_handler(Client *client, Channel *channel, const char *param
|
||||
/* TODO: send operoverride notice */
|
||||
} else {
|
||||
b->banstr = nextbanstr;
|
||||
b->is_ok_checktype = EXBCHK_ACCESS_ERR;
|
||||
b->is_ok_check = EXBCHK_ACCESS_ERR;
|
||||
extban->is_ok(b);
|
||||
safe_free(b);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
b->banstr = nextbanstr;
|
||||
b->is_ok_checktype = EXBCHK_PARAM;
|
||||
b->is_ok_check = EXBCHK_PARAM;
|
||||
if (!extban->is_ok(b))
|
||||
{
|
||||
safe_free(b);
|
||||
|
||||
@@ -119,7 +119,7 @@ void unban_user(Client *client, Channel *channel, Client *acptr, char chmode)
|
||||
b = safe_alloc(sizeof(BanContext));
|
||||
b->client = acptr;
|
||||
b->channel = channel;
|
||||
b->checktype = BANCHK_JOIN;
|
||||
b->ban_check_types = BANCHK_JOIN;
|
||||
|
||||
for (ban = *banlist; ban; ban = bnext)
|
||||
{
|
||||
@@ -134,7 +134,7 @@ void unban_user(Client *client, Channel *channel, Client *acptr, char chmode)
|
||||
}
|
||||
else if (chmode != 'I' && *ban->banstr == '~' && (extban = findmod_by_bantype(ban->banstr, &nextbanstr)))
|
||||
{
|
||||
if ((extban->options & EXTBOPT_CHSVSMODE) && (extban->is_banned_events & b->checktype))
|
||||
if ((extban->options & EXTBOPT_CHSVSMODE) && (extban->is_banned_events & b->ban_check_types))
|
||||
{
|
||||
b->banstr = nextbanstr;
|
||||
if (extban->is_banned(b))
|
||||
|
||||
+3
-3
@@ -1306,9 +1306,9 @@ int parse_extended_server_ban(const char *mask_in, Client *client, char **error,
|
||||
b = safe_alloc(sizeof(BanContext));
|
||||
b->client = client;
|
||||
b->banstr = nextbanstr;
|
||||
b->is_ok_checktype = EXBCHK_PARAM;
|
||||
b->is_ok_check = EXBCHK_PARAM;
|
||||
b->what = MODE_ADD;
|
||||
b->what2 = EXBTYPE_TKL;
|
||||
b->ban_type = EXBTYPE_TKL;
|
||||
|
||||
/* Run .is_ok() for the extban. This check is skipped if coming from a remote user/server */
|
||||
if (skip_checking == 0)
|
||||
@@ -5177,7 +5177,7 @@ int _match_user_extended_server_ban(const char *banstr, Client *client)
|
||||
b = safe_alloc(sizeof(BanContext));
|
||||
b->client = client;
|
||||
b->banstr = nextbanstr;
|
||||
b->checktype = BANCHK_TKL;
|
||||
b->ban_check_types = BANCHK_TKL;
|
||||
ret = extban->is_banned(b);
|
||||
safe_free(b);
|
||||
return ret;
|
||||
|
||||
Reference in New Issue
Block a user