Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/libexec/telnetd dual-stack telnetd.



details:   https://anonhg.NetBSD.org/src/rev/5961a3561efa
branches:  trunk
changeset: 474245:5961a3561efa
user:      itojun <itojun%NetBSD.org@localhost>
date:      Fri Jul 02 06:32:08 1999 +0000

description:
dual-stack telnetd.

diffstat:

 libexec/telnetd/Makefile  |    4 +-
 libexec/telnetd/telnetd.8 |   17 +++++-
 libexec/telnetd/telnetd.c |  122 +++++++++++++++++++++++++++------------------
 3 files changed, 92 insertions(+), 51 deletions(-)

diffs (295 lines):

diff -r a09c444dffe1 -r 5961a3561efa libexec/telnetd/Makefile
--- a/libexec/telnetd/Makefile  Fri Jul 02 06:05:21 1999 +0000
+++ b/libexec/telnetd/Makefile  Fri Jul 02 06:32:08 1999 +0000
@@ -1,10 +1,12 @@
-#      $NetBSD: Makefile,v 1.19 1999/06/07 00:53:11 thorpej Exp $
+#      $NetBSD: Makefile,v 1.20 1999/07/02 06:32:08 itojun Exp $
 #      from: @(#)Makefile      8.2 (Berkeley) 12/15/93
 
 .include <bsd.own.mk>                  # for EXPORTABLE_SYSTEM definition
 
 MAN=   telnetd.8
 
+CPPFLAGS+=-DINET6
+
 # XXX Keep telnetd(8) and libtelnet from getting out of sync during the build
 # XXX process.
 .if (!exists(${.CURDIR}/../../domestic/libexec/telnetd) && \
diff -r a09c444dffe1 -r 5961a3561efa libexec/telnetd/telnetd.8
--- a/libexec/telnetd/telnetd.8 Fri Jul 02 06:05:21 1999 +0000
+++ b/libexec/telnetd/telnetd.8 Fri Jul 02 06:32:08 1999 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: telnetd.8,v 1.19 1999/04/06 04:54:20 cgd Exp $
+.\"    $NetBSD: telnetd.8,v 1.20 1999/07/02 06:32:08 itojun Exp $
 .\"
 .\" Copyright (c) 1983, 1993
 .\"    The Regents of the University of California.  All rights reserved.
@@ -43,7 +43,7 @@
 protocol server
 .Sh SYNOPSIS
 .Nm /usr/libexec/telnetd
-.Op Fl Uhlkns
+.Op Fl Uhlkns46
 .Op Fl D Ar debugmode
 .Op Fl I Ns Ar initid
 .Op Fl S Ar tos
@@ -322,6 +322,19 @@
 can be used to temporarily disable
 a specific authentication type without having to recompile
 .Nm "" .
+.It Fl 4
+.It Fl 6
+Specifies address family to be used on
+.Fl debug
+mode.
+During normal operation
+.Po
+called from
+.Xr inetd 8
+.Pc
+.Nm
+will use the file descriptor passed from
+.Xr inetd 8 .
 .El
 .Pp
 .Nm
diff -r a09c444dffe1 -r 5961a3561efa libexec/telnetd/telnetd.c
--- a/libexec/telnetd/telnetd.c Fri Jul 02 06:05:21 1999 +0000
+++ b/libexec/telnetd/telnetd.c Fri Jul 02 06:32:08 1999 +0000
@@ -1,4 +1,33 @@
-/*     $NetBSD: telnetd.c,v 1.15 1999/02/12 05:30:12 dean Exp $        */
+/*
+ * Copyright (C) 1997 and 1998 WIDE Project.
+ * All rights reserved.
+ * 
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the project nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ * 
+ * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*     $NetBSD: telnetd.c,v 1.16 1999/07/02 06:32:08 itojun Exp $      */
 
 /*
  * Copyright (c) 1989, 1993
@@ -40,7 +69,7 @@
 #if 0
 static char sccsid[] = "@(#)telnetd.c  8.4 (Berkeley) 5/30/95";
 #else
-__RCSID("$NetBSD: telnetd.c,v 1.15 1999/02/12 05:30:12 dean Exp $");
+__RCSID("$NetBSD: telnetd.c,v 1.16 1999/07/02 06:32:08 itojun Exp $");
 #endif
 #endif /* not lint */
 
@@ -49,6 +78,7 @@
 
 #include <arpa/inet.h>
 
+#include <err.h>
 #include <termcap.h>
 
 #define P __P
@@ -140,7 +170,7 @@
 void usage __P((void));
 int getterminaltype __P((char *));
 int getent __P((char *, char *));
-void doit __P((struct sockaddr_in *));
+void doit __P((struct sockaddr *));
 void _gettermname __P((void));
 int terminaltypeok __P((char *));
 char *getstr __P((char *, char **));
@@ -152,6 +182,7 @@
  */
 char valid_opts[] = {
        'd', ':', 'g', ':', 'h', 'k', 'n', 'S', ':', 'u', ':', 'U',
+       '4', '6',
 #ifdef AUTHENTICATION
        'a', ':', 'X', ':',
 #endif
@@ -176,12 +207,14 @@
        '\0'
 };
 
+int family = AF_INET;
+
 int
 main(argc, argv)
        int argc;
        char *argv[];
 {
-       struct sockaddr_in from;
+       struct sockaddr_storage from;
        int on = 1, fromlen;
        register int ch;
 #if    defined(IPPROTO_IP) && defined(IP_TOS)
@@ -368,6 +401,14 @@
                        break;
 #endif /* AUTHENTICATION */
 
+               case '4':
+                       family = AF_INET;
+                       break;
+                       
+               case '6':
+                       family = AF_INET6;
+                       break;
+                       
                default:
                        fprintf(stderr, "telnetd: %c: unknown option\n", ch);
                        /* FALLTHROUGH */
@@ -381,42 +422,36 @@
        argv += optind;
 
        if (debug) {
-           int s, ns, foo;
-           struct servent *sp;
-           static struct sockaddr_in sin = { AF_INET };
+           int s, ns, foo, error;
+           char *service = "telnet";
+           struct addrinfo hints, *res;
 
            if (argc > 1) {
                usage();
                /* NOT REACHED */
-           } else if (argc == 1) {
-                   if ((sp = getservbyname(*argv, "tcp"))) {
-                       sin.sin_port = sp->s_port;
-                   } else {
-                       sin.sin_port = atoi(*argv);
-                       if ((int)sin.sin_port <= 0) {
-                           fprintf(stderr, "telnetd: %s: bad port #\n", *argv);
-                           usage();
-                           /* NOT REACHED */
-                       }
-                       sin.sin_port = htons((u_short)sin.sin_port);
-                  }
-           } else {
-               sp = getservbyname("telnet", "tcp");
-               if (sp == 0) {
-                   fprintf(stderr, "telnetd: tcp/telnet: unknown service\n");
-                   exit(1);
-               }
-               sin.sin_port = sp->s_port;
+           } else if (argc == 1)
+               service = *argv;
+
+           memset(&hints, 0, sizeof(hints));
+           hints.ai_flags = AI_PASSIVE;
+           hints.ai_family = family;
+           hints.ai_socktype = SOCK_STREAM;
+           hints.ai_protocol = 0;
+           error = getaddrinfo(NULL, service, &hints, &res);
+
+           if (error) {
+               errx(1, "tcp/%s: %s\n", service, gai_strerror(error));
+               usage();
            }
 
-           s = socket(AF_INET, SOCK_STREAM, 0);
+           s = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
            if (s < 0) {
                    perror("telnetd: socket");;
                    exit(1);
            }
            (void) setsockopt(s, SOL_SOCKET, SO_REUSEADDR,
                                (char *)&on, sizeof(on));
-           if (bind(s, (struct sockaddr *)&sin, sizeof sin) < 0) {
+           if (bind(s, res->ai_addr, res->ai_addrlen) < 0) {
                perror("bind");
                exit(1);
            }
@@ -424,8 +459,8 @@
                perror("listen");
                exit(1);
            }
-           foo = sizeof sin;
-           ns = accept(s, (struct sockaddr *)&sin, &foo);
+           foo = res->ai_addrlen;
+           ns = accept(s, res->ai_addr, &foo);
            if (ns < 0) {
                perror("accept");
                exit(1);
@@ -513,7 +548,7 @@
        }
 
 #if    defined(IPPROTO_IP) && defined(IP_TOS)
-       {
+       if (from.__ss_family == AF_INET) {
 # if   defined(HAS_GETTOS)
                struct tosent *tp;
                if (tos < 0 && (tp = gettosbyname("telnet", "tcp")))
@@ -528,8 +563,9 @@
                        syslog(LOG_WARNING, "setsockopt (IP_TOS): %m");
        }
 #endif /* defined(IPPROTO_IP) && defined(IP_TOS) */
+
        net = 0;
-       doit(&from);
+       doit((struct sockaddr *)&from);
        /* NOTREACHED */
 #ifdef __GNUC__
        exit(0);
@@ -782,10 +818,10 @@
  */
 void
 doit(who)
-       struct sockaddr_in *who;
+       struct sockaddr *who;
 {
        char *host;
-       struct hostent *hp;
+       int error;
        int level;
        int ptynum;
        char user_name[256];
@@ -830,27 +866,17 @@
 #endif /* _SC_CRAY_SECURE_SYS */
 
        /* get name of connected client */
-       hp = gethostbyaddr((char *)&who->sin_addr, sizeof (struct in_addr),
-               who->sin_family);
+       error = getnameinfo(who, who->sa_len, remote_host_name, 
+                           sizeof(remote_host_name), NULL, 0, 0);
 
-       if (hp == NULL && registerd_host_only) {
+       if (error) {
                fatal(net, "Couldn't resolve your address into a host name.\r\n\
         Please contact your net administrator");
 #ifdef __GNUC__
                host = NULL;    /* XXX gcc */
 #endif
-       } else if (hp &&
-           (strlen(hp->h_name) <= (unsigned int)((utmp_len < 0) ? -utmp_len
-                                                                : utmp_len))) {
-               host = hp->h_name;
-       } else {
-               host = inet_ntoa(who->sin_addr);
        }
-       /*
-        * We must make a copy because Kerberos is probably going
-        * to also do a gethost* and overwrite the static data...
-        */
-       strncpy(remote_host_name, host, sizeof(remote_host_name)-1);
+
        remote_host_name[sizeof(remote_host_name)-1] = 0;
        host = remote_host_name;
 



Home | Main Index | Thread Index | Old Index