From mandree@FreeBSD.org  Wed Mar  6 19:16:36 2013
Return-Path: <mandree@FreeBSD.org>
Received: from apollo.emma.line.org (freefall.freebsd.org [IPv6:2001:1900:2254:206c::16:87])
	by hub.freebsd.org (Postfix) with ESMTP id 76DECAE5
	for <FreeBSD-gnats-submit@freebsd.org>; Wed,  6 Mar 2013 19:16:36 +0000 (UTC)
	(envelope-from mandree@FreeBSD.org)
Received: from mandree by apollo.emma.line.org with local (Exim 4.80.1 (FreeBSD))
	(envelope-from <mandree@FreeBSD.org>)
	id 1UDJUy-000KkJ-PY
	for FreeBSD-gnats-submit@freebsd.org; Wed, 06 Mar 2013 19:55:32 +0100
Message-Id: <E1UDJUy-000KkJ-PY@apollo.emma.line.org>
Date: Wed, 06 Mar 2013 19:55:32 +0100
From: Matthias Andree <mandree@FreeBSD.org>
Reply-To: Matthias Andree <mandree@FreeBSD.org>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: incorrect fetch(1) exit codes with -s option versus ftp proxy use 
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         176697
>Category:       bin
>Synopsis:       incorrect fetch(1) exit codes with -s option versus ftp proxy use
>Confidential:   no
>Severity:       serious
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Mar 06 19:20:00 UTC 2013
>Closed-Date:    
>Last-Modified:  Sun Mar 10 04:47:07 UTC 2013
>Originator:     Matthias Andree
>Release:        FreeBSD 9.1-RELEASE amd64
>Organization:
>Environment:
System: FreeBSD apollo.emma.line.org 9.1-RELEASE FreeBSD 9.1-RELEASE #2 r244869: Sun Dec 30 22:05:16 CET 2012 toor@apollo.emma.line.org:/usr/obj/usr/src/sys/GENERIC amd64


	
>Description:
fetch -s exit codes are not consistent across proxy vs. non-proxy
setups when checking for a non-existent file on an ftp server, with
fetch -svv ftp://ftp.freebsd.org/pub/FreeBSD/releases/amd64/8.3-RELEASE/base.txz

With Squid as proxy, we get exit code 1 (correct) and an error message.

Without proxy, we get "Unknown" as result, and an exit code of 0 (bogus).
Since fetch failed to obtain the requested file size, it must not use
EXIT_SUCCESS (0), but must report the error.

Expected behaviour: fetch should, when it is unable to obtain the file size,
always exit with code 1 after printing an error message.

Log, first the correct case with proxy:

$ fetch -svv ftp://ftp.freebsd.org/pub/FreeBSD/releases/amd64/8.3-RELEASE/base.txz ; echo $?
scheme:   [ftp]
user:     []
password: []
host:     [ftp.freebsd.org]
port:     [0]
document: [/pub/FreeBSD/releases/amd64/8.3-RELEASE/base.txz]
scheme:   [http]
user:     []
password: []
host:     [proxy]
port:     [8080]
document: [/]
---> proxy:8080
looking up proxy
connecting to proxy:8080
requesting ftp://ftp.freebsd.org/pub/FreeBSD/releases/amd64/8.3-RELEASE/base.txz
 >>> HEAD ftp://ftp.freebsd.org/pub/FreeBSD/releases/amd64/8.3-RELEASE/base.txz HTTP/1.1
 >>> Host: ftp.freebsd.org
 >>> User-Agent: fetch libfetch/2.0
 >>> Connection: close
 >>> 
 <<< HTTP/1.1 404 Not Found
 <<< Server: squid/3.2.7
 <<< Mime-Version: 1.0
 <<< Date: Wed, 06 Mar 2013 18:33:46 GMT
 <<< Content-Type: text/html
 <<< Content-Length: 3807
 <<< X-Squid-Error: ERR_FTP_NOT_FOUND 0
 content length: [3807]
 <<< Vary: Accept-Language
 <<< Content-Language: en
 <<< X-Cache: MISS from proxy.madpilot.net
 <<< Via: 1.1 proxy.madpilot.net (squid/3.2.7)
 <<< Connection: close
 <<< 
 offset 0, length -1, size -1, clength 3807
 fetch: Not Found
 1
 
 Now the faulty one, without proxy:
 
 $ /usr/bin/fetch -svvv ftp://ftp.freebsd.org/pub/FreeBSD/releases/amd64/8.3-RELEASE/base.txz ; echo $?
 scheme:   [ftp]
 user:     []
 password: []
 host:     [ftp.freebsd.org]
 port:     [0]
 document: [/pub/FreeBSD/releases/amd64/8.3-RELEASE/base.txz]
 ---> ftp.freebsd.org:21
 looking up ftp.freebsd.org
 connecting to ftp.freebsd.org:21
 <<< 220 beastie.tdk.net FTP server (Version 6.00LS) ready.
 >>> USER anonymous
 <<< 331 Guest login ok, send your email address as password.
 >>> PASS mandree@apollo.emma.line.org
 <<< 230 Guest login ok, access restrictions apply.
 >>> PWD
 <<< 257 "/" is current directory.
 >>> CWD pub/FreeBSD/releases/amd64/8.3-RELEASE
 <<< 250 CWD command successful.
 >>> MODE S
 <<< 200 MODE S accepted.
 >>> TYPE I
 <<< 200 Type set to I.
 >>> SIZE base.txz
 <<< 550 base.txz: No such file or directory.
 >>> QUIT
 <<< 221 Goodbye.
 Unknown
 0
>How-To-Repeat:
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:
