浏览代码

* Fix oidentd.conf usage
* Cleanup old entries from my-ip and botnick
* Only bother with oidentd.conf if using ident-botnick=1 and oidentd=1

svn: 3535

Bryan Drewery 19 年之前
父节点
当前提交
fb732ef3f6
共有 8 个文件被更改,包括 76 次插入26 次删除
  1. 3 3
      src/botnet.c
  2. 5 5
      src/chanprog.c
  3. 50 5
      src/dccutil.c
  4. 1 1
      src/dccutil.h
  5. 3 3
      src/misc.c
  6. 3 2
      src/mod/server.mod/servmsg.c
  7. 9 5
      src/net.c
  8. 2 2
      src/net.h

+ 3 - 3
src/botnet.c

@@ -1058,10 +1058,10 @@ static void botlink_dns_callback(int id, void *client_data, const char *host, ch
   dcc[i].sock = getsock(SOCK_STRONGCONN);
 #endif /* USE_IPV6 */
 
-  if (dcc[i].sock > 0)
-    identd_open();                      /* will be closed when an ident is replied. */
+//  if (dcc[i].sock > 0)
+//    identd_open();                      /* will be closed when an ident is replied. */
 
-  if (dcc[i].sock < 0 || open_telnet_raw(dcc[i].sock, ips[0], dcc[i].port, 0) < 0)
+  if (dcc[i].sock < 0 || open_telnet_raw(dcc[i].sock, ips[0], dcc[i].port, 0, 1) < 0)
     failed_link(i);
   else { /* let's attempt to initiate SSL before ANYTHING else... */
 #ifdef HAVE_SSL

+ 5 - 5
src/chanprog.c

@@ -564,17 +564,17 @@ void chanprog()
   char *ip4 = NULL, *ip6 = NULL;
 
   if (cached_ip) {
-    ip4 = strdup(myipstr(4));
-    ip6 = strdup(myipstr(6));
+    ip4 = strdup(myipstr(AF_INET));
+    ip6 = strdup(myipstr(AF_INET6));
   }
 
   cache_my_ip();
-  sdprintf("ip4: %s", myipstr(4));
-  sdprintf("ip6: %s", myipstr(6));
+  sdprintf("ip4: %s", myipstr(AF_INET));
+  sdprintf("ip6: %s", myipstr(AF_INET6));
 
   /* Check if our ip changed during a rehash */
   if (ip4) {
-    if (strcmp(ip4, myipstr(4)) || strcmp(ip6, myipstr(6))) {
+    if (strcmp(ip4, myipstr(AF_INET)) || strcmp(ip6, myipstr(AF_INET6))) {
       if (tands > 0) {
         botnet_send_chat(-1, conf.bot->nick, "IP changed.");
         botnet_send_bye("IP changed.");

+ 50 - 5
src/dccutil.c

@@ -10,6 +10,7 @@
 
 
 #include <sys/stat.h>
+#include <sys/file.h>
 #include "common.h"
 #include "color.h"
 #include "chanprog.h"
@@ -867,7 +868,7 @@ listen_all(port_t lport, bool off)
         /* now setup ipv4/ipv6 listening port */
         idx = new_dcc(&DCC_TELNET, 0);
         dcc[idx].addr = 0L;
-        strcpy(dcc[idx].host6, myipstr(6));
+        strcpy(dcc[idx].host6, myipstr(AF_INET6));
         dcc[idx].port = port;
         dcc[idx].sock = i6;
         dcc[idx].timeval = now;
@@ -921,7 +922,7 @@ listen_all(port_t lport, bool off)
 }
 
 void
-identd_open()
+identd_open(const char *sourceIp, const char *destIp)
 {
   int idx;
   int i = -1;
@@ -959,14 +960,58 @@ identd_open()
       killsock(i);
   }
 
-  if (conf.homedir && oidentd) {
+  /* Only makes sense if we're spoofing by nick */
+  if (conf.homedir && oidentd && ident_botnick) {
     char oidentd_conf[1024] = "";
 
     simple_snprintf(oidentd_conf, sizeof(oidentd_conf), "%s/.oidentd.conf", conf.homedir);
 
-    FILE *f = fopen(oidentd_conf, "w");
+    sdprintf("Attempting to spoof ident with oidentd (%s)", oidentd_conf);
+    FILE *f = NULL;
+
+    /* Wait for any locks to finish up */
+    while ((f = fopen(oidentd_conf, "a+")) == NULL)
+      ;
+
     if (f) {
-      fprintf(f, "global { reply \"%s\" }\n", origbotname);
+      flock(fileno(f), LOCK_EX);
+      fseek(f, 0, SEEK_SET);
+
+      char inbuf[100] = "", outbuf[2048] = "";
+
+      /* Clear any of my matching ips and username */
+
+      while (fgets(inbuf, sizeof(inbuf), f) != NULL) {
+        if(inbuf[0] == '\n') continue;
+        char *line = strdup(inbuf), *p = line;
+        newsplit(&line); /* to */
+        newsplit(&line); /* ip */
+        if (!strcmp(newsplit(&line), "from") && !strcmp(newsplit(&line), sourceIp)) {
+          free(p);
+          continue;
+        }
+
+
+        char reply[100] = "";
+        simple_snprintf(reply, sizeof(reply), "reply \"%s\"", origbotname);
+
+        if (strstr(line, reply)) {
+          free(p);
+          continue;
+        }
+
+        strlcat(outbuf, inbuf, sizeof(outbuf));
+        free(p);
+      }
+
+      ftruncate(fileno(f), 0);
+      fwrite(outbuf, 1, strlen(outbuf), f);
+
+      //And make a record in the oidentd.conf to spoof the ident request from this port->dest-prot
+      fprintf(f, "to %s from %s { reply \"%s\" }\n", destIp, sourceIp, origbotname);
+      
+      fflush(f);
+      flock(fileno(f), LOCK_UN);
       fclose(f);
     }
   }

+ 1 - 1
src/dccutil.h

@@ -50,7 +50,7 @@ char *add_cr(char *);
 void changeover_dcc(int, struct dcc_table *, int);
 void do_boot(int, char *, char *);
 int detect_dcc_flood(time_t *, struct chat_info *, int);
-void identd_open();
+void identd_open(const char * = NULL, const char * = NULL);
 void identd_close();
 int listen_all(port_t, bool);
 bool valid_idx(int);

+ 3 - 3
src/misc.c

@@ -639,7 +639,7 @@ readsocks(const char *fname)
   if (servidx >= 0) {
     char nserv[50] = "";
 
-    if ((ip4 && ip6) && (strcmp(ip4, myipstr(4)) || strcmp(ip6, myipstr(6)))) {
+    if ((ip4 && ip6) && (strcmp(ip4, myipstr(AF_INET)) || strcmp(ip6, myipstr(AF_INET6)))) {
       if (tands > 0) {		/* We're not linked yet.. but for future */
         botnet_send_chat(-1, conf.bot->nick, "IP changed.");
         botnet_send_bye("IP changed.");
@@ -711,8 +711,8 @@ restart(int idx)
   if (floodless)
     lfprintf(socks->f, "+server_floodless %d\n", floodless);
   lfprintf(socks->f, "+buildts %li\n", buildts);
-  lfprintf(socks->f, "+ip4 %s\n", myipstr(4));
-  lfprintf(socks->f, "+ip6 %s\n", myipstr(6));
+  lfprintf(socks->f, "+ip4 %s\n", myipstr(AF_INET));
+  lfprintf(socks->f, "+ip6 %s\n", myipstr(AF_INET6));
 
   fflush(socks->f);
   socks->my_close();

+ 3 - 2
src/mod/server.mod/servmsg.c

@@ -1572,9 +1572,10 @@ static void server_dns_callback(int id, void *client_data, const char *host, cha
   strcpy(serverpass, (char *) dcc[idx].u.dns->cbuf);
   changeover_dcc(idx, &SERVER_SOCKET, 0);
 
-  identd_open();
+//  identd_open(idx);
 
-  serv = open_telnet(ip, dcc[idx].port, 0);
+  //No proxy, use identd
+  serv = open_telnet(ip, dcc[idx].port, 0, 1);
 
   if (serv < 0) {
     putlog(LOG_SERV, "*", "Failed connect to %s (%s)", dcc[idx].host, strerror(errno));

+ 9 - 5
src/net.c

@@ -226,7 +226,7 @@ char *myipstr(int af_type)
 {
   if (cached_ip) {
 #ifdef USE_IPV6
-    if (af_type == 6) {
+    if (af_type == AF_INET6) {
       static char s[UHOSTLEN + 1] = "";
 
       egg_inet_ntop(AF_INET6, &cached_myip6_so.sin6.sin6_addr, s, 119);
@@ -234,7 +234,7 @@ char *myipstr(int af_type)
       return s;
     } else
 #endif /* USE_IPV6 */
-      if (af_type == 4) {
+      if (af_type == AF_INET) {
         static char s[UHOSTLEN + 1] = "";
 
         egg_inet_ntop(AF_INET, &cached_myip4_so.sin.sin_addr, s, 119);
@@ -614,7 +614,7 @@ void initialize_sockaddr(int af_type, const char *host, port_t port, union socka
  *   -1  strerror()/errno type error
  *   -2  can't resolve hostname
  */
-int open_telnet_raw(int sock, const char *ipIn, port_t sport, bool proxy_on)
+int open_telnet_raw(int sock, const char *ipIn, port_t sport, bool proxy_on, bool identd)
 {
   static port_t port = 0;
   union sockaddr_union so;
@@ -669,9 +669,13 @@ int open_telnet_raw(int sock, const char *ipIn, port_t sport, bool proxy_on)
       socklist[i].flags = (socklist[i].flags & ~SOCK_VIRTUAL) | SOCK_CONNECT;
       socklist[i].host = strdup(ipIn);
       socklist[i].port = port;
+      break;
     }
   }
 
+  if (identd)
+    identd_open(myipstr(is_resolved), ipIn);
+
   int rc = -1;
 
   /* make the connect attempt */
@@ -701,7 +705,7 @@ int open_telnet_raw(int sock, const char *ipIn, port_t sport, bool proxy_on)
 }
 
 /* Ordinary non-binary connection attempt */
-int open_telnet(const char *ip, port_t port, bool proxy)
+int open_telnet(const char *ip, port_t port, bool proxy, bool identd)
 {
   int sock = -1;
   
@@ -711,7 +715,7 @@ int open_telnet(const char *ip, port_t port, bool proxy)
   sock = getsock(0);
 #endif /* USE_IPV6 */
   if (sock >= 0)
-    return open_telnet_raw(sock, ip, port, proxy);
+    return open_telnet_raw(sock, ip, port, proxy, identd);
   return -1;
 }
 

+ 2 - 2
src/net.h

@@ -139,9 +139,9 @@ int open_address_listen(in_addr_t, int, port_t *);
 #else
 int open_address_listen(in_addr_t, port_t *);
 #endif /* USE_IPV6 */
-int open_telnet(const char *, port_t, bool);
+int open_telnet(const char *, port_t, bool proxy = 0, bool identd = 0);
 int open_telnet_dcc(int, char *, char *);
-int open_telnet_raw(int, const char *, port_t, bool);
+int open_telnet_raw(int, const char *, port_t, bool, bool = 0);
 void tputs(int, char *, size_t);
 void dequeue_sockets();
 int sockgets(char *, int *);