Make join-flood use the new framework too, well... partially anyway.

This commit is contained in:
Bram Matthys 2021-05-28 18:08:07 +02:00
parent 36b9faa7cd
commit 79ded54df1
No known key found for this signature in database
GPG key ID: BF8116B163EAAE98
2 changed files with 26 additions and 63 deletions

View file

@ -1707,6 +1707,7 @@ void config_setdefaultsettings(Configuration *i)
i->throttle_count = 3; i->throttle_period = 60; /* throttle protection: max 3 per 60s */
i->floodsettings = safe_alloc(sizeof(FloodCounter) * MAXFLOODOPTIONS);
config_parse_flood_generic("3:60", i->floodsettings, FLD_NICK); /* NICK flood protection: max 3 per 60s */
config_parse_flood_generic("3:90", i->floodsettings, FLD_JOIN); /* NICK flood protection: max 3 per 90s */
config_parse_flood_generic("4:120", i->floodsettings, FLD_AWAY); /* AWAY flood protection: max 4 per 120s */
config_parse_flood_generic("4:60", i->floodsettings, FLD_INVITE); /* INVITE flood protection: max 4 per 60s */
config_parse_flood_generic("4:120", i->floodsettings, FLD_KNOCK); /* KNOCK protection: max 4 per 120s */
@ -7584,6 +7585,10 @@ int _conf_set(ConfigFile *conf, ConfigEntry *ce)
{
config_parse_flood_generic(cepp->ce_vardata, tempiConf.floodsettings, FLD_NICK);
}
else if (!strcmp(cepp->ce_varname, "join-flood"))
{
config_parse_flood_generic(cepp->ce_vardata, tempiConf.floodsettings, FLD_JOIN);
}
else if (!strcmp(cepp->ce_varname, "invite-flood"))
{
config_parse_flood_generic(cepp->ce_vardata, tempiConf.floodsettings, FLD_INVITE);
@ -8507,6 +8512,20 @@ int _test_set(ConfigFile *conf, ConfigEntry *ce)
errors++;
}
}
else if (!strcmp(cepp->ce_varname, "join-flood"))
{
int cnt, period;
CheckNull(cepp);
if (!config_parse_flood(cepp->ce_vardata, &cnt, &period) ||
(cnt < 1) || (cnt > 255) || (period < 5))
{
config_error("%s:%i: join-flood error. Syntax is '<count>:<period>' (eg 5:60), "
"count should be 1-255, period should be greater than 4",
cepp->ce_fileptr->cf_filename, cepp->ce_varlinenum);
errors++;
}
}
else if (!strcmp(cepp->ce_varname, "invite-flood"))
{
int cnt, period;

View file

@ -23,10 +23,6 @@
#include "unrealircd.h"
/* Default settings for set::anti-flood::join-flood block: */
#define JOINTHROTTLE_DEFAULT_COUNT 3
#define JOINTHROTTLE_DEFAULT_TIME 90
ModuleHeader MOD_HEADER
= {
"jointhrottle",
@ -40,11 +36,6 @@ ModuleInfo *ModInfo = NULL;
ModDataInfo *jointhrottle_md; /* Module Data structure which we acquire */
struct {
unsigned short num;
unsigned short t;
} cfg;
typedef struct JoinFlood JoinFlood;
struct JoinFlood {
@ -55,8 +46,6 @@ struct JoinFlood {
};
/* Forward declarations */
int jointhrottle_config_test(ConfigFile *, ConfigEntry *, int, int *);
int jointhrottle_config_run(ConfigFile *, ConfigEntry *, int);
void jointhrottle_md_free(ModData *m);
int jointhrottle_can_join(Client *client, Channel *channel, char *key, char *parv[]);
int jointhrottle_local_join(Client *client, Channel *channel, MessageTag *mtags, char *parv[]);
@ -67,7 +56,6 @@ JoinFlood *jointhrottle_addentry(Client *client, Channel *channel);
MOD_TEST()
{
HookAdd(modinfo->handle, HOOKTYPE_CONFIGTEST, 0, jointhrottle_config_test);
return MOD_SUCCESS;
}
@ -89,12 +77,9 @@ MOD_INIT()
if (!jointhrottle_md)
abort();
HookAdd(modinfo->handle, HOOKTYPE_CONFIGRUN, 0, jointhrottle_config_run);
HookAdd(modinfo->handle, HOOKTYPE_CAN_JOIN, 0, jointhrottle_can_join);
HookAdd(modinfo->handle, HOOKTYPE_LOCAL_JOIN, 0, jointhrottle_local_join);
cfg.t = JOINTHROTTLE_DEFAULT_TIME;
cfg.num = JOINTHROTTLE_DEFAULT_COUNT;
return MOD_SUCCESS;
}
@ -109,53 +94,11 @@ MOD_UNLOAD()
return MOD_FAILED;
}
int jointhrottle_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *errs)
{
int errors = 0;
int cnt=0, period=0;
if (type != CONFIG_SET_ANTI_FLOOD)
return 0;
if (strcmp(ce->ce_varname, "join-flood"))
return 0; /* otherwise not interested */
if (!ce->ce_vardata || !config_parse_flood(ce->ce_vardata, &cnt, &period) ||
(cnt < 1) || (cnt > 255) || (period < 5))
{
config_error("%s:%i: set::anti-flood::join-flood. Syntax is '<count>:<period>' (eg 3:90), "
"count should be 1-255, period should be greater than 4",
ce->ce_fileptr->cf_filename, ce->ce_varlinenum);
errors++;
}
*errs = errors;
return errors ? -1 : 1;
}
int jointhrottle_config_run(ConfigFile *cf, ConfigEntry *ce, int type)
{
int cnt=0, period=0;
if (type != CONFIG_SET_ANTI_FLOOD)
return 0;
if (strcmp(ce->ce_varname, "join-flood"))
return 0; /* otherwise not interested */
config_parse_flood(ce->ce_vardata, &cnt, &period);
cfg.t = period;
cfg.num = cnt;
return 0;
}
static int isjthrottled(Client *client, Channel *channel)
{
JoinFlood *e;
int num = cfg.num;
int t = cfg.t;
int num = iConf.floodsettings->limit[FLD_JOIN];
int t = iConf.floodsettings->period[FLD_JOIN];
if (!MyUser(client))
return 0;
@ -196,7 +139,7 @@ static void jointhrottle_increase_usercounter(Client *client, Channel *channel)
e->firstjoin = TStime();
e->numjoins = 1;
} else
if ((TStime() - e->firstjoin) < cfg.t) /* still valid? */
if ((TStime() - e->firstjoin) < iConf.floodsettings->period[FLD_JOIN]) /* still valid? */
{
e->numjoins++;
} else {
@ -266,11 +209,12 @@ EVENT(jointhrottle_cleanup_structs)
{
jf_next = jf->next;
if (jf->firstjoin + cfg.t > TStime())
if (jf->firstjoin + iConf.floodsettings->period[FLD_JOIN] > TStime())
continue; /* still valid entry */
#ifdef DEBUGMODE
ircd_log(LOG_ERROR, "jointhrottle_cleanup_structs(): freeing %s/%s (%ld[%ld], %d)",
client->name, jf->chname, jf->firstjoin, (long)(TStime() - jf->firstjoin), cfg.t);
ircd_log(LOG_ERROR, "jointhrottle_cleanup_structs(): freeing %s/%s (%ld[%ld], %ld)",
client->name, jf->chname, jf->firstjoin, (long)(TStime() - jf->firstjoin),
iConf.floodsettings->period[FLD_JOIN]);
#endif
if (moddata_local_client(client, jointhrottle_md).ptr == jf)
{