aboutsummaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorPaul Traina <pst@FreeBSD.org>1997-01-07 19:47:58 +0000
committerPaul Traina <pst@FreeBSD.org>1997-01-07 19:47:58 +0000
commitb833b30221b8f4fd7d47f5bc365895e4f2ee776d (patch)
tree2dff9a048bc39e15cd0278ea5f5782688eeb49af /usr.bin
parent1158dfb736ca295317a33b77498ec87f05b4c41f (diff)
downloadsrc-b833b30221b8f4fd7d47f5bc365895e4f2ee776d.tar.gz
src-b833b30221b8f4fd7d47f5bc365895e4f2ee776d.zip
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
Notes
Notes: svn path=/head/; revision=21405
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 0da9e2528add..507830cd6ab5 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 255ed40e8b9d..ea58c0c3e231 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 476a44467ab8..43fdb43287be 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 f08161c0fb20..2ffd14722be7 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 ea0ac92aa377..3f735a8bcd69 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 6e3cf6917106..aeacbb0ffade 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);
}