Subject: bin/8137: Feature addition to ftpd - use `hostname' of IP connection
To: None <gnats-bugs@gnats.netbsd.org>
From: None <mason@primenet.com.au>
List: netbsd-bugs
Date: 08/03/1999 01:10:46
>Number:         8137
>Category:       bin
>Synopsis:       ftpd isn't always nice for multihoming
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Tue Aug  3 01:05:00 1999
>Last-Modified:
>Originator:     Geoff C. Wing
>Organization:
Geoff Wing : <gcw@pobox.com>     Work URL: http://www.primenet.com.au/
Rxvt Stuff : <gcw@rxvt.org>      Ego URL : http://pobox.com/~gcw/
Zsh Stuff  : <gcw@zsh.org>       Phone   : (Australia) 0413 431 874
>Release:        19990802
>Environment:
System: NetBSD c.primenet.com.au 1.4I NetBSD 1.4I (C) #0: Sat Jul 31 17:00:56 EST 1999 mason@c.primenet.com.au:/usr/netbsd/src/sys/arch/i386/compile/C i386


>Description:
	When you run ftpd on a multihomed machine with different names
	for the IPs, you can specify different configuration files and
	such (e.g. via twist in /etc/hosts.allow) but you can't specify
	a hostname.

	Also, when logging you don't know where it was connected to.

>How-To-Repeat:
	Obvious.
>Fix:
 	Either    1) allow specifying hostname in config file or command line
or (my preferred) 2) Apply patch below to pick up name from connection.
	Maybe it should have an option to turn this off/on?

--- libexec/ftpd/ftpd.c.org	Thu Jul 29 05:52:04 1999
+++ libexec/ftpd/ftpd.c	Tue Aug  3 17:51:05 1999
@@ -422,6 +422,12 @@
 	if (fcntl(fileno(stdin), F_SETOWN, getpid()) == -1)
 		syslog(LOG_ERR, "fcntl F_SETOWN: %m");
 #endif
+	if ((getnameinfo((struct sockaddr *)&ctrl_addr,
+			 ((struct sockaddr *)&ctrl_addr)->sa_len, hostname,
+			 sizeof(hostname), NULL, 0, 0)) != 0)
+		(void)gethostname(hostname, sizeof(hostname));
+	hostname[sizeof(hostname) - 1] = '\0';
+
 	dolog((struct sockaddr *)&his_addr);
 	/*
 	 * Set up default state
@@ -467,8 +473,6 @@
 		(void) fclose(fd);
 		/* reply(220,) must follow */
 	}
-	(void)gethostname(hostname, sizeof(hostname));
-	hostname[sizeof(hostname) - 1] = '\0';
 	reply(220, "%s FTP server (%s) ready.", hostname, version);
 	curclass.timeout = 300;		/* 5 minutes, as per login(1) */
 	(void) setjmp(errcatch);
@@ -1925,7 +1929,8 @@
 #endif /* HASSETPROCTITLE */
 
 	if (logging)
-		syslog(LOG_INFO, "connection from %s", remotehost);
+		syslog(LOG_INFO, "connection from %s to %s", remotehost,
+		       hostname);
 }
 
 /*
>Audit-Trail:
>Unformatted: