Subject: [fwtk-users] Re: Bug in ftp-gw.c/sendsaved ?

From: Michel Bardiaux <[email-masked]>
Date: Fri, 31 May 2002 14:43:53 +0200

Quoting an old posting of mine is the best intro:

Michel Bardiaux wrote:
> 
> Symptoms: FTP client (any) comes from behind a Checkpoint Firewall-1,
> goes through TIS FWTK 2.1 ftp-gw (configured incoming), to *any* ftp
> server, whather loval or in the DMZ. Client sends "USER foo", receives
> "331 Password required for ..." then "421 Service not available".
> 
> We looked in the FAQs, the FWTK archives, Google, the FWTK patches
> pages, etc... and found about the port-20 problem and patch (which was
> already applied), and about the problem of \r\n in a separate packet
> from the PORT command, which supposed to be fixed in 2.1.
> 
> We then added lots of trace printouts in ftp-gw.c and it finally emerged
> that there is one place where the \r\n problem is *not* completely fixed
> because there is one case when ftp-gw tals to the client not using
> sayn() but directly calling net_send(): in sendsaved(). After patching
> sendsaved() the sessions through FW-1 worked.
> 

The thread was more or less closed by Rick Murphy:

> Subject: 
>           [fwtk-users] Re: Bug in ftp-gw.c/sendsaved ?
>      Date: 
>           Tue, 04 Dec 2001 06:30:02 -0500
>     From: 
>           Rick Murphy <[email-masked]>
>  Reply-To: 
>           "fwtk-users" <[email-masked]>
>        To: 
>           "fwtk-users" <[email-masked]>
> 
> 
> 
> 
> At 03:37 PM 12/1/01 -0500, Ted Keller wrote:
> >So is there a bonified patch for this issue?  The updated looks pretty
> >easy - however, if you have a patch - would like to see it and post it to
> >fwtk.org.
> 
> I haven't seen a patch and I'm reluctant to just write one - I don't have 
> the ability to test any proposed fix.
>          -Rick
> 
At the time I was far too busy to create a proper patch, and there was
also a big mess between several versions of FWTK on our machines... Now
I have been able to find the source for ftp-gw.c, both pristine 2.1 and
patched for data-port. The same patch (attached) works in both cases (as
a patch, and as a fix!).

As for testing... obviously it worked for us, and I have just received a
success report from someone else:

> Subject: 
>             Re: Original 2.1 version, unpatched...
>       Date: 
>             Thu, 30 May 2002 13:21:55 -0400
>       From: 
>             "Michael C. Ibarra" <[email-masked]>
>         To: 
>             Michel Bardiaux <[email-masked]>
>  References: 
>             1 , 2 , 3 , 4 , 5 , 6
> 
> Yes! This worked! I owe you a drink, but you would have to come to
> NYC to redeem :-) Just for the record, I am using a Nokia/Checkpoint
> firewall. My Proxy server running ftp-gw is a Solaris 2.8 build and
> is on one DMZ of the Nokia, and my target ftp server is on a third
> DMZ, my client of course is on a separate DMZ as well. 
> 
> Best regards, and MANY thanks,
> 
> -mike

Will someone put the patch on fwtk.org, and/or merge it with the jumbo
patch?

Greetings,
-- 
Michel Bardiaux
Peaktime Belgium S.A.  Bd. du Souverain, 191  B-1160 Bruxelles
Tel : +32 2 790.29.41

--- ftp-gw.c	Thu May 30 17:46:01 2002
+++ our-ftp-gw.c	Thu May 30 17:46:23 2002
@@ -1687,6 +1687,10 @@

 /* flush saved lines prefixing them with 'code' */
+/*
+This routine as in the 'pristine' 2.1 is not working if connection is made from a FireWall1 because, CR/NL are send in a separate packet...
+This fix was done in fwtk2.1 in the sayn() routine but it seems that the author forgot this one...
+*/
 sendsaved(fd,code)
 int	fd;
 int	code;
@@ -1695,6 +1699,10 @@
 	int	x;
 
 	for(x = 0; x < saveresps; x++) {
+		char*	buf;
+		char*	p;
+		l = strlen(saveresp[x]);
+		p = buf = malloc(5+l+32 /* wide margin... */);
 		if(code != -1) {
 			char	xuf[5];
 			xuf[0] = (code / 100) + '0';
@@ -1702,16 +1710,13 @@
 			xuf[2] = (code % 10) + '0';
 			xuf[3] = '-';
 			xuf[4] = '(';
-			if(net_send(fd,xuf,5,0) != 5)
-				return(-1);
+			memcpy(p, xuf, 5);
+			p+=5;
 		}
-		l = strlen(saveresp[x]);
-		if(net_send(fd,saveresp[x],l,0) != l)
-			return(-1);
-		if(code != -1 && write(fd,")",1) != 1)
-			return(-1);
-		if(net_send(fd,"\r\n",2,0) != 2)
-			return(-1);
+		p+=sprintf(p, "%s)", saveresp[x]);
+		if(sayn(fd, buf, strlen(buf)))
+			return -1;
+		free(buf);
 	}
 	flushsaved();
 	return(0);

---
You are currently subscribed to fwtk-users as: [email-masked]
To unsubscribe send a blank email to [email-masked]