]> jfr.im git - solanum.git/blobdiff - modules/m_dline.c
Combine stats A output parameters (#35)
[solanum.git] / modules / m_dline.c
index 9c3a39882d069d7a457e41475732205bb31c9899..381f8a39538e2ffe454f4d399f444affe5044879 100644 (file)
@@ -26,7 +26,6 @@
 #include "channel.h"
 #include "class.h"
 #include "client.h"
-#include "common.h"
 #include "match.h"
 #include "ircd.h"
 #include "hostmask.h"
@@ -79,7 +78,6 @@ mo_dline(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source
        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;
@@ -93,14 +91,26 @@ mo_dline(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source
        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");
+               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;
        }
 
@@ -217,17 +227,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;
        }
-#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 */
@@ -255,8 +263,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))
@@ -357,9 +366,11 @@ 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");
+               sendto_one_notice(source_p, ":Invalid D-Line [%s] - doesn't look like IP[/cidr]", cidr);
                return;
        }