#define BAN_ACT_KLINE 800
#define BAN_ACT_SOFT_KLINE 850
#define BAN_ACT_SHUN 700
+#define BAN_ACT_SOFT_SHUN 650
#define BAN_ACT_KILL 600
+#define BAN_ACT_SOFT_KILL 550
#define BAN_ACT_TEMPSHUN 500
+#define BAN_ACT_SOFT_TEMPSHUN 450
#define BAN_ACT_VIRUSCHAN 400
+#define BAN_ACT_SOFT_VIRUSCHAN 350
#define BAN_ACT_DCCBLOCK 300
+#define BAN_ACT_SOFT_DCCBLOCK 250
#define BAN_ACT_BLOCK 200
+#define BAN_ACT_SOFT_BLOCK 150
#define BAN_ACT_WARN 100
-#define IsSoftBanAction(x) ((x == BAN_ACT_SOFT_GLINE) || (x == BAN_ACT_SOFT_KLINE))
+#define BAN_ACT_SOFT_WARN 50
+#define IsSoftBanAction(x) ((x == BAN_ACT_SOFT_GLINE) || (x == BAN_ACT_SOFT_KLINE) || \
+ (x == BAN_ACT_SOFT_SHUN) || (x == BAN_ACT_SOFT_KILL) || \
+ (x == BAN_ACT_SOFT_TEMPSHUN) || (x == BAN_ACT_SOFT_VIRUSCHAN) || \
+ (x == BAN_ACT_SOFT_DCCBLOCK) || (x == BAN_ACT_SOFT_BLOCK) || \
+ (x == BAN_ACT_SOFT_WARN))
#define CRULE_ALL 0
#define CRULE_AUTO 1
int antirandom_config_run(ConfigFile *, ConfigEntry *, int);
int antirandom_config_posttest(int *);
int antirandom_preconnect(aClient *sptr);
-static int is_except_host(aClient *sptr);
+static int is_exempt(aClient *sptr);
MOD_TEST(antirandom)
{
{
if (IsPerson(acptr))
{
- if (is_except_host(acptr))
+ if (is_exempt(acptr))
continue;
score = get_spam_score(acptr);
{
int score;
- if (!is_except_host(sptr))
+ if (!is_exempt(sptr))
{
score = get_spam_score(sptr);
if (score > cfg.threshold)
triples = NULL;
}
-/** Finds out if the host is on the except list. 1 if yes, 0 if no */
-static int is_except_host(aClient *sptr)
+/** Is this user exempt from antirandom interventions? */
+static int is_exempt(aClient *sptr)
{
+ /* WEBIRC gateway and exempt? */
if (cfg.except_webirc)
{
char *val = moddata_client_get(sptr, "webirc");
return 1;
}
+ /* Soft ban and logged in? */
+ if (IsSoftBanAction(cfg.ban_action) && IsLoggedIn(sptr))
+ return 1;
+
+ /* On except host? */
return unreal_mask_match(sptr, cfg.except_hosts);
}
text[len-1] = '\0'; /* remove CTCP REPLY terminator (ASCII 1) */
if ((ban = Find_ban(NULL, text, CONF_BAN_VERSION)))
+ {
+ if (IsSoftBanAction(ban->action) && IsLoggedIn(sptr))
+ return 0; /* we are exempt */
+
return place_host_ban(sptr, ban->action, ban->reason, BAN_VERSION_TKL_TIME);
+ }
return 0;
}
*/
int _place_host_ban(aClient *sptr, int action, char *reason, long duration)
{
+ /* If this is a soft action and the user is logged in, then the ban does not apply.
+ * NOTE: Actually in such a case it would be better if place_host_ban() would not
+ * be called at all. Or at least, since the caller should not take any action
+ * (eg: the message should be delivered, the user may connect, etc..)
+ * So this is more like secondary protection in case the caller forgets...
+ */
+ if (IsSoftBanAction(action) && IsLoggedIn(sptr))
+ return 0;
+
switch(action)
{
case BAN_ACT_TEMPSHUN:
reason);
SetShunned(sptr);
break;
- case BAN_ACT_SHUN:
- case BAN_ACT_SOFT_KLINE:
- case BAN_ACT_KLINE:
- case BAN_ACT_ZLINE:
- case BAN_ACT_SOFT_GLINE:
- case BAN_ACT_GLINE:
case BAN_ACT_GZLINE:
+ case BAN_ACT_GLINE:
+ case BAN_ACT_SOFT_GLINE:
+ case BAN_ACT_ZLINE:
+ case BAN_ACT_KLINE:
+ case BAN_ACT_SOFT_KLINE:
+ case BAN_ACT_SHUN:
+ case BAN_ACT_SOFT_SHUN:
{
- char ip[128], user[USERLEN+1], mo[100], mo2[100];
+ char ip[128], user[USERLEN+3], mo[100], mo2[100];
char *tkllayer[9] = {
me.name, /*0 server.name */
"+", /*1 +|- */
}
/* For soft bans we need to prefix the % in the username */
- if ((action == BAN_ACT_SOFT_KLINE) || (action == BAN_ACT_SOFT_GLINE))
+ if (IsSoftBanAction(action))
{
- char tmp[USERLEN+2];
+ char tmp[USERLEN+3];
snprintf(tmp, sizeof(tmp), "%%%s", tkllayer[3]);
- if (strlen(tmp) > USERLEN)
- {
- /* Due to the added %-prefix the username may now be oversized.
- * We'll replace the last character with an asterisk then.
- */
- tmp[USERLEN-1] = '*';
- tmp[USERLEN] = '\0';
- }
strlcpy(user, tmp, sizeof(user));
tkllayer[3] = user;
}
tkllayer[2] = "Z";
else if ((action == BAN_ACT_GLINE) || (action == BAN_ACT_SOFT_GLINE))
tkllayer[2] = "G";
- else if (action == BAN_ACT_SHUN)
+ else if ((action == BAN_ACT_SHUN) || (action == BAN_ACT_SOFT_SHUN))
tkllayer[2] = "s";
tkllayer[4] = ip;
tkllayer[5] = me.name;
tkllayer[7] = mo2;
tkllayer[8] = reason;
m_tkl(&me, &me, 9, tkllayer);
- if (action == BAN_ACT_SHUN)
+ if ((action == BAN_ACT_SHUN) || (action == BAN_ACT_SOFT_SHUN))
{
find_shun(sptr);
return -1;
if ((flags & SPAMFLAG_NOWARN) && (tk->ptr.spamf->action == BAN_ACT_WARN))
continue;
+ /* If the action is 'soft' (for non-logged in users only) then
+ * don't bother running the spamfilter if the user is logged in.
+ */
+ if (IsSoftBanAction(tk->ptr.spamf->action) && IsLoggedIn(sptr))
+ continue;
+
#ifdef SPAMFILTER_DETECTSLOW
memset(&rnow, 0, sizeof(rnow));
memset(&rprev, 0, sizeof(rnow));
/* Spamfilter matched, take action: */
- if (tk->ptr.spamf->action == BAN_ACT_BLOCK)
+ if ((tk->ptr.spamf->action == BAN_ACT_BLOCK) || (tk->ptr.spamf->action == BAN_ACT_SOFT_BLOCK))
{
switch(type)
{
}
return -1;
} else
- if (tk->ptr.spamf->action == BAN_ACT_WARN)
+ if ((tk->ptr.spamf->action == BAN_ACT_WARN) || (tk->ptr.spamf->action == BAN_ACT_SOFT_WARN))
{
if ((type != SPAMF_USER) && (type != SPAMF_QUIT))
sendto_one(sptr, rpl_str(RPL_SPAMCMDFWD),
unreal_decodespace(tk->ptr.spamf->tkl_reason));
return 0;
} else
- if (tk->ptr.spamf->action == BAN_ACT_DCCBLOCK)
+ if ((tk->ptr.spamf->action == BAN_ACT_DCCBLOCK) || (tk->ptr.spamf->action == BAN_ACT_SOFT_DCCBLOCK))
{
if (type == SPAMF_DCC)
{
}
return -1;
} else
- if (tk->ptr.spamf->action == BAN_ACT_VIRUSCHAN)
+ if ((tk->ptr.spamf->action == BAN_ACT_VIRUSCHAN) || (tk->ptr.spamf->action == BAN_ACT_SOFT_VIRUSCHAN))
{
if (IsVirus(sptr)) /* Already tagged */
return 0;
static BanActTable banacttable[] = {
{ BAN_ACT_KILL, 'K', "kill" },
+ { BAN_ACT_SOFT_KILL, 'i', "soft-kill" },
{ BAN_ACT_TEMPSHUN, 'S', "tempshun" },
+ { BAN_ACT_SOFT_TEMPSHUN,'T', "soft-tempshun" },
{ BAN_ACT_SHUN, 's', "shun" },
+ { BAN_ACT_SOFT_SHUN, 'H', "soft-shun" },
{ BAN_ACT_KLINE, 'k', "kline" },
+ { BAN_ACT_SOFT_KLINE, 'I', "soft-kline" },
{ BAN_ACT_ZLINE, 'z', "zline" },
{ BAN_ACT_GLINE, 'g', "gline" },
+ { BAN_ACT_SOFT_GLINE, 'G', "soft-gline" },
{ BAN_ACT_GZLINE, 'Z', "gzline" },
{ BAN_ACT_BLOCK, 'b', "block" },
+ { BAN_ACT_SOFT_BLOCK, 'B', "soft-block" },
{ BAN_ACT_DCCBLOCK, 'd', "dccblock" },
+ { BAN_ACT_SOFT_DCCBLOCK,'D', "soft-dccblock" },
{ BAN_ACT_VIRUSCHAN, 'v', "viruschan" },
+ { BAN_ACT_SOFT_VIRUSCHAN,'V', "soft-viruschan" },
{ BAN_ACT_WARN, 'w', "warn" },
- { BAN_ACT_SOFT_KLINE, 'I', "soft-kline" },
- { BAN_ACT_SOFT_GLINE, 'G', "soft-gline" },
+ { BAN_ACT_SOFT_WARN, 'W', "soft-warn" },
{ 0, 0, 0 }
};