From d25fdeb95058f7728fb5cd71a17d62bed4fb181c Mon Sep 17 00:00:00 2001 From: Bram Matthys Date: Sun, 9 Jul 2023 16:27:40 +0200 Subject: [PATCH] Some more BanAction fixes/improvements: * stats S one thingy (multi-actions) * STATS spamfilter (multi-actions) * warn w/user target ('u') if using multi-actions * moving some code --- include/h.h | 1 + src/misc.c | 12 ++++++++++++ src/modules/blacklist.c | 2 +- src/modules/stats.c | 2 +- src/modules/tkl.c | 22 ++++++---------------- 5 files changed, 21 insertions(+), 18 deletions(-) diff --git a/include/h.h b/include/h.h index dc64b49ea..af50206c0 100644 --- a/include/h.h +++ b/include/h.h @@ -739,6 +739,7 @@ extern void free_all_ban_actions(BanAction *actions); #define safe_free_all_ban_actions(x) do { free_all_ban_actions(x); x = NULL; } while(0) #define safe_free_single_ban_action(x) do { free_single_ban_action(x); x = NULL; } while(0) BanAction *duplicate_ban_actions(BanAction *actions); +extern int highest_spamfilter_action(BanAction *action); extern BanActionValue banact_stringtoval(const char *s); extern const char *banact_valtostring(BanActionValue val); extern BanActionValue banact_chartoval(char c); diff --git a/src/misc.c b/src/misc.c index b992756af..8d17c27be 100644 --- a/src/misc.c +++ b/src/misc.c @@ -1094,6 +1094,18 @@ const char *ban_actions_to_string(BanAction *actions) return buf; } +/* Find the highest value in a BanAction linked list (the strongest action, eg gline>block) */ +int highest_spamfilter_action(BanAction *action) +{ + int highest = 0; + + for (; action; action = action->next) + if (action->action > highest) + highest = action->action; + + return highest; +} + void free_single_ban_action(BanAction *action) { safe_free(action->var); diff --git a/src/modules/blacklist.c b/src/modules/blacklist.c index 0bcb013f2..bdf0776c3 100644 --- a/src/modules/blacklist.c +++ b/src/modules/blacklist.c @@ -876,7 +876,7 @@ int blacklist_preconnect(Client *client) return HOOK_CONTINUE; /* yup, so the softban does not apply. */ if (blacklist_action(client, blu->save_opernotice, blu->save_action, blu->save_reason, blu->save_tkltime, - blu->save_blacklist, blu->save_blacklist_dns_name, blu->save_blacklist_dns_reply)) + blu->save_blacklist, blu->save_blacklist_dns_name, blu->save_blacklist_dns_reply) > 0) { return HOOK_DENY; } diff --git a/src/modules/stats.c b/src/modules/stats.c index 057b5f8fc..1e2d785bb 100644 --- a/src/modules/stats.c +++ b/src/modules/stats.c @@ -868,7 +868,7 @@ int stats_set(Client *client, const char *para) sendtxtnumeric(client, "link::bind-ip: %s", LINK_BINDIP); sendtxtnumeric(client, "anti-flood::connect-flood: %d per %s", THROTTLING_COUNT, pretty_time_val(THROTTLING_PERIOD)); sendtxtnumeric(client, "anti-flood::handshake-data-flood::amount: %ld bytes", iConf.handshake_data_flood_amount); - sendtxtnumeric(client, "anti-flood::handshake-data-flood::ban-action: %s", banact_valtostring(iConf.handshake_data_flood_ban_action->action)); + sendtxtnumeric(client, "anti-flood::handshake-data-flood::ban-action: %s", ban_actions_to_string(iConf.handshake_data_flood_ban_action)); sendtxtnumeric(client, "anti-flood::handshake-data-flood::ban-time: %s", pretty_time_val(iConf.handshake_data_flood_ban_time)); /* set::anti-flood */ diff --git a/src/modules/tkl.c b/src/modules/tkl.c index 1a770f9f0..bd563fbc8 100644 --- a/src/modules/tkl.c +++ b/src/modules/tkl.c @@ -3756,7 +3756,7 @@ int tkl_stats_matcher(Client *client, int type, const char *para, TKLFlag *tklfl (tkl->type & TKL_GLOBAL) ? 'F' : 'f', unreal_match_method_valtostr(tkl->ptr.spamfilter->match->type), spamfilter_target_inttostring(tkl->ptr.spamfilter->target), - banact_valtostring(tkl->ptr.spamfilter->action->action), + ban_actions_to_string(tkl->ptr.spamfilter->action), (tkl->expire_at != 0) ? (long long)(tkl->expire_at - TStime()) : 0, (long long)(TStime() - tkl->set_at), (long long)tkl->ptr.spamfilter->tkl_duration, @@ -4183,8 +4183,12 @@ void _tkl_added(Client *client, TKL *tkl) sendnotice_tkl_add(tkl); /* spamfilter 'warn' action is special */ - if ((tkl->type & TKL_SPAMF) && (tkl->ptr.spamfilter->action->action == BAN_ACT_WARN) && (tkl->ptr.spamfilter->target & SPAMF_USER)) + if ((tkl->type & TKL_SPAMF) && + has_actions_of_type(tkl->ptr.spamfilter->action, BAN_ACT_WARN) && + (tkl->ptr.spamfilter->target & SPAMF_USER)) + { spamfilter_check_users(tkl); + } /* Ban checking executes during run loop for efficiency */ loop.do_bancheck = 1; @@ -4761,10 +4765,8 @@ void ban_act_set(Client *client, BanAction *action) void ban_action_run_all_sets(Client *client, BanAction *action) { for (; action; action = action->next) - { if (action->action == BAN_ACT_SET) ban_act_set(client, action); - } } /** Take an action on the user, such as banning or killing. @@ -4899,18 +4901,6 @@ int _take_action(Client *client, BanAction *actions, char *reason, long duration return highest; } -/* Find the highest value in a BanAction linked list (the strongest action, eg gline>block) */ -int highest_spamfilter_action(BanAction *action) -{ - int highest = 0; - - for (; action; action = action->next) - if (action->action > highest) - highest = action->action; - - return highest; -} - /** This function compares two spamfilters ('one' and 'two') and will return * a 'winner' based on which one has the strongest action. * If both have equal action then some additional logic is applied simply