Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/login Add a -a option to pass the host address of th...



details:   https://anonhg.NetBSD.org/src/rev/3b100decf001
branches:  trunk
changeset: 571231:3b100decf001
user:      christos <christos%NetBSD.org@localhost>
date:      Sun Nov 14 18:01:21 2004 +0000

description:
Add a -a option to pass the host address of the host we logged in from in
addition to the host name. This option is needed by programs suchs as
telnetd, because at the point they invoke login, they already have opened
a pty, and the stdin of login is no longer the socket connected to the
remote host. In addition don't chop the hostname up to the first dot if
the domain matches. These practices are 70's fashion and they only serve
to lose information. These days we have long enough fields in utmpx and
wtmpx to store the full names.

diffstat:

 usr.bin/login/login.1 |  12 ++++++++-
 usr.bin/login/login.c |  60 ++++++++++++++++++++++++++++++++++++++++++--------
 2 files changed, 60 insertions(+), 12 deletions(-)

diffs (181 lines):

diff -r 79373a7288bc -r 3b100decf001 usr.bin/login/login.1
--- a/usr.bin/login/login.1     Sun Nov 14 15:45:02 2004 +0000
+++ b/usr.bin/login/login.1     Sun Nov 14 18:01:21 2004 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: login.1,v 1.22 2003/08/07 11:14:25 agc Exp $
+.\"    $NetBSD: login.1,v 1.23 2004/11/14 18:01:21 christos Exp $
 .\"
 .\" Copyright (c) 1980, 1990, 1993
 .\"    The Regents of the University of California.  All rights reserved.
@@ -29,7 +29,7 @@
 .\"
 .\"    @(#)login.1     8.2 (Berkeley) 5/5/94
 .\"
-.Dd January 13, 1999
+.Dd November 14, 2004
 .Dt LOGIN 1
 .Os
 .Sh NAME
@@ -38,6 +38,7 @@
 .Sh SYNOPSIS
 .Nm
 .Op Fl Ffps
+.Op Fl a Ar address
 .Op Fl h Ar hostname
 .Op Ar user
 .Sh DESCRIPTION
@@ -63,6 +64,13 @@
 .Pp
 The options are as follows:
 .Bl -tag -width Ds
+.It Fl a
+The 
+.Fl a
+option specifies the address of the host from which the connection was received.
+It is used by various daemons such as
+.Xr telnetd  8 .
+This option may only be used by the super-user.
 .It Fl F
 The
 .Fl F
diff -r 79373a7288bc -r 3b100decf001 usr.bin/login/login.c
--- a/usr.bin/login/login.c     Sun Nov 14 15:45:02 2004 +0000
+++ b/usr.bin/login/login.c     Sun Nov 14 18:01:21 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: login.c,v 1.78 2004/07/13 11:56:24 wiz Exp $       */
+/*     $NetBSD: login.c,v 1.79 2004/11/14 18:01:21 christos Exp $       */
 
 /*-
  * Copyright (c) 1980, 1987, 1988, 1991, 1993, 1994
@@ -40,7 +40,7 @@
 #if 0
 static char sccsid[] = "@(#)login.c    8.4 (Berkeley) 4/2/94";
 #endif
-__RCSID("$NetBSD: login.c,v 1.78 2004/07/13 11:56:24 wiz Exp $");
+__RCSID("$NetBSD: login.c,v 1.79 2004/11/14 18:01:21 christos Exp $");
 #endif /* not lint */
 
 /*
@@ -88,6 +88,7 @@
 #ifdef LOGIN_CAP
 #include <login_cap.h>
 #endif
+#include <vis.h>
 
 #include "pathnames.h"
 
@@ -130,6 +131,8 @@
 #if defined(KERBEROS) || defined(KERBEROS5)
 void    dofork __P((void));
 #endif
+void    decode_ss __P((const char *));
+void    usage __P((void));
 
 #define        TTYGRPNAME      "tty"           /* name of group to own ttys */
 
@@ -167,7 +170,7 @@
 #endif
 
 struct passwd *pwd;
-int    failures;
+int    failures, have_ss;
 char   term[64], *envinit[1], *hostname, *username, *tty, *nested;
 struct timeval now;
 struct sockaddr_storage ss;
@@ -225,6 +228,8 @@
         * -f is used to skip a second login authentication
         * -h is used by other servers to pass the name of the remote host to
         *    login so that it may be placed in utmp/utmpx and wtmp/wtmpx
+        * -a in addition to -h, a server my supply -a to pass the actual
+        *    server address.
         * -s is used to force use of S/Key or equivalent.
         */
        domain = NULL;
@@ -235,12 +240,18 @@
        localhost[sizeof(localhost) - 1] = '\0';
 
        Fflag = fflag = hflag = pflag = sflag = 0;
+       have_ss = 0;
 #ifdef KERBEROS5
        have_forward = 0;
 #endif
        uid = getuid();
-       while ((ch = getopt(argc, argv, "Ffh:ps")) != -1)
+       while ((ch = getopt(argc, argv, "a:Ffh:ps")) != -1)
                switch (ch) {
+               case 'a':
+                       if (uid)
+                               errx(1, "-a option: %s", strerror(EPERM));
+                       decode_ss(optarg);
+                       break;
                case 'F':
                        Fflag = 1;
                        /* FALLTHROUGH */
@@ -251,9 +262,11 @@
                        if (uid)
                                errx(1, "-h option: %s", strerror(EPERM));
                        hflag = 1;
+#ifdef notdef
                        if (domain && (p = strchr(optarg, '.')) != NULL &&
                            strcasecmp(p, domain) == 0)
-                               *p = 0;
+                               *p = '\0';
+#endif
                        hostname = optarg;
                        break;
                case 'p':
@@ -264,10 +277,8 @@
                        break;
                default:
                case '?':
-                       (void)fprintf(stderr,
-                           "usage: %s [-Ffps] [-h hostname] [username]\n",
-                           getprogname());
-                       exit(1);
+                       usage();
+                       break;
                }
        argc -= optind;
        argv += optind;
@@ -923,7 +934,7 @@
 
                return;
        }
-       if (hostname != NULL) {
+       if (hostname != NULL && have_ss == 0) {
                socklen_t len = sizeof(ss);
                (void)getpeername(STDIN_FILENO, (struct sockaddr *)&ss, &len);
        }
@@ -1086,3 +1097,32 @@
        (void)sleep(5);
        exit(eval);
 }
+
+void
+decode_ss(arg)
+       const char *arg;
+{
+       struct sockaddr_storage *ssp;
+       size_t len = strlen(arg);
+       
+       if (len > sizeof(*ssp) * 4 + 1 || len < sizeof(*ssp))
+               errx(1, "Bad argument");
+
+       if ((ssp = malloc(len)) == NULL)
+               err(1, NULL);
+
+       if (strunvis((char *)ssp, arg) != sizeof(*ssp))
+               errx(1, "Decoding error");
+
+       (void)memcpy(&ss, ssp, sizeof(ss));
+       have_ss = 1;
+}
+
+void
+usage()
+{
+       (void)fprintf(stderr,
+           "Usage: %s [-Ffps] [-a address] [-h hostname] [username]\n",
+           getprogname());
+       exit(1);
+}



Home | Main Index | Thread Index | Old Index