summaryrefslogtreecommitdiffstats
path: root/usr.bin
diff options
context:
space:
mode:
authorpst <pst@FreeBSD.org>1997-01-07 19:47:58 +0000
committerpst <pst@FreeBSD.org>1997-01-07 19:47:58 +0000
commit8f7e8a658530e1968aabc0ac0f782fbed303d4bf (patch)
tree2dff9a048bc39e15cd0278ea5f5782688eeb49af /usr.bin
parent46b285b874270033b54c235b591d75d3042191ab (diff)
downloadFreeBSD-src-8f7e8a658530e1968aabc0ac0f782fbed303d4bf.zip
FreeBSD-src-8f7e8a658530e1968aabc0ac0f782fbed303d4bf.tar.gz
Import a few relatively minor fixes from current Borman telnet.
Add some buffer overrun fixes from OpenBSD and myself. Add skey calculator kludge from OpenBSD. TODO: do a real merge of dab's sources... probably just make telnet and telnetd contrib software. Obtained from: OpenBSD, dab@bsdi.com
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/telnet/Makefile1
-rw-r--r--usr.bin/telnet/commands.c51
-rw-r--r--usr.bin/telnet/externs.h3
-rw-r--r--usr.bin/telnet/sys_bsd.c16
-rw-r--r--usr.bin/telnet/telnet.c9
-rw-r--r--usr.bin/telnet/terminal.c3
6 files changed, 67 insertions, 16 deletions
diff --git a/usr.bin/telnet/Makefile b/usr.bin/telnet/Makefile
index 0da9e25..507830c 100644
--- a/usr.bin/telnet/Makefile
+++ b/usr.bin/telnet/Makefile
@@ -37,6 +37,7 @@ PROG= telnet
CFLAGS+=-DTERMCAP -DKLUDGELINEMODE -DUSE_TERMIO #-DAUTHENTICATION -DENCRYPTION
CFLAGS+=-DENV_HACK
+CFLAGS+=-DPATH_SKEY
CFLAGS+=-I${.CURDIR}/../../lib
#CFLAGS+= -DKRB4
diff --git a/usr.bin/telnet/commands.c b/usr.bin/telnet/commands.c
index 255ed40..ea58c0c 100644
--- a/usr.bin/telnet/commands.c
+++ b/usr.bin/telnet/commands.c
@@ -107,6 +107,37 @@ static char saveline[256];
static int margc;
static char *margv[20];
+#if defined(SKEY)
+#include <sys/wait.h>
+#define PATH_SKEY "/usr/bin/key"
+ int
+skey_calc(argc, argv)
+ int argc;
+ char **argv;
+{
+ int status;
+
+ if(argc != 3) {
+ printf("%s sequence challenge\n", argv[0]);
+ return;
+ }
+
+ switch(fork()) {
+ case 0:
+ execv(PATH_SKEY, argv);
+ exit (1);
+ case -1:
+ perror("fork");
+ break;
+ default:
+ (void) wait(&status);
+ if (WIFEXITED(status))
+ return (WEXITSTATUS(status));
+ return (0);
+ }
+}
+#endif
+
static void
makeargv()
{
@@ -499,7 +530,7 @@ togdebug()
}
#else /* NOT43 */
if (debug) {
- if (net > 0 && SetSockOpt(net, SOL_SOCKET, SO_DEBUG, 0, 0) < 0)
+ if (net > 0 && SetSockOpt(net, SOL_SOCKET, SO_DEBUG, 1) < 0)
perror("setsockopt (SO_DEBUG)");
} else
printf("Cannot turn off socket debugging\n");
@@ -2153,20 +2184,25 @@ tn(argc, argv)
} else {
#endif
temp = inet_addr(hostp);
- if (temp != (unsigned long) -1) {
+ if (temp != INADDR_NONE) {
sin.sin_addr.s_addr = temp;
sin.sin_family = AF_INET;
- (void) strcpy(_hostname, hostp);
+ host = gethostbyaddr((char *)&temp, sizeof(temp), AF_INET);
+ if (host)
+ (void) strncpy(_hostname, host->h_name, sizeof(_hostname));
+ else
+ (void) strncpy(_hostname, hostp, sizeof(_hostname));
+ _hostname[sizeof(_hostname)-1] = '\0';
hostname = _hostname;
} else {
host = gethostbyname(hostp);
if (host) {
sin.sin_family = host->h_addrtype;
#if defined(h_addr) /* In 4.3, this is a #define */
- memcpy((caddr_t)&sin.sin_addr,
+ memmove((caddr_t)&sin.sin_addr,
host->h_addr_list[0], host->h_length);
#else /* defined(h_addr) */
- memcpy((caddr_t)&sin.sin_addr, host->h_addr, host->h_length);
+ memmove((caddr_t)&sin.sin_addr, host->h_addr, host->h_length);
#endif /* defined(h_addr) */
strncpy(_hostname, host->h_name, sizeof(_hostname));
_hostname[sizeof(_hostname)-1] = '\0';
@@ -2356,6 +2392,9 @@ static Command cmdtab[] = {
#endif
{ "environ", envhelp, env_cmd, 0 },
{ "?", helphelp, help, 0 },
+#if defined(SKEY)
+ { "skey", NULL, skey_calc, 0 },
+#endif
0
};
@@ -2541,7 +2580,7 @@ cmdrc(m1, m2)
if (rcname == 0) {
rcname = getenv("HOME");
- if (rcname)
+ if (rcname && (strlen(rcname) + 10) < sizeof(rcbuf))
strcpy(rcbuf, rcname);
else
rcbuf[0] = '\0';
diff --git a/usr.bin/telnet/externs.h b/usr.bin/telnet/externs.h
index 476a444..43fdb43 100644
--- a/usr.bin/telnet/externs.h
+++ b/usr.bin/telnet/externs.h
@@ -144,7 +144,8 @@ extern int
#endif /* defined(TN3270) */
termdata, /* Print out terminal data flow */
#endif /* defined(unix) */
- debug; /* Debug level */
+ debug, /* Debug level */
+ clienteof; /* Client received EOF */
extern cc_t escape; /* Escape to command mode */
extern cc_t rlogin; /* Rlogin mode escape character */
diff --git a/usr.bin/telnet/sys_bsd.c b/usr.bin/telnet/sys_bsd.c
index f08161c..2ffd147 100644
--- a/usr.bin/telnet/sys_bsd.c
+++ b/usr.bin/telnet/sys_bsd.c
@@ -48,6 +48,7 @@ static char sccsid[] = "@(#)sys_bsd.c 8.2 (Berkeley) 12/15/93";
#include <signal.h>
#include <errno.h>
#include <arpa/telnet.h>
+#include <unistd.h>
#include "ring.h"
@@ -1150,17 +1151,24 @@ process_rings(netin, netout, netex, ttyin, ttyout, poll)
if (FD_ISSET(tin, &ibits)) {
FD_CLR(tin, &ibits);
c = TerminalRead(ttyiring.supply, ring_empty_consecutive(&ttyiring));
+ if (c < 0 && errno == EIO)
+ c = 0;
if (c < 0 && errno == EWOULDBLOCK) {
c = 0;
} else {
- /* EOF detection for line mode!!!! */
- if ((c == 0) && MODE_LOCAL_CHARS(globalmode) && isatty(tin)) {
+ if (c < 0) {
+ return -1;
+ }
+ if (c == 0) {
/* must be an EOF... */
+ if (MODE_LOCAL_CHARS(globalmode) && isatty(tin)) {
*ttyiring.supply = termEofChar;
c = 1;
+ } else {
+ clienteof = 1;
+ shutdown(net, 1);
+ return 0;
}
- if (c <= 0) {
- return -1;
}
if (termdata) {
Dump('<', ttyiring.supply, c);
diff --git a/usr.bin/telnet/telnet.c b/usr.bin/telnet/telnet.c
index ea0ac92..3f735a8 100644
--- a/usr.bin/telnet/telnet.c
+++ b/usr.bin/telnet/telnet.c
@@ -57,7 +57,7 @@ static char sccsid[] = "@(#)telnet.c 8.2 (Berkeley) 12/15/93";
#include "general.h"
-#define strip(x) ((x)&0x7f)
+#define strip(x) ((my_want_state_is_wont(TELOPT_BINARY)) ? ((x)&0x7f) : (x))
static unsigned char subbuffer[SUBBUFSIZE],
*subpointer, *subend; /* buffer for sub-options */
@@ -104,7 +104,8 @@ int
donelclchars, /* the user has set "localchars" */
donebinarytoggle, /* the user has put us in binary */
dontlecho, /* do we suppress local echoing right now? */
- globalmode;
+ globalmode,
+ clienteof = 0;
char *prompt = 0;
@@ -2097,9 +2098,9 @@ Scheduler(block)
ttyout = ring_full_count(&ttyoring);
#if defined(TN3270)
- ttyin = ring_empty_count(&ttyiring) && (shell_active == 0);
+ ttyin = ring_empty_count(&ttyiring) && (clienteof == 0) && (shell_active == 0);
#else /* defined(TN3270) */
- ttyin = ring_empty_count(&ttyiring);
+ ttyin = ring_empty_count(&ttyiring) && (clienteof == 0);
#endif /* defined(TN3270) */
#if defined(TN3270)
diff --git a/usr.bin/telnet/terminal.c b/usr.bin/telnet/terminal.c
index 6e3cf69..aeacbb0 100644
--- a/usr.bin/telnet/terminal.c
+++ b/usr.bin/telnet/terminal.c
@@ -140,7 +140,8 @@ ttyflush(drop)
n1 = n0 - n;
if (!drop)
n1 = TerminalWrite(ttyoring.bottom, n1);
- n += n1;
+ if (n1 > 0)
+ n += n1;
}
ring_consumed(&ttyoring, n);
}
OpenPOWER on IntegriCloud