jcs
/subtext
/amendments
/487
telnet: Crank obuf size, send DO BINARY and WILL BINARY
jcs made amendment 487 about 1 year ago
--- telnet.c Wed Mar 1 16:38:44 2023
+++ telnet.c Thu Apr 27 00:31:32 2023
@@ -94,7 +94,7 @@ struct telnet_node {
char ip_s[20];
struct session *session;
unsigned short obuflen;
- unsigned char obuf[512];
+ unsigned char obuf[1024];
unsigned char ibuf[64];
unsigned short ibuflen;
unsigned short ibufoff;
@@ -326,6 +326,8 @@ telnet_idle(void)
node->session->tspeed = 19200;
node->session->is_telnet = true;
node->session->log.ip_address = telnet_status_pb.remoteHost;
+ if (node->from_trusted_proxy)
+ node->session->can_nomodem = true;
break;
default:
if (telnet_status_pb.remoteHost == 0)
@@ -374,6 +376,8 @@ telnet_setup(struct session *session)
const char iacs[] = {
IAC, WILL, IAC_SGA, /* we will supress go-ahead */
IAC, WILL, IAC_ECHO, /* and we will echo for you */
+ IAC, WILL, IAC_BINARY, /* don't mess with binary data we send */
+ IAC, DO, IAC_BINARY, /* and you can send us binary */
IAC, DO, IAC_TSPEED, /* send your TSPEED */
IAC, DO, IAC_NAWS, /* send your NAWS */
IAC, DO, IAC_TTYPE, /* send your TTYPE */
@@ -407,7 +411,7 @@ telnet_input(struct session *session)
rlen = telnet_status_pb.amtUnreadData;
- if (session->transferring_file) {
+ if (session->direct_output) {
if (session->ibuflen + session->ibufoff + rlen >
sizeof(session->ibuf)) {
/* if we're already halfway through the buffer, reset */
@@ -740,6 +744,12 @@ telnet_output(struct session *session)
process_result:
if (node->tcp_wds[0].length) {
+ if (node->tcp_wds[0].length != node->escaped_obuflen &&
+ node->escaped_obuflen != node->obuflen)
+ warn("bug: tried to send %d (escaped from %d) but TCP says "
+ "we sent %d, how much to shift out?", node->escaped_obuflen,
+ node->obuflen, node->tcp_wds[0].length);
+
/* previous _TCPSend completed, shift out those bytes */
if (session->obuflen < node->obuflen) {
warn("bogus obuflen %d", session->obuflen);
@@ -759,7 +769,7 @@ process_result:
if (session->obuflen == 1 && session->obuf[0] != IAC) {
node->obuf[0] = session->obuf[0];
node->escaped_obuflen = node->obuflen = 1;
- } else if (session->transferring_file) {
+ } else if (session->direct_output) {
memcpy(node->obuf, session->obuf, session->obuflen);
node->escaped_obuflen = node->obuflen = session->obuflen;
} else {