=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/telnet/telnet.c,v retrieving revision 1.14 retrieving revision 1.15 diff -c -r1.14 -r1.15 *** src/usr.bin/telnet/telnet.c 2002/02/17 17:20:49 1.14 --- src/usr.bin/telnet/telnet.c 2002/03/22 13:49:28 1.15 *************** *** 1,4 **** ! /* $OpenBSD: telnet.c,v 1.14 2002/02/17 17:20:49 millert Exp $ */ /* $NetBSD: telnet.c,v 1.7 1996/02/28 21:04:15 thorpej Exp $ */ /* --- 1,4 ---- ! /* $OpenBSD: telnet.c,v 1.15 2002/03/22 13:49:28 hin Exp $ */ /* $NetBSD: telnet.c,v 1.7 1996/02/28 21:04:15 thorpej Exp $ */ /* *************** *** 76,81 **** --- 76,82 ---- askedSGA = 0, /* We have talked about suppress go ahead */ #endif /* defined(TN3270) */ telnetport, + wantencryption = 0, SYNCHing, /* we are in TELNET SYNCH mode */ flushout, /* flush output */ autoflush = 0, /* flush output when interrupting? */ *************** *** 91,96 **** --- 92,99 ---- char *prompt = 0; + int scheduler_lockout_tty = 0; + cc_t escape; cc_t rlogin; #ifdef KLUDGELINEMODE *************** *** 2110,2115 **** --- 2113,2123 ---- netex = !SYNCHing; /* If we have seen a signal recently, reset things */ + + if (scheduler_lockout_tty) { + ttyin = ttyout = 0; + } + # if defined(TN3270) && defined(unix) if (HaveInput) { HaveInput = 0; *************** *** 2159,2164 **** --- 2167,2174 ---- telnet(user) char *user; { + int printed_encrypt = 0; + sys_telnet_init(); #if defined(AUTHENTICATION) || defined(ENCRYPTION) *************** *** 2198,2203 **** --- 2208,2275 ---- } # endif /* !defined(TN3270) */ + #ifdef ENCRYPTION + /* + * Note: we assume a tie to the authentication option here. This + * is necessary so that authentication fails, we don't spin + * forever. + */ + if (wantencryption) { + extern int auth_has_failed; + time_t timeout = time(0) + 60; + + send_do(TELOPT_ENCRYPT, 1); + send_will(TELOPT_ENCRYPT, 1); + while (1) { + if (my_want_state_is_wont(TELOPT_AUTHENTICATION)) { + if (wantencryption == -1) { + break; + } else { + printf("\nServer refused to negotiate authentication,"); + printf(" which is required for encryption.\n"); + Exit(1); + } + } + if (auth_has_failed) { + printf("\nAuthentication negotation has failed,"); + printf(" which is required for encryption.\n"); + Exit(1); + } + if (my_want_state_is_dont(TELOPT_ENCRYPT) || + my_want_state_is_wont(TELOPT_ENCRYPT)) { + printf("\nServer refused to negotiate encryption.\n"); + Exit(1); + } + if (encrypt_is_encrypting()) + break; + if (time(0) > timeout) { + printf("\nEncryption could not be enabled.\n"); + Exit(1); + } + if (printed_encrypt == 0) { + printed_encrypt = 1; + printf("Waiting for encryption to be negotiated...\n"); + /* + * Turn on MODE_TRAPSIG and then turn off localchars + * so that ^C will cause telnet to exit. + */ + TerminalNewMode(getconnmode()|MODE_TRAPSIG); + intr_waiting = 1; + } + if (intr_happened) { + printf("\nUser interrupt.\n"); + Exit(1); + } + telnet_spin(); + } + if (printed_encrypt) { + printf("Encryption negotiated.\n"); + intr_waiting = 0; + setconnmode(0); + } + } + #endif + # if !defined(TN3270) for (;;) { int schedValue;