X-Git-Url: https://git.subgeniuskitty.com/unix-history/.git/blobdiff_plain/1d23bbc45e0226cc04408ae43df4ed2e553d180d..535c3003319a5eacf4664575c25f31986233cc2e:/usr/src/libexec/telnetd/state.c diff --git a/usr/src/libexec/telnetd/state.c b/usr/src/libexec/telnetd/state.c index 5314a4a180..be507ac07b 100644 --- a/usr/src/libexec/telnetd/state.c +++ b/usr/src/libexec/telnetd/state.c @@ -1,12 +1,12 @@ /* - * Copyright (c) 1989 Regents of the University of California. - * All rights reserved. + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. * * %sccs.include.redist.c% */ #ifndef lint -static char sccsid[] = "@(#)state.c 5.13 (Berkeley) %G%"; +static char sccsid[] = "@(#)state.c 8.4 (Berkeley) %G%"; #endif /* not lint */ #include "telnetd.h" @@ -14,10 +14,10 @@ static char sccsid[] = "@(#)state.c 5.13 (Berkeley) %G%"; #include #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; /* @@ -68,10 +68,10 @@ telrcv() if ((&ptyobuf[BUFSIZ] - pfrontp) < 2) break; c = *netip++ & 0377, ncc--; -#if defined(ENCRYPTION) +#ifdef ENCRYPTION if (decrypt_input) c = (*decrypt_input)(c); -#endif +#endif /* ENCRYPTION */ switch (state) { case TS_CR: @@ -100,10 +100,10 @@ telrcv() */ if ((c == '\r') && his_state_is_wont(TELOPT_BINARY)) { int nc = *netip; -#if defined(ENCRYPTION) +#ifdef ENCRYPTION if (decrypt_input) nc = (*decrypt_input)(nc & 0xff); -#endif +#endif /* ENCRYPTION */ #ifdef LINEMODE /* * If we are operating in linemode, @@ -116,10 +116,10 @@ telrcv() } else #endif { -#if defined(ENCRYPTION) +#ifdef ENCRYPTION if (decrypt_input) (void)(*decrypt_input)(-1); -#endif +#endif /* ENCRYPTION */ state = TS_CR; } } @@ -426,7 +426,7 @@ send_do(option, init) 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)); @@ -440,7 +440,7 @@ extern void doclientstat(); #endif #ifdef ENCRYPTION extern void encrypt_send_support(); -#endif +#endif /* ENCRYPTION */ void willoption(option) @@ -529,7 +529,8 @@ willoption(option) case TELOPT_NAWS: case TELOPT_TSPEED: case TELOPT_XDISPLOC: - case TELOPT_ENVIRON: + case TELOPT_NEW_ENVIRON: + case TELOPT_OLD_ENVIRON: changeok++; break; @@ -558,7 +559,7 @@ willoption(option) func = encrypt_send_support; changeok++; break; -#endif +#endif /* ENCRYPTION */ default: break; @@ -622,7 +623,7 @@ willoption(option) case TELOPT_ENCRYPT: func = encrypt_send_support; break; -#endif +#endif /* ENCRYPTION */ case TELOPT_LFLOW: func = flowstat; break; @@ -645,7 +646,7 @@ send_dont(option, init) 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)); @@ -689,7 +690,6 @@ wontoption(option) */ if (lmodetype != REAL_LINEMODE) break; - lmodetype = KLUDGE_LINEMODE; # endif /* KLUDGELINEMODE */ clientstat(TELOPT_LINEMODE, WONT, 0); break; @@ -743,7 +743,11 @@ wontoption(option) settimer(xdisplocsubopt); break; - case TELOPT_ENVIRON: + case TELOPT_OLD_ENVIRON: + settimer(oenvironsubopt); + break; + + case TELOPT_NEW_ENVIRON: settimer(environsubopt); break; @@ -791,7 +795,7 @@ send_will(option, init) 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)); @@ -909,18 +913,21 @@ dooption(option) /* NOT REACHED */ break; -#if defined(ENCRYPTION) +#ifdef ENCRYPTION case TELOPT_ENCRYPT: changeok++; break; -#endif +#endif /* ENCRYPTION */ case TELOPT_LINEMODE: case TELOPT_TTYPE: case TELOPT_NAWS: 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; } @@ -947,7 +954,7 @@ send_wont(option, init) 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)); @@ -1039,11 +1046,11 @@ dontoption(option) } /* 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 */ -# 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 */ /* @@ -1222,25 +1229,42 @@ suboption() 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(); - 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; + } +#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 - /* - * 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; @@ -1262,29 +1286,29 @@ suboption() 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++; - last = ENV_VAR; + last = OLD_ENV_VAR; 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++; - 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) { - 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; @@ -1299,10 +1323,10 @@ suboption() 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 @@ -1316,38 +1340,31 @@ suboption() * If we got exactly as many VALUEs as VARs and * USERVARs, the client has the same definitions. * - * If we get more VARs than the total number of VALUEs - * and USERVARs, the client has the same definitions. - * * If we got exactly as many VARs as VALUEs and * USERVARS, the client has reversed definitions. - * - * If we get more VALUEs than the total number of VARs - * and USERVARs, the client has reversed definitions */ - if ((got_uservar + got_var == got_value) || - (got_var > got_uservar + got_value)) { - env_var_ok: - env_var = ENV_VAR; - env_value = ENV_VALUE; - } else if ((got_uservar + got_value == got_var) || - (got_value > got_uservar + got_var)) { - env_var_wrong: - env_var = ENV_VALUE; - env_value = ENV_VAR; + if (got_uservar + got_var == got_value) { + env_ovar_ok: + env_ovar = OLD_ENV_VAR; + env_ovalue = OLD_ENV_VALUE; + } else if (got_uservar + got_value == got_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);}); } - } - SB_RESTORE(); + } + SB_RESTORE(); #endif - while (!SB_EOF()) { + while (!SB_EOF()) { c = SB_GET(); - if ((c == env_var) || (c == ENV_USERVAR)) + if ((c == env_ovar) || (c == ENV_USERVAR)) break; + } } if (SB_EOF()) @@ -1358,20 +1375,20 @@ suboption() 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) { - case ENV_VALUE: + case NEW_ENV_VALUE: *cp = '\0'; cp = valp = (char *)subpointer; break; - case ENV_VAR: + case NEW_ENV_VAR: case ENV_USERVAR: *cp = '\0'; if (valp) @@ -1398,7 +1415,7 @@ suboption() else unsetenv(varp); break; - } /* end of case TELOPT_ENVIRON */ + } /* end of case TELOPT_NEW_ENVIRON */ #if defined(AUTHENTICATION) case TELOPT_AUTHENTICATION: if (SB_EOF()) @@ -1420,7 +1437,7 @@ suboption() } break; #endif -#if defined(ENCRYPTION) +#ifdef ENCRYPTION case TELOPT_ENCRYPT: if (SB_EOF()) break; @@ -1462,7 +1479,7 @@ suboption() break; } break; -#endif +#endif /* ENCRYPTION */ default: break; @@ -1476,8 +1493,8 @@ doclientstat() clientstat(TELOPT_LINEMODE, WILL, 0); } -#define ADD(c) *ncp++ = c; -#define ADD_DATA(c) { *ncp++ = c; if (c == SE) *ncp++ = c; } +#define ADD(c) *ncp++ = c +#define ADD_DATA(c) { *ncp++ = c; if (c == SE || c == IAC) *ncp++ = c; } void send_status() { @@ -1502,18 +1519,14 @@ send_status() * 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 (i == IAC) - ADD(IAC); } if (his_want_state_is_will(i)) { ADD(DO); ADD_DATA(i); - if (i == IAC) - ADD(IAC); } } @@ -1528,15 +1541,14 @@ send_status() ADD(SE); if (restartany >= 0) { - ADD(SB) + ADD(SB); ADD(TELOPT_LFLOW); if (restartany) { ADD(LFLOW_RESTART_ANY); } else { ADD(LFLOW_RESTART_XON); } - ADD(SE) - ADD(SB); + ADD(SE); } } @@ -1549,8 +1561,6 @@ send_status() ADD(TELOPT_LINEMODE); ADD(LM_MODE); ADD_DATA(editmode); - if (editmode == IAC) - ADD(IAC); ADD(SE); ADD(SB);