char * telnet_gets (char *prompt, char *result, int length, int echo) { # if !HAVE_DECL_GETPASS extern char *getpass (); # endif extern int globalmode; int om = globalmode; char *res; TerminalNewMode (-1); if (echo) { printf ("%s", prompt); res = fgets (result, length, stdin); } else { res = getpass (prompt); if (res) { strncpy (result, res, length); memset (res, 0, strlen (res)); res = result; } } TerminalNewMode (om); return (res); }
void setconnmode (int force) { #ifdef ENCRYPTION static int enc_passwd = 0; #endif /* ENCRYPTION */ register int newmode; newmode = getconnmode () | (force ? MODE_FORCE : 0); TerminalNewMode (newmode); #ifdef ENCRYPTION if ((newmode & (MODE_ECHO | MODE_EDIT)) == MODE_EDIT) { if (my_want_state_is_will (TELOPT_ENCRYPT) && (enc_passwd == 0) && !encrypt_output) { encrypt_request_start (0, 0); enc_passwd = 1; } } else { if (enc_passwd) { encrypt_request_end (); enc_passwd = 0; } } #endif /* ENCRYPTION */ }
void setconnmode(int force) { int newmode; newmode = getconnmode()|(force?MODE_FORCE:0); TerminalNewMode(newmode); }
char * telnet_gets(char *prompt, char *result, int length, int echo) { int om = globalmode; char *res; TerminalNewMode(-1); if (echo) { printf("%s", prompt); res = fgets(result, length, stdin); } else if ((res = getpass(prompt))) { strlcpy(result, res, length); res = result; } TerminalNewMode(om); return(res); }
void setcommandmode (void) { TerminalNewMode (-1); }
/* * Select from tty and network... */ void my_telnet(char *user) { int printed_encrypt = 0; sys_telnet_init(); #if defined(AUTHENTICATION) || defined(ENCRYPTION) { static char local_host[256] = { 0 }; if (!local_host[0]) { /* XXX - should be k_gethostname? */ gethostname(local_host, sizeof(local_host)); local_host[sizeof(local_host)-1] = 0; } auth_encrypt_init(local_host, hostname, "TELNET", 0); auth_encrypt_user(user); } #endif if (telnetport) { #if defined(AUTHENTICATION) if (autologin) send_will(TELOPT_AUTHENTICATION, 1); #endif #if defined(ENCRYPTION) send_do(TELOPT_ENCRYPT, 1); send_will(TELOPT_ENCRYPT, 1); #endif send_do(TELOPT_SGA, 1); send_will(TELOPT_TTYPE, 1); send_will(TELOPT_NAWS, 1); send_will(TELOPT_TSPEED, 1); send_will(TELOPT_LFLOW, 1); send_will(TELOPT_LINEMODE, 1); send_will(TELOPT_NEW_ENVIRON, 1); send_do(TELOPT_STATUS, 1); if (env_getvalue((unsigned char *)"DISPLAY")) send_will(TELOPT_XDISPLOC, 1); if (binary) tel_enter_binary(binary); } #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 (telnetport && wantencryption) { 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,\n"); printf("which is required for encryption.\n"); Exit(1); } } if (auth_has_failed) { printf("\nAuthentication negotiation has failed,\n"); 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); } if (telnet_spin()) { printf("\nServer disconnected.\n"); Exit(1); } } if (printed_encrypt) { printf("Encryption negotiated.\n"); intr_waiting = 0; setconnmode(0); } } #endif for (;;) { int schedValue; while ((schedValue = Scheduler(0)) != 0) { if (schedValue == -1) { setcommandmode(); return; } } if (Scheduler(1) == -1) { setcommandmode(); return; } } }