Cleanup antirandom a bit (hardly used status on load option, and

lots of debugging). Also add newlog.
This commit is contained in:
Bram Matthys 2021-08-05 20:16:27 +02:00
parent 55f2ef502e
commit 01e86d547d
No known key found for this signature in database
GPG key ID: BF8116B163EAAE98

View file

@ -22,17 +22,6 @@
#include "unrealircd.h"
/* You can change this '//#undef' into '#define' if you want to see quite
* a flood for every user that connects (and on-load if cfg.fullstatus_on_load).
* Obviously only recommended for testing, use with care!
*/
#undef DEBUGMODE
/** Change this 'undef' to 'define' to get performance information.
* This really only meant for debugging purposes.
*/
#undef TIMING
ModuleHeader MOD_HEADER
= {
"antirandom",
@ -515,7 +504,6 @@ struct {
long ban_time;
int convert_to_lowercase;
int show_failedconnects;
int fullstatus_on_load;
ConfigItem_mask *except_hosts;
int except_webirc;
} cfg;
@ -553,19 +541,14 @@ MOD_INIT()
HookAdd(modinfo->handle, HOOKTYPE_CONFIGRUN, 0, antirandom_config_run);
/* Some default values: */
cfg.fullstatus_on_load = 1;
cfg.convert_to_lowercase = 1;
cfg.except_webirc = 1;
return MOD_SUCCESS;
}
void check_all_users(void);
MOD_LOAD()
{
if (cfg.fullstatus_on_load)
check_all_users();
return MOD_SUCCESS;
}
@ -644,9 +627,6 @@ int antirandom_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *errs)
if (!strcmp(cep->ce_varname, "convert-to-lowercase"))
{
} else
if (!strcmp(cep->ce_varname, "fullstatus-on-load"))
{
} else
if (!strcmp(cep->ce_varname, "show-failedconnects"))
{
} else
@ -705,10 +685,6 @@ int antirandom_config_run(ConfigFile *cf, ConfigEntry *ce, int type)
if (!strcmp(cep->ce_varname, "show-failedconnects"))
{
cfg.show_failedconnects = config_checkval(cep->ce_vardata, CFG_YESNO);
} else
if (!strcmp(cep->ce_varname, "fullstatus-on-load"))
{
cfg.fullstatus_on_load = config_checkval(cep->ce_vardata, CFG_YESNO);
}
}
return 1;
@ -821,23 +797,14 @@ static int internal_getscore(char *str)
if (digits >= 5)
{
score += 5 + (digits - 5);
#ifdef DEBUGMODE
sendto_ops_and_log("score@'%s': MATCH for digits check", str);
#endif
}
if (vowels >= 4)
{
score += 4 + (vowels - 4);
#ifdef DEBUGMODE
sendto_ops_and_log("score@'%s': MATCH for vowels check", str);
#endif
}
if (consonants >= 4)
{
score += 4 + (consonants - 4);
#ifdef DEBUGMODE
sendto_ops_and_log("score@'%s': MATCH for consonants check", str);
#endif
}
for (t=triples; t; t=t->next)
@ -846,10 +813,6 @@ static int internal_getscore(char *str)
if ((t->two[0] == s[0]) && (t->two[1] == s[1]) && s[2] && strchr(t->rest, s[2]))
{
score++; /* OK */
#ifdef DEBUGMODE
sendto_ops_and_log("score@'%s': MATCH for '%s[%s]' %c/%c/%c", str, t->two, t->rest,
s[0], s[1], s[2]);
#endif
}
}
@ -868,11 +831,6 @@ static int get_spam_score(Client *client)
char *gecos = client->info;
char nbuf[NICKLEN+1], ubuf[USERLEN+1], rbuf[REALLEN+1];
int nscore, uscore, gscore, score;
#ifdef TIMING
struct timeval tv_alpha, tv_beta;
gettimeofday(&tv_alpha, NULL);
#endif
if (cfg.convert_to_lowercase)
{
@ -889,46 +847,9 @@ static int get_spam_score(Client *client)
gscore = internal_getscore(gecos);
score = nscore + uscore + gscore;
#ifdef TIMING
gettimeofday(&tv_beta, NULL);
ircd_log(LOG_ERROR, "AntiRandom Timing: %ld microseconds",
((tv_beta.tv_sec - tv_alpha.tv_sec) * 1000000) + (tv_beta.tv_usec - tv_alpha.tv_usec));
#endif
#ifdef DEBUGMODE
sendto_ops_and_log("got score: %d/%d/%d = %d",
nscore, uscore, gscore, score);
#endif
return score;
}
void check_all_users(void)
{
Client *client;
int matches=0, score;
list_for_each_entry(client, &lclient_list, lclient_node)
{
if (IsUser(client))
{
if (is_exempt(client))
continue;
score = get_spam_score(client);
if (score > cfg.threshold)
{
if (!matches)
sendto_realops("[antirandom] Full status report follows:");
sendto_realops("%d points: %s!%s@%s:%s",
score, client->name, client->user->username, client->user->realhost, client->info);
matches++;
}
}
}
if (matches)
sendto_realops("[antirandom] %d match%s", matches, matches == 1 ? "" : "es");
}
int antirandom_preconnect(Client *client)
{
int score;
@ -941,13 +862,17 @@ int antirandom_preconnect(Client *client)
{
if (cfg.ban_action == BAN_ACT_WARN)
{
sendto_ops_and_log("[antirandom] would have denied access to user with score %d: %s!%s@%s:%s",
score, client->name, client->user->username, client->user->realhost, client->info);
unreal_log(LOG_INFO, "antirandom", "ANTIRANDOM_REJECTED_USER", client,
"[antirandom] would have denied access to user with score $score: $client:$client.info",
log_data_integer("score", score));
return HOOK_CONTINUE;
}
if (cfg.show_failedconnects)
sendto_ops_and_log("[antirandom] denied access to user with score %d: %s!%s@%s:%s",
score, client->name, client->user->username, client->user->realhost, client->info);
{
unreal_log(LOG_INFO, "antirandom", "ANTIRANDOM_REJECTED_USER", client,
"[antirandom] denied access to user with score $score: $client:$client.info",
log_data_integer("score", score));
}
place_host_ban(client, cfg.ban_action, cfg.ban_reason, cfg.ban_time);
return HOOK_DENY;
}