Просмотр исходного кода

* Added CIDR/mask matching support for all user hosts, ie, '.+host user *!jerry@1.2.0.0/16' will match 'bob!jerry@1.2.3.4'

svn: 2300
Bryan Drewery 21 лет назад
Родитель
Сommit
a2b5958929
2 измененных файлов с 24 добавлено и 2 удалено
  1. 1 0
      doc/UPDATES
  2. 23 2
      src/userrec.c

+ 1 - 0
doc/UPDATES

@@ -48,6 +48,7 @@ Lines prefixed with '-' were disabled before release and are not finished, or ar
 * Added confirmation for using 'set' on list variables without using the list functions. (#118)
 * Fixed bots auto-opping passwordless users on JOIN, to match cmd_mop.
 * Fixed typo for 'help nopass'
+* Added CIDR/mask matching support for all user hosts, ie, '.+host user *!jerry@1.2.0.0/16' will match 'bob!jerry@1.2.3.4'
 
 1.2.4
 * Fixed cmd_botset not displaying botnick.

+ 23 - 2
src/userrec.c

@@ -25,6 +25,7 @@
 #include "chanprog.h"
 #include "crypt.h"
 #include "core_binds.h"
+#include "socket.h"
 
 bool             noshare = 1;		/* don't send out to sharebots	    */
 struct userrec	*userlist = NULL;	/* user records are stored here	    */
@@ -190,21 +191,41 @@ struct userrec *get_user_by_host(char *host)
 
   struct userrec *u = NULL;
   struct list_type *q = NULL;
-  int cnt = 0, i;
-  char host2[UHOSTLEN] = "";
+  int cnt = 0, i, fcidr = 0;
+  char host2[UHOSTLEN] = "", *p = NULL;
+  bool do_cidr = 0;
 
   cache_miss++;
   strlcpy(host2, host, sizeof host2);
 
+  sdprintf("hostname: %s", host);
+  /* do CIDR matching if given host is an ip */
+  if ((p = strchr(host2, '@'))) {
+    sdprintf("IS_DOTTED_IP: %s", p);
+    if (is_dotted_ip(++p))
+      do_cidr = 1;
+  }
+  sdprintf("do_cidr: %d", do_cidr);
+
   for (u = userlist; u; u = u->next) {
     q = (struct list_type *) get_user(&USERENTRY_HOSTS, u);
     for (; q; q = q->next) {
+      if (do_cidr) {
+        fcidr = match_cidr(q->extra, host);
+        ret = u;
+      }
+
+      if (fcidr)
+        break;
+
       i = wild_match(q->extra, host);
       if (i > cnt) {
 	ret = u;
 	cnt = i;
       }
     }
+    if (fcidr)
+      break;
   }
   if (ret != NULL) {
     lastuser = ret;