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
This commit is contained in:
parent
1158dfb736
commit
b833b30221
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=21405
@ -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
|
||||
|
@ -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';
|
||||
|
@ -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 */
|
||||
|
@ -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);
|
||||
|
@ -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)
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user