[eggheads-patches] PATCH1.5: net_sockfail_nonfatal_1.5.patch

Fabian Knittel fknittel at gmx.de
Mon Oct 23 16:31:07 CST 2000


[ net_sockfail_nonfatal_1.5.patch ]

This patch changes a possible socket() failure to be a non-fatal
event. Originally, eggdrop would panic and call fatal(). The
patch allows it to reject and drop connections instead.

Fabian

--
Fabian Knittel <fknittel at gmx.de> -- http://www.esc-web.de/fabian/
Signed or encrypted mail preferred.    PGP DSA key ID: 0x838B4D20
-------------- next part --------------
diff -urN --exclude-from=/home/fabian/.diffex eggdrop1.5~/doc/UPDATES1.5 eggdrop1.5/doc/UPDATES1.5
--- eggdrop1.5~/doc/UPDATES1.5	Mon Oct 23 23:23:13 2000
+++ eggdrop1.5/doc/UPDATES1.5	Mon Oct 23 23:24:06 2000
@@ -4,6 +4,8 @@
 
 1.5.5
 Found by  Fixed by  What...
+Abraham,  Fabian    Changed failure of socket() to non-fatal event.
+TaKeDa
 TheUnknown Fabian   Fixed support for SunOS / Solaris.
           Fabian    Don't actually delete the bind structures immediately, use
                     centralised garbage collector instead. Cleaned up various
diff -urN --exclude-from=/home/fabian/.diffex eggdrop1.5~/language/core.english.lang eggdrop1.5/language/core.english.lang
--- eggdrop1.5~/language/core.english.lang	Thu Oct 19 19:25:38 2000
+++ eggdrop1.5/language/core.english.lang	Mon Oct 23 23:23:24 2000
@@ -147,6 +147,7 @@
 0x540,\nNickname.\n
 0x541,Last message repeated %d time(s).\n
 0x542,juped
+0x543,No free sockets available.
 
 # IRC_
 0x600,Banned
diff -urN --exclude-from=/home/fabian/.diffex eggdrop1.5~/language/core.german.lang eggdrop1.5/language/core.german.lang
--- eggdrop1.5~/language/core.german.lang	Thu Oct 19 19:25:38 2000
+++ eggdrop1.5/language/core.german.lang	Mon Oct 23 23:23:24 2000
@@ -156,6 +156,7 @@
 0x53f,Rotiere Logdatei %s da groesser als max-logsize (%d)
 0x540,\nNickname.\n
 0x541,Die letzte Meldung wiederholte sich %d mal.\n
+0x543,Keine freien Sockets verfuegbar.
 
 # IRC_
 0x600,gebannt
diff -urN --exclude-from=/home/fabian/.diffex eggdrop1.5~/src/botnet.c eggdrop1.5/src/botnet.c
--- eggdrop1.5~/src/botnet.c	Thu Oct 19 19:25:38 2000
+++ eggdrop1.5/src/botnet.c	Mon Oct 23 23:23:24 2000
@@ -1066,7 +1066,8 @@
   dcc[i].u.bot->numver = idx;
   dcc[i].u.bot->port = dcc[i].port;		/* Remember where i started */
   dcc[i].sock = getsock(SOCK_STRONGCONN);
-  if (open_telnet_raw(dcc[i].sock, iptostr(htonl(dcc[i].addr)),
+  if (dcc[i].sock < 0 ||
+      open_telnet_raw(dcc[i].sock, iptostr(htonl(dcc[i].addr)),
 		      dcc[i].port) < 0)
     failed_link(i);
 }
@@ -1104,7 +1105,8 @@
   dcc[uidx].u.relay->sock = dcc[idx].sock;
   dcc[idx].port++;
   dcc[idx].timeval = now;
-  if (open_telnet_raw(dcc[idx].sock, dcc[idx].addr ?
+  if (dcc[idx].sock < 0 ||
+      open_telnet_raw(dcc[idx].sock, dcc[idx].addr ?
 				     iptostr(htonl(dcc[idx].addr)) :
 				     dcc[idx].host, dcc[idx].port) < 0)
     failed_tandem_relay(idx);
@@ -1147,6 +1149,13 @@
     return;
   }
 
+  dcc[i].sock = getsock(SOCK_STRONGCONN | SOCK_VIRTUAL);
+  if (dcc[i].sock < 0) {
+    lostdcc(i);
+    dprintf(idx, "%s\n", MISC_NOFREESOCK);
+    return;
+  }
+
   dcc[i].port = bi->relay_port;
   dcc[i].addr = 0L;
   strcpy(dcc[i].nick, nick);
@@ -1160,7 +1169,6 @@
   dcc[idx].u.relay = get_data_ptr(sizeof(struct relay_info));
   dcc[idx].u.relay->chat = ci;
   dcc[idx].u.relay->old_status = dcc[idx].status;
-  dcc[i].sock = getsock(SOCK_STRONGCONN | SOCK_VIRTUAL);
   dcc[idx].u.relay->sock = dcc[i].sock;
   dcc[i].timeval = now;
   dcc[i].u.dns->ibuf = dcc[idx].sock;
diff -urN --exclude-from=/home/fabian/.diffex eggdrop1.5~/src/dcc.c eggdrop1.5/src/dcc.c
--- eggdrop1.5~/src/dcc.c	Mon Oct 23 23:19:30 2000
+++ eggdrop1.5/src/dcc.c	Mon Oct 23 23:23:24 2000
@@ -237,7 +237,8 @@
   dcc[idx].sock = getsock(SOCK_STRONGCONN);
   dcc[idx].port++;
   dcc[idx].timeval = now;
-  if (open_telnet_raw(dcc[idx].sock, dcc[idx].addr ?
+  if (dcc[idx].sock < 0 ||
+      open_telnet_raw(dcc[idx].sock, dcc[idx].addr ?
 		      iptostr(htonl(dcc[idx].addr)) : dcc[idx].host,
 		      dcc[idx].port) < 0) {
     failed_link(idx);
diff -urN --exclude-from=/home/fabian/.diffex eggdrop1.5~/src/lang.h eggdrop1.5/src/lang.h
--- eggdrop1.5~/src/lang.h	Thu Oct 19 19:25:38 2000
+++ eggdrop1.5/src/lang.h	Mon Oct 23 23:23:24 2000
@@ -124,6 +124,7 @@
 #define MISC_BANNER_STEALTH	get_language(0x540)
 #define MISC_LOGREPEAT		get_language(0x541)
 #define MISC_JUPED		get_language(0x542)
+#define MISC_NOFREESOCK		get_language(0x543)
 
 /* IRC */
 #define IRC_BANNED		get_language(0x600)
diff -urN --exclude-from=/home/fabian/.diffex eggdrop1.5~/src/mod/filesys.mod/filesys.c eggdrop1.5/src/mod/filesys.mod/filesys.c
--- eggdrop1.5~/src/mod/filesys.mod/filesys.c	Thu Oct 19 19:25:39 2000
+++ eggdrop1.5/src/mod/filesys.mod/filesys.c	Mon Oct 23 23:23:24 2000
@@ -812,7 +812,7 @@
     } else {
       dcc[i].timeval = now;
       dcc[i].sock = getsock(SOCK_BINARY);
-      if (open_telnet_dcc(dcc[i].sock, ip, prt) < 0)
+      if (dcc[i].sock < 0 || open_telnet_dcc(dcc[i].sock, ip, prt) < 0)
 	dcc[i].type->eof(i);
     }
   }
@@ -856,7 +856,7 @@
     ip = newsplit(&msg);
     prt = newsplit(&msg);
     sock = getsock(0);
-    if (open_telnet_dcc(sock, ip, prt) < 0) {
+    if (sock < 0 || open_telnet_dcc(sock, ip, prt) < 0) {
       neterror(buf);
       if (!quiet_reject)
         dprintf(DP_HELP, "NOTICE %s :%s (%s)\n", nick,
diff -urN --exclude-from=/home/fabian/.diffex eggdrop1.5~/src/mod/server.mod/server.c eggdrop1.5/src/mod/server.mod/server.c
--- eggdrop1.5~/src/mod/server.mod/server.c	Mon Oct 23 22:48:42 2000
+++ eggdrop1.5/src/mod/server.mod/server.c	Mon Oct 23 23:23:24 2000
@@ -1449,9 +1449,9 @@
     lostdcc(i);
     return;
   }
-  dcc[i].sock = getsock(0);
   egg_snprintf(ip, sizeof ip, "%lu", iptolong(htonl(dcc[i].addr)));
-  if (open_telnet_dcc(dcc[i].sock, ip, buf) < 0) {
+  dcc[i].sock = getsock(0);
+  if (dcc[i].sock < 0 || open_telnet_dcc(dcc[i].sock, ip, buf) < 0) {
     neterror(buf);
     if(!quiet_reject)
       dprintf(DP_HELP, "NOTICE %s :%s (%s)\n", dcc[i].nick,
diff -urN --exclude-from=/home/fabian/.diffex eggdrop1.5~/src/mod/share.mod/share.c eggdrop1.5/src/mod/share.mod/share.c
--- eggdrop1.5~/src/mod/share.mod/share.c	Mon Oct 23 23:19:30 2000
+++ eggdrop1.5/src/mod/share.mod/share.c	Mon Oct 23 23:23:24 2000
@@ -1025,10 +1025,10 @@
     putlog(LOG_MISC, "*", "CAN'T WRITE USERFILE DOWNLOAD FILE!");
     zapfbot(idx);
   } else {
-    sock = getsock(SOCK_BINARY);
     ip = newsplit(&par);
     port = newsplit(&par);
-    if (open_telnet_dcc(sock, ip, port) < 0) {
+    sock = getsock(SOCK_BINARY);
+    if (sock < 0 || open_telnet_dcc(sock, ip, port) < 0) {
       killsock(sock);
       putlog(LOG_BOTS, "*", "Asynchronous connection failed!");
       dprintf(idx, "s e Can't connect to you!\n");
diff -urN --exclude-from=/home/fabian/.diffex eggdrop1.5~/src/net.c eggdrop1.5/src/net.c
--- eggdrop1.5~/src/net.c	Mon Oct 23 22:48:42 2000
+++ eggdrop1.5/src/net.c	Mon Oct 23 23:23:24 2000
@@ -247,18 +247,22 @@
 {
   int sock = socket(AF_INET, SOCK_STREAM, 0);
 
-  if (sock < 0)
-    fatal("Can't open a socket at all!", 0);
-  setsock(sock, options);
+  if (sock >= 0)
+    setsock(sock, options);
+  else
+    putlog(LOG_MISC, "*", "Warning: Can't create new socket!");
   return sock;
 }
 
 /* Done with a socket
  */
-void killsock(int sock)
+void killsock(register int sock)
 {
-  int i;
+  register int	i;
 
+  /* Ignore invalid sockets.  */
+  if (sock < 0)
+    return;
   for (i = 0; i < MAXSOCKS; i++) {
     if ((socklist[i].sock == sock) && !(socklist[i].flags & SOCK_UNUSED)) {
       close(socklist[i].sock);
@@ -429,9 +433,12 @@
     putlog(LOG_MISC, "*", "!! Cant open a listen port (you are using a firewall)");
     return -1;
   }
+
   sock = getsock(SOCK_LISTEN);
-  egg_bzero((char *) &name, sizeof(struct sockaddr_in));
+  if (sock < 1)
+    return -1;
 
+  egg_bzero((char *) &name, sizeof(struct sockaddr_in));
   name.sin_family = AF_INET;
   name.sin_port = htons(*port);	/* 0 = just assign us a port */
   name.sin_addr.s_addr = addr;
diff -urN --exclude-from=/home/fabian/.diffex eggdrop1.5~/src/tcldcc.c eggdrop1.5/src/tcldcc.c
--- eggdrop1.5~/src/tcldcc.c	Thu Oct 19 19:25:38 2000
+++ eggdrop1.5/src/tcldcc.c	Mon Oct 23 23:23:24 2000
@@ -876,6 +876,10 @@
     return TCL_ERROR;
   }
   sock = getsock(0);
+  if (sock < 0) {
+    Tcl_AppendResult(irp, MISC_NOFREESOCK, NULL);
+    return TCL_ERROR;
+  }
   z = open_telnet_raw(sock, argv[1], atoi(argv[2]));
   if (z < 0) {
     killsock(sock);




More information about the Patches mailing list