A bunch of bugfixes.
authorDave A. Borman <dab@ucbvax.Berkeley.EDU>
Thu, 16 Dec 1993 03:40:05 +0000 (19:40 -0800)
committerDave A. Borman <dab@ucbvax.Berkeley.EDU>
Thu, 16 Dec 1993 03:40:05 +0000 (19:40 -0800)
Support for Solaris.
new LOGIN_R option for systems that
don't have "login -f".
Support for the new ENVIRON option.

SCCS-vsn: libexec/telnetd/ext.h 8.2
SCCS-vsn: libexec/telnetd/state.c 8.2
SCCS-vsn: libexec/telnetd/sys_term.c 8.2
SCCS-vsn: libexec/telnetd/telnetd.c 8.2
SCCS-vsn: libexec/telnetd/utility.c 8.2

usr/src/libexec/telnetd/ext.h
usr/src/libexec/telnetd/state.c
usr/src/libexec/telnetd/sys_term.c
usr/src/libexec/telnetd/telnetd.c
usr/src/libexec/telnetd/utility.c

index 130587e..2147cb5 100644 (file)
@@ -4,7 +4,7 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)ext.h       8.1 (Berkeley) %G%
+ *     @(#)ext.h       8.2 (Berkeley) %G%
  */
 
 /*
  */
 
 /*
@@ -132,7 +132,7 @@ extern int
        getnpty P((void)),
 #ifndef convex
        getpty P((int *)),
        getnpty P((void)),
 #ifndef convex
        getpty P((int *)),
-#endif convex
+#endif
        login_tty P((int)),
        spcset P((int, cc_t *, cc_t **)),
        stilloob P((int)),
        login_tty P((int)),
        spcset P((int, cc_t *, cc_t **)),
        stilloob P((int)),
@@ -186,6 +186,7 @@ extern struct {
        ttypesubopt,            /* ttype subopt is received */
        tspeedsubopt,           /* tspeed subopt is received */
        environsubopt,          /* environ subopt is received */
        ttypesubopt,            /* ttype subopt is received */
        tspeedsubopt,           /* tspeed subopt is received */
        environsubopt,          /* environ subopt is received */
+       oenvironsubopt,         /* old environ subopt is received */
        xdisplocsubopt,         /* xdisploc subopt is received */
        baseline,               /* time started to do timed action */
        gotDM;                  /* when did we last see a data mark */
        xdisplocsubopt,         /* xdisploc subopt is received */
        baseline,               /* time started to do timed action */
        gotDM;                  /* when did we last see a data mark */
index dead4b0..9376540 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)state.c    8.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)state.c    8.2 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "telnetd.h"
 #endif /* not lint */
 
 #include "telnetd.h"
@@ -14,10 +14,10 @@ static char sccsid[] = "@(#)state.c 8.1 (Berkeley) %G%";
 #include <libtelnet/auth.h>
 #endif
 
 #include <libtelnet/auth.h>
 #endif
 
-char   doopt[] = { IAC, DO, '%', 'c', 0 };
-char   dont[] = { IAC, DONT, '%', 'c', 0 };
-char   will[] = { IAC, WILL, '%', 'c', 0 };
-char   wont[] = { IAC, WONT, '%', 'c', 0 };
+unsigned char  doopt[] = { IAC, DO, '%', 'c', 0 };
+unsigned char  dont[] = { IAC, DONT, '%', 'c', 0 };
+unsigned char  will[] = { IAC, WILL, '%', 'c', 0 };
+unsigned char  wont[] = { IAC, WONT, '%', 'c', 0 };
 int    not42 = 1;
 
 /*
 int    not42 = 1;
 
 /*
@@ -426,7 +426,7 @@ send_do(option, init)
                        set_his_want_state_will(option);
                do_dont_resp[option]++;
        }
                        set_his_want_state_will(option);
                do_dont_resp[option]++;
        }
-       (void) sprintf(nfrontp, doopt, option);
+       (void) sprintf(nfrontp, (char *)doopt, option);
        nfrontp += sizeof (dont) - 2;
 
        DIAG(TD_OPTIONS, printoption("td: send do", option));
        nfrontp += sizeof (dont) - 2;
 
        DIAG(TD_OPTIONS, printoption("td: send do", option));
@@ -529,7 +529,8 @@ willoption(option)
                case TELOPT_NAWS:
                case TELOPT_TSPEED:
                case TELOPT_XDISPLOC:
                case TELOPT_NAWS:
                case TELOPT_TSPEED:
                case TELOPT_XDISPLOC:
-               case TELOPT_ENVIRON:
+               case TELOPT_NEW_ENVIRON:
+               case TELOPT_OLD_ENVIRON:
                        changeok++;
                        break;
 
                        changeok++;
                        break;
 
@@ -645,7 +646,7 @@ send_dont(option, init)
                set_his_want_state_wont(option);
                do_dont_resp[option]++;
        }
                set_his_want_state_wont(option);
                do_dont_resp[option]++;
        }
-       (void) sprintf(nfrontp, dont, option);
+       (void) sprintf(nfrontp, (char *)dont, option);
        nfrontp += sizeof (doopt) - 2;
 
        DIAG(TD_OPTIONS, printoption("td: send dont", option));
        nfrontp += sizeof (doopt) - 2;
 
        DIAG(TD_OPTIONS, printoption("td: send dont", option));
@@ -743,7 +744,11 @@ wontoption(option)
                        settimer(xdisplocsubopt);
                        break;
 
                        settimer(xdisplocsubopt);
                        break;
 
-               case TELOPT_ENVIRON:
+               case TELOPT_OLD_ENVIRON:
+                       settimer(oenvironsubopt);
+                       break;
+
+               case TELOPT_NEW_ENVIRON:
                        settimer(environsubopt);
                        break;
 
                        settimer(environsubopt);
                        break;
 
@@ -791,7 +796,7 @@ send_will(option, init)
                set_my_want_state_will(option);
                will_wont_resp[option]++;
        }
                set_my_want_state_will(option);
                will_wont_resp[option]++;
        }
-       (void) sprintf(nfrontp, will, option);
+       (void) sprintf(nfrontp, (char *)will, option);
        nfrontp += sizeof (doopt) - 2;
 
        DIAG(TD_OPTIONS, printoption("td: send will", option));
        nfrontp += sizeof (doopt) - 2;
 
        DIAG(TD_OPTIONS, printoption("td: send will", option));
@@ -920,7 +925,10 @@ dooption(option)
                case TELOPT_TSPEED:
                case TELOPT_LFLOW:
                case TELOPT_XDISPLOC:
                case TELOPT_TSPEED:
                case TELOPT_LFLOW:
                case TELOPT_XDISPLOC:
-               case TELOPT_ENVIRON:
+#ifdef TELOPT_ENVIRON
+               case TELOPT_NEW_ENVIRON:
+#endif
+               case TELOPT_OLD_ENVIRON:
                default:
                        break;
                }
                default:
                        break;
                }
@@ -947,7 +955,7 @@ send_wont(option, init)
                set_my_want_state_wont(option);
                will_wont_resp[option]++;
        }
                set_my_want_state_wont(option);
                will_wont_resp[option]++;
        }
-       (void) sprintf(nfrontp, wont, option);
+       (void) sprintf(nfrontp, (char *)wont, option);
        nfrontp += sizeof (wont) - 2;
 
        DIAG(TD_OPTIONS, printoption("td: send wont", option));
        nfrontp += sizeof (wont) - 2;
 
        DIAG(TD_OPTIONS, printoption("td: send wont", option));
@@ -1039,11 +1047,11 @@ dontoption(option)
 }  /* end of dontoption */
 
 #ifdef ENV_HACK
 }  /* end of dontoption */
 
 #ifdef ENV_HACK
-int env_var = -1;
-int env_value = -1;
+int env_ovar = -1;
+int env_ovalue = -1;
 #else  /* ENV_HACK */
 #else  /* ENV_HACK */
-# define env_var ENV_VAR
-# define env_value ENV_VALUE
+# define env_ovar OLD_ENV_VAR
+# define env_ovalue OLD_ENV_VALUE
 #endif /* ENV_HACK */
 
 /*
 #endif /* ENV_HACK */
 
 /*
@@ -1222,25 +1230,42 @@ suboption()
        break;
     }  /* end of case TELOPT_XDISPLOC */
 
        break;
     }  /* end of case TELOPT_XDISPLOC */
 
-    case TELOPT_ENVIRON: {
+#ifdef TELOPT_NEW_ENVIRON
+    case TELOPT_NEW_ENVIRON:
+#endif
+    case TELOPT_OLD_ENVIRON: {
        register int c;
        register char *cp, *varp, *valp;
 
        if (SB_EOF())
                return;
        c = SB_GET();
        register int c;
        register char *cp, *varp, *valp;
 
        if (SB_EOF())
                return;
        c = SB_GET();
-       if (c == TELQUAL_IS)
-               settimer(environsubopt);
-       else if (c != TELQUAL_INFO)
+       if (c == TELQUAL_IS) {
+               if (subchar == TELOPT_OLD_ENVIRON)
+                       settimer(oenvironsubopt);
+               else
+                       settimer(environsubopt);
+       } else if (c != TELQUAL_INFO) {
                return;
                return;
+       }
 
 
+#ifdef TELOPT_NEW_ENVIRON
+       if (subchar == TELOPT_NEW_ENVIRON) {
+           while (!SB_EOF()) {
+               c = SB_GET();
+               if ((c == NEW_ENV_VAR) || (c == ENV_USERVAR))
+                       break;
+           }
+       } else
+#endif
+       {
 #ifdef ENV_HACK
 #ifdef ENV_HACK
-       /*
-        * We only want to do this if we haven't already decided
-        * whether or not the other side has its VALUE and VAR
-        * reversed.
-        */
-       if (env_var < 0) {
+           /*
+            * We only want to do this if we haven't already decided
+            * whether or not the other side has its VALUE and VAR
+            * reversed.
+            */
+           if (env_ovar < 0) {
                register int last = -1;         /* invalid value */
                int empty = 0;
                int got_var = 0, got_value = 0, got_uservar = 0;
                register int last = -1;         /* invalid value */
                int empty = 0;
                int got_var = 0, got_value = 0, got_uservar = 0;
@@ -1262,29 +1287,29 @@ suboption()
                while (!SB_EOF()) {
                        c = SB_GET();
                        switch(c) {
                while (!SB_EOF()) {
                        c = SB_GET();
                        switch(c) {
-                       case ENV_VAR:
-                               if (last < 0 || last == ENV_VAR
-                                   || (empty && (last == ENV_VALUE)))
-                                       goto env_var_ok;
+                       case OLD_ENV_VAR:
+                               if (last < 0 || last == OLD_ENV_VAR
+                                   || (empty && (last == OLD_ENV_VALUE)))
+                                       goto env_ovar_ok;
                                got_var++;
                                got_var++;
-                               last = ENV_VAR;
+                               last = OLD_ENV_VAR;
                                break;
                                break;
-                       case ENV_VALUE:
-                               if (last < 0 || last == ENV_VALUE
-                                   || (empty && (last == ENV_VAR)))
-                                       goto env_var_wrong;
+                       case OLD_ENV_VALUE:
+                               if (last < 0 || last == OLD_ENV_VALUE
+                                   || (empty && (last == OLD_ENV_VAR)))
+                                       goto env_ovar_wrong;
                                got_value++;
                                got_value++;
-                               last = ENV_VALUE;
+                               last = OLD_ENV_VALUE;
                                break;
                        case ENV_USERVAR:
                                /* count strings of USERVAR as one */
                                if (last != ENV_USERVAR)
                                        got_uservar++;
                                if (empty) {
                                break;
                        case ENV_USERVAR:
                                /* count strings of USERVAR as one */
                                if (last != ENV_USERVAR)
                                        got_uservar++;
                                if (empty) {
-                                       if (last == ENV_VALUE)
-                                               goto env_var_ok;
-                                       if (last == ENV_VAR)
-                                               goto env_var_wrong;
+                                       if (last == OLD_ENV_VALUE)
+                                               goto env_ovar_ok;
+                                       if (last == OLD_ENV_VAR)
+                                               goto env_ovar_wrong;
                                }
                                last = ENV_USERVAR;
                                break;
                                }
                                last = ENV_USERVAR;
                                break;
@@ -1299,10 +1324,10 @@ suboption()
                        empty = 1;
                }
                if (empty) {
                        empty = 1;
                }
                if (empty) {
-                       if (last == ENV_VALUE)
-                               goto env_var_ok;
-                       if (last == ENV_VAR)
-                               goto env_var_wrong;
+                       if (last == OLD_ENV_VALUE)
+                               goto env_ovar_ok;
+                       if (last == OLD_ENV_VAR)
+                               goto env_ovar_wrong;
                }
                /*
                 * Ok, the first thing was a USERVAR, and there
                }
                /*
                 * Ok, the first thing was a USERVAR, and there
@@ -1320,26 +1345,27 @@ suboption()
                 * USERVARS, the client has reversed definitions.
                 */
                if (got_uservar + got_var == got_value) {
                 * USERVARS, the client has reversed definitions.
                 */
                if (got_uservar + got_var == got_value) {
-           env_var_ok:
-                       env_var = ENV_VAR;
-                       env_value = ENV_VALUE;
+           env_ovar_ok:
+                       env_ovar = OLD_ENV_VAR;
+                       env_ovalue = OLD_ENV_VALUE;
                } else if (got_uservar + got_value == got_var) {
                } else if (got_uservar + got_value == got_var) {
-           env_var_wrong:
-                       env_var = ENV_VALUE;
-                       env_value = ENV_VAR;
+           env_ovar_wrong:
+                       env_ovar = OLD_ENV_VALUE;
+                       env_ovalue = OLD_ENV_VAR;
                        DIAG(TD_OPTIONS, {sprintf(nfrontp,
                                "ENVIRON VALUE and VAR are reversed!\r\n");
                                nfrontp += strlen(nfrontp);});
 
                }
                        DIAG(TD_OPTIONS, {sprintf(nfrontp,
                                "ENVIRON VALUE and VAR are reversed!\r\n");
                                nfrontp += strlen(nfrontp);});
 
                }
-       }
-       SB_RESTORE();
+           }
+           SB_RESTORE();
 #endif
 
 #endif
 
-       while (!SB_EOF()) {
+           while (!SB_EOF()) {
                c = SB_GET();
                c = SB_GET();
-               if ((c == env_var) || (c == ENV_USERVAR))
+               if ((c == env_ovar) || (c == ENV_USERVAR))
                        break;
                        break;
+           }
        }
 
        if (SB_EOF())
        }
 
        if (SB_EOF())
@@ -1350,20 +1376,20 @@ suboption()
 
        while (!SB_EOF()) {
                c = SB_GET();
 
        while (!SB_EOF()) {
                c = SB_GET();
-#ifdef ENV_HACK
-               if (c == env_var)
-                       c = ENV_VAR;
-               else if (c == env_value)
-                       c = ENV_VALUE;
-#endif
+               if (subchar == TELOPT_OLD_ENVIRON) {
+                       if (c == env_ovar)
+                               c = NEW_ENV_VAR;
+                       else if (c == env_ovalue)
+                               c = NEW_ENV_VALUE;
+               }
                switch (c) {
 
                switch (c) {
 
-               case ENV_VALUE:
+               case NEW_ENV_VALUE:
                        *cp = '\0';
                        cp = valp = (char *)subpointer;
                        break;
 
                        *cp = '\0';
                        cp = valp = (char *)subpointer;
                        break;
 
-               case ENV_VAR:
+               case NEW_ENV_VAR:
                case ENV_USERVAR:
                        *cp = '\0';
                        if (valp)
                case ENV_USERVAR:
                        *cp = '\0';
                        if (valp)
@@ -1390,7 +1416,7 @@ suboption()
        else
                unsetenv(varp);
        break;
        else
                unsetenv(varp);
        break;
-    }  /* end of case TELOPT_ENVIRON */
+    }  /* end of case TELOPT_NEW_ENVIRON */
 #if    defined(AUTHENTICATION)
     case TELOPT_AUTHENTICATION:
        if (SB_EOF())
 #if    defined(AUTHENTICATION)
     case TELOPT_AUTHENTICATION:
        if (SB_EOF())
@@ -1494,7 +1520,7 @@ send_status()
         * WILL/DO, and the "want_state" will be WONT/DONT.  We
         * need to go by the latter.
         */
         * WILL/DO, and the "want_state" will be WONT/DONT.  We
         * need to go by the latter.
         */
-       for (i = 0; i < NTELOPTS; i++) {
+       for (i = 0; i < (unsigned char)NTELOPTS; i++) {
                if (my_want_state_is_will(i)) {
                        ADD(WILL);
                        ADD_DATA(i);
                if (my_want_state_is_will(i)) {
                        ADD(WILL);
                        ADD_DATA(i);
index 301e648..23782c3 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)sys_term.c 8.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)sys_term.c 8.2 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "telnetd.h"
 #endif /* not lint */
 
 #include "telnetd.h"
@@ -26,10 +26,11 @@ int utmp_len = MAXHOSTNAMELEN;      /* sizeof(init_request.host) */
 #else  /* NEWINIT*/
 # ifdef        UTMPX
 # include <utmpx.h>
 #else  /* NEWINIT*/
 # ifdef        UTMPX
 # include <utmpx.h>
+struct utmpx wtmp;
 # else
 # include <utmp.h>
 # else
 # include <utmp.h>
-# endif /* UTMPX */
 struct utmp wtmp;
 struct utmp wtmp;
+# endif /* UTMPX */
 
 int    utmp_len = sizeof(wtmp.ut_host);
 # ifndef PARENT_DOES_UTMP
 
 int    utmp_len = sizeof(wtmp.ut_host);
 # ifndef PARENT_DOES_UTMP
@@ -622,6 +623,7 @@ tty_setlinemode(on)
 # endif
 #endif /* TIOCEXT */
 }
 # endif
 #endif /* TIOCEXT */
 }
+#endif /* LINEMODE */
 
        int
 tty_isecho()
 
        int
 tty_isecho()
@@ -632,7 +634,6 @@ tty_isecho()
        return (termbuf.c_lflag & ECHO);
 #endif
 }
        return (termbuf.c_lflag & ECHO);
 #endif
 }
-#endif /* LINEMODE */
 
        int
 tty_flowmode()
 
        int
 tty_flowmode()
@@ -675,7 +676,6 @@ tty_setecho(on)
 #endif
 }
 
 #endif
 }
 
-#if    defined(LINEMODE) && defined(KLUDGELINEMODE)
        int
 tty_israw()
 {
        int
 tty_israw()
 {
@@ -685,7 +685,24 @@ tty_israw()
        return(!(termbuf.c_lflag & ICANON));
 #endif
 }
        return(!(termbuf.c_lflag & ICANON));
 #endif
 }
-#endif /* defined(LINEMODE) && defined(KLUDGELINEMODE) */
+
+#if    defined (AUTHENTICATION) && defined(NO_LOGIN_F) && defined(LOGIN_R)
+       int
+tty_setraw(on)
+{
+#  ifndef USE_TERMIO
+       if (on)
+               termbuf.sg.sg_flags |= RAW;
+       else
+               termbuf.sg.sg_flags &= ~RAW;
+#  else
+       if (on)
+               termbuf.c_lflag &= ~ICANON;
+       else
+               termbuf.c_lflag |= ICANON;
+#  endif
+}
+#endif
 
        void
 tty_binaryin(on)
 
        void
 tty_binaryin(on)
@@ -1103,8 +1120,17 @@ getptyslave()
 #endif /* !defined(CRAY) || !defined(NEWINIT) */
        if (net > 2)
                (void) close(net);
 #endif /* !defined(CRAY) || !defined(NEWINIT) */
        if (net > 2)
                (void) close(net);
-       if (pty > 2)
+#if    defined(AUTHENTICATION) && defined(NO_LOGIN_F) && defined(LOGIN_R)
+       /*
+        * Leave the pty open so that we can write out the rlogin
+        * protocol for /bin/login, if the authentication works.
+        */
+#else
+       if (pty > 2) {
                (void) close(pty);
                (void) close(pty);
+               pty = -1;
+       }
+#endif
 }
 
 #if    !defined(CRAY) || !defined(NEWINIT)
 }
 
 #if    !defined(CRAY) || !defined(NEWINIT)
@@ -1214,12 +1240,22 @@ cleanopen(line)
 #endif /* !defined(CRAY) || !defined(NEWINIT) */
 
 #if BSD <= 43
 #endif /* !defined(CRAY) || !defined(NEWINIT) */
 
 #if BSD <= 43
+
        int
 login_tty(t)
        int t;
 {
        int
 login_tty(t)
        int t;
 {
-       if (setsid() < 0)
-               fatalperror(net, "setsid()");
+       if (setsid() < 0) {
+#ifdef ultrix
+               /*
+                * The setsid() may have failed because we
+                * already have a pgrp == pid.  Zero out
+                * our pgrp and try again...
+                */
+               if ((setpgrp(0, 0) < 0) || (setsid() < 0))
+#endif
+                       fatalperror(net, "setsid()");
+       }
 # ifdef        TIOCSCTTY
        if (ioctl(t, TIOCSCTTY, (char *)0) < 0)
                fatalperror(net, "ioctl(sctty)");
 # ifdef        TIOCSCTTY
        if (ioctl(t, TIOCSCTTY, (char *)0) < 0)
                fatalperror(net, "ioctl(sctty)");
@@ -1233,6 +1269,14 @@ login_tty(t)
                fatalperror(net, "open(/dev/tty)");
 #  endif
 # else
                fatalperror(net, "open(/dev/tty)");
 #  endif
 # else
+       /*
+        * We get our controlling tty assigned as a side-effect
+        * of opening up a tty device.  But on BSD based systems,
+        * this only happens if our process group is zero.  The
+        * setsid() call above may have set our pgrp, so clear
+        * it out before opening the tty...
+        */
+       (void) setpgrp(0, 0);
        close(open(line, O_RDWR));
 # endif
        if (t != 0)
        close(open(line, O_RDWR));
 # endif
        if (t != 0)
@@ -1330,7 +1374,7 @@ startslave(host, autologin, autoname)
                utmp_sig_notify(pid);
 # endif        /* PARENT_DOES_UTMP */
        } else {
                utmp_sig_notify(pid);
 # endif        /* PARENT_DOES_UTMP */
        } else {
-               getptyslave();
+               getptyslave(autologin);
                start_login(host, autologin, autoname);
                /*NOTREACHED*/
        }
                start_login(host, autologin, autoname);
                /*NOTREACHED*/
        }
@@ -1428,11 +1472,12 @@ start_login(host, autologin, name)
        register char *cp;
        register char **argv;
        char **addarg();
        register char *cp;
        register char **argv;
        char **addarg();
+       extern char *getenv();
 #ifdef UTMPX
        register int pid = getpid();
        struct utmpx utmpx;
 #endif
 #ifdef UTMPX
        register int pid = getpid();
        struct utmpx utmpx;
 #endif
-#ifdef __svr4__
+#ifdef SOLARIS
        char *term;
        char termbuf[64];
 #endif
        char *term;
        char termbuf[64];
 #endif
@@ -1465,23 +1510,34 @@ start_login(host, autologin, name)
         * -f : force this login, he has already been authenticated
         */
        argv = addarg(0, "login");
         * -f : force this login, he has already been authenticated
         */
        argv = addarg(0, "login");
+
 #if    !defined(NO_LOGIN_H)
 #if    !defined(NO_LOGIN_H)
-       argv = addarg(argv, "-h");
-       argv = addarg(argv, host);
-#endif
-#ifdef __svr4__
+
+# if   defined (AUTHENTICATION) && defined(NO_LOGIN_F) && defined(LOGIN_R)
        /*
        /*
-        * SVR4 version of -h takes TERM= as second arg, or -
+        * Don't add the "-h host" option if we are going
+        * to be adding the "-r host" option down below...
         */
         */
-       term = getenv("TERM");
-       if (term == NULL || term[0] == 0) {
-               term = "-";
-       } else {
-               strcpy(termbuf, "TERM=");
-               strncat(termbuf, term, sizeof(termbuf) - 6);
-               term = termbuf;
+       if ((auth_level < 0) || (autologin != AUTH_VALID))
+# endif
+       {
+               argv = addarg(argv, "-h");
+               argv = addarg(argv, host);
+#ifdef SOLARIS
+               /*
+                * SVR4 version of -h takes TERM= as second arg, or -
+                */
+               term = getenv("TERM");
+               if (term == NULL || term[0] == 0) {
+                       term = "-";
+               } else {
+                       strcpy(termbuf, "TERM=");
+                       strncat(termbuf, term, sizeof(termbuf) - 6);
+                       term = termbuf;
+               }
+               argv = addarg(argv, term);
+#endif
        }
        }
-       argv = addarg(argv, term);
 #endif
 #if    !defined(NO_LOGIN_P)
        argv = addarg(argv, "-p");
 #endif
 #if    !defined(NO_LOGIN_P)
        argv = addarg(argv, "-p");
@@ -1508,13 +1564,86 @@ start_login(host, autologin, name)
        if (auth_level >= 0 && autologin == AUTH_VALID) {
 # if   !defined(NO_LOGIN_F)
                argv = addarg(argv, "-f");
        if (auth_level >= 0 && autologin == AUTH_VALID) {
 # if   !defined(NO_LOGIN_F)
                argv = addarg(argv, "-f");
+               argv = addarg(argv, name);
+# else
+#  if defined(LOGIN_R)
+               /*
+                * We don't have support for "login -f", but we
+                * can fool /bin/login into thinking that we are
+                * rlogind, and allow us to log in without a
+                * password.  The rlogin protocol expects
+                *      local-user\0remote-user\0term/speed\0
+                */
+
+               if (pty > 2) {
+                       register char *cp;
+                       char speed[128];
+                       int isecho, israw, xpty, len;
+                       extern int def_rspeed;
+#  ifndef LOGIN_HOST
+                       /*
+                        * Tell login that we are coming from "localhost".
+                        * If we passed in the real host name, then the
+                        * user would have to allow .rhost access from
+                        * every machine that they want authenticated
+                        * access to work from, which sort of defeats
+                        * the purpose of an authenticated login...
+                        * So, we tell login that the session is coming
+                        * from "localhost", and the user will only have
+                        * to have "localhost" in their .rhost file.
+                        */
+#                      define LOGIN_HOST "localhost"
+#  endif
+                       argv = addarg(argv, "-r");
+                       argv = addarg(argv, LOGIN_HOST);
+
+                       xpty = pty;
+# ifndef  STREAMSPTY
+                       pty = 0;
+# else
+                       ttyfd = 0;
 # endif
 # endif
+                       init_termbuf();
+                       isecho = tty_isecho();
+                       israw = tty_israw();
+                       if (isecho || !israw) {
+                               tty_setecho(0);         /* Turn off echo */
+                               tty_setraw(1);          /* Turn on raw */
+                               set_termbuf();
+                       }
+                       len = strlen(name)+1;
+                       write(xpty, name, len);
+                       write(xpty, name, len);
+                       sprintf(speed, "%s/%d", (cp = getenv("TERM")) ? cp : "",
+                               (def_rspeed > 0) ? def_rspeed : 9600);
+                       len = strlen(speed)+1;
+                       write(xpty, speed, len);
+
+                       if (isecho || !israw) {
+                               init_termbuf();
+                               tty_setecho(isecho);
+                               tty_setraw(israw);
+                               set_termbuf();
+                               if (!israw) {
+                                       /*
+                                        * Write a newline to ensure
+                                        * that login will be able to
+                                        * read the line...
+                                        */
+                                       write(xpty, "\n", 1);
+                               }
+                       }
+                       pty = xpty;
+               }
+#  else
                argv = addarg(argv, name);
                argv = addarg(argv, name);
+#  endif
+# endif
        } else
 #endif
        if (getenv("USER")) {
                argv = addarg(argv, getenv("USER"));
        } else
 #endif
        if (getenv("USER")) {
                argv = addarg(argv, getenv("USER"));
-#if    (defined(CRAY) || defined(__hpux)) && defined(NO_LOGIN_P)
+#if    defined(LOGIN_ARGS) && defined(NO_LOGIN_P)
                {
                        register char **cpp;
                        for (cpp = environ; *cpp; cpp++)
                {
                        register char **cpp;
                        for (cpp = environ; *cpp; cpp++)
@@ -1533,6 +1662,10 @@ start_login(host, autologin, name)
                 */
                unsetenv("USER");
        }
                 */
                unsetenv("USER");
        }
+#if    defined(AUTHENTICATION) && defined(NO_LOGIN_F) && defined(LOGIN_R)
+       if (pty > 2)
+               close(pty);
+#endif
        closelog();
        execv(_PATH_LOGIN, argv);
 
        closelog();
        execv(_PATH_LOGIN, argv);
 
@@ -1759,7 +1892,8 @@ cleantmp(wtp)
        struct utmp *utp;
        static int first = 1;
        register int mask, omask, ret;
        struct utmp *utp;
        static int first = 1;
        register int mask, omask, ret;
-       extern struct utmp *getutid P((struct utmp *));
+       extern struct utmp *getutid P((const struct utmp *_Id));
+
 
        mask = sigmask(WJSIGNAL);
 
 
        mask = sigmask(WJSIGNAL);
 
@@ -1853,6 +1987,7 @@ cleantmpdir(jid, tpath, user)
  */
 
 #ifdef UTMPX
  */
 
 #ifdef UTMPX
+       void
 rmut()
 {
        register f;
 rmut()
 {
        register f;
index 943c917..5e5d224 100644 (file)
@@ -12,7 +12,7 @@ static char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)telnetd.c  8.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)telnetd.c  8.2 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "telnetd.h"
 #endif /* not lint */
 
 #include "telnetd.h"
@@ -68,9 +68,9 @@ int   registerd_host_only = 0;
  * ptyibuf+1 to be on a full-word boundary.  The following wierdness
  * is simply to make that happen.
  */
  * ptyibuf+1 to be on a full-word boundary.  The following wierdness
  * is simply to make that happen.
  */
-char   ptyibufbuf[BUFSIZ+4];
-char   *ptyibuf = ptyibufbuf+3;
-char   *ptyip = ptyibufbuf+3;
+long   ptyibufbuf[BUFSIZ/sizeof(long)+1];
+char   *ptyibuf = ((char *)&ptyibufbuf[1])-1;
+char   *ptyip = ((char *)&ptyibufbuf[1])-1;
 char   ptyibuf2[BUFSIZ];
 unsigned char ctlbuf[BUFSIZ];
 struct strbuf strbufc, strbufd;
 char   ptyibuf2[BUFSIZ];
 unsigned char ctlbuf[BUFSIZ];
 struct strbuf strbufc, strbufd;
@@ -555,7 +555,9 @@ usage()
  *     Ask the other end to send along its terminal type and speed.
  * Output is the variable terminaltype filled in.
  */
  *     Ask the other end to send along its terminal type and speed.
  * Output is the variable terminaltype filled in.
  */
-static char ttytype_sbbuf[] = { IAC, SB, TELOPT_TTYPE, TELQUAL_SEND, IAC, SE };
+static unsigned char ttytype_sbbuf[] = {
+       IAC, SB, TELOPT_TTYPE, TELQUAL_SEND, IAC, SE
+};
 
     int
 getterminaltype(name)
 
     int
 getterminaltype(name)
@@ -583,7 +585,8 @@ getterminaltype(name)
     send_do(TELOPT_TTYPE, 1);
     send_do(TELOPT_TSPEED, 1);
     send_do(TELOPT_XDISPLOC, 1);
     send_do(TELOPT_TTYPE, 1);
     send_do(TELOPT_TSPEED, 1);
     send_do(TELOPT_XDISPLOC, 1);
-    send_do(TELOPT_ENVIRON, 1);
+    send_do(TELOPT_NEW_ENVIRON, 1);
+    send_do(TELOPT_OLD_ENVIRON, 1);
     while (
 #ifdef ENCRYPTION
           his_do_dont_is_changing(TELOPT_ENCRYPT) ||
     while (
 #ifdef ENCRYPTION
           his_do_dont_is_changing(TELOPT_ENCRYPT) ||
@@ -591,7 +594,8 @@ getterminaltype(name)
           his_will_wont_is_changing(TELOPT_TTYPE) ||
           his_will_wont_is_changing(TELOPT_TSPEED) ||
           his_will_wont_is_changing(TELOPT_XDISPLOC) ||
           his_will_wont_is_changing(TELOPT_TTYPE) ||
           his_will_wont_is_changing(TELOPT_TSPEED) ||
           his_will_wont_is_changing(TELOPT_XDISPLOC) ||
-          his_will_wont_is_changing(TELOPT_ENVIRON)) {
+          his_will_wont_is_changing(TELOPT_NEW_ENVIRON) ||
+          his_will_wont_is_changing(TELOPT_OLD_ENVIRON)) {
        ttloop();
     }
 #ifdef ENCRYPTION
        ttloop();
     }
 #ifdef ENCRYPTION
@@ -604,22 +608,32 @@ getterminaltype(name)
     }
 #endif /* ENCRYPTION */
     if (his_state_is_will(TELOPT_TSPEED)) {
     }
 #endif /* ENCRYPTION */
     if (his_state_is_will(TELOPT_TSPEED)) {
-       static char sbbuf[] = { IAC, SB, TELOPT_TSPEED, TELQUAL_SEND, IAC, SE };
+       static unsigned char sb[] =
+                       { IAC, SB, TELOPT_TSPEED, TELQUAL_SEND, IAC, SE };
 
 
-       bcopy(sbbuf, nfrontp, sizeof sbbuf);
-       nfrontp += sizeof sbbuf;
+       bcopy(sb, nfrontp, sizeof sb);
+       nfrontp += sizeof sb;
     }
     if (his_state_is_will(TELOPT_XDISPLOC)) {
     }
     if (his_state_is_will(TELOPT_XDISPLOC)) {
-       static char sbbuf[] = { IAC, SB, TELOPT_XDISPLOC, TELQUAL_SEND, IAC, SE };
+       static unsigned char sb[] =
+                       { IAC, SB, TELOPT_XDISPLOC, TELQUAL_SEND, IAC, SE };
+
+       bcopy(sb, nfrontp, sizeof sb);
+       nfrontp += sizeof sb;
+    }
+    if (his_state_is_will(TELOPT_NEW_ENVIRON)) {
+       static unsigned char sb[] =
+                       { IAC, SB, TELOPT_NEW_ENVIRON, TELQUAL_SEND, IAC, SE };
 
 
-       bcopy(sbbuf, nfrontp, sizeof sbbuf);
-       nfrontp += sizeof sbbuf;
+       bcopy(sb, nfrontp, sizeof sb);
+       nfrontp += sizeof sb;
     }
     }
-    if (his_state_is_will(TELOPT_ENVIRON)) {
-       static char sbbuf[] = { IAC, SB, TELOPT_ENVIRON, TELQUAL_SEND, IAC, SE };
+    else if (his_state_is_will(TELOPT_OLD_ENVIRON)) {
+       static unsigned char sb[] =
+                       { IAC, SB, TELOPT_OLD_ENVIRON, TELQUAL_SEND, IAC, SE };
 
 
-       bcopy(sbbuf, nfrontp, sizeof sbbuf);
-       nfrontp += sizeof sbbuf;
+       bcopy(sb, nfrontp, sizeof sb);
+       nfrontp += sizeof sb;
     }
     if (his_state_is_will(TELOPT_TTYPE)) {
 
     }
     if (his_state_is_will(TELOPT_TTYPE)) {
 
@@ -634,10 +648,14 @@ getterminaltype(name)
        while (sequenceIs(xdisplocsubopt, baseline))
            ttloop();
     }
        while (sequenceIs(xdisplocsubopt, baseline))
            ttloop();
     }
-    if (his_state_is_will(TELOPT_ENVIRON)) {
+    if (his_state_is_will(TELOPT_NEW_ENVIRON)) {
        while (sequenceIs(environsubopt, baseline))
            ttloop();
     }
        while (sequenceIs(environsubopt, baseline))
            ttloop();
     }
+    if (his_state_is_will(TELOPT_OLD_ENVIRON)) {
+       while (sequenceIs(oenvironsubopt, baseline))
+           ttloop();
+    }
     if (his_state_is_will(TELOPT_TTYPE)) {
        char first[256], last[256];
 
     if (his_state_is_will(TELOPT_TTYPE)) {
        char first[256], last[256];
 
@@ -1382,7 +1400,7 @@ int readstream(p, ibuf, bufsize)
        int newflow;
 
        strbufc.maxlen = BUFSIZ;
        int newflow;
 
        strbufc.maxlen = BUFSIZ;
-       strbufc.buf = ctlbuf;
+       strbufc.buf = (char *)ctlbuf;
        strbufd.maxlen = bufsize-1;
        strbufd.len = 0;
        strbufd.buf = ibuf+1;
        strbufd.maxlen = bufsize-1;
        strbufd.len = 0;
        strbufd.buf = ibuf+1;
index 4967f3c..1e80a84 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)utility.c  8.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)utility.c  8.2 (Berkeley) %G%";
 #endif /* not lint */
 
 #define PRINTOPTIONS
 #endif /* not lint */
 
 #define PRINTOPTIONS
@@ -422,7 +422,11 @@ putf(cp, where)
        char *slash;
        time_t t;
        char db[100];
        char *slash;
        time_t t;
        char db[100];
+#ifdef STREAMSPTY
+       extern char *index();
+#else
        extern char *rindex();
        extern char *rindex();
+#endif
 
        putlocation = where;
 
 
        putlocation = where;
 
@@ -529,7 +533,7 @@ printsub(direction, pointer, length)
            length -= 2;
        }
        if (length < 1) {
            length -= 2;
        }
        if (length < 1) {
-           sprintf(nfrontp, "(Empty suboption???)");
+           sprintf(nfrontp, "(Empty suboption??\?)");
            nfrontp += strlen(nfrontp);
            return;
        }
            nfrontp += strlen(nfrontp);
            return;
        }
@@ -555,7 +559,7 @@ printsub(direction, pointer, length)
            sprintf(nfrontp, "TERMINAL-SPEED");
            nfrontp += strlen(nfrontp);
            if (length < 2) {
            sprintf(nfrontp, "TERMINAL-SPEED");
            nfrontp += strlen(nfrontp);
            if (length < 2) {
-               sprintf(nfrontp, " (empty suboption???)");
+               sprintf(nfrontp, " (empty suboption??\?)");
                nfrontp += strlen(nfrontp);
                break;
            }
                nfrontp += strlen(nfrontp);
                break;
            }
@@ -582,7 +586,7 @@ printsub(direction, pointer, length)
            sprintf(nfrontp, "TOGGLE-FLOW-CONTROL");
            nfrontp += strlen(nfrontp);
            if (length < 2) {
            sprintf(nfrontp, "TOGGLE-FLOW-CONTROL");
            nfrontp += strlen(nfrontp);
            if (length < 2) {
-               sprintf(nfrontp, " (empty suboption???)");
+               sprintf(nfrontp, " (empty suboption??\?)");
                nfrontp += strlen(nfrontp);
                break;
            }
                nfrontp += strlen(nfrontp);
                break;
            }
@@ -609,7 +613,7 @@ printsub(direction, pointer, length)
            sprintf(nfrontp, "NAWS");
            nfrontp += strlen(nfrontp);
            if (length < 2) {
            sprintf(nfrontp, "NAWS");
            nfrontp += strlen(nfrontp);
            if (length < 2) {
-               sprintf(nfrontp, " (empty suboption???)");
+               sprintf(nfrontp, " (empty suboption??\?)");
                nfrontp += strlen(nfrontp);
                break;
            }
                nfrontp += strlen(nfrontp);
                break;
            }
@@ -641,7 +645,7 @@ printsub(direction, pointer, length)
            sprintf(nfrontp, "LINEMODE ");
            nfrontp += strlen(nfrontp);
            if (length < 2) {
            sprintf(nfrontp, "LINEMODE ");
            nfrontp += strlen(nfrontp);
            if (length < 2) {
-               sprintf(nfrontp, " (empty suboption???)");
+               sprintf(nfrontp, " (empty suboption??\?)");
                nfrontp += strlen(nfrontp);
                break;
            }
                nfrontp += strlen(nfrontp);
                break;
            }
@@ -660,7 +664,7 @@ printsub(direction, pointer, length)
            common:
                nfrontp += strlen(nfrontp);
                if (length < 3) {
            common:
                nfrontp += strlen(nfrontp);
                if (length < 3) {
-                   sprintf(nfrontp, "(no option???)");
+                   sprintf(nfrontp, "(no option??\?)");
                    nfrontp += strlen(nfrontp);
                    break;
                }
                    nfrontp += strlen(nfrontp);
                    break;
                }
@@ -730,7 +734,7 @@ printsub(direction, pointer, length)
                sprintf(nfrontp, "MODE ");
                nfrontp += strlen(nfrontp);
                if (length < 3) {
                sprintf(nfrontp, "MODE ");
                nfrontp += strlen(nfrontp);
                if (length < 3) {
-                   sprintf(nfrontp, "(no mode???)");
+                   sprintf(nfrontp, "(no mode??\?)");
                    nfrontp += strlen(nfrontp);
                    break;
                }
                    nfrontp += strlen(nfrontp);
                    break;
                }
@@ -862,8 +866,12 @@ printsub(direction, pointer, length)
            nfrontp += strlen(nfrontp);
            break;
 
            nfrontp += strlen(nfrontp);
            break;
 
-       case TELOPT_ENVIRON:
-           sprintf(nfrontp, "ENVIRON ");
+       case TELOPT_NEW_ENVIRON:
+           sprintf(nfrontp, "NEW-ENVIRON ");
+           goto env_common1;
+       case TELOPT_OLD_ENVIRON:
+           sprintf(nfrontp, "OLD-ENVIRON");
+       env_common1:
            nfrontp += strlen(nfrontp);
            switch (pointer[1]) {
            case TELQUAL_IS:
            nfrontp += strlen(nfrontp);
            switch (pointer[1]) {
            case TELQUAL_IS:
@@ -875,18 +883,18 @@ printsub(direction, pointer, length)
            case TELQUAL_INFO:
                sprintf(nfrontp, "INFO ");
            env_common:
            case TELQUAL_INFO:
                sprintf(nfrontp, "INFO ");
            env_common:
-           nfrontp += strlen(nfrontp);
+               nfrontp += strlen(nfrontp);
                {
                    register int noquote = 2;
                    for (i = 2; i < length; i++ ) {
                        switch (pointer[i]) {
                {
                    register int noquote = 2;
                    for (i = 2; i < length; i++ ) {
                        switch (pointer[i]) {
-                       case ENV_VAR:
+                       case NEW_ENV_VAR:
                            sprintf(nfrontp, "\" VAR " + noquote);
                            nfrontp += strlen(nfrontp);
                            noquote = 2;
                            break;
 
                            sprintf(nfrontp, "\" VAR " + noquote);
                            nfrontp += strlen(nfrontp);
                            noquote = 2;
                            break;
 
-                       case ENV_VALUE:
+                       case NEW_ENV_VALUE:
                            sprintf(nfrontp, "\" VALUE " + noquote);
                            nfrontp += strlen(nfrontp);
                            noquote = 2;
                            sprintf(nfrontp, "\" VALUE " + noquote);
                            nfrontp += strlen(nfrontp);
                            noquote = 2;
@@ -934,7 +942,7 @@ printsub(direction, pointer, length)
            nfrontp += strlen(nfrontp);
        
            if (length < 2) {
            nfrontp += strlen(nfrontp);
        
            if (length < 2) {
-               sprintf(nfrontp, " (empty suboption???)");
+               sprintf(nfrontp, " (empty suboption??\?)");
                nfrontp += strlen(nfrontp);
                break;
            }
                nfrontp += strlen(nfrontp);
                break;
            }
@@ -950,7 +958,7 @@ printsub(direction, pointer, length)
                    sprintf(nfrontp, "%d ", pointer[2]);
                nfrontp += strlen(nfrontp);
                if (length < 3) {
                    sprintf(nfrontp, "%d ", pointer[2]);
                nfrontp += strlen(nfrontp);
                if (length < 3) {
-                   sprintf(nfrontp, "(partial suboption???)");
+                   sprintf(nfrontp, "(partial suboption??\?)");
                    nfrontp += strlen(nfrontp);
                    break;
                }
                    nfrontp += strlen(nfrontp);
                    break;
                }
@@ -977,7 +985,7 @@ printsub(direction, pointer, length)
                        sprintf(nfrontp, "%d ", pointer[i]);
                    nfrontp += strlen(nfrontp);
                    if (++i >= length) {
                        sprintf(nfrontp, "%d ", pointer[i]);
                    nfrontp += strlen(nfrontp);
                    if (++i >= length) {
-                       sprintf(nfrontp, "(partial suboption???)");
+                       sprintf(nfrontp, "(partial suboption??\?)");
                        nfrontp += strlen(nfrontp);
                        break;
                    }
                        nfrontp += strlen(nfrontp);
                        break;
                    }
@@ -1015,7 +1023,7 @@ printsub(direction, pointer, length)
            sprintf(nfrontp, "ENCRYPT");
            nfrontp += strlen(nfrontp);
            if (length < 2) {
            sprintf(nfrontp, "ENCRYPT");
            nfrontp += strlen(nfrontp);
            if (length < 2) {
-               sprintf(nfrontp, " (empty suboption???)");
+               sprintf(nfrontp, " (empty suboption??\?)");
                nfrontp += strlen(nfrontp);
                break;
            }
                nfrontp += strlen(nfrontp);
                break;
            }
@@ -1046,7 +1054,7 @@ printsub(direction, pointer, length)
                                                        "IS" : "REPLY");
                nfrontp += strlen(nfrontp);
                if (length < 3) {
                                                        "IS" : "REPLY");
                nfrontp += strlen(nfrontp);
                if (length < 3) {
-                   sprintf(nfrontp, " (partial suboption???)");
+                   sprintf(nfrontp, " (partial suboption??\?)");
                    nfrontp += strlen(nfrontp);
                    break;
                }
                    nfrontp += strlen(nfrontp);
                    break;
                }