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

@ -4,22 +4,26 @@ $Id$
v0.39.2 21-Nov-2003 v0.39.2 21-Nov-2003
NOTE: Don't use this version yet, mbtelnetd might be removed again! NOTE: Don't use this version yet, mbtelnetd might be removed again!
Well, almost certain that it will be removed. This version is
in cvs because I need to test it on several machines at once.
general: general:
With the use of a proxy based on the iftelnetd from the ifmail With the use of a proxy based on the iftelnetd from the ifmail
package incoming telnet sessions are now supported. Outgoing package incoming telnet sessions are now supported.
telnet still doesn't work. Outgoing telnet finally works.
upgrade: upgrade:
See mbtelnetd.html how to install mbtelnetd. See mbtelnetd.html how to install mbtelnetd.
common.a: common.a:
A small fix in printable function. A small fix in printable log function.
Added a safety check for the TCP registrate function to prevent
stale TCP/IP mailer counts.
mbcico: mbcico:
If called by inetd with the -t itn parameters, mbcico aborts If called by inetd with the -t itn parameters, mbcico aborts
and writes a short instruction in the log to install mbtelnetd. and writes a short instruction in the log to install mbtelnetd.
Outgoing telnet works almost. Outgoing telnet works.
mbtelnetd: mbtelnetd:
New program, a proxy to handle incoming telnet/vmodem sessions. New program, a proxy to handle incoming telnet/vmodem sessions.

View File

@ -4,7 +4,7 @@
* Purpose ...............: Client/Server communications * Purpose ...............: Client/Server communications
* *
***************************************************************************** *****************************************************************************
* Copyright (C) 1997-2002 * Copyright (C) 1997-2003
* *
* Michiel Broek FIDO: 2:280/2802 * Michiel Broek FIDO: 2:280/2802
* Beekmansbos 10 * Beekmansbos 10
@ -37,6 +37,7 @@
int do_quiet = FALSE; /* Quiet flag */ int do_quiet = FALSE; /* Quiet flag */
int show_log = FALSE; /* Show loglines on screen */ int show_log = FALSE; /* Show loglines on screen */
int most_debug = FALSE; /* Toggle normal/most debugging */ int most_debug = FALSE; /* Toggle normal/most debugging */
int tcp_regged = FALSE; /* Safety TCP registration flag */
char progname[21]; /* Program name */ char progname[21]; /* Program name */
char logdebug[PATH_MAX]; /* Debug logfile */ char logdebug[PATH_MAX]; /* Debug logfile */
char logfile[PATH_MAX]; /* Normal logfile */ char logfile[PATH_MAX]; /* Normal logfile */
@ -383,7 +384,10 @@ void IsDoing(const char *format, ...)
void RegTCP(void) void RegTCP(void)
{ {
if (!tcp_regged)
SockS("ATCP:1,%d;", mypid); SockS("ATCP:1,%d;", mypid);
tcp_regged = TRUE;
} }

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

View File

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

View File

@ -1,6 +1,6 @@
/***************************************************************************** /*****************************************************************************
* *
* $id$ * $Id$
* Purpose ...............: Telnet IO filter * Purpose ...............: Telnet IO filter
* *
***************************************************************************** *****************************************************************************
@ -37,7 +37,7 @@
static int tellen; static int tellen;
static int buflen = 0;
/* --- This is an artwork of serge terekhov, 2:5000/13@fidonet :) --- */ /* --- 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; char *q, *p;
static char telbuf[4]; 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) { while ((n == 0) && (n = read (0, buf + tellen, H_ZIPBUFLEN - tellen)) > 0) {
Syslog('s', " n=%d tellen=%d", n, tellen);
if (n < 0) { if (n < 0) {
Syslog('s', "telnet_read n=%d", n);
return n; return n;
} }
if (tellen) { if (tellen) {
Syslog('s', " memcpy");
memcpy(buf, telbuf, tellen); memcpy(buf, telbuf, tellen);
n += tellen; n += tellen;
tellen = 0; tellen = 0;
} }
if (memchr (buf, IAC, n)) { if (memchr (buf, IAC, n)) {
Syslog('s', " IAC detected");
for (p = q = buf; n--; ) for (p = q = buf; n--; )
if ((m = (unsigned char)*q++) != IAC) if ((m = (unsigned char)*q++) != IAC)
*p++ = m; *p++ = m;
@ -154,7 +149,6 @@ int telnet_read(char *buf, int len)
} }
} }
Syslog('s', " return n=%d", n);
return n; return n;
} }
@ -168,7 +162,6 @@ int telnet_write(char *buf, int len)
char *q; char *q;
int k, l; int k, l;
Syslog('s', "telnet_write(buf, %d)", len);
l = len; l = len;
while ((len > 0) && (q = memchr(buf, IAC, len))) { while ((len > 0) && (q = memchr(buf, IAC, len))) {
k = (q - buf) + 1; 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 telnet_buffer(char *buf, int len)
{ {
int i, j, m = 0, rc; int i, j, m = 0, rc;
static char telbuf[4];
rc = len; 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)) { if (memchr (buf, IAC, rc)) {
Syslog('s', "telnet_buffer: IAC in input stream rc=%d", rc);
// Syslogp('s', printable(buf, rc));
j = 0; j = 0;
for (i = 0; i < rc; i++) { for (i = 0; i < rc; i++) {
if ((buf[i] & 0xff) == IAC) { if ((buf[i] & 0xff) == IAC) {
telbuf[buflen] = buf[i] & 0xff;
buflen++;
i++; i++;
if (i >= rc)
break;
switch (buf[i] & 0xff) { switch (buf[i] & 0xff) {
case WILL: i++; case WILL: if ((i+1) < rc) {
buflen = 0;
i++;
m = buf[i] & 0xff; m = buf[i] & 0xff;
Syslog('s', "Telnet recv WILL %d", m); Syslog('s', "Telnet recv WILL %d", m);
if (m != TOPT_BIN && m != TOPT_SUPP && m != TOPT_ECHO) if (m != TOPT_BIN && m != TOPT_SUPP && m != TOPT_ECHO)
telnet_answer(DONT, m); telnet_answer(DONT, m);
} else {
telbuf[buflen] = WILL;
buflen++;
}
break; break;
case WONT: i++; case WONT: if ((i+1) < rc) {
buflen = 0;
i++;
m = buf[i] & 0xff; m = buf[i] & 0xff;
Syslog('s', "Telnet recv WONT %d", m); Syslog('s', "Telnet recv WONT %d", m);
} else {
telbuf[buflen] = WONT;
buflen++;
}
break; break;
case DO: i++; case DO: if ((i+1) < rc) {
buflen = 0;
i++;
m = buf[i] & 0xff; m = buf[i] & 0xff;
Syslog('s', "Telnet recv DO %d", m); Syslog('s', "Telnet recv DO %d", m);
if (m != TOPT_BIN && m != TOPT_SUPP && m != TOPT_ECHO) if (m != TOPT_BIN && m != TOPT_SUPP && m != TOPT_ECHO)
telnet_answer(WONT, m); telnet_answer(WONT, m);
} else {
telbuf[buflen] = DO;
buflen++;
}
break; break;
case DONT: i++; case DONT: if ((i+1) < rc) {
buflen = 0;
i++;
m = buf[i] & 0xff; m = buf[i] & 0xff;
Syslog('s', "Telnet recv DONT %d", m); Syslog('s', "Telnet recv DONT %d", m);
} else {
telbuf[buflen] = DONT;
buflen++;
}
break; break;
case IAC: buf[j] = buf[i]; case IAC: buf[j] = buf[i];
j++; j++;
Syslog('s', "Telnet recv escaped IAC"); buflen = 0;
break; break;
default: m = buf[i] & 0xff; 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; buf[j] = IAC;
j++; j++;
buf[j] = m; buf[j] = m;
@ -239,8 +281,6 @@ int telnet_buffer(char *buf, int len)
} }
} }
rc = j; rc = j;
// Syslog('s', "new rc=%d", rc);
// Syslogp('s', printable(buf, rc));
} }
return rc; return rc;

View File

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

View File

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