Made outgoing telnet protocol work

This commit is contained in:
Michiel Broek
2003-11-24 22:19:50 +00:00
parent 4c919784a1
commit 54d9afdd17
8 changed files with 97 additions and 41 deletions

View File

@@ -126,13 +126,13 @@ filetime.o: ../config.h ../lib/libs.h filetime.h
ftsc.o: ../config.h ../lib/libs.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/nodelist.h ../lib/clcomm.h ../lib/mberrors.h session.h ttyio.h statetbl.h config.h ftsc.h rdoptions.h recvbark.h filelist.h sendbark.h respfreq.h xmrecv.h xmsend.h inbound.h
atoul.o: ../config.h ../lib/libs.h atoul.h
portsel.o: ../config.h ../lib/libs.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h portsel.h
ttyio.o: ../config.h ../lib/libs.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h telnio.h ttyio.h lutil.h
ttyio.o: ../config.h ../lib/libs.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h telnio.h hydra.h ttyio.h lutil.h
lutil.o: ../config.h ../lib/libs.h ../lib/structs.h ../lib/common.h ../lib/clcomm.h lutil.h
scanout.o: ../config.h ../lib/libs.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbftn.h config.h scanout.h lutil.h
emsi.o: ../config.h ../lib/libs.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/nodelist.h ../lib/dbnode.h ../lib/clcomm.h ../lib/mberrors.h ttyio.h session.h statetbl.h config.h emsi.h emsidat.h hydra.h rdoptions.h tcp.h wazoo.h inbound.h
ulock.o: ../config.h ../lib/libs.h ../lib/clcomm.h
callstat.o: ../config.h ../lib/libs.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/clcomm.h ../lib/common.h callstat.h
session.o: ../config.h ../lib/libs.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/nodelist.h ../lib/mberrors.h ttyio.h statetbl.h emsi.h ftsc.h session.h yoohoo.h mbcico.h binkp.h callstat.h inbound.h opentcp.h
session.o: ../config.h ../lib/libs.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/nodelist.h ../lib/mberrors.h ttyio.h statetbl.h emsi.h ftsc.h session.h yoohoo.h mbcico.h binkp.h callstat.h inbound.h opentcp.h telnio.h
call.o: ../config.h ../lib/libs.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/nodelist.h ../lib/clcomm.h ../lib/dbnode.h ../lib/mberrors.h session.h callstat.h call.h config.h dial.h lutil.h portsel.h openport.h opentcp.h rdoptions.h inbound.h
mbcico.o: ../config.h ../lib/libs.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/nodelist.h ../lib/clcomm.h ../lib/dbcfg.h ../lib/dbnode.h ../lib/dbftn.h ../lib/mberrors.h config.h answer.h call.h lutil.h mbcico.h session.h
outstat.o: ../config.h ../lib/libs.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/nodelist.h ../lib/clcomm.h ../lib/dbcfg.h ../lib/dbnode.h ../lib/dbftn.h ../lib/mberrors.h scanout.h callstat.h outstat.h

View File

@@ -53,6 +53,7 @@
extern int tcp_mode;
extern int telnet;
extern int immediatecall;
extern char *forcedphone;
extern char *forcedline;
@@ -178,6 +179,7 @@ int call(faddr *addr)
#ifdef USE_TELNET
} else if (strcmp(protocol, "telnet") == 0) {
tcp_mode = TCPMODE_ITN;
telnet = TRUE;
#endif
} else {
Syslog('+', "No common TCP/IP protocols for node %s", nlent->name);

View File

@@ -48,6 +48,7 @@
#include "callstat.h"
#include "inbound.h"
#include "opentcp.h"
#include "telnio.h"
extern int tcp_mode;

View File

@@ -1,6 +1,6 @@
/*****************************************************************************
*
* $id$
* $Id$
* Purpose ...............: Telnet IO filter
*
*****************************************************************************
@@ -37,7 +37,7 @@
static int tellen;
static int buflen = 0;
/* --- This is an artwork of serge terekhov, 2:5000/13@fidonet :) --- */
@@ -96,24 +96,19 @@ int telnet_read(char *buf, int len)
char *q, *p;
static char telbuf[4];
Syslog('s', "telnet_read(buf, %d tellen=%d)", len, tellen);
while ((n == 0) && (n = read (0, buf + tellen, H_ZIPBUFLEN - tellen)) > 0) {
Syslog('s', " n=%d tellen=%d", n, tellen);
if (n < 0) {
Syslog('s', "telnet_read n=%d", n);
return n;
}
if (tellen) {
Syslog('s', " memcpy");
memcpy(buf, telbuf, tellen);
n += tellen;
tellen = 0;
}
if (memchr (buf, IAC, n)) {
Syslog('s', " IAC detected");
for (p = q = buf; n--; )
if ((m = (unsigned char)*q++) != IAC)
*p++ = m;
@@ -154,7 +149,6 @@ int telnet_read(char *buf, int len)
}
}
Syslog('s', " return n=%d", n);
return n;
}
@@ -168,7 +162,6 @@ int telnet_write(char *buf, int len)
char *q;
int k, l;
Syslog('s', "telnet_write(buf, %d)", len);
l = len;
while ((len > 0) && (q = memchr(buf, IAC, len))) {
k = (q - buf) + 1;
@@ -187,46 +180,95 @@ int telnet_write(char *buf, int len)
/*
* Process a passed buffer for telnet escapes sequences. Use a temp
* buffer for sequences at the begin and end of a data block so that
* series of buffers are processed as if it is one stream.
*/
int telnet_buffer(char *buf, int len)
{
int i, j, m = 0, rc;
int i, j, m = 0, rc;
static char telbuf[4];
rc = len;
if (buflen > 2) {
WriteError("buflen=%d");
buflen = 0;
}
/*
* If from a previous call there are some telnet escape characters left in
* telbuf, insert these into the buffer array.
*/
if (buflen) {
memmove(buf+buflen, buf, (size_t)len);
memcpy(buf, telbuf, (size_t)buflen);
rc += buflen;
buflen = 0;
}
if (memchr (buf, IAC, rc)) {
Syslog('s', "telnet_buffer: IAC in input stream rc=%d", rc);
// Syslogp('s', printable(buf, rc));
j = 0;
for (i = 0; i < rc; i++) {
if ((buf[i] & 0xff) == IAC) {
telbuf[buflen] = buf[i] & 0xff;
buflen++;
i++;
if (i >= rc)
break;
switch (buf[i] & 0xff) {
case WILL: i++;
m = buf[i] & 0xff;
Syslog('s', "Telnet recv WILL %d", m);
if (m != TOPT_BIN && m != TOPT_SUPP && m != TOPT_ECHO)
telnet_answer(DONT, m);
case WILL: if ((i+1) < rc) {
buflen = 0;
i++;
m = buf[i] & 0xff;
Syslog('s', "Telnet recv WILL %d", m);
if (m != TOPT_BIN && m != TOPT_SUPP && m != TOPT_ECHO)
telnet_answer(DONT, m);
} else {
telbuf[buflen] = WILL;
buflen++;
}
break;
case WONT: i++;
m = buf[i] & 0xff;
Syslog('s', "Telnet recv WONT %d", m);
case WONT: if ((i+1) < rc) {
buflen = 0;
i++;
m = buf[i] & 0xff;
Syslog('s', "Telnet recv WONT %d", m);
} else {
telbuf[buflen] = WONT;
buflen++;
}
break;
case DO: i++;
m = buf[i] & 0xff;
Syslog('s', "Telnet recv DO %d", m);
if (m != TOPT_BIN && m != TOPT_SUPP && m != TOPT_ECHO)
telnet_answer(WONT, m);
case DO: if ((i+1) < rc) {
buflen = 0;
i++;
m = buf[i] & 0xff;
Syslog('s', "Telnet recv DO %d", m);
if (m != TOPT_BIN && m != TOPT_SUPP && m != TOPT_ECHO)
telnet_answer(WONT, m);
} else {
telbuf[buflen] = DO;
buflen++;
}
break;
case DONT: i++;
m = buf[i] & 0xff;
Syslog('s', "Telnet recv DONT %d", m);
case DONT: if ((i+1) < rc) {
buflen = 0;
i++;
m = buf[i] & 0xff;
Syslog('s', "Telnet recv DONT %d", m);
} else {
telbuf[buflen] = DONT;
buflen++;
}
break;
case IAC: buf[j] = buf[i];
j++;
Syslog('s', "Telnet recv escaped IAC");
buflen = 0;
break;
default: m = buf[i] & 0xff;
Syslog('s', "TELNET: recv IAC %d, this is not good", m);
Syslog('s', "TELNET: recv IAC %d, this is not good, i=%d j=%d", m, i, j);
buflen = 0;
buf[j] = IAC;
j++;
buf[j] = m;
@@ -239,8 +281,6 @@ int telnet_buffer(char *buf, int len)
}
}
rc = j;
// Syslog('s', "new rc=%d", rc);
// Syslogp('s', printable(buf, rc));
}
return rc;

View File

@@ -39,6 +39,7 @@
#include "../lib/common.h"
#include "../lib/clcomm.h"
#include "telnio.h"
#include "hydra.h"
#include "ttyio.h"
#include "lutil.h"

View File

@@ -67,10 +67,14 @@
#define SO 0x0e
#define SI 0x0f
#define DLE 0x10
#ifndef XON
#define XON 0x11
#endif
#define DC1 0x11
#define DC2 0x12
#ifndef XOFF
#define XOFF 0x13
#endif
#define DC3 0x13
#define DC4 0x14
#define NAK 0x15