Explorar o código

* Fixed CIDR host matching not checking for BEST MATCH as normal method does

svn: 2317
Bryan Drewery %!s(int64=21) %!d(string=hai) anos
pai
achega
b8a2a2dfc4
Modificáronse 2 ficheiros con 12 adicións e 15 borrados
  1. 6 6
      src/match.c
  2. 6 9
      src/userrec.c

+ 6 - 6
src/match.c

@@ -221,7 +221,7 @@ comp_with_mask(void *addr, void *dest, unsigned int mask)
 /* match_cidr()
  *
  * Input - mask, address
- * Ouput - 1 = Matched 0 = Did not match
+ * Ouput - + = Matched 0 = Did not match
  */
 
 int
@@ -229,7 +229,7 @@ match_cidr(const char *s1, const char *s2)
 {
   sockname_t ipaddr, maskaddr;
   char address[NICKLEN + UHOSTLEN + 6] = "", mask[NICKLEN + UHOSTLEN + 6] = "", *ipmask = NULL, *ip = NULL, *len = NULL;
-  int cidrlen, aftype;
+  int cidrlen = 0, aftype = 0, ret = 0;
 
   egg_bzero(&ipaddr, sizeof(ipaddr));
   egg_bzero(&maskaddr, sizeof(maskaddr));
@@ -269,14 +269,14 @@ match_cidr(const char *s1, const char *s2)
     inet_pton(aftype, ip, &ipaddr.u.ipv6.sin6_addr);
     inet_pton(aftype, ipmask, &maskaddr.u.ipv6.sin6_addr);
     if (comp_with_mask(&ipaddr.u.ipv6.sin6_addr.s6_addr, &maskaddr.u.ipv6.sin6_addr.s6_addr, cidrlen) && 
-       wild_match(mask, address))
-      return 1;
+       ((ret = wild_match(mask, address))))
+      return ret;
   } else if (aftype == AF_INET) {
     inet_pton(aftype, ip, &ipaddr.u.ipv4.sin_addr);
     inet_pton(aftype, ipmask, &maskaddr.u.ipv4.sin_addr);
     if (comp_with_mask(&ipaddr.u.ipv4.sin_addr.s_addr, &maskaddr.u.ipv4.sin_addr.s_addr, cidrlen) && 
-       wild_match(mask, address))
-      return 1;
+       ((ret = wild_match(mask, address))))
+      return ret;
   }
   return 0;
 }

+ 6 - 9
src/userrec.c

@@ -206,7 +206,7 @@ struct userrec *get_user_by_host(char *host)
 
   struct userrec *u = NULL;
   struct list_type *q = NULL;
-  int cnt = 0, i, fcidr = 0;
+  int cnt = 0, i;
   char host2[UHOSTLEN] = "", *p = NULL;
   bool do_cidr = 0;
 
@@ -222,12 +222,11 @@ struct userrec *get_user_by_host(char *host)
     q = (struct list_type *) get_user(&USERENTRY_HOSTS, u);
     for (; q; q = q->next) {
       if (do_cidr) {
-        fcidr = match_cidr(q->extra, host);
-      }
-
-      if (fcidr) {
-        ret = u;
-        break;
+        i = match_cidr(q->extra, host);
+        if (i > cnt) {
+          ret = u;
+          cnt = i;
+        }
       }
 
       i = wild_match(q->extra, host);
@@ -236,8 +235,6 @@ struct userrec *get_user_by_host(char *host)
 	cnt = i;
       }
     }
-    if (fcidr)
-      break;
   }
   if (ret != NULL) {
     lastuser = ret;