telnet/telnet-log-address.patch

76 lines
2.3 KiB
Diff
Raw Normal View History

diff --git a/telnetd/telnetd.8 b/telnetd/telnetd.8
index 02b48c7..c72ab76 100644
--- a/telnetd/telnetd.8
+++ b/telnetd/telnetd.8
@@ -42,7 +42,7 @@
protocol server
.Sh SYNOPSIS
.Nm /usr/sbin/in.telnetd
-.Op Fl hnNs
+.Op Fl ihnNs
.Op Fl a Ar authmode
.Op Fl D Ar debugmode
.Op Fl L Ar loginprg
@@ -158,6 +158,10 @@ option may be used to enable encryption debugging code.
.It Fl h
Disables the printing of host-specific information before
login has been completed.
+.It Fl i
+Disable reverse DNS lookups and use the numeric IP address in logs
+and REMOTEHOST environment variable. (-i switch corresponds to
+utilities like last)
.It Fl L Ar loginprg
This option may be used to specify a different login program.
By default,
diff --git a/telnetd/telnetd.c b/telnetd/telnetd.c
index a4988a9..2ac8bc1 100644
--- a/telnetd/telnetd.c
+++ b/telnetd/telnetd.c
@@ -84,6 +84,7 @@ int hostinfo = 1; /* do we print login banner? */
int debug = 0;
int debugsix = 0;
int keepalive = 1;
+int numeric_hosts = 0;
char *loginprg = _PATH_LOGIN;
char *progname;
int lookupself = 1;
@@ -113,7 +114,7 @@ main(int argc, char *argv[], char *env[])
progname = *argv;
- while ((ch = getopt(argc, argv, "d:a:e:lhnr:I:D:B:sS:a:X:L:N")) != EOF) {
+ while ((ch = getopt(argc, argv, "d:a:e:ilhnr:I:D:B:sS:a:X:L:N")) != EOF) {
switch(ch) {
#ifdef AUTHENTICATE
@@ -196,6 +197,14 @@ main(int argc, char *argv[], char *env[])
break;
#endif /* AUTHENTICATE */
+ /*
+ * Use ip address instead of hostname when
+ * calling login process.
+ */
+ case 'i':
+ numeric_hosts = 1;
+ break;
+
case 'h':
hostinfo = 0;
break;
@@ -663,10 +672,12 @@ doit(struct sockaddr *who, socklen_t wholen)
int error = -1;
char namebuf[255];
- error = getnameinfo(who, wholen, namebuf, sizeof(namebuf), NULL, 0, 0);
+ /* if we don't want hostname '-i', skip this call to getnameinfo */
+ if (numeric_hosts == 0)
+ error = getnameinfo(who, wholen, namebuf, sizeof(namebuf), NULL, 0, 0);
/* if we can't get a hostname now, settle for an address */
- if(error == EAI_AGAIN)
+ if(error == EAI_AGAIN || numeric_hosts != 0)
error = getnameinfo(who, wholen, namebuf, sizeof(namebuf),
NULL, 0, NI_NUMERICHOST);