Browse Source

* Identd now opens when needed, and closes as soon as a connection is made.

svn: 849
Bryan Drewery 22 years ago
parent
commit
6580006bd6
6 changed files with 37 additions and 6 deletions
  1. 2 1
      src/botnet.c
  2. 3 0
      src/dcc.c
  3. 29 2
      src/dccutil.c
  4. 2 1
      src/dccutil.h
  5. 0 2
      src/main.c
  6. 1 0
      src/mod/server.mod/servmsg.c

+ 2 - 1
src/botnet.c

@@ -1023,7 +1023,8 @@ static void botlink_resolve_success(int i)
   dcc[i].sock = getsock(SOCK_STRONGCONN);
   dcc[i].sock = getsock(SOCK_STRONGCONN);
 #endif /* USE_IPV6 */
 #endif /* USE_IPV6 */
   free(linker);
   free(linker);
-
+  if (dcc[i].sock > 0)
+    identd_open();			/* will be closed when an ident is replied. */
   if (dcc[i].sock < 0 ||
   if (dcc[i].sock < 0 ||
 #ifdef USE_IPV6
 #ifdef USE_IPV6
       open_telnet_raw(dcc[i].sock, dcc[i].host,
       open_telnet_raw(dcc[i].sock, dcc[i].host,

+ 3 - 0
src/dcc.c

@@ -583,6 +583,9 @@ static void dcc_identd(int idx, char *buf, int atr)
 
 
   egg_snprintf(outbuf, sizeof outbuf, "%s : USERID : UNIX : %s\n", buf, conf.bot->nick);
   egg_snprintf(outbuf, sizeof outbuf, "%s : USERID : UNIX : %s\n", buf, conf.bot->nick);
   tputs(dcc[idx].sock, outbuf, strlen(outbuf));
   tputs(dcc[idx].sock, outbuf, strlen(outbuf));
+
+  /* just close it, functions neededing it will open it. */
+  identd_close();
 }
 }
 
 
 static void eof_dcc_identd(int idx)
 static void eof_dcc_identd(int idx)

+ 29 - 2
src/dccutil.c

@@ -22,6 +22,7 @@
 #include "chan.h"
 #include "chan.h"
 #include "tandem.h"
 #include "tandem.h"
 #include "core_binds.h"
 #include "core_binds.h"
+#include "egg_timer.h"
 #include "src/mod/server.mod/server.h"
 #include "src/mod/server.mod/server.h"
 #include <stdarg.h>
 #include <stdarg.h>
 
 
@@ -672,10 +673,16 @@ int listen_all(int lport, int off)
   return idx;
   return idx;
 }
 }
 
 
-void open_identd()
+void identd_open()
 {
 {
   int idx = -1, port = 113, i = -1;
   int idx = -1, port = 113, i = -1;
 
 
+  for (idx = 0; idx < dcc_total; idx++)
+    if (dcc[idx].type == &DCC_IDENTD_CONNECT)
+      return; 		/* it's already open :) */
+
+  idx = -1;
+
 #ifdef USE_IPV6
 #ifdef USE_IPV6
   i = open_listen_by_af(&port, AF_INET6);
   i = open_listen_by_af(&port, AF_INET6);
 #else
 #else
@@ -684,13 +691,33 @@ void open_identd()
   if (i > 0) {
   if (i > 0) {
     idx = new_dcc(&DCC_IDENTD_CONNECT, 0);
     idx = new_dcc(&DCC_IDENTD_CONNECT, 0);
     if (idx > 0) {
     if (idx > 0) {
+      egg_timeval_t howlong;
+
       dcc[idx].addr = iptolong(getmyip());
       dcc[idx].addr = iptolong(getmyip());
       dcc[idx].port = port;
       dcc[idx].port = port;
       dcc[idx].sock = i;
       dcc[idx].sock = i;
       dcc[idx].timeval = now;
       dcc[idx].timeval = now;
       strcpy(dcc[idx].nick, STR("(identd)"));
       strcpy(dcc[idx].nick, STR("(identd)"));
       strcpy(dcc[idx].host, "*");
       strcpy(dcc[idx].host, "*");
-      putlog(LOG_MISC, "*", STR("Identd daemon started."), port, i, idx);
+      putlog(LOG_DEBUG, "*", STR("Identd daemon started."));
+      howlong.sec = 15;
+      howlong.usec = 0;
+      timer_create(&howlong, "identd_close()", (Function) identd_close);
     }
     }
   }
   }
 }
 }
+
+void identd_close()
+{
+  int idx;
+
+  for (idx = 0; idx < dcc_total; idx++) {
+    if (dcc[idx].type == &DCC_IDENTD_CONNECT) {
+      killsock(dcc[idx].sock);
+      lostdcc(idx);
+      putlog(LOG_DEBUG, "*", STR("Identd daemon stopped."));
+      break;
+    }
+  }
+
+}

+ 2 - 1
src/dccutil.h

@@ -44,7 +44,8 @@ char *add_cr(char *);
 void changeover_dcc(int, struct dcc_table *, int);
 void changeover_dcc(int, struct dcc_table *, int);
 void do_boot(int, char *, char *);
 void do_boot(int, char *, char *);
 int detect_dcc_flood(time_t *, struct chat_info *, int);
 int detect_dcc_flood(time_t *, struct chat_info *, int);
-void open_identd();
+void identd_open();
+void identd_close();
 
 
 extern int		max_dcc, connect_timeout;
 extern int		max_dcc, connect_timeout;
 
 

+ 0 - 2
src/main.c

@@ -724,8 +724,6 @@ int main(int argc, char **argv)
   console_init();
   console_init();
   ctcp_init();
   ctcp_init();
   chanprog();
   chanprog();
-  open_identd();
-
 
 
 #ifdef LEAF
 #ifdef LEAF
   if (localhub) {
   if (localhub) {

+ 1 - 0
src/mod/server.mod/servmsg.c

@@ -1248,6 +1248,7 @@ static void server_resolve_success(int idx)
   dcc[idx].addr = dcc[idx].u.dns->ip;
   dcc[idx].addr = dcc[idx].u.dns->ip;
   strcpy(pass, dcc[idx].u.dns->cbuf);
   strcpy(pass, dcc[idx].u.dns->cbuf);
   changeover_dcc(idx, &SERVER_SOCKET, 0);
   changeover_dcc(idx, &SERVER_SOCKET, 0);
+  identd_open();
 #ifdef USE_IPV6
 #ifdef USE_IPV6
   serv = open_telnet(dcc[idx].host, dcc[idx].port);
   serv = open_telnet(dcc[idx].host, dcc[idx].port);
 #else
 #else