]> jfr.im git - solanum.git/blobdiff - ircd/hostmask.c
Implement hook priorities
[solanum.git] / ircd / hostmask.c
index aa68603af07d7cb55c90ce5a311b333fef9321dc..942140411614b4f93e55ddc6736dcaa239ab217e 100644 (file)
@@ -76,7 +76,7 @@ parse_netmask(const char *text, struct rb_sockaddr_storage *naddr, int *nb)
                                return HM_HOST;
                } else
                        *b = 128;
-               if(rb_inet_pton_sock(ip, (struct sockaddr *)addr) > 0)
+               if(rb_inet_pton_sock(ip, addr) > 0)
                        return HM_IPV6;
                else
                        return HM_HOST;
@@ -94,7 +94,7 @@ parse_netmask(const char *text, struct rb_sockaddr_storage *naddr, int *nb)
                                return HM_HOST;
                } else
                        *b = 32;
-               if(rb_inet_pton_sock(ip, (struct sockaddr *)addr) > 0)
+               if(rb_inet_pton_sock(ip, addr) > 0)
                        return HM_IPV4;
                else
                        return HM_HOST;
@@ -216,6 +216,8 @@ find_conf_by_address(const char *name, const char *sockhost,
        unsigned long hprecv = 0;
        struct ConfItem *hprec = NULL;
        struct AddressRec *arec;
+       struct sockaddr_in ip4;
+       struct sockaddr *pip4 = NULL;
        int b;
 
        if(username == NULL)
@@ -223,9 +225,13 @@ find_conf_by_address(const char *name, const char *sockhost,
 
        if(addr)
        {
-               /* Check for IPV6 matches... */
-               if(fam == AF_INET6)
+               if (fam == AF_INET)
+                       pip4 = addr;
+
+               if (fam == AF_INET6)
                {
+                       if (type == CONF_KILL && rb_ipv4_from_ipv6((struct sockaddr_in6 *)addr, &ip4))
+                               pip4 = (struct sockaddr *)&ip4;
 
                        for (b = 128; b >= 0; b -= 16)
                        {
@@ -244,15 +250,15 @@ find_conf_by_address(const char *name, const char *sockhost,
                                        }
                        }
                }
-               else
-               if(fam == AF_INET)
+
+               if (pip4 != NULL)
                {
                        for (b = 32; b >= 0; b -= 8)
                        {
-                               for (arec = atable[hash_ipv4(addr, b)]; arec; arec = arec->next)
+                               for (arec = atable[hash_ipv4(pip4, b)]; arec; arec = arec->next)
                                        if(arec->type == (type & ~0x1) &&
                                           arec->masktype == HM_IPV4 &&
-                                          comp_with_mask_sock(addr, (struct sockaddr *)&arec->Mask.ipa.addr,
+                                          comp_with_mask_sock(pip4, (struct sockaddr *)&arec->Mask.ipa.addr,
                                                               arec->Mask.ipa.bits) &&
                                                (type & 0x1 || match(arec->username, username)) &&
                                                (type != CONF_CLIENT || !arec->auth_user ||
@@ -364,7 +370,6 @@ find_address_conf(const char *host, const char *sockhost, const char *user,
 {
        struct ConfItem *iconf, *kconf;
        const char *vuser;
-       struct sockaddr_in ip4;
 
        /* Find the best I-line... If none, return NULL -A1kmm */
        if(!(iconf = find_conf_by_address(host, sockhost, NULL, ip, CONF_CLIENT, aftype, user, auth_user)))
@@ -378,34 +383,38 @@ find_address_conf(const char *host, const char *sockhost, const char *user,
        if(IsConfExemptKline(iconf))
                return iconf;
 
-       /* Find the best K-line... -A1kmm */
-       kconf = find_conf_by_address(host, sockhost, NULL, ip, CONF_KILL, aftype, user, NULL);
-
-       /* If they are K-lined, return the K-line */
-       if(kconf)
-               return kconf;
-
        /* if theres a spoof, check it against klines.. */
        if(IsConfDoSpoofIp(iconf))
        {
                char *p = strchr(iconf->info.name, '@');
 
                /* note, we dont need to pass sockhost here, as its
-                * guaranteed to not match by whats above.. --anfl
+                * guaranteed to not match by whats below.. --anfl
                 */
                if(p)
                {
                        *p = '\0';
-                       kconf = find_conf_by_address(p+1, NULL, NULL, ip, CONF_KILL, aftype, iconf->info.name, NULL);
+                       kconf = find_conf_by_address(p+1, NULL, NULL, NULL, CONF_KILL, aftype, iconf->info.name, NULL);
                        *p = '@';
                }
                else
-                       kconf = find_conf_by_address(iconf->info.name, NULL, NULL, ip, CONF_KILL, aftype, vuser, NULL);
+                       kconf = find_conf_by_address(iconf->info.name, NULL, NULL, NULL, CONF_KILL, aftype, vuser, NULL);
 
                if(kconf)
                        return kconf;
+
+               /* everything else checks real hosts, if they're kline_spoof_ip we're done */
+               if(IsConfKlineSpoof(iconf))
+                       return iconf;
        }
 
+       /* Find the best K-line... -A1kmm */
+       kconf = find_conf_by_address(host, sockhost, NULL, ip, CONF_KILL, aftype, user, NULL);
+
+       /* If they are K-lined, return the K-line */
+       if(kconf)
+               return kconf;
+
        /* if no_tilde, check the username without tilde against klines too
         * -- jilles */
        if(user != vuser)
@@ -415,14 +424,6 @@ find_address_conf(const char *host, const char *sockhost, const char *user,
                        return kconf;
        }
 
-       if(ip != NULL && ip->sa_family == AF_INET6 &&
-                       rb_ipv4_from_ipv6((const struct sockaddr_in6 *)(const void *)ip, &ip4))
-       {
-               kconf = find_conf_by_address(NULL, NULL, NULL, (struct sockaddr *)&ip4, CONF_KILL, AF_INET, vuser, NULL);
-               if(kconf)
-                       return kconf;
-       }
-
        return iconf;
 }