Przeglądaj źródła

* Automatic host adding by localhubs now sanity checks if the hosts will conflict with other bots/users. (#137)

svn: 2309
Bryan Drewery 21 lat temu
rodzic
commit
ce3e8c0aac
5 zmienionych plików z 30 dodań i 19 usunięć
  1. 1 0
      doc/UPDATES
  2. 5 5
      src/conf.c
  3. 8 14
      src/mod/server.mod/servmsg.c
  4. 15 0
      src/userrec.c
  5. 1 0
      src/userrec.h

+ 1 - 0
doc/UPDATES

@@ -54,6 +54,7 @@ Lines prefixed with '-' were disabled before release and are not finished, or ar
 * Removed cmd line param '-s'; Tracing bot on startup will always make the bot die right away.
 * Trace detection cannot be set to 'ignore', lowest setting is now: 'die'
 * Fixed cmd_slowjoin (#129)
+* Automatic host adding by localhubs now sanity checks if the hosts will conflict with other bots/users. (#137)
 
 1.2.4
 * Fixed cmd_botset not displaying botnick.

+ 5 - 5
src/conf.c

@@ -1083,26 +1083,26 @@ void conf_add_userlist_bots()
       }
       if (bot->net.ip) {
         simple_snprintf(uhost, sizeof(uhost), "*!%s@%s", conf.username, bot->net.ip);
-        if (!user_has_host(NULL, u, uhost))
+        if (!user_has_host(NULL, u, uhost) && !host_conflicts(uhost))
           addhost_by_handle(bot->nick, uhost);
 
         simple_snprintf(uhost, sizeof(uhost), "*!~%s@%s", bot->nick, bot->net.ip);
-        if (!user_has_host(NULL, u, uhost))
+        if (!user_has_host(NULL, u, uhost) && !host_conflicts(uhost))
           addhost_by_handle(bot->nick, uhost);
       }
       if (bot->net.host) {
         simple_snprintf(uhost, sizeof(uhost), "*!%s@%s", conf.username, bot->net.host);
-        if (!user_has_host(NULL, u, uhost))
+        if (!user_has_host(NULL, u, uhost) && !host_conflicts(uhost))
           addhost_by_handle(bot->nick, uhost);
       }
       if (bot->net.host6) {
         simple_snprintf(uhost, sizeof(uhost), "*!%s@%s", conf.username, bot->net.host6);
-        if (!user_has_host(NULL, u, uhost))
+        if (!user_has_host(NULL, u, uhost) && !host_conflicts(uhost))
           addhost_by_handle(bot->nick, uhost);
       }
       if (bot->net.ip6) {
         simple_snprintf(uhost, sizeof(uhost), "*!%s@%s", conf.username, bot->net.ip6);
-        if (!user_has_host(NULL, u, uhost))
+        if (!user_has_host(NULL, u, uhost) && !host_conflicts(uhost))
           addhost_by_handle(bot->nick, uhost);
       }
     }

+ 8 - 14
src/mod/server.mod/servmsg.c

@@ -1144,21 +1144,15 @@ void check_hostmask()
 
   /* dont add the host if it conflicts with another in the userlist */
   struct userrec *u = NULL;
-  struct list_type *q = NULL;
-
-  for (u = userlist; u; u = u->next) {
-    q = (struct list_type *) get_user(&USERENTRY_HOSTS, u);
-    for (; q; q = q->next) {
-      if (wild_match(s, q->extra) || wild_match(q->extra, s)) {
-        if (u != conf.bot->u) {
-          putlog(LOG_WARN, "*", "My automatic hostmask '%s' would conflict with user: '%s'. (Not adding)", s, u->handle);
-          sdprintf("I am %s, they are: %s, (%X vs %X)", conf.bot->u->handle, u->handle, conf.bot->u, u);
-        } else
-          sdprintf("Already have hostmask '%s' added for myself", s);
-        return;
-      }
-    }
+  if ((u = host_conflicts(s))) {
+    if (u != conf.bot->u) {
+      putlog(LOG_WARN, "*", "My automatic hostmask '%s' would conflict with user: '%s'. (Not adding)", s, u->handle);
+      sdprintf("I am %s, they are: %s, (%X vs %X)", conf.bot->u->handle, u->handle, conf.bot->u, u);
+    } else
+      sdprintf("Already have hostmask '%s' added for myself", s);
+    return;
   }
+
   addhost_by_handle(conf.bot->nick, s);
 
   putlog(LOG_GETIN, "*", "Updated my hostmask: %s", s);

+ 15 - 0
src/userrec.c

@@ -60,6 +60,21 @@ static struct userrec *check_dcclist_hand(char *handle)
   return NULL;
 }
 
+struct userrec *host_conflicts(char *host)
+{
+  struct userrec *u = NULL;
+  struct list_type *q = NULL;
+
+  for (u = userlist; u; u = u->next) {
+    for (q = (struct list_type *) get_user(&USERENTRY_HOSTS, u); q; q = q->next) {
+      if (wild_match(host, q->extra) || wild_match(q->extra, host))
+        return u;
+    }
+  }
+
+  return NULL;
+}
+
 struct userrec *get_user_by_handle(struct userrec *bu, char *handle)
 {
   if (!handle)

+ 1 - 0
src/userrec.h

@@ -15,6 +15,7 @@ bool write_user(struct userrec *u, FILE * f, int shr);
 int write_userfile(int);
 void touch_laston(struct userrec *, char *, time_t);
 void user_del_chan(char *);
+struct userrec *host_conflicts(char *);
 
 extern struct userrec  		*userlist, *lastuser;
 extern int			cache_hit, cache_miss, userfile_perm;