]> jfr.im git - solanum.git/blobdiff - modules/m_xline.c
msg: remove last vestiges of the fakelag system. charybdis has never supported fakelag.
[solanum.git] / modules / m_xline.c
index deb441f13aa765b90b8148bb87c2dc862442e58b..b3650ed2e258b90d04fcd6b5f126eab3b2550a5e 100644 (file)
@@ -1,5 +1,5 @@
 /* modules/m_xline.c
- * 
+ *
  *  Copyright (C) 2002-2003 Lee Hardy <lee@leeh.co.uk>
  *  Copyright (C) 2002-2005 ircd-ratbox development team
  *
 #include "s_newconf.h"
 #include "reject.h"
 #include "bandbi.h"
+#include "operhash.h"
 
-static int mo_xline(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
-static int ms_xline(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
-static int me_xline(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
-static int mo_unxline(struct Client *client_p, struct Client *source_p, int parc,
+static int mo_xline(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
+static int ms_xline(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
+static int me_xline(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
+static int mo_unxline(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc,
                      const char *parv[]);
-static int ms_unxline(struct Client *client_p, struct Client *source_p, int parc,
+static int ms_unxline(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc,
                      const char *parv[]);
-static int me_unxline(struct Client *client_p, struct Client *source_p, int parc,
+static int me_unxline(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc,
                      const char *parv[]);
 
 struct Message xline_msgtab = {
-       "XLINE", 0, 0, 0, MFLG_SLOW,
+       "XLINE", 0, 0, 0, 0,
        {mg_unreg, mg_not_oper, {ms_xline, 5}, {ms_xline, 5}, {me_xline, 5}, {mo_xline, 3}}
 };
 
 struct Message unxline_msgtab = {
-       "UNXLINE", 0, 0, 0, MFLG_SLOW,
+       "UNXLINE", 0, 0, 0, 0,
        {mg_unreg, mg_not_oper, {ms_unxline, 3}, {ms_unxline, 3}, {me_unxline, 2}, {mo_unxline, 2}}
 };
 
@@ -78,7 +79,7 @@ DECLARE_MODULE_AV1(xline, NULL, NULL, xline_clist, NULL, NULL, "$Revision$");
 
 static int valid_xline(struct Client *, const char *, const char *);
 static void apply_xline(struct Client *client_p, const char *name,
-                       const char *reason, int temp_time);
+                       const char *reason, int temp_time, int propagated);
 static void propagate_xline(struct Client *source_p, const char *target,
                            int temp_time, const char *name, const char *type, const char *reason);
 static void cluster_xline(struct Client *source_p, int temp_time,
@@ -88,7 +89,8 @@ static void handle_remote_xline(struct Client *source_p, int temp_time,
                                const char *name, const char *reason);
 static void handle_remote_unxline(struct Client *source_p, const char *name);
 
-static void remove_xline(struct Client *source_p, const char *name);
+static void remove_xline(struct Client *source_p, const char *name,
+                        int propagated);
 
 
 /* m_xline()
@@ -98,7 +100,7 @@ static void remove_xline(struct Client *source_p, const char *name);
  * parv[3] - reason
  */
 static int
-mo_xline(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
+mo_xline(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
 {
        struct ConfItem *aconf;
        const char *name;
@@ -106,6 +108,7 @@ mo_xline(struct Client *client_p, struct Client *source_p, int parc, const char
        const char *target_server = NULL;
        int temp_time;
        int loc = 1;
+       int propagated = ConfigFileEntry.use_propagated_bans;
 
        if(!IsOperXline(source_p))
        {
@@ -151,8 +154,11 @@ mo_xline(struct Client *client_p, struct Client *source_p, int parc, const char
 
                if(!match(target_server, me.name))
                        return 0;
+
+               /* Set as local-only. */
+               propagated = 0;
        }
-       else if(rb_dlink_list_length(&cluster_conf_list) > 0)
+       else if(!propagated && rb_dlink_list_length(&cluster_conf_list) > 0)
                cluster_xline(source_p, temp_time, name, reason);
 
        if((aconf = find_xline_mask(name)) != NULL)
@@ -165,7 +171,13 @@ mo_xline(struct Client *client_p, struct Client *source_p, int parc, const char
        if(!valid_xline(source_p, name, reason))
                return 0;
 
-       apply_xline(source_p, name, reason, temp_time);
+       if(propagated && temp_time == 0)
+       {
+               sendto_one_notice(source_p, ":Cannot set a permanent global ban");
+               return 0;
+       }
+
+       apply_xline(source_p, name, reason, temp_time, propagated);
 
        return 0;
 }
@@ -175,7 +187,7 @@ mo_xline(struct Client *client_p, struct Client *source_p, int parc, const char
  * handles a remote xline
  */
 static int
-ms_xline(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
+ms_xline(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
 {
        /* parv[0]  parv[1]      parv[2]  parv[3]  parv[4]
         * oper     target serv  xline    type     reason
@@ -194,7 +206,7 @@ ms_xline(struct Client *client_p, struct Client *source_p, int parc, const char
 }
 
 static int
-me_xline(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
+me_xline(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
 {
        /* time name type :reason */
        if(!IsPerson(source_p))
@@ -225,7 +237,7 @@ handle_remote_xline(struct Client *source_p, int temp_time, const char *name, co
                return;
        }
 
-       apply_xline(source_p, name, reason, temp_time);
+       apply_xline(source_p, name, reason, temp_time, 0);
 }
 
 /* valid_xline()
@@ -244,18 +256,6 @@ valid_xline(struct Client *source_p, const char *gecos, const char *reason)
                return 0;
        }
 
-       if(strchr(reason, ':') != NULL)
-       {
-               sendto_one_notice(source_p, ":Invalid character ':' in comment");
-               return 0;
-       }
-
-       if(strchr(reason, '"'))
-       {
-               sendto_one_notice(source_p, ":Invalid character '\"' in comment");
-               return 0;
-       }
-
        if(!valid_wild_card_simple(gecos))
        {
                sendto_one_notice(source_p,
@@ -269,7 +269,7 @@ valid_xline(struct Client *source_p, const char *gecos, const char *reason)
 }
 
 void
-apply_xline(struct Client *source_p, const char *name, const char *reason, int temp_time)
+apply_xline(struct Client *source_p, const char *name, const char *reason, int temp_time, int propagated)
 {
        struct ConfItem *aconf;
 
@@ -280,7 +280,34 @@ apply_xline(struct Client *source_p, const char *name, const char *reason, int t
        aconf->passwd = rb_strdup(reason);
        collapse(aconf->host);
 
-       if(temp_time > 0)
+       aconf->info.oper = operhash_add(get_oper_name(source_p));
+
+       if(propagated)
+       {
+               aconf->flags |= CONF_FLAGS_MYOPER | CONF_FLAGS_TEMPORARY;
+               aconf->hold = rb_current_time() + temp_time;
+               aconf->lifetime = aconf->hold;
+
+               replace_old_ban(aconf);
+               rb_dlinkAddAlloc(aconf, &prop_bans);
+
+               sendto_realops_snomask(SNO_GENERAL, L_ALL,
+                                      "%s added global %d min. X-Line for [%s] [%s]",
+                                      get_oper_name(source_p), temp_time / 60,
+                                      aconf->host, reason);
+               ilog(L_KLINE, "X %s %d %s %s",
+                    get_oper_name(source_p), temp_time / 60, name, reason);
+               sendto_one_notice(source_p, ":Added global %d min. X-Line [%s]",
+                                 temp_time / 60, aconf->host);
+               sendto_server(NULL, NULL, CAP_BAN|CAP_TS6, NOCAPS,
+                               ":%s BAN X * %s %lu %d %d * :%s",
+                               source_p->id, aconf->host,
+                               (unsigned long)aconf->created,
+                               (int)(aconf->hold - aconf->created),
+                               (int)(aconf->lifetime - aconf->created),
+                               reason);
+       }
+       else if(temp_time > 0)
        {
                aconf->hold = rb_current_time() + temp_time;
 
@@ -361,8 +388,10 @@ cluster_xline(struct Client *source_p, int temp_time, const char *name, const ch
  * parv[1] - thing to unxline
  */
 static int
-mo_unxline(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
+mo_unxline(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
 {
+       int propagated = 1;
+
        if(!IsOperXline(source_p))
        {
                sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "xline");
@@ -382,11 +411,12 @@ mo_unxline(struct Client *client_p, struct Client *source_p, int parc, const cha
 
                if(match(parv[3], me.name) == 0)
                        return 0;
+
+               propagated = 0;
        }
-       else if(rb_dlink_list_length(&cluster_conf_list))
-               cluster_generic(source_p, "UNXLINE", SHARED_UNXLINE, CAP_CLUSTER, "%s", parv[1]);
+       /* cluster{} moved to remove_xline */
 
-       remove_xline(source_p, parv[1]);
+       remove_xline(source_p, parv[1], propagated);
 
        return 0;
 }
@@ -396,7 +426,7 @@ mo_unxline(struct Client *client_p, struct Client *source_p, int parc, const cha
  * handles a remote unxline
  */
 static int
-ms_unxline(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
+ms_unxline(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
 {
        /* parv[0]  parv[1]        parv[2]
         * oper     target server  gecos
@@ -414,7 +444,7 @@ ms_unxline(struct Client *client_p, struct Client *source_p, int parc, const cha
 }
 
 static int
-me_unxline(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
+me_unxline(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
 {
        /* name */
        if(!IsPerson(source_p))
@@ -431,16 +461,17 @@ handle_remote_unxline(struct Client *source_p, const char *name)
                             source_p->servptr->name, SHARED_UNXLINE))
                return;
 
-       remove_xline(source_p, name);
+       remove_xline(source_p, name, 0);
 
        return;
 }
 
 static void
-remove_xline(struct Client *source_p, const char *name)
+remove_xline(struct Client *source_p, const char *name, int propagated)
 {
        struct ConfItem *aconf;
        rb_dlink_node *ptr;
+       time_t now;
 
        RB_DLINK_FOREACH(ptr, xline_conf_list.head)
        {
@@ -448,6 +479,42 @@ remove_xline(struct Client *source_p, const char *name)
 
                if(!irccmp(aconf->host, name))
                {
+                       if(aconf->lifetime)
+                       {
+                               if(!propagated)
+                               {
+                                       sendto_one_notice(source_p, ":Cannot remove global X-Line %s on specific servers", name);
+                                       return;
+                               }
+                               ptr = rb_dlinkFind(aconf, &prop_bans);
+                               if(ptr == NULL)
+                                       return;
+                               sendto_one_notice(source_p, ":X-Line for [%s] is removed", name);
+                               sendto_realops_snomask(SNO_GENERAL, L_ALL,
+                                                      "%s has removed the global X-Line for: [%s]",
+                                                      get_oper_name(source_p), name);
+                               ilog(L_KLINE, "UX %s %s", get_oper_name(source_p), name);
+                               now = rb_current_time();
+                               if(aconf->created < now)
+                                       aconf->created = now;
+                               else
+                                       aconf->created++;
+                               aconf->hold = aconf->created;
+                               operhash_delete(aconf->info.oper);
+                               aconf->info.oper = operhash_add(get_oper_name(source_p));
+                               aconf->flags |= CONF_FLAGS_MYOPER | CONF_FLAGS_TEMPORARY;
+                               sendto_server(NULL, NULL, CAP_BAN|CAP_TS6, NOCAPS,
+                                               ":%s BAN X * %s %lu %d %d * :*",
+                                               source_p->id, aconf->host,
+                                               (unsigned long)aconf->created,
+                                               0,
+                                               (int)(aconf->lifetime - aconf->created));
+                               remove_reject_mask(aconf->host, NULL);
+                               deactivate_conf(aconf, ptr, now);
+                               return;
+                       }
+                       else if(propagated && rb_dlink_list_length(&cluster_conf_list))
+                               cluster_generic(source_p, "UNXLINE", SHARED_UNXLINE, CAP_CLUSTER, "%s", name);
                        if(!aconf->hold)
                        {
                                bandb_del(BANDB_XLINE, aconf->host, NULL);
@@ -474,6 +541,9 @@ remove_xline(struct Client *source_p, const char *name)
                }
        }
 
+       if(propagated && rb_dlink_list_length(&cluster_conf_list))
+               cluster_generic(source_p, "UNXLINE", SHARED_UNXLINE, CAP_CLUSTER, "%s", name);
+
        sendto_one_notice(source_p, ":No X-Line for %s", name);
 
        return;