]> jfr.im git - irc/unrealircd/unrealircd.git/commitdiff
Add more soft actions. The full list is available on
authorBram Matthys <redacted>
Wed, 5 Sep 2018 07:39:44 +0000 (09:39 +0200)
committerBram Matthys <redacted>
Wed, 5 Sep 2018 07:39:44 +0000 (09:39 +0200)
https://www.unrealircd.org/docs/Actions
Also, some minor cleanups / simplifications.

include/struct.h
src/modules/antirandom.c
src/modules/m_message.c
src/modules/m_tkl.c
src/s_misc.c

index a4fb002be6dc4623feff97799a6583cb8963551a..cd17466c6eea51aa1823feee94e9ffeec2cbbd42 100644 (file)
@@ -974,13 +974,24 @@ struct _configflag_tld
 #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
index eec36854358539ee69ca4966d9078a65a0d526c2..e253f3f218c7d6bcf566c9536a40be68daf069b0 100644 (file)
@@ -569,7 +569,7 @@ int antirandom_config_test(ConfigFile *, ConfigEntry *, int, int *);
 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)
 {
@@ -1055,7 +1055,7 @@ void check_all_users(void)
        {
                if (IsPerson(acptr))
                {
-                       if (is_except_host(acptr))
+                       if (is_exempt(acptr))
                                continue;
 
                        score = get_spam_score(acptr);
@@ -1077,7 +1077,7 @@ int antirandom_preconnect(aClient *sptr)
 {
 int score;
 
-       if (!is_except_host(sptr))
+       if (!is_exempt(sptr))
        {
                score = get_spam_score(sptr);
                if (score > cfg.threshold)
@@ -1126,9 +1126,10 @@ Triples *t, *t_next;
        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");
@@ -1136,5 +1137,10 @@ static int is_except_host(aClient *sptr)
                        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);
 }
index 4b5f9bc7021875ed37e2470064fd20274da77e50..930bd2a4f03d9a80b6d88f2f89f885624d2ce639 100644 (file)
@@ -865,7 +865,12 @@ int        ban_version(aClient *sptr, char *text)
                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;
 }
index b692053db75164d88d321b5f755357b7bf14ec60..9914a2785175176fbdd2a0ea8c6413c80338d196 100644 (file)
@@ -2467,6 +2467,15 @@ int _m_tkl(aClient *cptr, aClient *sptr, int parc, char *parv[])
  */
 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:
@@ -2478,15 +2487,16 @@ int _place_host_ban(aClient *sptr, int action, char *reason, long duration)
                                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  +|- */
@@ -2511,18 +2521,10 @@ int _place_host_ban(aClient *sptr, int action, char *reason, long duration)
                        }
 
                        /* 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;
                        }
@@ -2535,7 +2537,7 @@ int _place_host_ban(aClient *sptr, int action, char *reason, long duration)
                                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;
@@ -2548,7 +2550,7 @@ int _place_host_ban(aClient *sptr, int action, char *reason, long duration)
                        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;
@@ -2699,6 +2701,12 @@ long ms_past;
                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));
@@ -2779,7 +2787,7 @@ long ms_past;
 
        /* 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)
                {
@@ -2818,7 +2826,7 @@ long ms_past;
                }
                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),
@@ -2826,7 +2834,7 @@ long ms_past;
                                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)
                {
@@ -2837,7 +2845,7 @@ long ms_past;
                }
                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;
index 0d71c1fe25709a129000631ecad6a1cd6c4f9bbe..c3e262580717b39cb06a8930e934022bbd077289 100644 (file)
@@ -74,18 +74,25 @@ typedef struct {
 
 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 }
 };