Переглянути джерело

* Protect bot linking with hostname matching

Bryan Drewery 16 роки тому
батько
коміт
36e5256e1c
2 змінених файлів з 31 додано та 0 видалено
  1. 2 0
      doc/UPDATES
  2. 29 0
      src/dcc.c

+ 2 - 0
doc/UPDATES

@@ -1,3 +1,5 @@
+* Bots must have a matching host to be able to link now.
+
 1.2.17 - http://wraith.botpack.net/milestone/1.2.17
 * Binary pass prompt has been changed to be more clear.
 * Fix uname checking on NetBSD and OpenBSD

+ 29 - 0
src/dcc.c

@@ -1710,6 +1710,35 @@ dcc_telnet_id(int idx, char *buf, int atr)
   } else {
   }
 
+  if (dcc[idx].bot) {
+    char shost[UHOSTLEN + 20] = "", sip[UHOSTLEN + 20] = "", user[30] = "";
+    simple_snprintf(shost, sizeof(shost), "-telnet!%s", dcc[idx].host);
+    char *p = strchr(dcc[idx].host, '@');
+    strlcpy(user, dcc[idx].host, p - dcc[idx].host + 1);
+    simple_snprintf(sip, sizeof(sip), "-telnet!%s@%s", user, iptostr(htonl(dcc[idx].addr)));
+
+    struct userrec *u = NULL;
+    ok = 1;
+
+    if (!u)
+      u = get_user_by_host(sip);			/* Check for -telnet!ident@ip */
+    if (!u)
+      u = get_user_by_host(shost);		/* Check for -telnet!ident@host */
+    if (!u)
+      ok = 0;
+
+    if (u && strcasecmp(nick, u->handle))
+      ok = 0;
+
+    if (!ok) {
+      putlog(LOG_BOTS, "*", "Denied link to '%s': Host not recognized: %s", nick, dcc[idx].host);
+      putlog(LOG_BOTS, "*", "If this host/bot is trusted: %s+host %s %s", settings.dcc_prefix, nick, shost);
+      killsock(dcc[idx].sock);
+      lostdcc(idx);
+      return;
+    }
+  }
+
   dcc_telnet_pass(idx, atr);
 }