From nobody@FreeBSD.org  Thu Apr 17 12:30:14 2014
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115])
	(using TLSv1 with cipher ADH-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by hub.freebsd.org (Postfix) with ESMTPS id BC7B0EC
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 17 Apr 2014 12:30:14 +0000 (UTC)
Received: from cgiserv.freebsd.org (cgiserv.freebsd.org [IPv6:2001:1900:2254:206a::50:4])
	(using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
	(Client did not present a certificate)
	by mx1.freebsd.org (Postfix) with ESMTPS id A967E1580
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 17 Apr 2014 12:30:14 +0000 (UTC)
Received: from cgiserv.freebsd.org ([127.0.1.6])
	by cgiserv.freebsd.org (8.14.8/8.14.8) with ESMTP id s3HCUDQm095604
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 17 Apr 2014 12:30:13 GMT
	(envelope-from nobody@cgiserv.freebsd.org)
Received: (from nobody@localhost)
	by cgiserv.freebsd.org (8.14.8/8.14.8/Submit) id s3HCU4Sm089340;
	Thu, 17 Apr 2014 12:30:04 GMT
	(envelope-from nobody)
Message-Id: <201404171230.s3HCU4Sm089340@cgiserv.freebsd.org>
Date: Thu, 17 Apr 2014 12:30:04 GMT
From: Zombie Man <ZombieTeam-2012@yandex.ua>
To: freebsd-gnats-submit@FreeBSD.org
Subject: Add "NoReverseDNS" feature
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         188726
>Category:       bin
>Synopsis:       [libexec] [patch] Add "NoReverseDNS" feature
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Thu Apr 17 12:40:00 UTC 2014
>Closed-Date:    
>Last-Modified:  Sun Apr 20 00:29:32 UTC 2014
>Originator:     Zombie Man
>Release:        FreeBSD 9.1-RELEASE
>Organization:
>Environment:
>Description:
For some reason (for exammple, in home networks), DNS is not available
or improperly configured this can result in ftpd blocking ("stalling")
until the libc resolver code times out. Using NoReverseDNS (-N command
line option) will solve this problem.

>How-To-Repeat:

>Fix:
patch file attached

Patch attached with submission follows:

Index: extern.h
===================================================================
--- extern.h	(revision 264526)
+++ extern.h	(working copy)
@@ -97,6 +97,7 @@
 extern	int type;
 extern	char *typenames[]; /* defined in <arpa/ftp.h> included from ftpd.c */
 extern	int usedefault;
+extern	int NoReverseDNS;
 
 struct sockaddr_in;
 struct sockaddr_in6;
Index: ftpd.8
===================================================================
--- ftpd.8	(revision 264526)
+++ ftpd.8	(working copy)
@@ -36,7 +36,7 @@
 .Nd Internet File Transfer Protocol server
 .Sh SYNOPSIS
 .Nm
-.Op Fl 468ADdEhMmOoRrSUvW
+.Op Fl 468ADdEhMmNOoRrSUvW
 .Op Fl l Op Fl l
 .Op Fl a Ar address
 .Op Fl P Ar port
@@ -133,6 +133,9 @@
 existing files if allowed by file system permissions.
 By default, anonymous users cannot modify existing files;
 in particular, files to upload will be created under a unique name.
+.It Fl N
+Disable reverse DNS lookup for clients (useful for home LAN's without DNS).
+All client addresses logged in dotted form.
 .It Fl O
 Put server in write-only mode for anonymous users only.
 RETR is disabled for anonymous users, preventing anonymous downloads.
Index: ftpd.c
===================================================================
--- ftpd.c	(revision 264526)
+++ ftpd.c	(working copy)
@@ -140,6 +140,7 @@
 int	noguestretr = 0;	/* RETR command is disabled for anon users. */
 int	noguestmkd = 0;		/* MKD command is disabled for anon users. */
 int	noguestmod = 1;		/* anon users may not modify existing files. */
+int	NoReverseDNS;		/* 0 = do reverse DNS lookup for clients */
 
 off_t	file_size;
 off_t	byte_count;
@@ -301,7 +302,7 @@
 	openlog("ftpd", LOG_PID | LOG_NDELAY, LOG_FTP);
 
 	while ((ch = getopt(argc, argv,
-	                    "468a:AdDEhlmMoOp:P:rRSt:T:u:UvW")) != -1) {
+	                    "468a:AdDEhlmMNoOp:P:rRSt:T:u:UvW")) != -1) {
 		switch (ch) {
 		case '4':
 			family = (family == AF_INET6) ? AF_UNSPEC : AF_INET;
@@ -351,6 +352,10 @@
 			noguestmkd = 1;
 			break;
 
+		case 'N':
+			NoReverseDNS = 1;
+			break;
+
 		case 'o':
 			noretr = 1;
 			break;
@@ -2715,11 +2720,16 @@
 {
 	char who_name[NI_MAXHOST];
 
-	realhostname_sa(remotehost, sizeof(remotehost) - 1, who, who->sa_len);
-	remotehost[sizeof(remotehost) - 1] = 0;
-	if (getnameinfo(who, who->sa_len,
-		who_name, sizeof(who_name) - 1, NULL, 0, NI_NUMERICHOST))
-			*who_name = 0;
+	if (NoReverseDNS) {
+		if (getnameinfo(who, who->sa_len, remotehost, sizeof(remotehost)-1, NULL, 0, NI_NUMERICHOST))
+			*remotehost = 0;
+	}
+	else
+		realhostname_sa(remotehost, sizeof(remotehost)-1, who, who->sa_len);
+	remotehost[sizeof(remotehost)-1] = 0;
+
+	if (getnameinfo(who, who->sa_len, who_name, sizeof(who_name)-1, NULL, 0, NI_NUMERICHOST))
+		*who_name = 0;
 	who_name[sizeof(who_name) - 1] = 0;
 
 #ifdef SETPROCTITLE
Index: logwtmp.c
===================================================================
--- logwtmp.c	(revision 264526)
+++ logwtmp.c	(working copy)
@@ -41,6 +41,7 @@
 #include <netinet/in.h>
 #include <arpa/inet.h>
 #include <sys/socket.h>
+#include <netdb.h>
 
 #include <libutil.h>
 #include <stdio.h>
@@ -60,9 +61,12 @@
 		/* Log in. */
 		ut.ut_type = USER_PROCESS;
 		(void)strncpy(ut.ut_user, user, sizeof(ut.ut_user));
-		if (addr != NULL)
-			realhostname_sa(ut.ut_host, sizeof(ut.ut_host),
-			    addr, addr->sa_len);
+		if (addr != NULL) {
+			if (NoReverseDNS)
+				getnameinfo(addr, addr->sa_len, ut.ut_host, sizeof(ut.ut_host)-1, NULL, 0, NI_NUMERICHOST);
+			else
+				realhostname_sa(ut.ut_host, sizeof(ut.ut_host), addr, addr->sa_len);
+		}
 	} else {
 		/* Log out. */
 		ut.ut_type = DEAD_PROCESS;


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