From sketchy@weirdo.netcraft.com  Thu Dec 21 11:07:46 2000
Return-Path: <sketchy@weirdo.netcraft.com>
Received: from weirdo.netcraft.com (weirdo.netcraft.com [195.92.95.47])
	by hub.freebsd.org (Postfix) with ESMTP id B618637B400
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 21 Dec 2000 11:07:45 -0800 (PST)
Received: (from sketchy@localhost)
	by weirdo.netcraft.com (8.11.1/8.11.1) id eBLJ71I77623;
	Thu, 21 Dec 2000 19:07:01 GMT
	(envelope-from sketchy)
Message-Id: <200012211907.eBLJ71I77623@weirdo.netcraft.com>
Date: Thu, 21 Dec 2000 19:07:01 GMT
From: Jonathan Perkin <sketchy@netcraft.com>
Sender: sketchy@weirdo.netcraft.com
Reply-To: Jonathan Perkin <sketchy@netcraft.com>
To: FreeBSD-gnats-submit@freebsd.org
Subject: fetch(1) no longer honours FTP_LOGIN / -R option doesn't preserve existing files
X-Send-Pr-Version: 3.2

>Number:         23719
>Category:       bin
>Synopsis:       New fetch(1) doesn't pick up FTP_LOGIN env var (older libftpio-linked version did).  Also fetch's -R option is either buggy or misleading.
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    des
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Dec 21 11:10:01 PST 2000
>Closed-Date:    Wed Dec 27 08:42:46 PST 2000
>Last-Modified:  Wed Dec 27 08:43:05 PST 2000
>Originator:     Jonathan Perkin
>Release:        FreeBSD 4.2-RELEASE i386
>Organization:
Metcraft Ltd.
>Environment:

	local:

	FreeBSD weirdo.netcraft.com 4.2-RELEASE FreeBSD 4.2-RELEASE
	#0: Wed Dec 13 19:07:21 GMT 2000
	sketchy@weirdo.netcraft.com:/usr/obj/usr/src/sys/WEIRDO  i386

	ftp server:
	FreeBSD tex.netcraft.com 3.5-STABLE FreeBSD 3.5-STABLE
	#0: Fri Dec  8 13:20:38 GMT 2000
	sketchy@tex.netcraft.com:/usr/src/sys/compile/TEX  i386

	ftp server is running standard /usr/libexec/ftpd

>Description:

	Versions of fetch(1) linked against libftpio (2.x/3.x) honour an
	FTP_LOGIN variable, whereas newer versions using libfetch do not.
	This can create interopable problems with scripts when upgrading
	to newer releases.

	fetch(1)'s -R option also malfunctions with respect to existing
	files which are being resumed - if fetch cannot resume the transfer,
	it should not unlink the file and start from the beginning.  Either
	that or the manpage should be updated to clarify the situation.

	This was noticed when trying to resume the last 1Gb or so of a
	7.6Gb transfer over a 2MB link.  Needless to say finding out the
	6Gb or so of data already transferred had been deleted wasn't fun :)

>How-To-Repeat:

	fetch a large file, interrupt it midway.
	Attempt to resume the transfer with "fetch -apRr"

	If the server cannot establish a resume transfer, fetch will
	delete the local file and start the transfer from the beginning.

>Fix:

	


>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->feedback 
State-Changed-By: des 
State-Changed-When: Fri Dec 22 01:18:05 PST 2000 
State-Changed-Why:  
Patches have been sent to originator. 


Responsible-Changed-From-To: freebsd-bugs->des 
Responsible-Changed-By: des 
Responsible-Changed-When: Fri Dec 22 01:18:05 PST 2000 
Responsible-Changed-Why:  
I maintain libfetch and fetch. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=23719 

From: Dag-Erling Smorgrav <des@ofug.org>
To: Jonathan Perkin <sketchy@netcraft.com>
Cc: FreeBSD-gnats-submit@FreeBSD.ORG
Subject: Re: bin/23719: fetch(1) no longer honours FTP_LOGIN / -R option doesn't preserve existing files
Date: 22 Dec 2000 10:17:52 +0100

 Jonathan Perkin <sketchy@netcraft.com> writes:
 > 	Versions of fetch(1) linked against libftpio (2.x/3.x) honour an
 > 	FTP_LOGIN variable, whereas newer versions using libfetch do not.
 > 	This can create interopable problems with scripts when upgrading
 > 	to newer releases.
 
 Try the following patch:
 
 Index: ftp.c
 ===================================================================
 RCS file: /home/ncvs/src/lib/libfetch/ftp.c,v
 retrieving revision 1.56
 diff -u -r1.56 ftp.c
 --- ftp.c	2000/12/06 09:23:27	1.56
 +++ ftp.c	2000/12/21 19:31:38
 @@ -762,6 +762,8 @@
      /* send user name and password */
      user = url->user;
      if (!user || !*user)
 +	user = getenv("FTP_LOGIN");
 +    if (!user || !*user)
  	user = FTP_ANONYMOUS_USER;
      if (purl && url->port == _fetch_default_port(url->scheme))
  	e = _ftp_cmd(cd, "USER %s@%s", user, url->host);
 
 > 	fetch(1)'s -R option also malfunctions with respect to existing
 > 	files which are being resumed - if fetch cannot resume the transfer,
 > 	it should not unlink the file and start from the beginning.  Either
 > 	that or the manpage should be updated to clarify the situation.
 
 This only happens if the local and remote modification times do not
 match, which means that the remote file changed or fetch was killed
 hard (a normal INTR will abort the transfer, but still set the mtime
 of the local file to that of the remote file). Try the following
 patch:
 
 Index: fetch.c
 ===================================================================
 RCS file: /home/ncvs/src/usr.bin/fetch/fetch.c,v
 retrieving revision 1.24
 diff -u -r1.24 fetch.c
 --- fetch.c	2000/12/13 11:26:27	1.24
 +++ fetch.c	2000/12/22 09:12:17
 @@ -322,6 +322,11 @@
  	if (!F_flag && us.mtime && sb.st_mtime != us.mtime) {
  	    /* no match! have to refetch */
  	    fclose(f);
 +	    /* if precious, warn the user and give up */
 +	    if (R_flag) {
 +		warnx("%s: local and remote modification times do not match");
 +		goto failure_keep;
 +	    }
  	    url->offset = 0;
  	    if ((f = fetchXGet(url, &us, flags)) == NULL) {
  		warnx("%s: %s", path, fetchLastErrString);
 
 DES
 -- 
 Dag-Erling Smorgrav - des@ofug.org
 
State-Changed-From-To: feedback->closed 
State-Changed-By: des 
State-Changed-When: Wed Dec 27 08:42:46 PST 2000 
State-Changed-Why:  
Fixed in -CURRENT and -STABLE. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=23719 
>Unformatted:
