📄 state.c
字号:
/* * See comments below for more info. */ not42 = 0; /* looks like a 4.2 system */ break; case TELOPT_TM: /* * This telnetd implementation does not really * support timing marks, it just uses them to * support the kludge linemode stuff. If we * receive a will or wont TM in response to our * do TM request that may have been sent to * determine kludge linemode support, process * it, otherwise TM should get a negative * response back. */ /* * Handle the linemode kludge stuff. * If we are not currently supporting any * linemode at all, then we assume that this * is the client telling us to use kludge * linemode in response to our query. Set the * linemode type that is to be supported, note * that the client wishes to use linemode, and * eat the will TM as though it never arrived. */ if (lmodetype < KLUDGE_LINEMODE) { lmodetype = KLUDGE_LINEMODE; clientstat (TELOPT_LINEMODE, WILL, 0); send_wont (TELOPT_SGA, 1); } else if (lmodetype == NO_AUTOKLUDGE) lmodetype = KLUDGE_OK; /* * We never respond to a WILL TM, and * we leave the state WONT. */ return; case TELOPT_LFLOW: /* * If we are going to support flow control * option, then don't worry peer that we can't * change the flow control characters. */ slctab[SLC_XON].defset.flag &= ~SLC_LEVELBITS; slctab[SLC_XON].defset.flag |= SLC_DEFAULT; slctab[SLC_XOFF].defset.flag &= ~SLC_LEVELBITS; slctab[SLC_XOFF].defset.flag |= SLC_DEFAULT; case TELOPT_TTYPE: case TELOPT_SGA: case TELOPT_NAWS: case TELOPT_TSPEED: case TELOPT_XDISPLOC: case TELOPT_NEW_ENVIRON: case TELOPT_OLD_ENVIRON: changeok++; break; case TELOPT_LINEMODE: /* * Note client's desire to use linemode. */ lmodetype = REAL_LINEMODE; func = doclientstat; changeok++; break;#ifdef AUTHENTICATION case TELOPT_AUTHENTICATION: func = auth_request; changeok++; break;#endif#ifdef ENCRYPTION case TELOPT_ENCRYPT: func = encrypt_send_support; changeok++; break;#endif /* ENCRYPTION */ default: break; } if (changeok) { set_his_want_state_will (option); send_do (option, 0); } else { do_dont_resp[option]++; send_dont (option, 0); } } else { /* * Option processing that should happen when * we receive conformation of a change in * state that we had requested. */ switch (option) { case TELOPT_ECHO: not42 = 0; /* looks like a 4.2 system */ /* * Egads, he responded "WILL ECHO". Turn * it off right now! */ send_dont (option, 1); /* * "WILL ECHO". Kludge upon kludge! * A 4.2 client is now echoing user input at * the tty. This is probably undesireable and * it should be stopped. The client will * respond WONT TM to the DO TM that we send to * check for kludge linemode. When the WONT TM * arrives, linemode will be turned off and a * change propogated to the pty. This change * will cause us to process the new pty state * in localstat(), which will notice that * linemode is off and send a WILL ECHO * so that we are properly in character mode and * all is well. */ break; case TELOPT_LINEMODE: /* * Note client's desire to use linemode. */ lmodetype = REAL_LINEMODE; func = doclientstat; break;#ifdef AUTHENTICATION case TELOPT_AUTHENTICATION: func = auth_request; break;#endif#ifdef ENCRYPTION case TELOPT_ENCRYPT: func = encrypt_send_support; break;#endif /* ENCRYPTION */ case TELOPT_LFLOW: func = flowstat; break; } } } set_his_state_will (option); if (func) (*func) ();} /* end of willoption */voidsend_dont (int option, int init){ if (init) { if ((do_dont_resp[option] == 0 && his_state_is_wont (option)) || his_want_state_is_wont (option)) return; set_his_want_state_wont (option); do_dont_resp[option]++; } net_output_data (dont, option); DEBUG(debug_options, 1, printoption ("td: send dont", option));}voidwontoption (int option){ /* * Process client input. */ DEBUG(debug_options, 1, printoption ("td: recv wont", option)); if (do_dont_resp[option]) { do_dont_resp[option]--; if (do_dont_resp[option] && his_state_is_wont (option)) do_dont_resp[option]--; } if (do_dont_resp[option] == 0) { if (his_want_state_is_will (option)) { /* it is always ok to change to negative state */ switch (option) { case TELOPT_ECHO: not42 = 1; /* doesn't seem to be a 4.2 system */ break; case TELOPT_BINARY: init_termbuf (); tty_binaryin (0); set_termbuf (); break; case TELOPT_LINEMODE: /* * If real linemode is supported, then client is * asking to turn linemode off. */ if (lmodetype != REAL_LINEMODE) break; clientstat (TELOPT_LINEMODE, WONT, 0); break; case TELOPT_TM: /* * If we get a WONT TM, and had sent a DO TM, * don't respond with a DONT TM, just leave it * as is. Short circut the state machine to * achive this. */ set_his_want_state_wont (TELOPT_TM); return; case TELOPT_LFLOW: /* * If we are not going to support flow control * option, then let peer know that we can't * change the flow control characters. */ slctab[SLC_XON].defset.flag &= ~SLC_LEVELBITS; slctab[SLC_XON].defset.flag |= SLC_CANTCHANGE; slctab[SLC_XOFF].defset.flag &= ~SLC_LEVELBITS; slctab[SLC_XOFF].defset.flag |= SLC_CANTCHANGE; break;#if defined(AUTHENTICATION) case TELOPT_AUTHENTICATION: auth_finished (0, AUTH_REJECT); break;#endif /* * For options that we might spin waiting for * sub-negotiation, if the client turns off the * option rather than responding to the request, * we have to treat it here as if we got a response * to the sub-negotiation, (by updating the timers) * so that we'll break out of the loop. */ case TELOPT_TTYPE: settimer (ttypesubopt); break; case TELOPT_TSPEED: settimer (tspeedsubopt); break; case TELOPT_XDISPLOC: settimer (xdisplocsubopt); break; case TELOPT_OLD_ENVIRON: settimer (oenvironsubopt); break; case TELOPT_NEW_ENVIRON: settimer (environsubopt); break; default: break; } set_his_want_state_wont (option); if (his_state_is_will (option)) send_dont (option, 0); } else { switch (option) { case TELOPT_TM: if (lmodetype < NO_AUTOKLUDGE) { lmodetype = NO_LINEMODE; clientstat (TELOPT_LINEMODE, WONT, 0); send_will (TELOPT_SGA, 1); send_will (TELOPT_ECHO, 1); } break;#if defined(AUTHENTICATION) case TELOPT_AUTHENTICATION: auth_finished (0, AUTH_REJECT); break;#endif default: break; } } } set_his_state_wont (option);} /* end of wontoption */voidsend_will (int option, int init){ if (init) { if ((will_wont_resp[option] == 0 && my_state_is_will (option)) || my_want_state_is_will (option)) return; set_my_want_state_will (option); will_wont_resp[option]++; } net_output_data (will, option); DEBUG(debug_options, 1,printoption ("td: send will", option));}voiddooption (int option){ int changeok = 0; /* * Process client input. */ DEBUG(debug_options, 1, printoption ("td: recv do", option)); if (will_wont_resp[option]) { will_wont_resp[option]--; if (will_wont_resp[option] && my_state_is_will (option)) will_wont_resp[option]--; } if ((will_wont_resp[option] == 0) && (my_want_state_is_wont (option))) { switch (option) { case TELOPT_ECHO: if (lmodetype == NO_LINEMODE) { init_termbuf (); tty_setecho (1); set_termbuf (); } changeok++; break; case TELOPT_BINARY: init_termbuf (); tty_binaryout (1); set_termbuf (); changeok++; break; case TELOPT_SGA: /* * If kludge linemode is in use, then we must * process an incoming do SGA for linemode * purposes. */ if (lmodetype == KLUDGE_LINEMODE) { /* * Receipt of "do SGA" in kludge * linemode is the peer asking us to * turn off linemode. Make note of * the request. */ clientstat (TELOPT_LINEMODE, WONT, 0); /* * If linemode did not get turned off * then don't tell peer that we did. * Breaking here forces a wont SGA to * be returned. */ if (linemode) break; } changeok++; break; case TELOPT_STATUS: changeok++; break; case TELOPT_TM: /* * Special case for TM. We send a WILL, but * pretend we sent a WONT. */ send_will (option, 0); set_my_want_state_wont (option); set_my_state_wont (option); return; case TELOPT_LOGOUT: /* * When we get a LOGOUT option, respond * with a WILL LOGOUT, make sure that * it gets written out to the network, * and then just go away... */ set_my_want_state_will (TELOPT_LOGOUT); send_will (TELOPT_LOGOUT, 0); set_my_state_will (TELOPT_LOGOUT); netflush (); cleanup (0); /* NOT REACHED */ break;#ifdef ENCRYPTION case TELOPT_ENCRYPT: changeok++; break;#endif /* ENCRYPTION */ case TELOPT_LINEMODE: case TELOPT_TTYPE: case TELOPT_NAWS: case TELOPT_TSPEED: case TELOPT_LFLOW: case TELOPT_XDISPLOC:#ifdef TELOPT_ENVIRON case TELOPT_NEW_ENVIRON:#endif case TELOPT_OLD_ENVIRON: default: break; } if (changeok) { set_my_want_state_will (option); send_will (option, 0); } else { will_wont_resp[option]++; send_wont (option, 0); } } set_my_state_will (option);} /* end of dooption */voidsend_wont (int option, int init){ if (init) { if ((will_wont_resp[option] == 0 && my_state_is_wont (option)) || my_want_state_is_wont (option)) return; set_my_want_state_wont (option); will_wont_resp[option]++; } net_output_data (wont, option); DEBUG(debug_options, 1, printoption ("td: send wont", option));}voiddontoption (int option){ /* * Process client input. */ DEBUG(debug_options, 1,printoption ("td: recv dont", option)); if (will_wont_resp[option]) { will_wont_resp[option]--; if (will_wont_resp[option] && my_state_is_wont (option)) will_wont_resp[option]--; } if ((will_wont_resp[option] == 0) && (my_want_state_is_will (option))) { switch (option) { case TELOPT_BINARY: init_termbuf (); tty_binaryout (0); set_termbuf (); break; case TELOPT_ECHO: /* we should stop echoing */ if ((lmodetype != REAL_LINEMODE) && (lmodetype != KLUDGE_LINEMODE)) { init_termbuf (); tty_setecho (0); set_termbuf (); } break; case TELOPT_SGA: /* * If kludge linemode is in use, then we * must process an incoming do SGA for * linemode purposes. */ if ((lmodetype == KLUDGE_LINEMODE) || (lmodetype == KLUDGE_OK)) { /* * The client is asking us to turn * linemode on. */ lmodetype = KLUDGE_LINEMODE; clientstat (TELOPT_LINEMODE, WILL, 0); /* * If we did not turn line mode on, * then what do we say? Will SGA? * This violates design of telnet. * Gross. Very Gross. */ } break; default: break; } set_my_want_state_wont (option); if (my_state_is_will (option)) send_wont (option, 0); } set_my_state_wont (option);} /* end of dontoption */#ifdef ENV_HACKint env_ovar = -1;int env_ovalue = -1;#else /* ENV_HACK */#define env_ovar OLD_ENV_VAR#define env_ovalue OLD_ENV_VALUE#endif /* ENV_HACK *//* * suboption() * * Look at the sub-option buffer, and try to be helpful to the other * side. * * Currently we recognize: * * Terminal type is * Linemode * Window size * Terminal speed */voidsuboption (){ register int subchar;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -