From hua@chromatic.com  Wed Jun 25 14:36:35 1997
Received: from chromatic.com ([204.182.30.9])
          by hub.freebsd.org (8.8.5/8.8.5) with ESMTP id OAA15707
          for <FreeBSD-gnats-submit@freebsd.org>; Wed, 25 Jun 1997 14:36:34 -0700 (PDT)
Received: from ohio.chromatic.com (ohio [172.16.82.5])
	by chromatic.com (8.8.5/8.8.5) with ESMTP id OAA05088
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 25 Jun 1997 14:34:46 -0700 (PDT)
Received: (from hua@localhost)
	by ohio.chromatic.com (8.8.5/8.8.5) id OAA07491;
	Wed, 25 Jun 1997 14:36:04 -0700 (PDT)
Message-Id: <199706252136.OAA07491@ohio.chromatic.com>
Date: Wed, 25 Jun 1997 14:36:04 -0700 (PDT)
From: Ernest Hua <hua@chromatic.com>
Reply-To: hua@chromatic.com
To: FreeBSD-gnats-submit@freebsd.org
Subject: BUG REPORT + FIX: Mirror 2.8 passive mode does not work
X-Send-Pr-Version: 3.2

>Number:         3955
>Category:       ports
>Synopsis:       -kpassive_ftp=true fails on socket connection
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    torstenb
>State:          closed
>Quarter:
>Keywords:
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Jun 25 14:40:01 PDT 1997
>Closed-Date:    Tue Nov 25 00:23:54 PST 1997
>Last-Modified:  Tue Nov 25 00:24:26 PST 1997
>Originator:     Ernest Hua
>Release:        FreeBSD 2.2.2-RELEASE i386
>Organization:
Chromatic Research
>Environment:

	FreeBSD 2.2.2-RELEASE on generic P133 PC clone.

>Description:

	The socket connection when attempting to transition over to passive
	mode ftp fails to connect.

>How-To-Repeat:

	Set passive_ftp to true.

>Fix:

	This is a patch of mirror-2.8 in /usr/local/lib/mirror.

	The bottom line is that the original code used $var instead of var
	where a file handle was necessary, and it presumed a particular
	textual annotation where no one particular annotation was required
	in the protocol.

diff -bwrc mirror/ftp.pl mirror.dist/ftp.pl
*** mirror/ftp.pl	Tue Jun 24 17:00:20 1997
--- mirror.dist/ftp.pl	Sun May 18 00:07:38 1997
***************
*** 430,436 ****
  		return 0;
  	}
  	if( $ret == 1 ) {
! 		$response =~ m/^227 .* \((\d+),(\d+),(\d+),(\d+),(\d+),(\d+)\)$/;
  		$newhost = sprintf( "%d.%d.%d.%d", $1, $2, $3, $4 );
  		$newport = $5 * 256 + $6;
  	}
--- 430,436 ----
  		return 0;
  	}
  	if( $ret == 1 ) {
! 		$response =~ m/^227 Entering Passive Mode \((\d+),(\d+),(\d+),(\d+),(\d+),(\d+)\)$/;
  		$newhost = sprintf( "%d.%d.%d.%d", $1, $2, $3, $4 );
  		$newport = $5 * 256 + $6;
  	}
diff -bwrc mirror/lchat.pl mirror.dist/lchat.pl
*** mirror/lchat.pl	Tue Jun 24 17:21:27 1997
--- mirror.dist/lchat.pl	Sun May 18 00:07:38 1997
***************
*** 123,129 ****
  # Similar to open_port, but does less.  Used for PASV code with ftp.pl
  # -Erez Zadok.
  sub open_newport { ## public
! 	local($server, $port, *newsock) = @_;
  
  	local($serveraddr,$serverproc);
  
--- 123,129 ----
  # Similar to open_port, but does less.  Used for PASV code with ftp.pl
  # -Erez Zadok.
  sub open_newport { ## public
! 	local($server, $port, $newsock) = @_;
  
  	local($serveraddr,$serverproc);
  
***************
*** 142,159 ****
  	}
  	$serverproc = pack($sockaddr, 2, $port, $serveraddr);
  
! 	unless (connect(newsock, $serverproc)) {
! 		($!) = ($!, close(newsock)); # close newsock while saving $!
  		return undef;
  	}
  # We opened with the local address set to ANY, at this stage we know
  # which interface we are using.  This is critical if our machine is
  # multi-homed, with IP forwarding off, so fix-up.
  	local($fam,$lport);
! 	($fam,$lport,$thisaddr) = unpack($sockaddr, getsockname(newsock));
  	$thisproc = pack($sockaddr, 2, 0, $thisaddr);
  # end of post-connect fixup
! 	select((select(newsock), $| = 1)[0]);
  	return 1;
  }
  ##############################################################################
--- 142,159 ----
  	}
  	$serverproc = pack($sockaddr, 2, $port, $serveraddr);
  
! 	unless (connect($newsock, $serverproc)) {
! 		($!) = ($!, close($newsock)); # close newsock while saving $!
  		return undef;
  	}
  # We opened with the local address set to ANY, at this stage we know
  # which interface we are using.  This is critical if our machine is
  # multi-homed, with IP forwarding off, so fix-up.
  	local($fam,$lport);
! 	($fam,$lport,$thisaddr) = unpack($sockaddr, getsockname($newsock));
  	$thisproc = pack($sockaddr, 2, 0, $thisaddr);
  # end of post-connect fixup
! 	select((select($newsock), $| = 1)[0]);
  	return 1;
  }
  ##############################################################################
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-ports->torstenb 
Responsible-Changed-By: fenner 
Responsible-Changed-When: Mon Sep 22 10:41:55 PDT 1997 
Responsible-Changed-Why:  
torstenb is port maintainer 
State-Changed-From-To: open->closed 
State-Changed-By: torstenb 
State-Changed-When: Tue Nov 25 00:23:54 PST 1997 
State-Changed-Why:  
suggested fix applied - thanks ! 
>Unformatted:
