From nobody@FreeBSD.org  Fri Jan  2 12:49:47 2004
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id DCBE116A4CE
	for <freebsd-gnats-submit@FreeBSD.org>; Fri,  2 Jan 2004 12:49:47 -0800 (PST)
Received: from www.freebsd.org (www.freebsd.org [216.136.204.117])
	by mx1.FreeBSD.org (Postfix) with ESMTP id ABA3E43D45
	for <freebsd-gnats-submit@FreeBSD.org>; Fri,  2 Jan 2004 12:49:46 -0800 (PST)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.12.10/8.12.10) with ESMTP id i02KnkdL053772
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 2 Jan 2004 12:49:46 -0800 (PST)
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.12.10/8.12.10/Submit) id i02Knkmn053771;
	Fri, 2 Jan 2004 12:49:46 -0800 (PST)
	(envelope-from nobody)
Message-Id: <200401022049.i02Knkmn053771@www.freebsd.org>
Date: Fri, 2 Jan 2004 12:49:46 -0800 (PST)
From: Alexander Melkov <melkov@comptek.ru>
To: freebsd-gnats-submit@FreeBSD.org
Subject: ftpd send_data()+oldway: anonymous transfer not logged if client drops conn. [patch]
X-Send-Pr-Version: www-2.0

>Number:         60834
>Category:       bin
>Synopsis:       [patch] ftpd(8) send_data()+oldway: anonymous transfer not logged if client drops conn.
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Jan 02 12:50:07 PST 2004
>Closed-Date:    
>Last-Modified:  Mon Oct 24 00:30:16 GMT 2005
>Originator:     Alexander Melkov
>Release:        4.9-STABLE
>Organization:
>Environment:
FreeBSD melkov.ru 4.9-STABLE FreeBSD 4.9-STABLE #2: Thu Jan  1 08:50:39 MSK 2004     root@melkov.ru:/usr/obj/usr/src/sys/MELKOV  i386
>Description:
Ftpd sends a file using 'oldway' (not sendfile), when sendfile is 
not available, for example, the file is on a mounted nfs or smbfs
filesystem.
If the client ungracefully terminates the connection, ftpd receives a
signal and dies, so the transfer does not appear in /var/log/ftpd.

>How-To-Repeat:
(a)
run /usr/libexec/ftpd -ADllS

create /var/log/ftpd file

Mount a NFS or SMBFS filesystem under anonymous ftp root.
Get a file from that filesystem via some ftp client.
While file transfer is in progress, terminate the ftp client.
See tail /var/log/ftpd

(b)
Look into ftpd.c file
- at send_data() function, label oldway:.
- at lostconn(), sigquit() and dologout() functions.
The problem should be apparent :)

>Fix:
ftpd.c is 1.62.2.51
melkov:/usr/src/libexec/ftpd# diff ftpd.c.orig ftpd.c
222a223,227
> char *xfer_name;           /* to be able to call logxfer() from dologout() */
> off_t xfer_size;
> time_t xfer_start;
> int xfer_log_progress = 0; /* whether transfer is in progress */
> 
264c269
< static void      logxfer __P((char *, off_t, time_t));
---
> static void      logxfer __P((void));
1655a1661,1664
> 	xfer_name = name;
> 	xfer_size = st.st_size;
> 	xfer_start = start;
> 	xfer_log_progress = cmd == 0 && guest && stats;
1657a1667
> 	xfer_log_progress = 0;
1659c1669
< 		logxfer(name, st.st_size, start);
---
> 		logxfer();
2604a2615,2620
> 
> 	if (statfd >= 0 && xfer_log_progress) {
> 		xfer_log_progress = 0;
> 		logxfer();
> 	}
> 
3140,3143c3156
< logxfer(name, size, start)
< 	char *name;
< 	off_t size;
< 	time_t start;
---
> logxfer()
3153,3154c3166,3167
< 			path, name, (long long)size,
< 			(long)(now - start + (now == start)));
---
> 			path, xfer_name, (long long)xfer_size,
> 			(long)(now - xfer_start + (now == xfer_start)));

>Release-Note:
>Audit-Trail:
>Unformatted:
