Subject: [772] hanging ftpds fix for wu-ftpd 2.4

From: Casper Dik <[email-masked]>
Date: Fri, 25 Nov 1994 15:00:18 +0100

The following patch works around a problem with wu-ftpd.
Recently we've seen an increasing number of ftpd's sticking around.

This scenario has become increasingly common since netscape was released
and from our logs it does look like web-browser connections caused this
problem.

After some investigation it turned out that ftpd hung in accept.
(thanks to lsof and truss).  

Problem scenario:

	client sends "PASV"
	client sends "RETR file"
	client doesn't open a connection, instead the client aborts.

This fix may not be portable, but works for me on Solaris 2.x and probably
works on SunOS 4.1.x and BSD derivatives with fd_set typedef'ed as well.
Some systes may need to include extra files.

The fix is a timeout on accept with select().  The timeout is set to 120
seconds, but I have no idea whether that is sufficient.

Please include me in any replies, as I'm not on this list.

Casper

*** ftpd.c.org	Thu Apr 14 22:05:35 1994
--- ftpd.c	Mon Nov 21 19:40:59 1994
***************
*** 1710,1717 ****
--- 1710,1731 ----
          int s,
            fromlen = sizeof(from);
  
+ #ifdef FD_ZERO
+ 	struct timeval timeout;
+ 	fd_set set;
+ 
+ 	FD_ZERO(&set);
+ 	FD_SET(pdata, &set);
+ 
+ 	timeout.tv_usec = 0;
+ 	timeout.tv_sec = 120;
+ 
+ 	if (select(pdata+1, &set, (fd_set *) 0, (fd_set *) 0, &timeout) == 0 ||
+ 	    (s = accept(pdata, (struct sockaddr *) &from, &fromlen)) < 0) {
+ #else
          s = accept(pdata, (struct sockaddr *) &from, &fromlen);
          if (s < 0) {
+ #endif
              reply(425, "Can't open data connection.");
              (void) close(pdata);
              pdata = -1;