bin/188726: Add "NoReverseDNS" feature
Zombie Man
ZombieTeam-2012 at yandex.ua
Thu Apr 17 12:40:01 UTC 2014
>Number: 188726
>Category: bin
>Synopsis: 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:
>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:
More information about the freebsd-bugs
mailing list