From 3c68c0cb1cbcf4d25639f5d293ea1811f0bc92ce Mon Sep 17 00:00:00 2001 From: jesopo Date: Fri, 15 Apr 2022 13:55:22 +0000 Subject: [PATCH] run spamfilters against NICK --- extensions/filter.c | 25 +++++++++++++++++++++++++ modules/core/m_nick.c | 6 ++++++ 2 files changed, 31 insertions(+) diff --git a/extensions/filter.c b/extensions/filter.c index bebcbdfca..fecba7542 100644 --- a/extensions/filter.c +++ b/extensions/filter.c @@ -56,6 +56,7 @@ static const char filter_desc[] = "Filter messages using a precompiled Hyperscan static void filter_msg_user(void *data); static void filter_msg_channel(void *data); static void filter_client_quit(void *data); +static void filter_client_nick(void *data); static void on_client_exit(void *data); static void mo_setfilter(struct MsgBuf *, struct Client *, struct Client *, int, const char **); @@ -93,6 +94,7 @@ mapi_hfn_list_av1 filter_hfnlist[] = { { "privmsg_user", filter_msg_user }, { "privmsg_channel", filter_msg_channel }, { "client_quit", filter_client_quit }, + { "local_nick_change", filter_client_nick }, { "client_exit", on_client_exit }, { NULL, NULL } }; @@ -483,6 +485,29 @@ filter_client_quit(void *data_) /* No point in doing anything with ACT_KILL */ } +void +filter_client_nick(void *data_) +{ + hook_cdata *data = data_; + struct Client *s = data->client; + if (IsOper(s)) { + return; + } + + unsigned r = match_message("0", s, "NICK", NULL, data->arg2); + if (r & ACT_DROP) { + data->arg2 = NULL; + } + if (r & ACT_ALARM) { + sendto_realops_snomask(SNO_GENERAL, L_ALL | L_NETWIDE, + "FILTER: %s!%s@%s [%s]", + s->name, s->username, s->host, s->sockhost); + } + if (r & ACT_KILL) { + exit_client(NULL, s, s, FILTER_EXIT_MSG); + } +} + void on_client_exit(void *data_) { diff --git a/modules/core/m_nick.c b/modules/core/m_nick.c index 890d0c2b3..3bce4e80d 100644 --- a/modules/core/m_nick.c +++ b/modules/core/m_nick.c @@ -673,6 +673,12 @@ change_local_nick(struct Client *client_p, struct Client *source_p, hook_info.arg2 = nick; call_hook(h_local_nick_change, &hook_info); + if (!hook_info.arg2) { + sendto_one(source_p, form_str(ERR_ERRONEUSNICKNAME), + me.name, EmptyString(source_p->name) ? "*" : source_p->name, nick); + return; + } + sendto_realops_snomask(SNO_NCHANGE, L_ALL, "Nick change: From %s to %s [%s@%s]", source_p->name, nick, source_p->username, source_p->host);