]> jfr.im git - solanum.git/blobdiff - modules/m_dline.c
add separate priv (oper:message) for walking over CALLERID (umode +g) (#152)
[solanum.git] / modules / m_dline.c
index a4bc988753402fb39ac7b0953b1d8931088fc38a..eb8edcf3530d566c375e892b27398f038a0eae54 100644 (file)
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
  *  USA
- *
- *  $Id$
  */
 
 #include "stdinc.h"
 #include "channel.h"
 #include "class.h"
 #include "client.h"
-#include "common.h"
 #include "match.h"
 #include "ircd.h"
 #include "hostmask.h"
 #include "bandbi.h"
 #include "operhash.h"
 
-static int mo_dline(struct Client *, struct Client *, int, const char **);
-static int me_dline(struct Client *, struct Client *, int, const char **);
-static int mo_undline(struct Client *, struct Client *, int, const char **);
-static int me_undline(struct Client *, struct Client *, int, const char **);
+static const char dline_desc[] = "Provides the DLINE facility to ban users via IP address";
+
+static void mo_dline(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
+static void me_dline(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
+static void mo_undline(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
+static void me_undline(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
 
 struct Message dline_msgtab = {
-       "DLINE", 0, 0, 0, MFLG_SLOW,
+       "DLINE", 0, 0, 0, 0,
        {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, {me_dline, 4}, {mo_dline, 2}}
 };
 
 struct Message undline_msgtab = {
-       "UNDLINE", 0, 0, 0, MFLG_SLOW,
+       "UNDLINE", 0, 0, 0, 0,
        {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, {me_undline, 2}, {mo_undline, 2}}
 };
 
 mapi_clist_av1 dline_clist[] = { &dline_msgtab, &undline_msgtab, NULL };
 
-DECLARE_MODULE_AV1(dline, NULL, NULL, dline_clist, NULL, NULL, "$Revision$");
+DECLARE_MODULE_AV2(dline, NULL, NULL, dline_clist, NULL, NULL, NULL, NULL, dline_desc);
 
-static int remove_temp_dline(struct ConfItem *);
-static int apply_dline(struct Client *, const char *, int, char *);
-static int apply_undline(struct Client *, const char *);
+static bool remove_temp_dline(struct ConfItem *);
+static void apply_dline(struct Client *, const char *, int, char *);
+static void apply_undline(struct Client *, const char *);
 
 /* mo_dline()
  *
  *   parv[1] - dline to add
  *   parv[2] - reason
  */
-static int
-mo_dline(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
+static void
+mo_dline(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
 {
        char def[] = "No Reason";
        const char *dlhost;
        char *reason = def;
-       char cidr_form_host[HOSTLEN + 1];
        int tdline_time = 0;
        const char *target_server = NULL;
        int loc = 1;
@@ -87,21 +85,33 @@ mo_dline(struct Client *client_p, struct Client *source_p, int parc, const char
        if(!IsOperK(source_p))
        {
                sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "kline");
-               return 0;
+               return;
        }
 
        if((tdline_time = valid_temp_time(parv[loc])) >= 0)
                loc++;
 
+       if (loc >= parc)
+       {
+               sendto_one_notice(source_p, ":Need an IP to D-Line");
+               return;
+       }
+
        dlhost = parv[loc];
-       rb_strlcpy(cidr_form_host, dlhost, sizeof(cidr_form_host));
        loc++;
 
        /* would break the protocol */
        if (*dlhost == ':')
        {
-               sendto_one_notice(source_p, ":Invalid D-Line");
-               return 0;
+               sendto_one_notice(source_p, ":Invalid D-Line [%s] - IP cannot start with :", dlhost);
+               return;
+       }
+
+       int ty = parse_netmask_strict(dlhost, NULL, NULL);
+       if (ty != HM_IPV4 && ty != HM_IPV6)
+       {
+               sendto_one_notice(source_p, ":Invalid D-Line [%s] - doesn't look like IP[/cidr]", dlhost);
+               return;
        }
 
        if(parc >= loc + 2 && !irccmp(parv[loc], "ON"))
@@ -110,7 +120,7 @@ mo_dline(struct Client *client_p, struct Client *source_p, int parc, const char
                {
                        sendto_one(source_p, form_str(ERR_NOPRIVS),
                                   me.name, source_p->name, "remoteban");
-                       return 0;
+                       return;
                }
 
                target_server = parv[loc + 1];
@@ -128,21 +138,20 @@ mo_dline(struct Client *client_p, struct Client *source_p, int parc, const char
                                   target_server, tdline_time, dlhost, reason);
 
                if(!match(target_server, me.name))
-                       return 0;
+                       return;
        }
 
        apply_dline(source_p, dlhost, tdline_time, reason);
 
        check_dlines();
-       return 0;
 }
 
 /* mo_undline()
  *
  *      parv[1] = dline to remove
  */
-static int
-mo_undline(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
+static void
+mo_undline(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
 {
        const char *cidr;
        const char *target_server = NULL;
@@ -150,7 +159,7 @@ mo_undline(struct Client *client_p, struct Client *source_p, int parc, const cha
        if(!IsOperK(source_p))
        {
                sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "unkline");
-               return 0;
+               return;
        }
 
        cidr = parv[1];
@@ -161,7 +170,7 @@ mo_undline(struct Client *client_p, struct Client *source_p, int parc, const cha
                {
                        sendto_one(source_p, form_str(ERR_NOPRIVS),
                                   me.name, source_p->name, "remoteban");
-                       return 0;
+                       return;
                }
 
                target_server = parv[3];
@@ -169,16 +178,14 @@ mo_undline(struct Client *client_p, struct Client *source_p, int parc, const cha
                                   CAP_ENCAP, NOCAPS, "ENCAP %s UNDLINE %s", target_server, cidr);
 
                if(!match(target_server, me.name))
-                       return 0;
+                       return;
        }
 
        apply_undline(source_p, cidr);
-
-       return 0;
 }
 
-static int
-me_dline(struct Client *client_p, struct Client *source_p, int parc, const char **parv)
+static void
+me_dline(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char **parv)
 {
        int tdline_time = atoi(parv[1]);
        /* Since this is coming over a server link, assume that the originating
@@ -186,35 +193,23 @@ me_dline(struct Client *client_p, struct Client *source_p, int parc, const char
         */
 
        if(!IsPerson(source_p))
-               return 0;
-
-       if(!find_shared_conf(source_p->username, source_p->host,
-                            source_p->servptr->name,
-                            tdline_time > 0 ? SHARED_TDLINE : SHARED_PDLINE))
-               return 0;
+               return;
 
        apply_dline(source_p, parv[2], tdline_time, LOCAL_COPY(parv[3]));
 
        check_dlines();
-       return 0;
 }
 
-static int
-me_undline(struct Client *client_p, struct Client *source_p, int parc, const char **parv)
+static void
+me_undline(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char **parv)
 {
        if(!IsPerson(source_p))
-               return 0;
-
-       if(!find_shared_conf(source_p->username, source_p->host,
-                            source_p->servptr->name, SHARED_UNDLINE))
-               return 0;
+               return;
 
        apply_undline(source_p, parv[1]);
-
-       return 0;
 }
 
-static int
+static void
 apply_dline(struct Client *source_p, const char *dlhost, int tdline_time, char *reason)
 {
        struct ConfItem *aconf;
@@ -223,17 +218,15 @@ apply_dline(struct Client *source_p, const char *dlhost, int tdline_time, char *
        int t = AF_INET, ty, b;
        const char *creason;
 
-       ty = parse_netmask(dlhost, &daddr, &b);
-       if(ty == HM_HOST)
+       ty = parse_netmask_strict(dlhost, &daddr, &b);
+       if(ty != HM_IPV4 && ty != HM_IPV6)
        {
                sendto_one(source_p, ":%s NOTICE %s :Invalid D-Line", me.name, source_p->name);
-               return 0;
+               return;
        }
-#ifdef RB_IPV6
        if(ty == HM_IPV6)
                t = AF_INET6;
        else
-#endif
                t = AF_INET;
 
        /* This means dlines wider than /16 cannot be set remotely */
@@ -243,7 +236,7 @@ apply_dline(struct Client *source_p, const char *dlhost, int tdline_time, char *
                {
                        sendto_one_notice(source_p,
                                          ":For safety, bitmasks less than 8 require conf access.");
-                       return 0;
+                       return;
                }
        }
        else
@@ -252,7 +245,7 @@ apply_dline(struct Client *source_p, const char *dlhost, int tdline_time, char *
                {
                        sendto_one_notice(source_p,
                                          ":Dline bitmasks less than 16 are for admins only.");
-                       return 0;
+                       return;
                }
        }
 
@@ -261,8 +254,9 @@ apply_dline(struct Client *source_p, const char *dlhost, int tdline_time, char *
                if((aconf = find_dline((struct sockaddr *) &daddr, t)) != NULL)
                {
                        int bx;
-                       parse_netmask(aconf->host, NULL, &bx);
-                       if(b >= bx)
+                       int masktype = parse_netmask_strict(aconf->host, NULL, &bx);
+
+                       if (masktype != HM_ERROR && b >= bx)
                        {
                                creason = aconf->passwd ? aconf->passwd : "<No Reason>";
                                if(IsConfExemptKline(aconf))
@@ -275,7 +269,7 @@ apply_dline(struct Client *source_p, const char *dlhost, int tdline_time, char *
                                                   ":%s NOTICE %s :[%s] already D-lined by [%s] - %s",
                                                   me.name, source_p->name, dlhost, aconf->host,
                                                   creason);
-                               return 0;
+                               return;
                        }
                }
        }
@@ -309,7 +303,7 @@ apply_dline(struct Client *source_p, const char *dlhost, int tdline_time, char *
 
                if(EmptyString(oper_reason))
                {
-                       sendto_realops_snomask(SNO_GENERAL, L_ALL,
+                       sendto_realops_snomask(SNO_GENERAL, L_NETWIDE,
                                               "%s added temporary %d min. D-Line for [%s] [%s]",
                                               get_oper_name(source_p), tdline_time / 60,
                                               aconf->host, reason);
@@ -318,7 +312,7 @@ apply_dline(struct Client *source_p, const char *dlhost, int tdline_time, char *
                }
                else
                {
-                       sendto_realops_snomask(SNO_GENERAL, L_ALL,
+                       sendto_realops_snomask(SNO_GENERAL, L_NETWIDE,
                                               "%s added temporary %d min. D-Line for [%s] [%s|%s]",
                                               get_oper_name(source_p), tdline_time / 60,
                                               aconf->host, reason, oper_reason);
@@ -339,7 +333,7 @@ apply_dline(struct Client *source_p, const char *dlhost, int tdline_time, char *
 
                if(EmptyString(oper_reason))
                {
-                       sendto_realops_snomask(SNO_GENERAL, L_ALL,
+                       sendto_realops_snomask(SNO_GENERAL, L_NETWIDE,
                                               "%s added D-Line for [%s] [%s]",
                                               get_oper_name(source_p), aconf->host, reason);
                        ilog(L_KLINE, "D %s 0 %s %s",
@@ -347,7 +341,7 @@ apply_dline(struct Client *source_p, const char *dlhost, int tdline_time, char *
                }
                else
                {
-                       sendto_realops_snomask(SNO_GENERAL, L_ALL,
+                       sendto_realops_snomask(SNO_GENERAL, L_NETWIDE,
                                               "%s added D-Line for [%s] [%s|%s]",
                                               get_oper_name(source_p), aconf->host, reason, oper_reason);
                        ilog(L_KLINE, "D %s 0 %s %s|%s",
@@ -355,27 +349,27 @@ apply_dline(struct Client *source_p, const char *dlhost, int tdline_time, char *
                             aconf->host, reason, oper_reason);
                }
        }
-
-       return 0;
 }
 
-static int
+static void
 apply_undline(struct Client *source_p, const char *cidr)
 {
        char buf[BUFSIZE];
        struct ConfItem *aconf;
 
-       if(parse_netmask(cidr, NULL, NULL) == HM_HOST)
+       int masktype = parse_netmask(cidr, NULL, NULL);
+
+       if(masktype != HM_IPV4 && masktype != HM_IPV6)
        {
-               sendto_one_notice(source_p, ":Invalid D-Line");
-               return 0;
+               sendto_one_notice(source_p, ":Invalid D-Line [%s] - doesn't look like IP[/cidr]", cidr);
+               return;
        }
 
        aconf = find_exact_conf_by_address(cidr, CONF_DLINE, NULL);
        if(aconf == NULL)
        {
                sendto_one_notice(source_p, ":No D-Line for %s", cidr);
-               return 0;
+               return;
        }
 
        rb_strlcpy(buf, aconf->host, sizeof buf);
@@ -384,32 +378,30 @@ apply_undline(struct Client *source_p, const char *cidr)
                sendto_one(source_p,
                           ":%s NOTICE %s :Un-dlined [%s] from temporary D-lines",
                           me.name, source_p->name, buf);
-               sendto_realops_snomask(SNO_GENERAL, L_ALL,
+               sendto_realops_snomask(SNO_GENERAL, L_NETWIDE,
                                       "%s has removed the temporary D-Line for: [%s]",
                                       get_oper_name(source_p), buf);
                ilog(L_KLINE, "UD %s %s", get_oper_name(source_p), buf);
-               return 0;
+               return;
        }
 
        bandb_del(BANDB_DLINE, aconf->host, NULL);
 
        sendto_one(source_p, ":%s NOTICE %s :D-Line for [%s] is removed", me.name, source_p->name,
                   aconf->host);
-       sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s has removed the D-Line for: [%s]",
+       sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, "%s has removed the D-Line for: [%s]",
                               get_oper_name(source_p), aconf->host);
        ilog(L_KLINE, "UD %s %s", get_oper_name(source_p), aconf->host);
        delete_one_address_conf(aconf->host, aconf);
-
-       return 0;
 }
 
 /* remove_temp_dline()
  *
  * inputs       - confitem to undline
- * outputs      -
+ * outputs      - true if removed, false otherwise.
  * side effects - tries to undline anything that matches
  */
-static int
+static bool
 remove_temp_dline(struct ConfItem *aconf)
 {
        rb_dlink_node *ptr;
@@ -423,10 +415,10 @@ remove_temp_dline(struct ConfItem *aconf)
                        {
                                rb_dlinkDestroy(ptr, &temp_dlines[i]);
                                delete_one_address_conf(aconf->host, aconf);
-                               return YES;
+                               return true;
                        }
                }
        }
 
-       return NO;
+       return false;
 }