Add support for new ENVIRON command.
authorDave A. Borman <dab@ucbvax.Berkeley.EDU>
Thu, 16 Dec 1993 03:36:05 +0000 (19:36 -0800)
committerDave A. Borman <dab@ucbvax.Berkeley.EDU>
Thu, 16 Dec 1993 03:36:05 +0000 (19:36 -0800)
Latest Kerberos V code from MIT (includes new
options '-f' and '-F' to control the forwarding
of credentials.)  Various bugfixes to keep some
C compilers happy.

SCCS-vsn: usr.bin/telnet/commands.c 8.2
SCCS-vsn: usr.bin/telnet/externs.h 8.2
SCCS-vsn: usr.bin/telnet/main.c 8.2
SCCS-vsn: usr.bin/telnet/network.c 8.2
SCCS-vsn: usr.bin/telnet/sys_bsd.c 8.2
SCCS-vsn: usr.bin/telnet/telnet.c 8.2
SCCS-vsn: usr.bin/telnet/utilities.c 8.2

usr/src/usr.bin/telnet/commands.c
usr/src/usr.bin/telnet/externs.h
usr/src/usr.bin/telnet/main.c
usr/src/usr.bin/telnet/network.c
usr/src/usr.bin/telnet/sys_bsd.c
usr/src/usr.bin/telnet/telnet.c
usr/src/usr.bin/telnet/utilities.c

index b6fc017..7d4c527 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)commands.c 8.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)commands.c 8.2 (Berkeley) %G%";
 #endif /* not lint */
 
 #if    defined(unix)
 #endif /* not lint */
 
 #if    defined(unix)
@@ -1550,7 +1550,7 @@ extern void
        env_export P((unsigned char *)),
        env_unexport P((unsigned char *)),
        env_send P((unsigned char *)),
        env_export P((unsigned char *)),
        env_unexport P((unsigned char *)),
        env_send P((unsigned char *)),
-#ifdef ENV_HACK
+#if defined(OLD_ENVIRON) && defined(ENV_HACK)
        env_varval P((unsigned char *)),
 #endif
        env_list P((void));
        env_varval P((unsigned char *)),
 #endif
        env_list P((void));
@@ -1569,7 +1569,7 @@ struct envlist EnvList[] = {
     { "send",  "Send an environment variable", env_send,       1 },
     { "list",  "List the current environment variables",
                                                env_list,       0 },
     { "send",  "Send an environment variable", env_send,       1 },
     { "list",  "List the current environment variables",
                                                env_list,       0 },
-#ifdef ENV_HACK
+#if defined(OLD_ENVIRON) && defined(ENV_HACK)
     { "varval", "Reverse VAR and VALUE (auto, right, wrong, status)",
                                                env_varval,    1 },
 #endif
     { "varval", "Reverse VAR and VALUE (auto, right, wrong, status)",
                                                env_varval,    1 },
 #endif
@@ -1776,7 +1776,11 @@ env_send(var)
 {
        register struct env_lst *ep;
 
 {
        register struct env_lst *ep;
 
-        if (my_state_is_wont(TELOPT_ENVIRON)) {
+        if (my_state_is_wont(TELOPT_NEW_ENVIRON)
+#ifdef OLD_ENVIRON
+           && my_state_is_wont(TELOPT_OLD_ENVIRON)
+#endif
+               ) {
                fprintf(stderr,
                    "Cannot send '%s': Telnet ENVIRON option not enabled\n",
                                                                        var);
                fprintf(stderr,
                    "Cannot send '%s': Telnet ENVIRON option not enabled\n",
                                                                        var);
@@ -1834,37 +1838,37 @@ env_getvalue(var)
        return(NULL);
 }
 
        return(NULL);
 }
 
-#ifdef ENV_HACK
+#if defined(OLD_ENVIRON) && defined(ENV_HACK)
        void
 env_varval(what)
        unsigned char *what;
 {
        void
 env_varval(what)
        unsigned char *what;
 {
-       extern int env_var, env_value, env_auto;
-       int len = strlen(what);
+       extern int old_env_var, old_env_value, env_auto;
+       int len = strlen((char *)what);
 
        if (len == 0)
                goto unknown;
 
 
        if (len == 0)
                goto unknown;
 
-       if (strncasecmp(what, "status", len) == 0) {
+       if (strncasecmp((char *)what, "status", len) == 0) {
                if (env_auto)
                        printf("%s%s", "VAR and VALUE are/will be ",
                                        "determined automatically\n");
                if (env_auto)
                        printf("%s%s", "VAR and VALUE are/will be ",
                                        "determined automatically\n");
-               if (env_var == ENV_VAR)
+               if (old_env_var == OLD_ENV_VAR)
                        printf("VAR and VALUE set to correct definitions\n");
                else
                        printf("VAR and VALUE definitions are reversed\n");
                        printf("VAR and VALUE set to correct definitions\n");
                else
                        printf("VAR and VALUE definitions are reversed\n");
-       } else if (strncasecmp(what, "auto", len) == 0) {
+       } else if (strncasecmp((char *)what, "auto", len) == 0) {
                env_auto = 1;
                env_auto = 1;
-               env_var = ENV_VALUE;
-               env_value = ENV_VAR;
-       } else if (strncasecmp(what, "right", len) == 0) {
+               old_env_var = OLD_ENV_VALUE;
+               old_env_value = OLD_ENV_VAR;
+       } else if (strncasecmp((char *)what, "right", len) == 0) {
                env_auto = 0;
                env_auto = 0;
-               env_var = ENV_VAR;
-               env_value = ENV_VALUE;
-       } else if (strncasecmp(what, "wrong", len) == 0) {
+               old_env_var = OLD_ENV_VAR;
+               old_env_value = OLD_ENV_VALUE;
+       } else if (strncasecmp((char *)what, "wrong", len) == 0) {
                env_auto = 0;
                env_auto = 0;
-               env_var = ENV_VALUE;
-               env_value = ENV_VAR;
+               old_env_var = OLD_ENV_VALUE;
+               old_env_value = OLD_ENV_VAR;
        } else {
 unknown:
                printf("Unknown \"varval\" command. (\"auto\", \"right\", \"wrong\", \"status\")\n");
        } else {
 unknown:
                printf("Unknown \"varval\" command. (\"auto\", \"right\", \"wrong\", \"status\")\n");
index 7ca42ea..f5762e4 100644 (file)
@@ -4,7 +4,7 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)externs.h   8.1 (Berkeley) %G%
+ *     @(#)externs.h   8.2 (Berkeley) %G%
  */
 
 #ifndef        BSD
  */
 
 #ifndef        BSD
 #define BSD 43
 #endif
 
 #define BSD 43
 #endif
 
-#if (BSD > 43 || defined(SYSV_TERMIO)) && !defined(USE_TERMIO)
-# define USE_TERMIO
+#ifndef        USE_TERMIO
+# if BSD > 43 || defined(SYSV_TERMIO)
+#  define USE_TERMIO
+# endif
 #endif
 
 #include <stdio.h>
 #endif
 
 #include <stdio.h>
index 5392d33..c9f6dd6 100644 (file)
@@ -12,7 +12,7 @@ static char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)main.c     8.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)main.c     8.2 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/types.h>
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -21,6 +21,15 @@ static char sccsid[] = "@(#)main.c   8.1 (Berkeley) %G%";
 #include "externs.h"
 #include "defines.h"
 
 #include "externs.h"
 #include "defines.h"
 
+/* These values need to be the same as defined in libtelnet/kerberos5.c */
+/* Either define them in both places, or put in some common header file. */
+#define OPTS_FORWARD_CREDS           0x00000002
+#define OPTS_FORWARDABLE_CREDS       0x00000001
+
+#if 0
+#define FORWARD
+#endif
+
 /*
  * Initialize variables.
  */
 /*
  * Initialize variables.
  */
@@ -47,7 +56,7 @@ usage()
            prompt,
 #ifdef AUTHENTICATION
            "[-8] [-E] [-K] [-L] [-S tos] [-X atype] [-a] [-c] [-d] [-e char]",
            prompt,
 #ifdef AUTHENTICATION
            "[-8] [-E] [-K] [-L] [-S tos] [-X atype] [-a] [-c] [-d] [-e char]",
-           "\n\t[-k realm] [-l user] [-n tracefile] ",
+           "\n\t[-k realm] [-l user] [-f/-F] [-n tracefile] ",
 #else
            "[-8] [-E] [-L] [-S tos] [-a] [-c] [-d] [-e char] [-l user]",
            "\n\t[-n tracefile]",
 #else
            "[-8] [-E] [-L] [-S tos] [-a] [-c] [-d] [-e char] [-l user]",
            "\n\t[-n tracefile]",
@@ -83,6 +92,9 @@ main(argc, argv)
        extern int optind;
        int ch;
        char *user, *strrchr();
        extern int optind;
        int ch;
        char *user, *strrchr();
+#ifdef FORWARD
+       extern int forward_flags;
+#endif /* FORWARD */
 
        tninit();               /* Clear out things */
 #if    defined(CRAY) && !defined(__STDC__)
 
        tninit();               /* Clear out things */
 #if    defined(CRAY) && !defined(__STDC__)
@@ -101,7 +113,7 @@ main(argc, argv)
        rlogin = (strncmp(prompt, "rlog", 4) == 0) ? '~' : _POSIX_VDISABLE;
        autologin = -1;
 
        rlogin = (strncmp(prompt, "rlog", 4) == 0) ? '~' : _POSIX_VDISABLE;
        autologin = -1;
 
-       while ((ch = getopt(argc, argv, "8EKLS:X:acde:k:l:n:rt:x")) != EOF) {
+       while ((ch = getopt(argc, argv, "8EKLS:X:acde:fFk:l:n:rt:x")) != EOF) {
                switch(ch) {
                case '8':
                        eight = 3;      /* binary output and input */
                switch(ch) {
                case '8':
                        eight = 3;      /* binary output and input */
@@ -151,6 +163,37 @@ main(argc, argv)
                case 'e':
                        set_escape_char(optarg);
                        break;
                case 'e':
                        set_escape_char(optarg);
                        break;
+               case 'f':
+#if defined(AUTHENTICATION) && defined(KRB5) && defined(FORWARD)
+                       if (forward_flags & OPTS_FORWARD_CREDS) {
+                           fprintf(stderr, 
+                                   "%s: Only one of -f and -F allowed.\n",
+                                   prompt);
+                           usage();
+                       }
+                       forward_flags |= OPTS_FORWARD_CREDS;
+#else
+                       fprintf(stderr,
+                        "%s: Warning: -f ignored, no Kerberos V5 support.\n", 
+                               prompt);
+#endif
+                       break;
+               case 'F':
+#if defined(AUTHENTICATION) && defined(KRB5) && defined(FORWARD)
+                       if (forward_flags & OPTS_FORWARD_CREDS) {
+                           fprintf(stderr, 
+                                   "%s: Only one of -f and -F allowed.\n",
+                                   prompt);
+                           usage();
+                       }
+                       forward_flags |= OPTS_FORWARD_CREDS;
+                       forward_flags |= OPTS_FORWARDABLE_CREDS;
+#else
+                       fprintf(stderr,
+                        "%s: Warning: -F ignored, no Kerberos V5 support.\n", 
+                               prompt);
+#endif
+                       break;
                case 'k':
 #if defined(AUTHENTICATION) && defined(KRB4)
                    {
                case 'k':
 #if defined(AUTHENTICATION) && defined(KRB4)
                    {
index 7cfe960..725b1d5 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)network.c  8.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)network.c  8.2 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/types.h>
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -108,7 +108,7 @@ netflush()
 #endif /* ENCRYPTION */
     if ((n1 = n = ring_full_consecutive(&netoring)) > 0) {
        if (!ring_at_mark(&netoring)) {
 #endif /* ENCRYPTION */
     if ((n1 = n = ring_full_consecutive(&netoring)) > 0) {
        if (!ring_at_mark(&netoring)) {
-           n = send(net, netoring.consume, n, 0);      /* normal write */
+           n = send(net, (char *)netoring.consume, n, 0); /* normal write */
        } else {
            /*
             * In 4.2 (and 4.3) systems, there is some question about
        } else {
            /*
             * In 4.2 (and 4.3) systems, there is some question about
@@ -118,7 +118,7 @@ netflush()
             * we really have more the TCP philosophy of urgent data
             * rather than the Unix philosophy of OOB data).
             */
             * we really have more the TCP philosophy of urgent data
             * rather than the Unix philosophy of OOB data).
             */
-           n = send(net, netoring.consume, 1, MSG_OOB);/* URGENT data */
+           n = send(net, (char *)netoring.consume, 1, MSG_OOB);/* URGENT data */
        }
     }
     if (n < 0) {
        }
     }
     if (n < 0) {
index 4762494..9ca6199 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)sys_bsd.c  8.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)sys_bsd.c  8.2 (Berkeley) %G%";
 #endif /* not lint */
 
 /*
 #endif /* not lint */
 
 /*
@@ -39,7 +39,7 @@ static char sccsid[] = "@(#)sys_bsd.c 8.1 (Berkeley) %G%";
 
 #ifdef SIGINFO
 extern SIG_FUNC_RET ayt_status();
 
 #ifdef SIGINFO
 extern SIG_FUNC_RET ayt_status();
-#endif SIGINFO
+#endif
 
 int
        tout,                   /* Output file descriptor */
 
 int
        tout,                   /* Output file descriptor */
@@ -585,18 +585,18 @@ TerminalNewMode(f)
 
     if (f != -1) {
 #ifdef SIGTSTP
 
     if (f != -1) {
 #ifdef SIGTSTP
-       static SIG_FUNC_RET susp();
+       SIG_FUNC_RET susp();
 #endif /* SIGTSTP */
 #ifdef SIGINFO
 #endif /* SIGTSTP */
 #ifdef SIGINFO
-       static SIG_FUNC_RET ayt();
-#endif SIGINFO
+       SIG_FUNC_RET ayt();
+#endif
 
 #ifdef SIGTSTP
        (void) signal(SIGTSTP, susp);
 #endif /* SIGTSTP */
 #ifdef SIGINFO
        (void) signal(SIGINFO, ayt);
 
 #ifdef SIGTSTP
        (void) signal(SIGTSTP, susp);
 #endif /* SIGTSTP */
 #ifdef SIGINFO
        (void) signal(SIGINFO, ayt);
-#endif SIGINFO
+#endif
 #if    defined(USE_TERMIO) && defined(NOKERNINFO)
        tmp_tc.c_lflag |= NOKERNINFO;
 #endif
 #if    defined(USE_TERMIO) && defined(NOKERNINFO)
        tmp_tc.c_lflag |= NOKERNINFO;
 #endif
@@ -640,7 +640,7 @@ TerminalNewMode(f)
        SIG_FUNC_RET ayt_status();
 
        (void) signal(SIGINFO, ayt_status);
        SIG_FUNC_RET ayt_status();
 
        (void) signal(SIGINFO, ayt_status);
-#endif SIGINFO
+#endif
 #ifdef SIGTSTP
        (void) signal(SIGTSTP, SIG_DFL);
        (void) sigsetmask(sigblock(0) & ~(1<<(SIGTSTP-1)));
 #ifdef SIGTSTP
        (void) signal(SIGTSTP, SIG_DFL);
        (void) sigsetmask(sigblock(0) & ~(1<<(SIGTSTP-1)));
@@ -784,7 +784,7 @@ NetSetPgrp(fd)
  */
 
     /* ARGSUSED */
  */
 
     /* ARGSUSED */
-    static SIG_FUNC_RET
+    SIG_FUNC_RET
 deadpeer(sig)
     int sig;
 {
 deadpeer(sig)
     int sig;
 {
@@ -793,7 +793,7 @@ deadpeer(sig)
 }
 
     /* ARGSUSED */
 }
 
     /* ARGSUSED */
-    static SIG_FUNC_RET
+    SIG_FUNC_RET
 intr(sig)
     int sig;
 {
 intr(sig)
     int sig;
 {
@@ -806,7 +806,7 @@ intr(sig)
 }
 
     /* ARGSUSED */
 }
 
     /* ARGSUSED */
-    static SIG_FUNC_RET
+    SIG_FUNC_RET
 intr2(sig)
     int sig;
 {
 intr2(sig)
     int sig;
 {
@@ -823,7 +823,7 @@ intr2(sig)
 
 #ifdef SIGTSTP
     /* ARGSUSED */
 
 #ifdef SIGTSTP
     /* ARGSUSED */
-    static SIG_FUNC_RET
+    SIG_FUNC_RET
 susp(sig)
     int sig;
 {
 susp(sig)
     int sig;
 {
@@ -836,7 +836,7 @@ susp(sig)
 
 #ifdef SIGWINCH
     /* ARGSUSED */
 
 #ifdef SIGWINCH
     /* ARGSUSED */
-    static SIG_FUNC_RET
+    SIG_FUNC_RET
 sendwin(sig)
     int sig;
 {
 sendwin(sig)
     int sig;
 {
@@ -848,7 +848,7 @@ sendwin(sig)
 
 #ifdef SIGINFO
     /* ARGSUSED */
 
 #ifdef SIGINFO
     /* ARGSUSED */
-    static SIG_FUNC_RET
+    SIG_FUNC_RET
 ayt(sig)
     int sig;
 {
 ayt(sig)
     int sig;
 {
@@ -1087,7 +1087,7 @@ process_rings(netin, netout, netex, ttyin, ttyout, poll)
        }
        settimer(didnetreceive);
 #else  /* !defined(SO_OOBINLINE) */
        }
        settimer(didnetreceive);
 #else  /* !defined(SO_OOBINLINE) */
-       c = recv(net, netiring.supply, canread, 0);
+       c = recv(net, (char *)netiring.supply, canread, 0);
 #endif /* !defined(SO_OOBINLINE) */
        if (c < 0 && errno == EWOULDBLOCK) {
            c = 0;
 #endif /* !defined(SO_OOBINLINE) */
        if (c < 0 && errno == EWOULDBLOCK) {
            c = 0;
index 77362b4..d63ec4a 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)telnet.c   8.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)telnet.c   8.2 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/types.h>
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -102,6 +102,11 @@ cc_t echoc;
 #define        TS_SE           8               /* looking for sub-option end */
 
 static int     telrcv_state;
 #define        TS_SE           8               /* looking for sub-option end */
 
 static int     telrcv_state;
+#ifdef OLD_ENVIRON
+unsigned char telopt_environ = TELOPT_NEW_ENVIRON;
+#else
+# define telopt_environ TELOPT_NEW_ENVIRON
+#endif
 
 jmp_buf        toplevel = { 0 };
 jmp_buf        peerdied;
 
 jmp_buf        toplevel = { 0 };
 jmp_buf        peerdied;
@@ -461,12 +466,26 @@ dooption(option)
            case TELOPT_LFLOW:          /* local flow control */
            case TELOPT_TTYPE:          /* terminal type option */
            case TELOPT_SGA:            /* no big deal */
            case TELOPT_LFLOW:          /* local flow control */
            case TELOPT_TTYPE:          /* terminal type option */
            case TELOPT_SGA:            /* no big deal */
-           case TELOPT_ENVIRON:        /* environment variable option */
 #ifdef ENCRYPTION
            case TELOPT_ENCRYPT:        /* encryption variable option */
 #endif /* ENCRYPTION */
                new_state_ok = 1;
                break;
 #ifdef ENCRYPTION
            case TELOPT_ENCRYPT:        /* encryption variable option */
 #endif /* ENCRYPTION */
                new_state_ok = 1;
                break;
+
+           case TELOPT_NEW_ENVIRON:    /* New environment variable option */
+#ifdef OLD_ENVIRON
+               if (my_state_is_will(TELOPT_OLD_ENVIRON))
+                       send_wont(TELOPT_OLD_ENVIRON, 1); /* turn off the old */
+               goto env_common;
+           case TELOPT_OLD_ENVIRON:    /* Old environment variable option */
+               if (my_state_is_will(TELOPT_NEW_ENVIRON))
+                       break;          /* Don't enable if new one is in use! */
+           env_common:
+               telopt_environ = option;
+#endif
+               new_state_ok = 1;
+               break;
+
 #if    defined(AUTHENTICATION)
            case TELOPT_AUTHENTICATION:
                if (autologin)
 #if    defined(AUTHENTICATION)
            case TELOPT_AUTHENTICATION:
                if (autologin)
@@ -540,6 +559,16 @@ dontoption(option)
            case TELOPT_LINEMODE:
                linemode = 0;   /* put us back to the default state */
                break;
            case TELOPT_LINEMODE:
                linemode = 0;   /* put us back to the default state */
                break;
+#ifdef OLD_ENVIRON
+           case TELOPT_NEW_ENVIRON:
+               /*
+                * The new environ option wasn't recognized, try
+                * the old one.
+                */
+               send_will(TELOPT_OLD_ENVIRON, 1);
+               telopt_environ = TELOPT_OLD_ENVIRON;
+               break;
+#endif
            }
            /* we always accept a DONT */
            set_my_want_state_wont(option);
            }
            /* we always accept a DONT */
            set_my_want_state_wont(option);
@@ -757,8 +786,10 @@ gettermname()
     static void
 suboption()
 {
     static void
 suboption()
 {
+    unsigned char subchar;
+
     printsub('<', subbuffer, SB_LEN()+2);
     printsub('<', subbuffer, SB_LEN()+2);
-    switch (SB_GET()) {
+    switch (subchar = SB_GET()) {
     case TELOPT_TTYPE:
        if (my_want_state_is_wont(TELOPT_TTYPE))
            return;
     case TELOPT_TTYPE:
        if (my_want_state_is_wont(TELOPT_TTYPE))
            return;
@@ -864,17 +895,20 @@ suboption()
        }
        break;
 
        }
        break;
 
-    case TELOPT_ENVIRON:
+#ifdef OLD_ENVIRON
+    case TELOPT_OLD_ENVIRON:
+#endif
+    case TELOPT_NEW_ENVIRON:
        if (SB_EOF())
            return;
        switch(SB_PEEK()) {
        case TELQUAL_IS:
        case TELQUAL_INFO:
        if (SB_EOF())
            return;
        switch(SB_PEEK()) {
        case TELQUAL_IS:
        case TELQUAL_INFO:
-           if (my_want_state_is_dont(TELOPT_ENVIRON))
+           if (my_want_state_is_dont(subchar))
                return;
            break;
        case TELQUAL_SEND:
                return;
            break;
        case TELQUAL_SEND:
-           if (my_want_state_is_wont(TELOPT_ENVIRON)) {
+           if (my_want_state_is_wont(subchar)) {
                return;
            }
            break;
                return;
            }
            break;
@@ -1426,7 +1460,8 @@ slc_update()
        return(need_update);
 }
 
        return(need_update);
 }
 
-#ifdef ENV_HACK
+#ifdef OLD_ENVIRON
+# ifdef        ENV_HACK
 /*
  * Earlier version of telnet/telnetd from the BSD code had
  * the definitions of VALUE and VAR reversed.  To ensure
 /*
  * Earlier version of telnet/telnetd from the BSD code had
  * the definitions of VALUE and VAR reversed.  To ensure
@@ -1437,11 +1472,12 @@ slc_update()
  * know what type of server it is.
  */
 int env_auto = 1;
  * know what type of server it is.
  */
 int env_auto = 1;
-int env_var = ENV_VALUE;
-int env_value = ENV_VAR;
-#else
-#define env_var ENV_VAR
-#define env_value ENV_VALUE
+int old_env_var = OLD_ENV_VAR;
+int old_env_value = OLD_ENV_VALUE;
+# else
+#  define old_env_var OLD_ENV_VAR
+#  define old_env_value OLD_ENV_VALUE
+# endif
 #endif
 
        void
 #endif
 
        void
@@ -1459,22 +1495,27 @@ env_opt(buf, len)
                        env_opt_add(NULL);
                } else for (i = 1; i < len; i++) {
                        switch (buf[i]&0xff) {
                        env_opt_add(NULL);
                } else for (i = 1; i < len; i++) {
                        switch (buf[i]&0xff) {
-                       case ENV_VAR:
-#ifdef ENV_HACK
-                               if (env_auto) {
-                                       /* The server has correct definitions */
-                                       env_var = ENV_VAR;
-                                       env_value = ENV_VALUE;
+#ifdef OLD_ENVIRON
+                       case OLD_ENV_VAR:
+# ifdef        ENV_HACK
+                               if (telopt_environ == TELOPT_OLD_ENVIRON
+                                   && env_auto) {
+                                       /* Server has the same definitions */
+                                       old_env_var = OLD_ENV_VAR;
+                                       old_env_value = OLD_ENV_VALUE;
                                }
                                /* FALL THROUGH */
                                }
                                /* FALL THROUGH */
-#endif
-                       case ENV_VALUE:
+# endif
+                       case OLD_ENV_VALUE:
                                /*
                                /*
-                                * Although ENV_VALUE is not legal, we will
+                                * Although OLD_ENV_VALUE is not legal, we will
                                 * still recognize it, just in case it is an
                                 * old server that has VAR & VALUE mixed up...
                                 */
                                /* FALL THROUGH */
                                 * still recognize it, just in case it is an
                                 * old server that has VAR & VALUE mixed up...
                                 */
                                /* FALL THROUGH */
+#else
+                       case NEW_ENV_VAR:
+#endif
                        case ENV_USERVAR:
                                if (ep) {
                                        *epc = 0;
                        case ENV_USERVAR:
                                if (ep) {
                                        *epc = 0;
@@ -1529,7 +1570,7 @@ env_opt_start()
        opt_replyend = opt_reply + OPT_REPLY_SIZE;
        *opt_replyp++ = IAC;
        *opt_replyp++ = SB;
        opt_replyend = opt_reply + OPT_REPLY_SIZE;
        *opt_replyp++ = IAC;
        *opt_replyp++ = SB;
-       *opt_replyp++ = TELOPT_ENVIRON;
+       *opt_replyp++ = telopt_environ;
        *opt_replyp++ = TELQUAL_IS;
 }
 
        *opt_replyp++ = TELQUAL_IS;
 }
 
@@ -1579,7 +1620,12 @@ env_opt_add(ep)
                opt_replyend = opt_reply + len;
        }
        if (opt_welldefined(ep))
                opt_replyend = opt_reply + len;
        }
        if (opt_welldefined(ep))
-               *opt_replyp++ = env_var;
+#ifdef OLD_ENVIRON
+               if (telopt_environ == TELOPT_OLD_ENVIRON)
+                       *opt_replyp++ = old_env_var;
+               else
+#endif
+                       *opt_replyp++ = NEW_ENV_VAR;
        else
                *opt_replyp++ = ENV_USERVAR;
        for (;;) {
        else
                *opt_replyp++ = ENV_USERVAR;
        for (;;) {
@@ -1588,8 +1634,8 @@ env_opt_add(ep)
                        case IAC:
                                *opt_replyp++ = IAC;
                                break;
                        case IAC:
                                *opt_replyp++ = IAC;
                                break;
-                       case ENV_VALUE:
-                       case ENV_VAR:
+                       case NEW_ENV_VAR:
+                       case NEW_ENV_VALUE:
                        case ENV_ESC:
                        case ENV_USERVAR:
                                *opt_replyp++ = ENV_ESC;
                        case ENV_ESC:
                        case ENV_USERVAR:
                                *opt_replyp++ = ENV_ESC;
@@ -1598,7 +1644,12 @@ env_opt_add(ep)
                        *opt_replyp++ = c;
                }
                if (ep = vp) {
                        *opt_replyp++ = c;
                }
                if (ep = vp) {
-                       *opt_replyp++ = env_value;
+#ifdef OLD_ENVIRON
+                       if (telopt_environ == TELOPT_OLD_ENVIRON)
+                               *opt_replyp++ = old_env_value;
+                       else
+#endif
+                               *opt_replyp++ = NEW_ENV_VALUE;
                        vp = NULL;
                } else
                        break;
                        vp = NULL;
                } else
                        break;
@@ -2200,7 +2251,7 @@ telnet(user)
        send_will(TELOPT_TSPEED, 1);
        send_will(TELOPT_LFLOW, 1);
        send_will(TELOPT_LINEMODE, 1);
        send_will(TELOPT_TSPEED, 1);
        send_will(TELOPT_LFLOW, 1);
        send_will(TELOPT_LINEMODE, 1);
-       send_will(TELOPT_ENVIRON, 1);
+       send_will(TELOPT_NEW_ENVIRON, 1);
        send_do(TELOPT_STATUS, 1);
        if (env_getvalue((unsigned char *)"DISPLAY"))
            send_will(TELOPT_XDISPLOC, 1);
        send_do(TELOPT_STATUS, 1);
        if (env_getvalue((unsigned char *)"DISPLAY"))
            send_will(TELOPT_XDISPLOC, 1);
index 6ca5ecd..a8c152b 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)utilities.c        8.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)utilities.c        8.2 (Berkeley) %G%";
 #endif /* not lint */
 
 #define        TELOPTS
 #endif /* not lint */
 
 #define        TELOPTS
@@ -177,10 +177,12 @@ printoption(direction, cmd, option)
                } else
                    fprintf(NetTrace, "%s %d %d", direction, cmd, option);
        }
                } else
                    fprintf(NetTrace, "%s %d %d", direction, cmd, option);
        }
-       if (NetTrace == stdout)
+       if (NetTrace == stdout) {
            fprintf(NetTrace, "\r\n");
            fprintf(NetTrace, "\r\n");
-       else
+           fflush(NetTrace);
+       } else {
            fprintf(NetTrace, "\n");
            fprintf(NetTrace, "\n");
+       }
        return;
 }
 
        return;
 }
 
@@ -302,7 +304,9 @@ printsub(direction, pointer, length)
            length -= 2;
        }
        if (length < 1) {
            length -= 2;
        }
        if (length < 1) {
-           fprintf(NetTrace, "(Empty suboption???)");
+           fprintf(NetTrace, "(Empty suboption??\?)");
+           if (NetTrace == stdout)
+               fflush(NetTrace);
            return;
        }
        switch (pointer[0]) {
            return;
        }
        switch (pointer[0]) {
@@ -324,7 +328,7 @@ printsub(direction, pointer, length)
        case TELOPT_TSPEED:
            fprintf(NetTrace, "TERMINAL-SPEED");
            if (length < 2) {
        case TELOPT_TSPEED:
            fprintf(NetTrace, "TERMINAL-SPEED");
            if (length < 2) {
-               fprintf(NetTrace, " (empty suboption???)");
+               fprintf(NetTrace, " (empty suboption??\?)");
                break;
            }
            switch (pointer[1]) {
                break;
            }
            switch (pointer[1]) {
@@ -346,7 +350,7 @@ printsub(direction, pointer, length)
        case TELOPT_LFLOW:
            fprintf(NetTrace, "TOGGLE-FLOW-CONTROL");
            if (length < 2) {
        case TELOPT_LFLOW:
            fprintf(NetTrace, "TOGGLE-FLOW-CONTROL");
            if (length < 2) {
-               fprintf(NetTrace, " (empty suboption???)");
+               fprintf(NetTrace, " (empty suboption??\?)");
                break;
            }
            switch (pointer[1]) {
                break;
            }
            switch (pointer[1]) {
@@ -368,7 +372,7 @@ printsub(direction, pointer, length)
        case TELOPT_NAWS:
            fprintf(NetTrace, "NAWS");
            if (length < 2) {
        case TELOPT_NAWS:
            fprintf(NetTrace, "NAWS");
            if (length < 2) {
-               fprintf(NetTrace, " (empty suboption???)");
+               fprintf(NetTrace, " (empty suboption??\?)");
                break;
            }
            if (length == 2) {
                break;
            }
            if (length == 2) {
@@ -393,7 +397,7 @@ printsub(direction, pointer, length)
        case TELOPT_AUTHENTICATION:
            fprintf(NetTrace, "AUTHENTICATION");
            if (length < 2) {
        case TELOPT_AUTHENTICATION:
            fprintf(NetTrace, "AUTHENTICATION");
            if (length < 2) {
-               fprintf(NetTrace, " (empty suboption???)");
+               fprintf(NetTrace, " (empty suboption??\?)");
                break;
            }
            switch (pointer[1]) {
                break;
            }
            switch (pointer[1]) {
@@ -406,7 +410,7 @@ printsub(direction, pointer, length)
                else
                    fprintf(NetTrace, "%d ", pointer[2]);
                if (length < 3) {
                else
                    fprintf(NetTrace, "%d ", pointer[2]);
                if (length < 3) {
-                   fprintf(NetTrace, "(partial suboption???)");
+                   fprintf(NetTrace, "(partial suboption??\?)");
                    break;
                }
                fprintf(NetTrace, "%s|%s",
                    break;
                }
                fprintf(NetTrace, "%s|%s",
@@ -428,7 +432,7 @@ printsub(direction, pointer, length)
                    else
                        fprintf(NetTrace, "%d ", pointer[i]);
                    if (++i >= length) {
                    else
                        fprintf(NetTrace, "%d ", pointer[i]);
                    if (++i >= length) {
-                       fprintf(NetTrace, "(partial suboption???)");
+                       fprintf(NetTrace, "(partial suboption??\?)");
                        break;
                    }
                    fprintf(NetTrace, "%s|%s ",
                        break;
                    }
                    fprintf(NetTrace, "%s|%s ",
@@ -460,7 +464,7 @@ printsub(direction, pointer, length)
        case TELOPT_ENCRYPT:
            fprintf(NetTrace, "ENCRYPT");
            if (length < 2) {
        case TELOPT_ENCRYPT:
            fprintf(NetTrace, "ENCRYPT");
            if (length < 2) {
-               fprintf(NetTrace, " (empty suboption???)");
+               fprintf(NetTrace, " (empty suboption??\?)");
                break;
            }
            switch (pointer[1]) {
                break;
            }
            switch (pointer[1]) {
@@ -485,7 +489,7 @@ printsub(direction, pointer, length)
                fprintf(NetTrace, " %s ", (pointer[1] == ENCRYPT_IS) ?
                                                        "IS" : "REPLY");
                if (length < 3) {
                fprintf(NetTrace, " %s ", (pointer[1] == ENCRYPT_IS) ?
                                                        "IS" : "REPLY");
                if (length < 3) {
-                   fprintf(NetTrace, " (partial suboption???)");
+                   fprintf(NetTrace, " (partial suboption??\?)");
                    break;
                }
                if (ENCTYPE_NAME_OK(pointer[2]))
                    break;
                }
                if (ENCTYPE_NAME_OK(pointer[2]))
@@ -530,7 +534,7 @@ printsub(direction, pointer, length)
        case TELOPT_LINEMODE:
            fprintf(NetTrace, "LINEMODE ");
            if (length < 2) {
        case TELOPT_LINEMODE:
            fprintf(NetTrace, "LINEMODE ");
            if (length < 2) {
-               fprintf(NetTrace, " (empty suboption???)");
+               fprintf(NetTrace, " (empty suboption??\?)");
                break;
            }
            switch (pointer[1]) {
                break;
            }
            switch (pointer[1]) {
@@ -547,7 +551,7 @@ printsub(direction, pointer, length)
                fprintf(NetTrace, "DONT ");
            common:
                if (length < 3) {
                fprintf(NetTrace, "DONT ");
            common:
                if (length < 3) {
-                   fprintf(NetTrace, "(no option???)");
+                   fprintf(NetTrace, "(no option??\?)");
                    break;
                }
                switch (pointer[2]) {
                    break;
                }
                switch (pointer[2]) {
@@ -600,7 +604,7 @@ printsub(direction, pointer, length)
            case LM_MODE:
                fprintf(NetTrace, "MODE ");
                if (length < 3) {
            case LM_MODE:
                fprintf(NetTrace, "MODE ");
                if (length < 3) {
-                   fprintf(NetTrace, "(no mode???)");
+                   fprintf(NetTrace, "(no mode??\?)");
                    break;
                }
                {
                    break;
                }
                {
@@ -721,8 +725,14 @@ printsub(direction, pointer, length)
            }
            break;
 
            }
            break;
 
-       case TELOPT_ENVIRON:
-           fprintf(NetTrace, "ENVIRON ");
+       case TELOPT_NEW_ENVIRON:
+           fprintf(NetTrace, "NEW-ENVIRON ");
+#ifdef OLD_ENVIRON
+           goto env_common1;
+       case TELOPT_OLD_ENVIRON:
+           fprintf(NetTrace, "OLD-ENVIRON");
+       env_common1:
+#endif
            switch (pointer[1]) {
            case TELQUAL_IS:
                fprintf(NetTrace, "IS ");
            switch (pointer[1]) {
            case TELQUAL_IS:
                fprintf(NetTrace, "IS ");
@@ -735,28 +745,40 @@ printsub(direction, pointer, length)
            env_common:
                {
                    register int noquote = 2;
            env_common:
                {
                    register int noquote = 2;
-#ifdef ENV_HACK
-                   extern int env_var, env_value;
+#if defined(ENV_HACK) && defined(OLD_ENVIRON)
+                   extern int old_env_var, old_env_value;
 #endif
                    for (i = 2; i < length; i++ ) {
                        switch (pointer[i]) {
 #endif
                    for (i = 2; i < length; i++ ) {
                        switch (pointer[i]) {
-                       case ENV_VAR:
-#ifdef ENV_HACK
-                           if (env_var == ENV_VALUE)
-                               fprintf(NetTrace, "\" (VALUE) " + noquote);
-                           else
-#endif
-                           fprintf(NetTrace, "\" VAR " + noquote);
+                       case NEW_ENV_VALUE:
+#ifdef OLD_ENVIRON
+                    /* case NEW_ENV_OVAR: */
+                           if (pointer[0] == TELOPT_OLD_ENVIRON) {
+# ifdef        ENV_HACK
+                               if (old_env_var == OLD_ENV_VALUE)
+                                   fprintf(NetTrace, "\" (VALUE) " + noquote);
+                               else
+# endif
+                                   fprintf(NetTrace, "\" VAR " + noquote);
+                           } else
+#endif /* OLD_ENVIRON */
+                               fprintf(NetTrace, "\" VALUE " + noquote);
                            noquote = 2;
                            break;
 
                            noquote = 2;
                            break;
 
-                       case ENV_VALUE:
-#ifdef ENV_HACK
-                           if (env_value == ENV_VAR)
-                               fprintf(NetTrace, "\" (VAR) " + noquote);
-                           else
-#endif
-                           fprintf(NetTrace, "\" VALUE " + noquote);
+                       case NEW_ENV_VAR:
+#ifdef OLD_ENVIRON
+                    /* case OLD_ENV_VALUE: */
+                           if (pointer[0] == TELOPT_OLD_ENVIRON) {
+# ifdef        ENV_HACK
+                               if (old_env_value == OLD_ENV_VAR)
+                                   fprintf(NetTrace, "\" (VAR) " + noquote);
+                               else
+# endif
+                                   fprintf(NetTrace, "\" VALUE " + noquote);
+                           } else
+#endif /* OLD_ENVIRON */
+                               fprintf(NetTrace, "\" VAR " + noquote);
                            noquote = 2;
                            break;
 
                            noquote = 2;
                            break;
 
@@ -808,6 +830,8 @@ printsub(direction, pointer, length)
            else
                fprintf(NetTrace, "\n");
        }
            else
                fprintf(NetTrace, "\n");
        }
+       if (NetTrace == stdout)
+           fflush(NetTrace);
     }
 }
 
     }
 }