-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
run spamfilters against NICK #330
Open
jesopo
wants to merge
4
commits into
main
Choose a base branch
from
jess/filter-nick
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,8 @@ | |
#include "operhash.h" | ||
#include "inline/stringops.h" | ||
#include "msgbuf.h" | ||
#include "hostmask.h" | ||
#include "s_conf.h" | ||
|
||
#include <hs_common.h> | ||
#include <hs_runtime.h> | ||
|
@@ -56,6 +58,8 @@ 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_set(void *data); | ||
static void filter_client_nick_change(void *data); | ||
static void on_client_exit(void *data); | ||
|
||
static void mo_setfilter(struct MsgBuf *, struct Client *, struct Client *, int, const char **); | ||
|
@@ -93,6 +97,8 @@ mapi_hfn_list_av1 filter_hfnlist[] = { | |
{ "privmsg_user", filter_msg_user }, | ||
{ "privmsg_channel", filter_msg_channel }, | ||
{ "client_quit", filter_client_quit }, | ||
{ "local_nick_set_approve", filter_client_nick_set }, | ||
{ "local_nick_change_approve", filter_client_nick_change }, | ||
{ "client_exit", on_client_exit }, | ||
{ NULL, NULL } | ||
}; | ||
|
@@ -351,21 +357,21 @@ unsigned match_message(const char *prefix, | |
snprintf(check_buffer, sizeof check_buffer, "%s:%s!%s@%s#%c %s%s%s :%s", | ||
prefix, | ||
#if FILTER_NICK | ||
source->name, | ||
source ? source->name : "*", | ||
#else | ||
"*", | ||
#endif | ||
#if FILTER_USER | ||
source->username, | ||
source ? source->username : "*", | ||
#else | ||
"*", | ||
#endif | ||
#if FILTER_HOST | ||
source->host, | ||
source ? source->host : "*", | ||
#else | ||
"*", | ||
#endif | ||
source->user && source->user->suser[0] != '\0' ? '1' : '0', | ||
source && source->user && source->user->suser[0] != '\0' ? '1' : '0', | ||
command, | ||
target ? " " : "", | ||
target ? target : "", | ||
|
@@ -483,6 +489,54 @@ filter_client_quit(void *data_) | |
/* No point in doing anything with ACT_KILL */ | ||
} | ||
|
||
void | ||
filter_client_nick_change(void *data_) | ||
{ | ||
hook_data_nick_approval *data = data_; | ||
struct Client *s = data->client; | ||
if (IsOper(s)) { | ||
return; | ||
} | ||
|
||
unsigned r = match_message("0", s, "NICK", NULL, data->nick); | ||
if (r & ACT_DROP) { | ||
data->approved = 0; | ||
} | ||
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 | ||
filter_client_nick_set(void *data_) | ||
{ | ||
hook_data_nick_approval *data = data_; | ||
struct Client *s = data->client; | ||
struct sockaddr *addr = (void *)&s->localClient->ip; | ||
|
||
if(find_conf_by_address( | ||
NULL, NULL, NULL, addr, CONF_EXEMPTDLINE | 1, GET_SS_FAMILY(addr), NULL, NULL)) | ||
return; | ||
|
||
unsigned r = match_message("0", NULL, "NICK", NULL, data->nick); | ||
if (r & ACT_DROP) { | ||
data->approved = 0; | ||
} | ||
if (r & ACT_ALARM) { | ||
sendto_realops_snomask(SNO_GENERAL, L_ALL | L_NETWIDE, | ||
"FILTER:REGISTER: %s@%s", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is my initial solution for how alarm consumers are going to handle this case: slightly different snote. bikeshed on the format please |
||
s->id, s->sockhost); | ||
} | ||
if (r & ACT_KILL) { | ||
exit_client(NULL, s, s, FILTER_EXIT_MSG); | ||
} | ||
} | ||
|
||
void | ||
on_client_exit(void *data_) | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can't make people immune from this by them being an oper, obviously, and this is the only alternative that came to mind
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or maybe we just treat it like a RESV. you have to connect first and then switch your nick