From d93317b132bdf92168ef71e626e843527e11b68c Mon Sep 17 00:00:00 2001 From: Michiel Broek Date: Wed, 26 Nov 2003 20:48:48 +0000 Subject: [PATCH] Telnet: back to basics --- mbcico/Makefile | 11 ++- mbcico/call.c | 6 +- mbcico/emsidat.c | 4 +- mbcico/mbcico.c | 13 ++- mbcico/opentcp.c | 11 ++- mbcico/session.c | 4 - mbcico/telnio.c | 227 ----------------------------------------------- mbcico/telnio.h | 22 ----- mbcico/ttyio.c | 23 +---- 9 files changed, 28 insertions(+), 293 deletions(-) delete mode 100644 mbcico/telnio.c delete mode 100644 mbcico/telnio.h diff --git a/mbcico/Makefile b/mbcico/Makefile index 7f886826..b1dd98c0 100644 --- a/mbcico/Makefile +++ b/mbcico/Makefile @@ -12,7 +12,7 @@ SRCS = zmmisc.c zmrle.c zmrecv.c zmsend.c binkp.c md5b.c \ filetime.c ftsc.c atoul.c portsel.c \ ttyio.c lutil.c scanout.c emsi.c ulock.c \ callstat.c session.c call.c mbcico.c \ - outstat.c nlinfo.c mbout.c telnio.c + outstat.c nlinfo.c mbout.c HDRS = zmodem.h binkp.h config.h statetbl.h md5b.h \ xmsend.h xmrecv.h m7recv.h m7send.h hydra.h inbound.h \ answer.h chat.h dial.h dietifna.h emsidat.h filelist.h \ @@ -21,7 +21,7 @@ HDRS = zmodem.h binkp.h config.h statetbl.h md5b.h \ filetime.h ftsc.h atoul.h portsel.h \ ttyio.h lutil.h scanout.h emsi.h ulock.h \ callstat.h session.h call.h mbcico.h \ - outstat.h nlinfo.h telnio.h + outstat.h nlinfo.h MBCICO_OBJS = zmmisc.o zmrle.o zmrecv.o zmsend.o binkp.o md5b.o \ xmsend.o xmrecv.o m7recv.o m7send.o hydra.o inbound.o \ answer.o chat.o dial.o dietifna.o emsidat.o filelist.o \ @@ -29,7 +29,7 @@ MBCICO_OBJS = zmmisc.o zmrle.o zmrecv.o zmsend.o binkp.o md5b.o \ recvbark.o respfreq.o sendbark.o tcp.o tcpproto.o wazoo.o \ filetime.o ftsc.o atoul.o portsel.o \ ttyio.o lutil.o scanout.o emsi.o ulock.o \ - callstat.o session.o call.o telnio.o mbcico.o + callstat.o session.o call.o mbcico.o MBOUT_OBJS = outstat.o nlinfo.o mbout.o scanout.o callstat.o LIBS += ../lib/libclcomm.a ../lib/libcommon.a \ ../lib/libmsgbase.a ../lib/libdbase.a ../lib/libnodelist.a @@ -120,17 +120,16 @@ 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 hydra.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 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 telnio.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 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 nlinfo.o: ../config.h ../lib/libs.h ../lib/structs.h ../lib/common.h ../lib/nodelist.h ../lib/clcomm.h nlinfo.h mbout.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 outstat.h nlinfo.h -telnio.o: ../config.h ../lib/libs.h ../lib/clcomm.h hydra.h telnio.h # End of generated dependencies diff --git a/mbcico/call.c b/mbcico/call.c index 56643466..cbea3b60 100644 --- a/mbcico/call.c +++ b/mbcico/call.c @@ -176,9 +176,9 @@ int call(faddr *addr) tcp_mode = TCPMODE_IBN; } else if (strcmp(protocol, "fido") == 0) { tcp_mode = TCPMODE_IFC; - } else if (strcmp(protocol, "telnet") == 0) { - tcp_mode = TCPMODE_ITN; - telnet = TRUE; +// } else if (strcmp(protocol, "telnet") == 0) { +// tcp_mode = TCPMODE_ITN; +// telnet = TRUE; } else { Syslog('+', "No common TCP/IP protocols for node %s", nlent->name); free(inetaddr); diff --git a/mbcico/emsidat.c b/mbcico/emsidat.c index a74b2d57..ce330357 100644 --- a/mbcico/emsidat.c +++ b/mbcico/emsidat.c @@ -163,8 +163,8 @@ char *mkemsidat(int caller) } p=xstrcat(p,(char *)"{"); -// if (emsi_local_protos & PROT_TCP) -// p=xstrcat(p,(char *)"TCP,"); + if (emsi_local_protos & PROT_TCP) + p=xstrcat(p,(char *)"TCP,"); if (emsi_local_protos & PROT_HYD) p=xstrcat(p,(char *)"HYD,"); if (emsi_local_protos & PROT_JAN) diff --git a/mbcico/mbcico.c b/mbcico/mbcico.c index 2d2335bc..e1a15c45 100644 --- a/mbcico/mbcico.c +++ b/mbcico/mbcico.c @@ -83,11 +83,11 @@ void usage(void) { fprintf(stderr,"ifcico; (c) Eugene G. Crosser, 1993-1997\n"); fprintf(stderr,"mbcico ver. %s; (c) %s\n\n", VERSION, SHORTRIGHT); - fprintf(stderr,"mbcico [-a inetaddr[:port]] [-n phone] [-l tty] [-t ibn|-t ifc|-t itn] node\n"); + fprintf(stderr,"mbcico [-a inetaddr[:port]] [-n phone] [-l tty] [-t ibn|-t ifc] node\n"); fprintf(stderr,"node should be in domain form, e.g. f11.n22.z3\n"); fprintf(stderr," (this implies master mode)\n"); fprintf(stderr," or:\n"); - fprintf(stderr,"mbcico tsync|yoohoo|**EMSI_INQC816|-t ibn|-t ifc|-t itn\n"); + fprintf(stderr,"mbcico tsync|yoohoo|**EMSI_INQC816|-t ibn|-t ifc\n"); fprintf(stderr," (this implies slave mode)\n"); } @@ -357,7 +357,14 @@ int main(int argc, char *argv[]) if (rc > maxrc) maxrc=rc; } else { - /* slave */ + /* + * Slave (answer) mode + */ + if (telnet) { + WriteError("Answering calls with the \"-t itn\" option no longer supported"); + WriteError("Install mbtelind to answer incoming telnet calls"); + die(MBERR_COMMANDLINE); + } if (!answermode && tcp_mode == TCPMODE_IBN) answermode = xstrcpy((char *)"ibn"); rc = maxrc = answer(answermode); diff --git a/mbcico/opentcp.c b/mbcico/opentcp.c index b80a037b..cc472306 100644 --- a/mbcico/opentcp.c +++ b/mbcico/opentcp.c @@ -63,7 +63,6 @@ static int tcp_is_open = FALSE; /* opentcp() was rewritten by Martin Junius */ -/* telnet mode was written by T.Tanaka */ int opentcp(char *name) { @@ -103,11 +102,11 @@ int opentcp(char *name) else server.sin_port = htons(FIDOPORT); break; - case TCPMODE_ITN: if ((se = getservbyname("telnet", "tcp"))) - server.sin_port = se->s_port; - else - server.sin_port = htons(TELNPORT); - break; +// case TCPMODE_ITN: if ((se = getservbyname("telnet", "tcp"))) +// server.sin_port = se->s_port; +// else +// server.sin_port = htons(TELNPORT); +// break; case TCPMODE_IBN: if ((se = getservbyname("binkd", "tcp"))) server.sin_port = se->s_port; else diff --git a/mbcico/session.c b/mbcico/session.c index 9aa959a0..446ff803 100644 --- a/mbcico/session.c +++ b/mbcico/session.c @@ -48,11 +48,9 @@ #include "callstat.h" #include "inbound.h" #include "opentcp.h" -#include "telnio.h" extern int tcp_mode; -extern int telnet; node *nlent; @@ -112,8 +110,6 @@ int session(faddr *a, node *nl, int role, int tp, char *dt) } session_flags |= SESSION_TCP; } - if (telnet && (session_flags & SESSION_TCP)) - telnet_init(); if (data) free(data); diff --git a/mbcico/telnio.c b/mbcico/telnio.c deleted file mode 100644 index 533848c4..00000000 --- a/mbcico/telnio.c +++ /dev/null @@ -1,227 +0,0 @@ -/***************************************************************************** - * - * $Id$ - * Purpose ...............: Telnet IO filter - * - ***************************************************************************** - * Copyright (C) 1997-2003 - * - * Michiel Broek FIDO: 2:280/2802 - * Beekmansbos 10 - * 1971 BV IJmuiden - * the Netherlands - * - * This file is part of MBSE BBS. - * - * This BBS is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation; either version 2, or (at your option) any - * later version. - * - * MBSE BBS is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with MBSE BBS; see the file COPYING. If not, write to the Free - * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. - *****************************************************************************/ - -#include "../config.h" -#include "../lib/libs.h" -#include "../lib/clcomm.h" -#include "hydra.h" -#include "telnio.h" - - -static int buflen = 0; - - -void telnet_answer(int tag, int opt) -{ - char buf[3]; - char *r = (char *)"???"; - - switch (tag) { - case WILL: - r = (char *)"WILL"; - break; - case WONT: - r = (char *)"WONT"; - break; - case DO: - r = (char *)"DO"; - break; - case DONT: - r = (char *)"DONT"; - break; - } - Syslog('s', "TELNET send %s %d", r, opt); - - buf[0] = IAC; - buf[1] = tag; - buf[2] = opt; - if (write (1, buf, 3) != 3) - WriteError("$answer cant send"); -} - - - -int telnet_init(void) -{ - Syslog('s', "telnet_init()"); - telnet_answer(DO, TOPT_SUPP); - telnet_answer(WILL, TOPT_SUPP); - telnet_answer(DO, TOPT_BIN); - telnet_answer(WILL, TOPT_BIN); - telnet_answer(DO, TOPT_ECHO); - telnet_answer(WILL, TOPT_ECHO); - return 1; -} - - - -/* - * Telnet output filter, IAC characters are escaped. - */ -int telnet_write(char *buf, int len) -{ - char *q; - int k, l; - int c = 0; - - Syslog('s', "telnet_write(buf, %d)", len); - l = len; - while ((len > 0) && (q = memchr(buf, IAC, len))) { - k = (q - buf) + 1; - if ((write(1, buf, k) != k) || (write(1, q, 1) != 1)) { - return -1; - } - c += k; - c += 1; - buf += k; - len -= k; - } - - c += len; - if ((len > 0) && write(1, buf, len) != len) { - return -1; - } - - Syslog('s', "telnet_write: real sent %d", c); - return l; -} - - - -/* - * 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; - static char telbuf[4]; - - Syslog('s', "telnet_buffer(buf, %d) buflen=%d", len, buflen); - 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)) { - 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: 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: 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: 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: 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++; - buflen = 0; - break; - default: m = buf[i] & 0xff; - 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; - j++; - break; - } - } else { - buf[j] = buf[i]; - j++; - } - } - rc = j; - } - - Syslog('s', "telnet_buffer: rc=%d buflen=%d", rc, buflen); - - return rc; -} - - diff --git a/mbcico/telnio.h b/mbcico/telnio.h deleted file mode 100644 index 7c1352bb..00000000 --- a/mbcico/telnio.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef _TELNIO_H -#define _TELNIO_H - -/* $Id$ */ - - -#define MBT_WILL 251 -#define MBT_WONT 252 -#define MBT_DO 253 -#define MBT_DONT 254 -#define MBT_IAC 255 - -#define TOPT_BIN 0 -#define TOPT_ECHO 1 -#define TOPT_SUPP 3 - -void telnet_answer(int, int); -int telnet_init(void); -int telnet_write(char *, int); -int telnet_buffer(char *, int); - -#endif diff --git a/mbcico/ttyio.c b/mbcico/ttyio.c index aef5a209..c63a0142 100644 --- a/mbcico/ttyio.c +++ b/mbcico/ttyio.c @@ -38,13 +38,10 @@ #include "../lib/records.h" #include "../lib/common.h" #include "../lib/clcomm.h" -#include "telnio.h" -#include "hydra.h" #include "ttyio.h" #include "lutil.h" extern int hanged_up; -extern int telnet; extern char *inetaddr; #define TT_BUFSIZ 1024 @@ -236,7 +233,7 @@ static int tty_read(char *buf, int size, int tot) } rc = read(0,buf,size); - Syslog('t', "tty_read: real read %d", rc); + if (rc <= 0) { Syslog('t', "tty_read: return %d",rc); if (hanged_up || (errno == EPIPE) || (errno == ECONNRESET)) { @@ -247,13 +244,8 @@ static int tty_read(char *buf, int size, int tot) Syslog('!', "tty_read: error flag"); } rc=-tty_status; - } else { - if (telnet) { - rc = telnet_buffer(buf, rc); - } } - Syslog('t', "tty_read: rc=%d", rc); return rc; } @@ -264,10 +256,7 @@ int tty_write(char *buf, int size) int result; tty_status=0; - if (telnet) - result = telnet_write(buf, size); - else - result = write(1, buf, size); + result = write(1, buf, size); if (result != size) { if (hanged_up || (errno == EPIPE) || (errno == ECONNRESET)) { @@ -584,19 +573,13 @@ int tty_putget(char **obuf, int *osize, char **ibuf, int *isize) WriteError("$tty_putget: read failed"); tty_status=STAT_ERROR; } else { - if (telnet) { - rc = telnet_buffer(*ibuf, rc); - } (*ibuf)+=rc; (*isize)-=rc; } } if (FD_ISSET(1,&writefds) && *osize) { - if (telnet) - rc = telnet_write(*obuf,*osize); - else - rc=write(1,*obuf,*osize); + rc=write(1, *obuf, *osize); if (rc < 0) { WriteError("$tty_putget: write failed"); tty_status=STAT_ERROR;