diff -r -c /var/tmp/krb5-1.2.2/src/appl/telnet/telnetd/authenc.c ./authenc.c *** /var/tmp/krb5-1.2.2/src/appl/telnet/telnetd/authenc.c Wed Feb 28 17:06:51 2001 --- ./authenc.c Thu Jul 26 23:19:26 2001 *************** *** 37,56 **** #include "telnetd.h" #include ! int net_write(str, len) unsigned char *str; int len; { ! if (nfrontp + len < netobuf + BUFSIZ) { ! memcpy((void *)nfrontp, (void *)str, len); ! nfrontp += len; ! return(len); ! } ! return(0); } ! void net_encrypt() { #ifdef ENCRYPTION --- 37,53 ---- #include "telnetd.h" #include ! int net_write(str, len) unsigned char *str; int len; { ! if (len < 0) ! return 0; ! return netwrite(str, len); } ! void net_encrypt() { #ifdef ENCRYPTION *************** *** 87,93 **** return((char *)0); } #endif /* defined(AUTHENTICATION) || defined(ENCRYPTION) */ - - - - --- 84,86 ---- diff -r -c /var/tmp/krb5-1.2.2/src/appl/telnet/telnetd/configure ./configure *** /var/tmp/krb5-1.2.2/src/appl/telnet/telnetd/configure Wed Feb 28 17:08:49 2001 --- ./configure Mon Jul 30 17:04:52 2001 *************** *** 2149,2155 **** fi done ! for ac_func in gettosbyname do echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 echo "configure:2156: checking for $ac_func" >&5 --- 2149,2155 ---- fi done ! for ac_func in gettosbyname vsnprintf do echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 echo "configure:2156: checking for $ac_func" >&5 diff -r -c /var/tmp/krb5-1.2.2/src/appl/telnet/telnetd/configure.in ./configure.in *** /var/tmp/krb5-1.2.2/src/appl/telnet/telnetd/configure.in Wed Feb 28 17:06:51 2001 --- ./configure.in Mon Jul 30 17:03:20 2001 *************** *** 23,29 **** fi AC_HEADER_TIME AC_CHECK_HEADERS(string.h arpa/nameser.h utmp.h sys/time.h sys/tty.h sac.h sys/ptyvar.h sys/filio.h sys/stream.h sys/utsname.h) ! AC_CHECK_FUNCS(gettosbyname) dnl Make our operating system-specific security checks and definitions for dnl login. dnl --- 23,29 ---- fi AC_HEADER_TIME AC_CHECK_HEADERS(string.h arpa/nameser.h utmp.h sys/time.h sys/tty.h sac.h sys/ptyvar.h sys/filio.h sys/stream.h sys/utsname.h) ! AC_CHECK_FUNCS(gettosbyname vsnprintf) dnl Make our operating system-specific security checks and definitions for dnl login. dnl diff -r -c /var/tmp/krb5-1.2.2/src/appl/telnet/telnetd/ext.h ./ext.h *** /var/tmp/krb5-1.2.2/src/appl/telnet/telnetd/ext.h Wed Feb 28 17:06:51 2001 --- ./ext.h Mon Jul 30 17:05:20 2001 *************** *** 187,194 **** tty_setsofttab P((int)), tty_tspeed P((int)), willoption P((int)), ! wontoption P((int)), ! writenet P((unsigned char *, int)); #ifdef ENCRYPTION extern char *nclearto; --- 187,199 ---- tty_setsofttab P((int)), tty_tspeed P((int)), willoption P((int)), ! wontoption P((int)); ! ! extern void netprintf P((const char *, ...)); ! extern void netprintf_urg P((const char *fmt, ...)); ! extern void netprintf_noflush P((const char *fmt, ...)); ! extern int netwrite P((const char *, size_t)); ! extern void netputs P((const char *)); #ifdef ENCRYPTION extern char *nclearto; diff -r -c /var/tmp/krb5-1.2.2/src/appl/telnet/telnetd/slc.c ./slc.c *** /var/tmp/krb5-1.2.2/src/appl/telnet/telnetd/slc.c Wed Feb 28 17:06:51 2001 --- ./slc.c Wed Jul 25 19:28:18 2001 *************** *** 198,204 **** (void) sprintf((char *)slcptr, "%c%c", IAC, SE); slcptr += 2; len = slcptr - slcbuf; ! writenet(slcbuf, len); netflush(); /* force it out immediately */ DIAG(TD_OPTIONS, printsub('>', slcbuf+2, len-2);); } --- 198,204 ---- (void) sprintf((char *)slcptr, "%c%c", IAC, SE); slcptr += 2; len = slcptr - slcbuf; ! netwrite(slcbuf, len); netflush(); /* force it out immediately */ DIAG(TD_OPTIONS, printsub('>', slcbuf+2, len-2);); } diff -r -c /var/tmp/krb5-1.2.2/src/appl/telnet/telnetd/state.c ./state.c *** /var/tmp/krb5-1.2.2/src/appl/telnet/telnetd/state.c Wed Feb 28 17:06:51 2001 --- ./state.c Fri Jul 27 09:24:47 2001 *************** *** 86,92 **** if (!auth_negotiated) { static char *error = "An environment option was sent before authentication negotiation completed.\r\nThis may create a security hazard. Connection dropped.\r\n"; ! writenet(error, strlen(error)); netflush(); exit(1); } --- 86,92 ---- if (!auth_negotiated) { static char *error = "An environment option was sent before authentication negotiation completed.\r\nThis may create a security hazard. Connection dropped.\r\n"; ! netputs(error); netflush(); exit(1); } *************** *** 209,217 **** } netclear(); /* clear buffer back */ ! *nfrontp++ = IAC; ! *nfrontp++ = DM; ! neturg = nfrontp-1; /* off by one XXX */ DIAG(TD_OPTIONS, printoption("td: send IAC", DM)); break; --- 209,215 ---- } netclear(); /* clear buffer back */ ! netprintf_urg("%c%c", IAC, DM); DIAG(TD_OPTIONS, printoption("td: send IAC", DM)); break; *************** *** 381,389 **** pfrontp = opfrontp; pfrontp += term_input(xptyobuf, pfrontp, n, BUFSIZ+NETSLOP, xbuf2, &oc, BUFSIZ); ! for (cp = xbuf2; oc > 0; --oc) ! if ((*nfrontp++ = *cp++) == IAC) ! *nfrontp++ = IAC; } #endif /* defined(CRAY2) && defined(UNICOS5) */ } /* end of telrcv */ --- 379,390 ---- pfrontp = opfrontp; pfrontp += term_input(xptyobuf, pfrontp, n, BUFSIZ+NETSLOP, xbuf2, &oc, BUFSIZ); ! for (cp = xbuf2; oc > 0; --oc) { ! if (*cp == IAC) ! netprintf("%c%c", *cp++, IAC); ! else ! netprintf("%c", *cp++); ! } } #endif /* defined(CRAY2) && defined(UNICOS5) */ } /* end of telrcv */ *************** *** 463,470 **** set_his_want_state_will(option); do_dont_resp[option]++; } ! (void) sprintf(nfrontp, (char *)doopt, option); ! nfrontp += sizeof (dont) - 2; DIAG(TD_OPTIONS, printoption("td: send do", option)); } --- 464,470 ---- set_his_want_state_will(option); do_dont_resp[option]++; } ! netprintf((char *)doopt, option); DIAG(TD_OPTIONS, printoption("td: send do", option)); } *************** *** 683,690 **** set_his_want_state_wont(option); do_dont_resp[option]++; } ! (void) sprintf(nfrontp, (char *)dont, option); ! nfrontp += sizeof (doopt) - 2; DIAG(TD_OPTIONS, printoption("td: send dont", option)); } --- 683,689 ---- set_his_want_state_wont(option); do_dont_resp[option]++; } ! netprintf((char *)dont, option); DIAG(TD_OPTIONS, printoption("td: send dont", option)); } *************** *** 833,840 **** set_my_want_state_will(option); will_wont_resp[option]++; } ! (void) sprintf(nfrontp, (char *)will, option); ! nfrontp += sizeof (doopt) - 2; DIAG(TD_OPTIONS, printoption("td: send will", option)); } --- 832,838 ---- set_my_want_state_will(option); will_wont_resp[option]++; } ! netprintf((char *)will, option); DIAG(TD_OPTIONS, printoption("td: send will", option)); } *************** *** 993,1000 **** set_my_want_state_wont(option); will_wont_resp[option]++; } ! (void) sprintf(nfrontp, (char *)wont, option); ! nfrontp += sizeof (wont) - 2; DIAG(TD_OPTIONS, printoption("td: send wont", option)); } --- 991,997 ---- set_my_want_state_wont(option); will_wont_resp[option]++; } ! netprintf((char *)wont, option); DIAG(TD_OPTIONS, printoption("td: send wont", option)); } *************** *** 1393,1402 **** 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(); --- 1390,1397 ---- env_ovar_wrong: env_ovar = OLD_ENV_VALUE; env_ovalue = OLD_ENV_VAR; ! DIAG(TD_OPTIONS, ! netputs("ENVIRON VALUE and VAR are reversed!\r\n")); } } SB_RESTORE(); *************** *** 1633,1639 **** ADD(IAC); ADD(SE); ! writenet(statusbuf, ncp - statusbuf); netflush(); /* Send it on its way */ DIAG(TD_OPTIONS, --- 1628,1634 ---- ADD(IAC); ADD(SE); ! netwrite(statusbuf, ncp - statusbuf); netflush(); /* Send it on its way */ DIAG(TD_OPTIONS, diff -r -c /var/tmp/krb5-1.2.2/src/appl/telnet/telnetd/telnetd.c ./telnetd.c *** /var/tmp/krb5-1.2.2/src/appl/telnet/telnetd/telnetd.c Wed Feb 28 17:06:51 2001 --- ./telnetd.c Fri Jul 27 09:21:20 2001 *************** *** 693,699 **** char *error_message = "Encryption was not successfully negotiated. Goodbye.\r\n\r\n"; ! writenet(error_message, strlen(error_message)); netflush(); exit(1); } --- 693,699 ---- char *error_message = "Encryption was not successfully negotiated. Goodbye.\r\n\r\n"; ! netputs(error_message); netflush(); exit(1); } *************** *** 780,830 **** if (his_state_is_will(TELOPT_TSPEED)) { static unsigned char sb[] = { IAC, SB, TELOPT_TSPEED, TELQUAL_SEND, IAC, SE }; ! ! if(nfrontp - netobuf + sizeof(sb) < sizeof(netobuf)) { ! memcpy(nfrontp, sb, sizeof(sb)); ! nfrontp += sizeof(sb); ! *nfrontp = '\0'; ! } } if (his_state_is_will(TELOPT_XDISPLOC)) { static unsigned char sb[] = { IAC, SB, TELOPT_XDISPLOC, TELQUAL_SEND, IAC, SE }; ! ! if(nfrontp - netobuf + sizeof(sb) < sizeof(netobuf)) { ! memcpy(nfrontp, sb, sizeof(sb)); ! nfrontp += sizeof(sb); ! *nfrontp = '\0'; ! } } if (his_state_is_will(TELOPT_NEW_ENVIRON)) { static unsigned char sb[] = { IAC, SB, TELOPT_NEW_ENVIRON, TELQUAL_SEND, IAC, SE }; ! ! if(nfrontp - netobuf + sizeof(sb) < sizeof(netobuf)) { ! memcpy(nfrontp, sb, sizeof(sb)); ! nfrontp += sizeof(sb); ! *nfrontp = '\0'; ! } } else if (his_state_is_will(TELOPT_OLD_ENVIRON)) { static unsigned char sb[] = { IAC, SB, TELOPT_OLD_ENVIRON, TELQUAL_SEND, IAC, SE }; ! ! if(nfrontp - netobuf + sizeof(sb) < sizeof(netobuf)) { ! memcpy(nfrontp, sb, sizeof(sb)); ! nfrontp += sizeof(sb); ! *nfrontp = '\0'; ! } } ! if (his_state_is_will(TELOPT_TTYPE)) { - if(nfrontp - netobuf + sizeof(ttytype_sbbuf) < sizeof(netobuf)) { - memcpy(nfrontp, ttytype_sbbuf, sizeof(ttytype_sbbuf)); - nfrontp += sizeof(ttytype_sbbuf); - *nfrontp = '\0'; - } - } if (his_state_is_will(TELOPT_TSPEED)) { while (sequenceIs(tspeedsubopt, baseline)) ttloop(); --- 780,805 ---- if (his_state_is_will(TELOPT_TSPEED)) { static unsigned char sb[] = { IAC, SB, TELOPT_TSPEED, TELQUAL_SEND, IAC, SE }; ! netwrite(sb, sizeof(sb)); } if (his_state_is_will(TELOPT_XDISPLOC)) { static unsigned char sb[] = { IAC, SB, TELOPT_XDISPLOC, TELQUAL_SEND, IAC, SE }; ! netwrite(sb, sizeof(sb)); } if (his_state_is_will(TELOPT_NEW_ENVIRON)) { static unsigned char sb[] = { IAC, SB, TELOPT_NEW_ENVIRON, TELQUAL_SEND, IAC, SE }; ! netwrite(sb, sizeof(sb)); } else if (his_state_is_will(TELOPT_OLD_ENVIRON)) { static unsigned char sb[] = { IAC, SB, TELOPT_OLD_ENVIRON, TELQUAL_SEND, IAC, SE }; ! netwrite(sb, sizeof(sb)); } ! if (his_state_is_will(TELOPT_TTYPE)) ! netwrite(ttytype_sbbuf, sizeof(ttytype_sbbuf)); if (his_state_is_will(TELOPT_TSPEED)) { while (sequenceIs(tspeedsubopt, baseline)) ttloop(); *************** *** 901,911 **** if (his_state_is_wont(TELOPT_TTYPE)) return; settimer(baseline); ! if(nfrontp - netobuf + sizeof(ttytype_sbbuf)) { ! memcpy(nfrontp, ttytype_sbbuf, sizeof(ttytype_sbbuf)); ! nfrontp += sizeof(ttytype_sbbuf); ! *nfrontp = '\0'; ! } while (sequenceIs(ttypesubopt, baseline)) ttloop(); } --- 876,882 ---- if (his_state_is_wont(TELOPT_TTYPE)) return; settimer(baseline); ! netwrite(ttytype_sbbuf, sizeof(ttytype_sbbuf)); while (sequenceIs(ttypesubopt, baseline)) ttloop(); } *************** *** 1177,1185 **** * mode, which we do not want. */ if (his_want_state_is_will(TELOPT_ECHO)) { ! DIAG(TD_OPTIONS, ! {sprintf(nfrontp, "td: simulating recv\r\n"); ! nfrontp += strlen(nfrontp);}); willoption(TELOPT_ECHO); } --- 1148,1154 ---- * mode, which we do not want. */ if (his_want_state_is_will(TELOPT_ECHO)) { ! DIAG(TD_OPTIONS, netputs("td: simulating recv\r\n")); willoption(TELOPT_ECHO); } *************** *** 1308,1316 **** localstat(); #endif /* LINEMODE */ ! DIAG(TD_REPORT, ! {sprintf(nfrontp, "td: Entering processing loop\r\n"); ! nfrontp += strlen(nfrontp);}); #ifdef convex startslave(host); --- 1277,1283 ---- localstat(); #endif /* LINEMODE */ ! DIAG(TD_REPORT, netputs("td: Entering processing loop\r\n")); #ifdef convex startslave(host); *************** *** 1435,1442 **** netip = netibuf; } DIAG((TD_REPORT | TD_NETDATA), ! {sprintf(nfrontp, "td: netread %d chars\r\n", ncc); ! nfrontp += strlen(nfrontp);}); DIAG(TD_NETDATA, printdata("nd", netip, ncc)); } --- 1402,1408 ---- netip = netibuf; } DIAG((TD_REPORT | TD_NETDATA), ! netprintf("td: netread %d chars\r\n", ncc)); DIAG(TD_NETDATA, printdata("nd", netip, ncc)); } *************** *** 1483,1491 **** * royally if we send them urgent * mode data. */ ! *nfrontp++ = IAC; ! *nfrontp++ = DM; ! neturg = nfrontp-1; /* off by one XXX */ #endif } if (his_state_is_will(TELOPT_LFLOW) && --- 1449,1455 ---- * royally if we send them urgent * mode data. */ ! netprintf_urg("%c%c", IAC, DM); #endif } if (his_state_is_will(TELOPT_LFLOW) && *************** *** 1495,1507 **** ptyibuf[0] & TIOCPKT_DOSTOP ? 1 : 0; if (newflow != flowmode) { flowmode = newflow; ! (void) sprintf(nfrontp, ! "%c%c%c%c%c%c", IAC, SB, TELOPT_LFLOW, flowmode ? LFLOW_ON : LFLOW_OFF, IAC, SE); - nfrontp += 6; } } pcc--; --- 1459,1469 ---- ptyibuf[0] & TIOCPKT_DOSTOP ? 1 : 0; if (newflow != flowmode) { flowmode = newflow; ! netprintf("%c%c%c%c%c%c", IAC, SB, TELOPT_LFLOW, flowmode ? LFLOW_ON : LFLOW_OFF, IAC, SE); } } pcc--; *************** *** 1524,1542 **** break; c = *ptyip++ & 0377, pcc--; if (c == IAC) ! *nfrontp++ = c; #if defined(CRAY2) && defined(UNICOS5) else if (c == '\n' && my_state_is_wont(TELOPT_BINARY) && newmap) ! *nfrontp++ = '\r'; #endif /* defined(CRAY2) && defined(UNICOS5) */ ! *nfrontp++ = c; if ((c == '\r') && (my_state_is_wont(TELOPT_BINARY))) { if (pcc > 0 && ((*ptyip & 0377) == '\n')) { ! *nfrontp++ = *ptyip++ & 0377; pcc--; } else ! *nfrontp++ = '\0'; } } #if defined(CRAY2) && defined(UNICOS5) --- 1486,1504 ---- break; c = *ptyip++ & 0377, pcc--; if (c == IAC) ! netprintf("%c", c); #if defined(CRAY2) && defined(UNICOS5) else if (c == '\n' && my_state_is_wont(TELOPT_BINARY) && newmap) ! netputs("\r"); #endif /* defined(CRAY2) && defined(UNICOS5) */ ! netprintf("%c", c); if ((c == '\r') && (my_state_is_wont(TELOPT_BINARY))) { if (pcc > 0 && ((*ptyip & 0377) == '\n')) { ! netprintf("%c", *ptyip++ & 0377); pcc--; } else ! netprintf("%c", '\0'); } } #if defined(CRAY2) && defined(UNICOS5) *************** *** 1698,1704 **** * When we get an AYT, if ^T is enabled, use that. Otherwise, * just send back "[Yes]". */ ! void recv_ayt() { #if defined(SIGINFO) && defined(TCSIG) --- 1660,1666 ---- * When we get an AYT, if ^T is enabled, use that. Otherwise, * just send back "[Yes]". */ ! void recv_ayt() { #if defined(SIGINFO) && defined(TCSIG) *************** *** 1707,1716 **** return; } #endif ! (void) strncpy(nfrontp, "\r\n[Yes]\r\n", ! sizeof(netobuf) - 1 - (nfrontp - netobuf)); ! nfrontp += 9; ! *nfrontp = '\0'; } void --- 1669,1675 ---- return; } #endif ! netputs("\r\n[Yes]\r\n"); } void diff -r -c /var/tmp/krb5-1.2.2/src/appl/telnet/telnetd/termstat.c ./termstat.c *** /var/tmp/krb5-1.2.2/src/appl/telnet/telnetd/termstat.c Wed Feb 28 17:06:51 2001 --- ./termstat.c Wed Jul 25 20:00:03 2001 *************** *** 283,292 **** # endif /* KLUDGELINEMODE */ send_do(TELOPT_LINEMODE, 1); /* send along edit modes */ ! (void) sprintf(nfrontp, "%c%c%c%c%c%c%c", IAC, SB, TELOPT_LINEMODE, LM_MODE, useeditmode, IAC, SE); - nfrontp += 7; editmode = useeditmode; # ifdef KLUDGELINEMODE } --- 283,291 ---- # endif /* KLUDGELINEMODE */ send_do(TELOPT_LINEMODE, 1); /* send along edit modes */ ! netprintf("%c%c%c%c%c%c%c", IAC, SB, TELOPT_LINEMODE, LM_MODE, useeditmode, IAC, SE); editmode = useeditmode; # ifdef KLUDGELINEMODE } *************** *** 312,321 **** /* * Send along appropriate edit mode mask. */ ! (void) sprintf(nfrontp, "%c%c%c%c%c%c%c", IAC, SB, TELOPT_LINEMODE, LM_MODE, useeditmode, IAC, SE); - nfrontp += 7; editmode = useeditmode; } --- 311,319 ---- /* * Send along appropriate edit mode mask. */ ! (void) netprintf("%c%c%c%c%c%c%c", IAC, SB, TELOPT_LINEMODE, LM_MODE, useeditmode, IAC, SE); editmode = useeditmode; } *************** *** 359,378 **** if (his_state_is_will(TELOPT_LFLOW)) { if (tty_flowmode() != flowmode) { flowmode = tty_flowmode(); ! (void) sprintf(nfrontp, "%c%c%c%c%c%c", IAC, SB, TELOPT_LFLOW, flowmode ? LFLOW_ON : LFLOW_OFF, IAC, SE); - nfrontp += 6; } if (tty_restartany() != restartany) { restartany = tty_restartany(); ! (void) sprintf(nfrontp, "%c%c%c%c%c%c", IAC, SB, TELOPT_LFLOW, restartany ? LFLOW_RESTART_ANY : LFLOW_RESTART_XON, IAC, SE); - nfrontp += 6; } } } --- 357,374 ---- if (his_state_is_will(TELOPT_LFLOW)) { if (tty_flowmode() != flowmode) { flowmode = tty_flowmode(); ! netprintf("%c%c%c%c%c%c", IAC, SB, TELOPT_LFLOW, flowmode ? LFLOW_ON : LFLOW_OFF, IAC, SE); } if (tty_restartany() != restartany) { restartany = tty_restartany(); ! netprintf("%c%c%c%c%c%c", IAC, SB, TELOPT_LFLOW, restartany ? LFLOW_RESTART_ANY : LFLOW_RESTART_XON, IAC, SE); } } } *************** *** 445,454 **** useeditmode |= MODE_SOFT_TAB; if (tty_islitecho()) useeditmode |= MODE_LIT_ECHO; ! (void) sprintf(nfrontp, "%c%c%c%c%c%c%c", IAC, SB, TELOPT_LINEMODE, LM_MODE, ! useeditmode, IAC, SE); ! nfrontp += 7; editmode = useeditmode; } --- 441,449 ---- useeditmode |= MODE_SOFT_TAB; if (tty_islitecho()) useeditmode |= MODE_LIT_ECHO; ! netprintf("%c%c%c%c%c%c%c", IAC, SB, TELOPT_LINEMODE, LM_MODE, ! useeditmode, IAC, SE); editmode = useeditmode; } *************** *** 504,514 **** set_termbuf(); if (!ack) { ! (void) sprintf(nfrontp, "%c%c%c%c%c%c%c", IAC, SB, TELOPT_LINEMODE, LM_MODE, useeditmode|MODE_ACK, IAC, SE); - nfrontp += 7; } editmode = useeditmode; --- 499,508 ---- set_termbuf(); if (!ack) { ! netprintf("%c%c%c%c%c%c%c", IAC, SB, TELOPT_LINEMODE, LM_MODE, useeditmode|MODE_ACK, IAC, SE); } editmode = useeditmode; diff -r -c /var/tmp/krb5-1.2.2/src/appl/telnet/telnetd/utility.c ./utility.c *** /var/tmp/krb5-1.2.2/src/appl/telnet/telnetd/utility.c Wed Feb 28 17:06:52 2001 --- ./utility.c Mon Jul 30 19:43:05 2001 *************** *** 33,38 **** --- 33,39 ---- /* based on @(#)utility.c 8.1 (Berkeley) 6/4/93 */ + #include #define PRINTOPTIONS #include "telnetd.h" *************** *** 58,65 **** { void netflush(); ! DIAG(TD_REPORT, {sprintf(nfrontp, "td: ttloop\r\n"); ! nfrontp += strlen(nfrontp);}); if (nfrontp-nbackp) { netflush(); } --- 59,65 ---- { void netflush(); ! DIAG(TD_REPORT, netputs("td: ttloop\r\n")); if (nfrontp-nbackp) { netflush(); } *************** *** 74,81 **** syslog(LOG_INFO, "ttloop: peer died: %m"); exit(1); } ! DIAG(TD_REPORT, {sprintf(nfrontp, "td: ttloop read %d chars\r\n", ncc); ! nfrontp += strlen(nfrontp);}); netip = netibuf; telrcv(); /* state machine */ if (ncc > 0) { --- 74,80 ---- syslog(LOG_INFO, "ttloop: peer died: %m"); exit(1); } ! DIAG(TD_REPORT, netprintf("td: ttloop read %d chars\r\n", ncc)); netip = netibuf; telrcv(); /* state machine */ if (ncc > 0) { *************** *** 118,125 **** if ((n = pfrontp - pbackp) > 0) { DIAG((TD_REPORT | TD_PTYDATA), ! { sprintf(nfrontp, "td: ptyflush %d chars\r\n", n); ! nfrontp += strlen(nfrontp); }); DIAG(TD_PTYDATA, printdata("pd", pbackp, n)); n = write(pty, pbackp, n); } --- 117,123 ---- if ((n = pfrontp - pbackp) > 0) { DIAG((TD_REPORT | TD_PTYDATA), ! netprintf("td: ptyflush %d chars\r\n", n)); DIAG(TD_PTYDATA, printdata("pd", pbackp, n)); n = write(pty, pbackp, n); } *************** *** 244,261 **** * Send as much data as possible to the network, * handling requests for urgent data. */ ! void netflush() { int n; extern int not42; if ((n = nfrontp - nbackp) > 0) { ! DIAG(TD_REPORT, ! { sprintf(nfrontp, "td: netflush %d chars\r\n", n); ! n += strlen(nfrontp); /* get count first */ ! nfrontp += strlen(nfrontp); /* then move pointer */ ! }); #ifdef ENCRYPTION if (encrypt_output) { char *s = nclearto ? nclearto : nbackp; --- 242,256 ---- * Send as much data as possible to the network, * handling requests for urgent data. */ ! void netflush() { int n; extern int not42; if ((n = nfrontp - nbackp) > 0) { ! DIAG(TD_REPORT, {netprintf_noflush("td: netflush %d chars\r\n", n); ! n = nfrontp - nbackp;}); #ifdef ENCRYPTION if (encrypt_output) { char *s = nclearto ? nclearto : nbackp; *************** *** 312,344 **** return; } /* end of netflush */ /* ! * writenet * ! * Just a handy little function to write a bit of raw data to the net. ! * It will force a transmit of the buffer if necessary * ! * arguments ! * ptr - A pointer to a character string to write ! * len - How many bytes to write */ ! void ! writenet(ptr, len) ! register unsigned char *ptr; ! register int len; ! { ! /* flush buffer if no room for new data) */ ! if ((&netobuf[BUFSIZ] - nfrontp) < len) { ! /* if this fails, don't worry, buffer is a little big */ ! netflush(); } ! memcpy(nfrontp, ptr, len); nfrontp += len; ! } /* end of writenet */ /* * miscellaneous functions doing a variety of little jobs follow ... --- 307,437 ---- return; } /* end of netflush */ + /* + * L8_256(x) = log8(256**x), rounded up, including sign (for decimal + * strings too). log8(256) = 8/3, but we use integer math to round + * up. + */ + #define L8_256(x) (((x * 8 + 2) / 3) + 1) /* ! * netprintf * ! * Do the equivalent of printf() to the NETOBUF "ring buffer", ! * possibly calling netflush() if needed. * ! * Thou shalt not call this with a "%s" format; use netputs instead. ! * We also don't deal with floating point widths in here. */ ! void ! netprintf_ext(int noflush, int seturg, const char *fmt, va_list args) ! { ! size_t remain; ! size_t maxoutlen; ! char buf[BUFSIZ]; ! const char *cp; ! int len; ! ! buf[0] = '\0'; /* nul-terminate */ ! remain = sizeof(netobuf) - (nfrontp - netobuf); ! for (maxoutlen = 0, cp = fmt; *cp; cp++) { ! if (*cp == '%') ! /* Ok so this is slightly overkill... */ ! maxoutlen += L8_256(sizeof(long)); ! else ! maxoutlen++; } + if (maxoutlen >= sizeof(buf)) + return; /* highly unlikely */ ! #ifdef HAVE_VSNPRINTF ! len = vsnprintf(buf, sizeof(buf), fmt, args); ! #else ! len = vsprintf(buf, fmt, args); /* XXX need to fix for SunOS? */ ! #endif ! ! /* ! * The return value from sprintf()-like functions may be the ! * number of characters that *would* have been output, not the ! * number actually output. ! */ ! if (len <= 0 || len > sizeof(buf)) ! return; ! if (remain < len && !noflush) { ! netflush(); ! remain = sizeof(netobuf) - (nfrontp - netobuf); ! } ! if (remain < len) ! return; /* still not enough space? */ ! memcpy(nfrontp, buf, (size_t)len); nfrontp += len; + if (seturg) + neturg = nfrontp - 1; + } ! void ! netprintf(const char *fmt, ...) ! { ! va_list args; ! ! va_start(args, fmt); ! netprintf_ext(0, 0, fmt, args); ! va_end(args); ! } ! ! void ! netprintf_urg(const char *fmt, ...) ! { ! va_list args; ! ! va_start(args, fmt); ! netprintf_ext(0, 1, fmt, args); ! va_end(args); ! } ! ! void ! netprintf_noflush(const char *fmt, ...) ! { ! va_list args; ! ! va_start(args, fmt); ! netprintf_ext(1, 0, fmt, args); ! va_end(args); ! } ! ! /* ! * netwrite ! * ! * Copy BUF into the NETOBUF "ring buffer", possibly calling ! * netflush() if needed. ! */ ! int ! netwrite(const char *buf, size_t len) ! { ! size_t remain; ! ! remain = sizeof(netobuf) - (nfrontp - netobuf); ! if (remain < len) { ! netflush(); ! remain = sizeof(netobuf) - (nfrontp - netobuf); ! } ! if (remain < len) ! return 0; ! memcpy(nfrontp, buf, len); ! nfrontp += len; ! return len; ! } + /* + * netputs + * + * Write S to the NETOBUF "ring buffer". Does not write a '\n'. + */ + void + netputs(const char *s) + { + netwrite(s, strlen(s)); + } /* * miscellaneous functions doing a variety of little jobs follow ... *************** *** 522,543 **** /* * Print telnet options and commands in plain text, if possible. */ ! void printoption(fmt, option) register char *fmt; register int option; { ! if (TELOPT_OK(option)) ! sprintf(nfrontp, "%s %s\r\n", fmt, TELOPT(option)); ! else if (TELCMD_OK(option)) ! sprintf(nfrontp, "%s %s\r\n", fmt, TELCMD(option)); ! else ! sprintf(nfrontp, "%s %d\r\n", fmt, option); ! nfrontp += strlen(nfrontp); return; } ! void printsub(direction, pointer, length) char direction; /* '<' or '>' */ unsigned char *pointer; /* where suboption data sits */ --- 615,640 ---- /* * Print telnet options and commands in plain text, if possible. */ ! void printoption(fmt, option) register char *fmt; register int option; { ! netputs(fmt); ! netputs(" "); ! if (TELOPT_OK(option)) { ! netputs(TELOPT(option)); ! netputs("\r\n"); ! } else if (TELCMD_OK(option)) { ! netputs(TELCMD(option)); ! netputs("\r\n"); ! } else { ! netprintf("%d\r\n", option); ! } return; } ! void printsub(direction, pointer, length) char direction; /* '<' or '>' */ unsigned char *pointer; /* where suboption data sits */ *************** *** 550,558 **** return; if (direction) { ! sprintf(nfrontp, "td: %s suboption ", ! direction == '<' ? "recv" : "send"); ! nfrontp += strlen(nfrontp); if (length >= 3) { register int j; --- 647,655 ---- return; if (direction) { ! netputs("td: "); ! netputs(direction == '<' ? "recv" : "send"); ! netputs(" suboption "); if (length >= 3) { register int j; *************** *** 560,820 **** j = pointer[length-1]; if (i != IAC || j != SE) { ! sprintf(nfrontp, "(terminated by "); ! nfrontp += strlen(nfrontp); if (TELOPT_OK(i)) ! sprintf(nfrontp, "%s ", TELOPT(i)); else if (TELCMD_OK(i)) ! sprintf(nfrontp, "%s ", TELCMD(i)); else ! sprintf(nfrontp, "%d ", i); ! nfrontp += strlen(nfrontp); if (TELOPT_OK(j)) ! sprintf(nfrontp, "%s", TELOPT(j)); else if (TELCMD_OK(j)) ! sprintf(nfrontp, "%s", TELCMD(j)); else ! sprintf(nfrontp, "%d", j); ! nfrontp += strlen(nfrontp); ! sprintf(nfrontp, ", not IAC SE!) "); ! nfrontp += strlen(nfrontp); } } length -= 2; } if (length < 1) { ! sprintf(nfrontp, "(Empty suboption??\?)"); ! nfrontp += strlen(nfrontp); return; } switch (pointer[0]) { case TELOPT_TTYPE: ! sprintf(nfrontp, "TERMINAL-TYPE "); ! nfrontp += strlen(nfrontp); switch (pointer[1]) { case TELQUAL_IS: ! sprintf(nfrontp, "IS \"%.*s\"", length-2, (char *)pointer+2); break; case TELQUAL_SEND: ! sprintf(nfrontp, "SEND"); break; default: ! sprintf(nfrontp, ! "- unknown qualifier %d (0x%x).", ! pointer[1], pointer[1]); } - nfrontp += strlen(nfrontp); break; case TELOPT_TSPEED: ! sprintf(nfrontp, "TERMINAL-SPEED"); ! nfrontp += strlen(nfrontp); if (length < 2) { ! sprintf(nfrontp, " (empty suboption??\?)"); ! nfrontp += strlen(nfrontp); break; } switch (pointer[1]) { case TELQUAL_IS: ! sprintf(nfrontp, " IS %.*s", length-2, (char *)pointer+2); ! nfrontp += strlen(nfrontp); break; default: if (pointer[1] == 1) ! sprintf(nfrontp, " SEND"); else ! sprintf(nfrontp, " %d (unknown)", pointer[1]); ! nfrontp += strlen(nfrontp); ! for (i = 2; i < length; i++) { ! sprintf(nfrontp, " ?%d?", pointer[i]); ! nfrontp += strlen(nfrontp); ! } break; } break; case TELOPT_LFLOW: ! sprintf(nfrontp, "TOGGLE-FLOW-CONTROL"); ! nfrontp += strlen(nfrontp); if (length < 2) { ! sprintf(nfrontp, " (empty suboption??\?)"); ! nfrontp += strlen(nfrontp); break; } switch (pointer[1]) { case LFLOW_OFF: ! sprintf(nfrontp, " OFF"); break; case LFLOW_ON: ! sprintf(nfrontp, " ON"); break; case LFLOW_RESTART_ANY: ! sprintf(nfrontp, " RESTART-ANY"); break; case LFLOW_RESTART_XON: ! sprintf(nfrontp, " RESTART-XON"); break; default: ! sprintf(nfrontp, " %d (unknown)", pointer[1]); ! } ! nfrontp += strlen(nfrontp); ! for (i = 2; i < length; i++) { ! sprintf(nfrontp, " ?%d?", pointer[i]); ! nfrontp += strlen(nfrontp); } break; case TELOPT_NAWS: ! sprintf(nfrontp, "NAWS"); ! nfrontp += strlen(nfrontp); if (length < 2) { ! sprintf(nfrontp, " (empty suboption??\?)"); ! nfrontp += strlen(nfrontp); break; } if (length == 2) { ! sprintf(nfrontp, " ?%d?", pointer[1]); ! nfrontp += strlen(nfrontp); break; } ! sprintf(nfrontp, " %d %d (%d)", pointer[1], pointer[2], (int)((((unsigned int)pointer[1])<<8)|((unsigned int)pointer[2]))); - nfrontp += strlen(nfrontp); if (length == 4) { ! sprintf(nfrontp, " ?%d?", pointer[3]); ! nfrontp += strlen(nfrontp); break; } ! sprintf(nfrontp, " %d %d (%d)", pointer[3], pointer[4], (int)((((unsigned int)pointer[3])<<8)|((unsigned int)pointer[4]))); ! nfrontp += strlen(nfrontp); ! for (i = 5; i < length; i++) { ! sprintf(nfrontp, " ?%d?", pointer[i]); ! nfrontp += strlen(nfrontp); ! } break; case TELOPT_LINEMODE: ! sprintf(nfrontp, "LINEMODE "); ! nfrontp += strlen(nfrontp); if (length < 2) { ! sprintf(nfrontp, " (empty suboption??\?)"); ! nfrontp += strlen(nfrontp); break; } switch (pointer[1]) { case WILL: ! sprintf(nfrontp, "WILL "); goto common; case WONT: ! sprintf(nfrontp, "WONT "); goto common; case DO: ! sprintf(nfrontp, "DO "); goto common; case DONT: ! sprintf(nfrontp, "DONT "); common: - nfrontp += strlen(nfrontp); if (length < 3) { ! sprintf(nfrontp, "(no option??\?)"); ! nfrontp += strlen(nfrontp); break; } switch (pointer[2]) { case LM_FORWARDMASK: ! sprintf(nfrontp, "Forward Mask"); ! nfrontp += strlen(nfrontp); ! for (i = 3; i < length; i++) { ! sprintf(nfrontp, " %x", pointer[i]); ! nfrontp += strlen(nfrontp); ! } break; default: ! sprintf(nfrontp, "%d (unknown)", pointer[2]); ! nfrontp += strlen(nfrontp); ! for (i = 3; i < length; i++) { ! sprintf(nfrontp, " %d", pointer[i]); ! nfrontp += strlen(nfrontp); ! } break; } break; case LM_SLC: ! sprintf(nfrontp, "SLC"); ! nfrontp += strlen(nfrontp); for (i = 2; i < length - 2; i += 3) { ! if (SLC_NAME_OK(pointer[i+SLC_FUNC])) ! sprintf(nfrontp, " %s", SLC_NAME(pointer[i+SLC_FUNC])); ! else ! sprintf(nfrontp, " %d", pointer[i+SLC_FUNC]); ! nfrontp += strlen(nfrontp); switch (pointer[i+SLC_FLAGS]&SLC_LEVELBITS) { case SLC_NOSUPPORT: ! sprintf(nfrontp, " NOSUPPORT"); break; case SLC_CANTCHANGE: ! sprintf(nfrontp, " CANTCHANGE"); break; case SLC_VARIABLE: ! sprintf(nfrontp, " VARIABLE"); break; case SLC_DEFAULT: ! sprintf(nfrontp, " DEFAULT"); break; } ! nfrontp += strlen(nfrontp); ! sprintf(nfrontp, "%s%s%s", ! pointer[i+SLC_FLAGS]&SLC_ACK ? "|ACK" : "", ! pointer[i+SLC_FLAGS]&SLC_FLUSHIN ? "|FLUSHIN" : "", ! pointer[i+SLC_FLAGS]&SLC_FLUSHOUT ? "|FLUSHOUT" : ""); ! nfrontp += strlen(nfrontp); if (pointer[i+SLC_FLAGS]& ~(SLC_ACK|SLC_FLUSHIN| SLC_FLUSHOUT| SLC_LEVELBITS)) { ! sprintf(nfrontp, "(0x%x)", pointer[i+SLC_FLAGS]); ! nfrontp += strlen(nfrontp); } ! sprintf(nfrontp, " %d;", pointer[i+SLC_VALUE]); ! nfrontp += strlen(nfrontp); if ((pointer[i+SLC_VALUE] == IAC) && (pointer[i+SLC_VALUE+1] == IAC)) i++; } ! for (; i < length; i++) { ! sprintf(nfrontp, " ?%d?", pointer[i]); ! nfrontp += strlen(nfrontp); ! } break; case LM_MODE: ! sprintf(nfrontp, "MODE "); ! nfrontp += strlen(nfrontp); if (length < 3) { ! sprintf(nfrontp, "(no mode??\?)"); ! nfrontp += strlen(nfrontp); break; } { ! char tbuf[32]; ! sprintf(tbuf, "%s%s%s%s%s", ! pointer[2]&MODE_EDIT ? "|EDIT" : "", ! pointer[2]&MODE_TRAPSIG ? "|TRAPSIG" : "", ! pointer[2]&MODE_SOFT_TAB ? "|SOFT_TAB" : "", ! pointer[2]&MODE_LIT_ECHO ? "|LIT_ECHO" : "", ! pointer[2]&MODE_ACK ? "|ACK" : ""); ! sprintf(nfrontp, "%s", tbuf[1] ? &tbuf[1] : "0"); ! nfrontp += strlen(nfrontp); ! } ! if (pointer[2]&~(MODE_EDIT|MODE_TRAPSIG|MODE_ACK)) { ! sprintf(nfrontp, " (0x%x)", pointer[2]); ! nfrontp += strlen(nfrontp); ! } ! for (i = 3; i < length; i++) { ! sprintf(nfrontp, " ?0x%x?", pointer[i]); ! nfrontp += strlen(nfrontp); ! } break; default: ! sprintf(nfrontp, "%d (unknown)", pointer[1]); ! nfrontp += strlen(nfrontp); ! for (i = 2; i < length; i++) { ! sprintf(nfrontp, " %d", pointer[i]); ! nfrontp += strlen(nfrontp); ! } } break; --- 657,879 ---- j = pointer[length-1]; if (i != IAC || j != SE) { ! netputs("(terminated by "); if (TELOPT_OK(i)) ! netputs(TELOPT(i)); else if (TELCMD_OK(i)) ! netputs(TELCMD(i)); else ! netprintf("%d", i); ! netputs(" "); if (TELOPT_OK(j)) ! netputs(TELOPT(j)); else if (TELCMD_OK(j)) ! netputs(TELCMD(j)); else ! netprintf("%d", j); ! netputs(", not IAC SE!) "); } } length -= 2; } if (length < 1) { ! netputs("(Empty suboption??\?)"); return; } switch (pointer[0]) { case TELOPT_TTYPE: ! netputs("TERMINAL-TYPE "); switch (pointer[1]) { case TELQUAL_IS: ! netputs("IS \""); ! netwrite((char *)pointer + 2, (size_t)(length - 2)); ! netputs("\""); break; case TELQUAL_SEND: ! netputs("SEND"); break; default: ! netprintf("- unknown qualifier %d (0x%x).", ! pointer[1], pointer[1]); } break; case TELOPT_TSPEED: ! netputs("TERMINAL-SPEED "); if (length < 2) { ! netputs("(empty suboption??\?)"); break; } switch (pointer[1]) { case TELQUAL_IS: ! netputs("IS "); ! netwrite((char *)pointer + 2, (size_t)(length - 2)); break; default: if (pointer[1] == 1) ! netputs("SEND"); else ! netprintf("%d (unknown)", pointer[1]); ! for (i = 2; i < length; i++) ! netprintf(" ?%d?", pointer[i]); break; } break; case TELOPT_LFLOW: ! netputs("TOGGLE-FLOW-CONTROL "); if (length < 2) { ! netputs("(empty suboption??\?)"); break; } switch (pointer[1]) { case LFLOW_OFF: ! netputs("OFF"); break; case LFLOW_ON: ! netputs("ON"); break; case LFLOW_RESTART_ANY: ! netputs("RESTART-ANY"); break; case LFLOW_RESTART_XON: ! netputs("RESTART-XON"); break; default: ! netprintf("%d (unknown)", pointer[1]); } + for (i = 2; i < length; i++) + netprintf(" ?%d?", pointer[i]); break; case TELOPT_NAWS: ! netputs("NAWS"); if (length < 2) { ! netputs(" (empty suboption??\?)"); break; } if (length == 2) { ! netprintf(" ?%d?", pointer[1]); break; } ! netprintf(" %d %d (%d)", pointer[1], pointer[2], (int)((((unsigned int)pointer[1])<<8)|((unsigned int)pointer[2]))); if (length == 4) { ! netprintf(" ?%d?", pointer[3]); break; } ! netprintf(" %d %d (%d)", pointer[3], pointer[4], (int)((((unsigned int)pointer[3])<<8)|((unsigned int)pointer[4]))); ! for (i = 5; i < length; i++) ! netprintf(" ?%d?", pointer[i]); break; case TELOPT_LINEMODE: ! netputs("LINEMODE "); if (length < 2) { ! netputs("(empty suboption??\?)"); break; } switch (pointer[1]) { case WILL: ! netputs("WILL "); goto common; case WONT: ! netputs("WONT "); goto common; case DO: ! netputs("DO "); goto common; case DONT: ! netputs("DONT "); common: if (length < 3) { ! netputs("(no option??\?)"); break; } switch (pointer[2]) { case LM_FORWARDMASK: ! netputs("Forward Mask"); ! for (i = 3; i < length; i++) ! netprintf(" %x", pointer[i]); break; default: ! netprintf("%d (unknown)", pointer[2]); ! for (i = 3; i < length; i++) ! netprintf(" %d", pointer[i]); break; } break; case LM_SLC: ! netputs("SLC"); for (i = 2; i < length - 2; i += 3) { ! if (SLC_NAME_OK(pointer[i+SLC_FUNC])) { ! netputs(" "); ! netputs(SLC_NAME(pointer[i+SLC_FUNC])); ! } else ! netprintf(" %d", pointer[i+SLC_FUNC]); switch (pointer[i+SLC_FLAGS]&SLC_LEVELBITS) { case SLC_NOSUPPORT: ! netputs(" NOSUPPORT"); break; case SLC_CANTCHANGE: ! netputs(" CANTCHANGE"); break; case SLC_VARIABLE: ! netputs(" VARIABLE"); break; case SLC_DEFAULT: ! netputs(" DEFAULT"); break; } ! netputs(pointer[i+SLC_FLAGS]&SLC_ACK ! ? "|ACK" : ""); ! netputs(pointer[i+SLC_FLAGS]&SLC_FLUSHIN ! ? "|FLUSHIN" : ""); ! netputs(pointer[i+SLC_FLAGS]&SLC_FLUSHOUT ! ? "|FLUSHOUT" : ""); if (pointer[i+SLC_FLAGS]& ~(SLC_ACK|SLC_FLUSHIN| SLC_FLUSHOUT| SLC_LEVELBITS)) { ! netprintf("(0x%x)", pointer[i+SLC_FLAGS]); } ! netprintf(" %d;", pointer[i+SLC_VALUE]); if ((pointer[i+SLC_VALUE] == IAC) && (pointer[i+SLC_VALUE+1] == IAC)) i++; } ! for (; i < length; i++) ! netprintf(" ?%d?", pointer[i]); break; case LM_MODE: ! netputs("MODE "); if (length < 3) { ! netputs("(no mode??\?)"); break; } { ! int wrotemode = 0; ! ! #define NETPUTS_MODE(x) \ ! do { \ ! if (pointer[2] & (MODE_##x)) { \ ! if (wrotemode) netputs("|"); \ ! netputs(#x); \ ! wrotemode++; \ ! } \ ! } while (0) ! NETPUTS_MODE(EDIT); ! NETPUTS_MODE(TRAPSIG); ! NETPUTS_MODE(SOFT_TAB); ! NETPUTS_MODE(LIT_ECHO); ! NETPUTS_MODE(ACK); ! #undef NETPUTS_MODE ! if (!wrotemode) ! netputs("0"); ! } ! if (pointer[2] & ~(MODE_EDIT|MODE_TRAPSIG|MODE_ACK)) ! netprintf(" (0x%x)", pointer[2]); ! for (i = 3; i < length; i++) ! netprintf(" ?0x%x?", pointer[i]); break; default: ! netprintf("%d (unknown)", pointer[1]); ! for (i = 2; i < length; i++) ! netprintf(" %d", pointer[i]); } break; *************** *** 822,845 **** register char *cp; register int j, k; ! sprintf(nfrontp, "STATUS"); ! nfrontp += strlen(nfrontp); switch (pointer[1]) { default: if (pointer[1] == TELQUAL_SEND) ! sprintf(nfrontp, " SEND"); else ! sprintf(nfrontp, " %d (unknown)", pointer[1]); ! nfrontp += strlen(nfrontp); ! for (i = 2; i < length; i++) { ! sprintf(nfrontp, " ?%d?", pointer[i]); ! nfrontp += strlen(nfrontp); ! } break; case TELQUAL_IS: ! sprintf(nfrontp, " IS\r\n"); ! nfrontp += strlen(nfrontp); for (i = 2; i < length; i++) { switch(pointer[i]) { --- 881,899 ---- register char *cp; register int j, k; ! netputs("STATUS"); switch (pointer[1]) { default: if (pointer[1] == TELQUAL_SEND) ! netputs(" SEND"); else ! netprintf(" %d (unknown)", pointer[1]); ! for (i = 2; i < length; i++) ! netprintf(" ?%d?", pointer[i]); break; case TELQUAL_IS: ! netputs(" IS\r\n"); for (i = 2; i < length; i++) { switch(pointer[i]) { *************** *** 849,867 **** case WONT: cp = "WONT"; goto common2; common2: i++; if (TELOPT_OK(pointer[i])) ! sprintf(nfrontp, " %s %s", cp, TELOPT(pointer[i])); else ! sprintf(nfrontp, " %s %d", cp, pointer[i]); ! nfrontp += strlen(nfrontp); ! sprintf(nfrontp, "\r\n"); ! nfrontp += strlen(nfrontp); break; case SB: ! sprintf(nfrontp, " SB "); ! nfrontp += strlen(nfrontp); i++; j = k = i; while (j < length) { --- 903,921 ---- case WONT: cp = "WONT"; goto common2; common2: i++; + netputs(" "); + netputs(cp); + netputs(" "); if (TELOPT_OK(pointer[i])) ! netputs(TELOPT(pointer[i])); else ! netprintf("%d", pointer[i]); ! netputs("\r\n"); break; case SB: ! netputs(" SB "); i++; j = k = i; while (j < length) { *************** *** 877,896 **** } printsub(0, &pointer[i], k - i); if (i < length) { ! sprintf(nfrontp, " SE"); ! nfrontp += strlen(nfrontp); i = j; } else i = j - 1; ! sprintf(nfrontp, "\r\n"); ! nfrontp += strlen(nfrontp); break; default: ! sprintf(nfrontp, " %d", pointer[i]); ! nfrontp += strlen(nfrontp); break; } } --- 931,947 ---- } printsub(0, &pointer[i], k - i); if (i < length) { ! netputs(" SE"); i = j; } else i = j - 1; ! netputs("\r\n"); break; default: ! netprintf(" %d", pointer[i]); break; } } *************** *** 900,985 **** } case TELOPT_XDISPLOC: ! sprintf(nfrontp, "X-DISPLAY-LOCATION "); ! nfrontp += strlen(nfrontp); switch (pointer[1]) { case TELQUAL_IS: ! sprintf(nfrontp, "IS \"%.*s\"", length-2, (char *)pointer+2); break; case TELQUAL_SEND: ! sprintf(nfrontp, "SEND"); break; default: ! sprintf(nfrontp, "- unknown qualifier %d (0x%x).", ! pointer[1], pointer[1]); } - nfrontp += strlen(nfrontp); break; case TELOPT_NEW_ENVIRON: ! sprintf(nfrontp, "NEW-ENVIRON "); goto env_common1; case TELOPT_OLD_ENVIRON: ! sprintf(nfrontp, "OLD-ENVIRON"); env_common1: - nfrontp += strlen(nfrontp); switch (pointer[1]) { case TELQUAL_IS: ! sprintf(nfrontp, "IS "); goto env_common; case TELQUAL_SEND: ! sprintf(nfrontp, "SEND "); goto env_common; case TELQUAL_INFO: ! sprintf(nfrontp, "INFO "); env_common: - nfrontp += strlen(nfrontp); { register int noquote = 2; for (i = 2; i < length; i++ ) { switch (pointer[i]) { case NEW_ENV_VAR: ! sprintf(nfrontp, "\" VAR " + noquote); ! nfrontp += strlen(nfrontp); noquote = 2; break; case NEW_ENV_VALUE: ! sprintf(nfrontp, "\" VALUE " + noquote); ! nfrontp += strlen(nfrontp); noquote = 2; break; case ENV_ESC: ! sprintf(nfrontp, "\" ESC " + noquote); ! nfrontp += strlen(nfrontp); noquote = 2; break; case ENV_USERVAR: ! sprintf(nfrontp, "\" USERVAR " + noquote); ! nfrontp += strlen(nfrontp); noquote = 2; break; default: if (isprint(pointer[i]) && pointer[i] != '"') { if (noquote) { ! *nfrontp++ = '"'; noquote = 0; } ! *nfrontp++ = pointer[i]; } else { ! sprintf(nfrontp, "\" %03o " + noquote, ! pointer[i]); ! nfrontp += strlen(nfrontp); noquote = 2; } break; } } if (!noquote) ! *nfrontp++ = '"'; break; } } --- 951,1029 ---- } case TELOPT_XDISPLOC: ! netputs("X-DISPLAY-LOCATION "); switch (pointer[1]) { case TELQUAL_IS: ! netputs("IS \""); ! netwrite((char *)pointer + 2, (size_t)(length - 2)); ! netputs("\""); break; case TELQUAL_SEND: ! netputs("SEND"); break; default: ! netprintf("- unknown qualifier %d (0x%x).", ! pointer[1], pointer[1]); } break; case TELOPT_NEW_ENVIRON: ! netputs("NEW-ENVIRON "); goto env_common1; case TELOPT_OLD_ENVIRON: ! netputs("OLD-ENVIRON "); env_common1: switch (pointer[1]) { case TELQUAL_IS: ! netputs("IS "); goto env_common; case TELQUAL_SEND: ! netputs("SEND "); goto env_common; case TELQUAL_INFO: ! netputs("INFO "); env_common: { register int noquote = 2; for (i = 2; i < length; i++ ) { switch (pointer[i]) { case NEW_ENV_VAR: ! netputs("\" VAR " + noquote); noquote = 2; break; case NEW_ENV_VALUE: ! netputs("\" VALUE " + noquote); noquote = 2; break; case ENV_ESC: ! netputs("\" ESC " + noquote); noquote = 2; break; case ENV_USERVAR: ! netputs("\" USERVAR " + noquote); noquote = 2; break; default: if (isprint(pointer[i]) && pointer[i] != '"') { if (noquote) { ! netputs("\""); noquote = 0; } ! netprintf("%c", pointer[i]); } else { ! netprintf("\" %03o " + noquote, ! pointer[i]); noquote = 2; } break; } } if (!noquote) ! netputs("\""); break; } } *************** *** 987,1077 **** #if defined(AUTHENTICATION) case TELOPT_AUTHENTICATION: ! sprintf(nfrontp, "AUTHENTICATION"); ! nfrontp += strlen(nfrontp); if (length < 2) { ! sprintf(nfrontp, " (empty suboption??\?)"); ! nfrontp += strlen(nfrontp); break; } switch (pointer[1]) { case TELQUAL_REPLY: case TELQUAL_IS: ! sprintf(nfrontp, " %s ", (pointer[1] == TELQUAL_IS) ? ! "IS" : "REPLY"); ! nfrontp += strlen(nfrontp); if (AUTHTYPE_NAME_OK(pointer[2])) ! sprintf(nfrontp, "%s ", AUTHTYPE_NAME(pointer[2])); else ! sprintf(nfrontp, "%d ", pointer[2]); ! nfrontp += strlen(nfrontp); if (length < 3) { ! sprintf(nfrontp, "(partial suboption??\?)"); ! nfrontp += strlen(nfrontp); break; } ! sprintf(nfrontp, "%s|%s%s", ! ((pointer[3] & AUTH_WHO_MASK) == AUTH_WHO_CLIENT) ? ! "CLIENT" : "SERVER", ! ((pointer[3] & AUTH_HOW_MASK) == AUTH_HOW_MUTUAL) ? ! "MUTUAL" : "ONE-WAY", ! ((pointer[3] & AUTH_ENCRYPT_MASK) == AUTH_ENCRYPT_ON) ? ! "|ENCRYPT" : ""); ! nfrontp += strlen(nfrontp); auth_printsub(&pointer[1], length - 1, buf, sizeof(buf)); ! sprintf(nfrontp, "%s", buf); ! nfrontp += strlen(nfrontp); break; case TELQUAL_SEND: i = 2; ! sprintf(nfrontp, " SEND "); ! nfrontp += strlen(nfrontp); while (i < length) { if (AUTHTYPE_NAME_OK(pointer[i])) ! sprintf(nfrontp, "%s ", AUTHTYPE_NAME(pointer[i])); else ! sprintf(nfrontp, "%d ", pointer[i]); ! nfrontp += strlen(nfrontp); if (++i >= length) { ! sprintf(nfrontp, "(partial suboption??\?)"); ! nfrontp += strlen(nfrontp); break; } ! sprintf(nfrontp, "%s|%s%s ", ! ((pointer[i] & AUTH_WHO_MASK) == AUTH_WHO_CLIENT) ? ! "CLIENT" : "SERVER", ! ((pointer[i] & AUTH_HOW_MASK) == AUTH_HOW_MUTUAL) ? ! "MUTUAL" : "ONE-WAY", ! ((pointer[3] & AUTH_ENCRYPT_MASK) == AUTH_ENCRYPT_ON) ? ! "|ENCRYPT" : ""); ! nfrontp += strlen(nfrontp); ++i; } break; case TELQUAL_NAME: i = 2; ! sprintf(nfrontp, " NAME \""); ! nfrontp += strlen(nfrontp); while (i < length) { if (isprint(pointer[i])) ! *nfrontp++ = pointer[i++]; else { ! sprintf(nfrontp, "\"%03o",pointer[i++]); ! nfrontp += strlen(nfrontp); } } ! *nfrontp++ = '"'; break; default: ! for (i = 2; i < length; i++) { ! sprintf(nfrontp, " ?%d?", pointer[i]); ! nfrontp += strlen(nfrontp); ! } break; } break; --- 1031,1104 ---- #if defined(AUTHENTICATION) case TELOPT_AUTHENTICATION: ! netputs("AUTHENTICATION"); if (length < 2) { ! netputs(" (empty suboption??\?)"); break; } switch (pointer[1]) { case TELQUAL_REPLY: case TELQUAL_IS: ! netputs((pointer[1] == TELQUAL_IS) ? " IS " : " REPLY "); if (AUTHTYPE_NAME_OK(pointer[2])) ! netputs(AUTHTYPE_NAME(pointer[2])); else ! netprintf(" %d ", pointer[2]); if (length < 3) { ! netputs("(partial suboption??\?)"); break; } ! netputs(((pointer[3] & AUTH_WHO_MASK) == AUTH_WHO_CLIENT) ! ? "CLIENT|" : "SERVER|"); ! netputs(((pointer[3] & AUTH_HOW_MASK) == AUTH_HOW_MUTUAL) ! ? "MUTUAL" : "ONE-WAY"); ! netputs(((pointer[3] & AUTH_ENCRYPT_MASK) == AUTH_ENCRYPT_ON) ! ? "|ENCRYPT" : ""); auth_printsub(&pointer[1], length - 1, buf, sizeof(buf)); ! netputs(buf); break; case TELQUAL_SEND: i = 2; ! netputs(" SEND "); while (i < length) { if (AUTHTYPE_NAME_OK(pointer[i])) ! netputs(AUTHTYPE_NAME(pointer[i])); else ! netprintf("%d", pointer[i]); ! netputs(" "); if (++i >= length) { ! netputs("(partial suboption??\?)"); break; } ! netputs(((pointer[i] & AUTH_WHO_MASK) == AUTH_WHO_CLIENT) ! ? "CLIENT|" : "SERVER|"); ! netputs(((pointer[i] & AUTH_HOW_MASK) == AUTH_HOW_MUTUAL) ! ? "MUTUAL" : "ONE-WAY"); ! if ((pointer[3] & AUTH_ENCRYPT_MASK) == AUTH_ENCRYPT_ON) ! netputs("|ENCRYPT"); ++i; } break; case TELQUAL_NAME: i = 2; ! netputs(" NAME \""); while (i < length) { if (isprint(pointer[i])) ! netprintf("%c", pointer[i++]); else { ! netprintf("\\%03o", pointer[i++]); } } ! netputs("\""); break; default: ! for (i = 2; i < length; i++) ! netprintf(" ?%d?", pointer[i]); break; } break; *************** *** 1079,1165 **** #ifdef ENCRYPTION case TELOPT_ENCRYPT: ! sprintf(nfrontp, "ENCRYPT"); ! nfrontp += strlen(nfrontp); if (length < 2) { ! sprintf(nfrontp, " (empty suboption??\?)"); ! nfrontp += strlen(nfrontp); break; } switch (pointer[1]) { case ENCRYPT_START: ! sprintf(nfrontp, " START"); ! nfrontp += strlen(nfrontp); break; case ENCRYPT_END: ! sprintf(nfrontp, " END"); ! nfrontp += strlen(nfrontp); break; case ENCRYPT_REQSTART: ! sprintf(nfrontp, " REQUEST-START"); ! nfrontp += strlen(nfrontp); break; case ENCRYPT_REQEND: ! sprintf(nfrontp, " REQUEST-END"); ! nfrontp += strlen(nfrontp); break; case ENCRYPT_IS: case ENCRYPT_REPLY: ! sprintf(nfrontp, " %s ", (pointer[1] == ENCRYPT_IS) ? ! "IS" : "REPLY"); ! nfrontp += strlen(nfrontp); if (length < 3) { ! sprintf(nfrontp, " (partial suboption??\?)"); ! nfrontp += strlen(nfrontp); break; } if (ENCTYPE_NAME_OK(pointer[2])) ! sprintf(nfrontp, "%s ", ENCTYPE_NAME(pointer[2])); else ! sprintf(nfrontp, " %d (unknown)", pointer[2]); ! nfrontp += strlen(nfrontp); encrypt_printsub(&pointer[1], length - 1, buf, sizeof(buf)); ! sprintf(nfrontp, "%s", buf); ! nfrontp += strlen(nfrontp); break; case ENCRYPT_SUPPORT: i = 2; ! sprintf(nfrontp, " SUPPORT "); ! nfrontp += strlen(nfrontp); while (i < length) { if (ENCTYPE_NAME_OK(pointer[i])) ! sprintf(nfrontp, "%s ", ENCTYPE_NAME(pointer[i])); else ! sprintf(nfrontp, "%d ", pointer[i]); ! nfrontp += strlen(nfrontp); i++; } break; case ENCRYPT_ENC_KEYID: ! sprintf(nfrontp, " ENC_KEYID", pointer[1]); ! nfrontp += strlen(nfrontp); goto encommon; case ENCRYPT_DEC_KEYID: ! sprintf(nfrontp, " DEC_KEYID", pointer[1]); ! nfrontp += strlen(nfrontp); goto encommon; default: ! sprintf(nfrontp, " %d (unknown)", pointer[1]); ! nfrontp += strlen(nfrontp); encommon: ! for (i = 2; i < length; i++) { ! sprintf(nfrontp, " %d", pointer[i]); ! nfrontp += strlen(nfrontp); ! } break; } break; --- 1106,1177 ---- #ifdef ENCRYPTION case TELOPT_ENCRYPT: ! netputs("ENCRYPT"); if (length < 2) { ! netputs(" (empty suboption??\?)"); break; } switch (pointer[1]) { case ENCRYPT_START: ! netputs(" START"); break; case ENCRYPT_END: ! netputs(" END"); break; case ENCRYPT_REQSTART: ! netputs(" REQUEST-START"); break; case ENCRYPT_REQEND: ! netputs(" REQUEST-END"); break; case ENCRYPT_IS: case ENCRYPT_REPLY: ! netputs((pointer[1] == ENCRYPT_IS) ! ? " IS " : " REPLY "); if (length < 3) { ! netputs(" (partial suboption??\?)"); break; } if (ENCTYPE_NAME_OK(pointer[2])) ! netputs(ENCTYPE_NAME(pointer[2])); else ! netprintf("%d (unknown)", pointer[2]); ! netputs(" "); encrypt_printsub(&pointer[1], length - 1, buf, sizeof(buf)); ! netputs(buf); break; case ENCRYPT_SUPPORT: i = 2; ! netputs(" SUPPORT "); while (i < length) { if (ENCTYPE_NAME_OK(pointer[i])) ! netputs(ENCTYPE_NAME(pointer[i])); else ! netprintf("%d", pointer[i]); ! netputs(" "); i++; } break; case ENCRYPT_ENC_KEYID: ! netputs(" ENC_KEYID"); goto encommon; case ENCRYPT_DEC_KEYID: ! netputs(" DEC_KEYID"); goto encommon; default: ! netprintf(" %d (unknown)", pointer[1]); encommon: ! for (i = 2; i < length; i++) ! netprintf(" %d", pointer[i]); break; } break; *************** *** 1167,1184 **** default: if (TELOPT_OK(pointer[0])) ! sprintf(nfrontp, "%s (unknown)", TELOPT(pointer[0])); else ! sprintf(nfrontp, "%d (unknown)", pointer[i]); ! nfrontp += strlen(nfrontp); ! for (i = 1; i < length; i++) { ! sprintf(nfrontp, " %d", pointer[i]); ! nfrontp += strlen(nfrontp); ! } break; } ! sprintf(nfrontp, "\r\n"); ! nfrontp += strlen(nfrontp); } /* --- 1179,1193 ---- default: if (TELOPT_OK(pointer[0])) ! netputs(TELOPT(pointer[0])); else ! netprintf("%d", pointer[0]); ! netputs(" (unknown)"); ! for (i = 1; i < length; i++) ! netprintf(" %d", pointer[i]); break; } ! netputs("\r\n"); } /* *************** *** 1194,1225 **** char xbuf[30]; while (cnt) { - /* flush net output buffer if no room for new data) */ - if ((&netobuf[BUFSIZ] - nfrontp) < 80) { - netflush(); - } - /* add a line of output */ ! sprintf(nfrontp, "%s: ", tag); ! nfrontp += strlen(nfrontp); for (i = 0; i < 20 && cnt; i++) { ! sprintf(nfrontp, "%02x", *ptr); ! nfrontp += strlen(nfrontp); if (isprint(*ptr)) { xbuf[i] = *ptr; } else { xbuf[i] = '.'; } ! if (i % 2) { ! *nfrontp = ' '; ! nfrontp++; ! } cnt--; ptr++; } xbuf[i] = '\0'; ! sprintf(nfrontp, " %s\r\n", xbuf ); ! nfrontp += strlen(nfrontp); } } #endif /* DIAGNOSTICS */ --- 1203,1227 ---- char xbuf[30]; while (cnt) { /* add a line of output */ ! netputs(tag); ! netputs(": "); for (i = 0; i < 20 && cnt; i++) { ! netprintf("%02x", *ptr); if (isprint(*ptr)) { xbuf[i] = *ptr; } else { xbuf[i] = '.'; } ! if (i % 2) ! netputs(" "); cnt--; ptr++; } xbuf[i] = '\0'; ! netputs(" "); ! netputs(xbuf); ! netputs("\r\n"); } } #endif /* DIAGNOSTICS */