summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorArtur Grabowski <art@cvs.openbsd.org>1998-03-12 04:57:48 +0000
committerArtur Grabowski <art@cvs.openbsd.org>1998-03-12 04:57:48 +0000
commitff07d4940bd49261ee22ce0ace862e5589593044 (patch)
treef425ce5c7200ee7aba8c8aef0e45753733167523 /usr.bin
parentdc9f07b18d9385c5d9662784d3fd1ac69b5c271a (diff)
encryption support from kth-krb 0.9.8 (kerberos only)
plus some tweaks for better binary/8-bit support.
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/telnet/Makefile18
-rw-r--r--usr.bin/telnet/authenc.c31
-rw-r--r--usr.bin/telnet/commands.c1113
-rw-r--r--usr.bin/telnet/defines.h6
-rw-r--r--usr.bin/telnet/externs.h425
-rw-r--r--usr.bin/telnet/fdset.h52
-rw-r--r--usr.bin/telnet/general.h48
-rw-r--r--usr.bin/telnet/main.c77
-rw-r--r--usr.bin/telnet/network.c31
-rw-r--r--usr.bin/telnet/ring.c76
-rw-r--r--usr.bin/telnet/ring.h16
-rw-r--r--usr.bin/telnet/sys_bsd.c101
-rw-r--r--usr.bin/telnet/telnet.117
-rw-r--r--usr.bin/telnet/telnet.c249
-rw-r--r--usr.bin/telnet/telnet_locl.h92
-rw-r--r--usr.bin/telnet/terminal.c42
-rw-r--r--usr.bin/telnet/tn3270.c21
-rw-r--r--usr.bin/telnet/utilities.c126
18 files changed, 1314 insertions, 1227 deletions
diff --git a/usr.bin/telnet/Makefile b/usr.bin/telnet/Makefile
index 359314d4f07..a8db8d78724 100644
--- a/usr.bin/telnet/Makefile
+++ b/usr.bin/telnet/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.5 1997/09/21 11:51:10 deraadt Exp $
+# $OpenBSD: Makefile,v 1.6 1998/03/12 04:57:26 art Exp $
#
# Copyright (c) 1990 The Regents of the University of California.
# All rights reserved.
@@ -37,21 +37,21 @@
PROG= telnet
CFLAGS+=-DTERMCAP -DKLUDGELINEMODE -DUSE_TERMIO -DSKEY -Dunix
-CFLAGS+=-DENV_HACK
+CFLAGS+=-DENV_HACK
CFLAGS+=-I${.CURDIR}/../../lib
LDADD+= -ltermcap -ltelnet
DPADD= ${LIBTERMCAP} ${LIBTELNET}
-
SRCS= authenc.c commands.c main.c network.c ring.c sys_bsd.c telnet.c \
terminal.c tn3270.c utilities.c
-# These are the sources that have encryption stuff in them.
-CRYPT_SRC= authenc.c commands.c externs.h main.c network.c
-CRYPT_SRC+= ring.c ring.h telnet.c terminal.c utilities.c Makefile
-NOCRYPT_DIR=${.CURDIR}/Nocrypt
+.include <bsd.own.mk> # for KERBEROS
+
+.if (${KERBEROS} == "yes")
+CFLAGS+=-DENCRYPTION -DAUTHENTICATION -DKRB4
+LDADD+= -lkrb -ldes
+DPADD+= ${LIBDES} ${LIBKRB}
+.endif
.include <bsd.prog.mk>
-nocrypt:
- @echo "Encryption code already removed."
diff --git a/usr.bin/telnet/authenc.c b/usr.bin/telnet/authenc.c
index 99fc2ac9d81..26100e47ff8 100644
--- a/usr.bin/telnet/authenc.c
+++ b/usr.bin/telnet/authenc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: authenc.c,v 1.2 1996/03/27 19:32:57 niklas Exp $ */
+/* $OpenBSD: authenc.c,v 1.3 1998/03/12 04:57:27 art Exp $ */
/* $NetBSD: authenc.c,v 1.5 1996/02/28 21:03:52 thorpej Exp $ */
/*-
@@ -34,26 +34,9 @@
* SUCH DAMAGE.
*/
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#)authenc.c 8.1 (Berkeley) 6/6/93";
-static char rcsid[] = "$NetBSD: authenc.c,v 1.5 1996/02/28 21:03:52 thorpej Exp $";
-#else
-static char rcsid[] = "$OpenBSD: authenc.c,v 1.2 1996/03/27 19:32:57 niklas Exp $";
-#endif
-#endif /* not lint */
-
-#if defined(AUTHENTICATION)
-#include <sys/types.h>
-#include <arpa/telnet.h>
-#include <libtelnet/encrypt.h>
-#include <libtelnet/misc.h>
+#include "telnet_locl.h"
-#include "general.h"
-#include "ring.h"
-#include "externs.h"
-#include "defines.h"
-#include "types.h"
+#if defined(AUTHENTICATION) || defined(ENCRYPTION)
int
net_write(str, len)
@@ -72,6 +55,12 @@ net_write(str, len)
void
net_encrypt()
{
+#if defined(ENCRYPTION)
+ if (encrypt_output)
+ ring_encrypt(&netoring, encrypt_output);
+ else
+ ring_clearto(&netoring);
+#endif
}
int
@@ -103,7 +92,7 @@ telnet_gets(prompt, result, length, echo)
if (echo) {
printf("%s", prompt);
res = fgets(result, length, stdin);
- } else if (res = getpass(prompt)) {
+ } else if ((res = getpass(prompt))) {
strncpy(result, res, length);
res = result;
}
diff --git a/usr.bin/telnet/commands.c b/usr.bin/telnet/commands.c
index a7de6983550..5db9aa1d1e9 100644
--- a/usr.bin/telnet/commands.c
+++ b/usr.bin/telnet/commands.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: commands.c,v 1.9 1996/12/22 03:26:08 tholo Exp $ */
+/* $OpenBSD: commands.c,v 1.10 1998/03/12 04:57:29 art Exp $ */
/* $NetBSD: commands.c,v 1.14 1996/03/24 22:03:48 jtk Exp $ */
/*
@@ -34,61 +34,7 @@
* SUCH DAMAGE.
*/
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#)commands.c 8.4 (Berkeley) 5/30/95";
-static char rcsid[] = "$NetBSD: commands.c,v 1.14 1996/03/24 22:03:48 jtk Exp $";
-#else
-static char rcsid[] = "$OpenBSD: commands.c,v 1.9 1996/12/22 03:26:08 tholo Exp $";
-#endif
-#endif /* not lint */
-
-#if defined(unix)
-#include <sys/param.h>
-#if defined(CRAY) || defined(sysV88)
-#include <sys/types.h>
-#endif
-#include <sys/file.h>
-#else
-#include <sys/types.h>
-#endif /* defined(unix) */
-#include <sys/socket.h>
-#include <netinet/in.h>
-#ifdef CRAY
-#include <fcntl.h>
-#endif /* CRAY */
-
-#include <signal.h>
-#include <netdb.h>
-#include <ctype.h>
-#include <pwd.h>
-#include <varargs.h>
-#include <errno.h>
-
-#include <arpa/telnet.h>
-#include <sys/cdefs.h>
-#define P __P
-
-#include "general.h"
-
-#include "ring.h"
-
-#include "externs.h"
-#include "defines.h"
-#include "types.h"
-
-#if !defined(CRAY) && !defined(sysV88)
-#include <netinet/in_systm.h>
-# if (defined(vax) || defined(tahoe) || defined(hp300)) && !defined(ultrix)
-# include <machine/endian.h>
-# endif /* vax */
-#endif /* !defined(CRAY) && !defined(sysV88) */
-#include <netinet/ip.h>
-
-
-#ifndef MAXHOSTNAMELEN
-#define MAXHOSTNAMELEN 64
-#endif MAXHOSTNAMELEN
+#include "telnet_locl.h"
#if defined(IPPROTO_IP) && defined(IP_TOS)
int tos = -1;
@@ -97,13 +43,8 @@ int tos = -1;
char *hostname;
static char _hostname[MAXHOSTNAMELEN];
-extern char *getenv();
-
-extern int isprefix();
-extern char **genget();
-extern int Ambiguous();
-
-static call();
+typedef int (*intrtn_t)(int, char**);
+static int call __P((intrtn_t, ...));
typedef struct {
char *name; /* command name */
@@ -164,7 +105,7 @@ makeargv()
margc++;
cp++;
}
- while (c = *cp) {
+ while ((c = *cp)) {
register int inquote = 0;
while (isspace(c))
c = *++cp;
@@ -336,14 +277,13 @@ sendcmd(argc, argv)
{
int count; /* how many bytes we are going to need to send */
int i;
- int question = 0; /* was at least one argument a question */
struct sendlist *s; /* pointer to current command */
int success = 0;
int needconnect = 0;
if (argc < 2) {
- printf("need at least one argument for 'send' command\n");
- printf("'send ?' for help\n");
+ printf("need at least one argument for 'send' command\r\n");
+ printf("'send ?' for help\r\n");
return 0;
}
/*
@@ -356,17 +296,17 @@ sendcmd(argc, argv)
for (i = 1; i < argc; i++) {
s = GETSEND(argv[i]);
if (s == 0) {
- printf("Unknown send argument '%s'\n'send ?' for help.\n",
+ printf("Unknown send argument '%s'\r\n'send ?' for help.\r\n",
argv[i]);
return 0;
} else if (Ambiguous(s)) {
- printf("Ambiguous send argument '%s'\n'send ?' for help.\n",
+ printf("Ambiguous send argument '%s'\r\n'send ?' for help.\r\n",
argv[i]);
return 0;
}
if (i + s->narg >= argc) {
fprintf(stderr,
- "Need %d argument%s to 'send %s' command. 'send %s ?' for help.\n",
+ "Need %d argument%s to 'send %s' command. 'send %s ?' for help.\r\n",
s->narg, s->narg == 1 ? "" : "s", s->name, s->name);
return 0;
}
@@ -380,23 +320,23 @@ sendcmd(argc, argv)
needconnect += s->needconnect;
}
if (!connected && needconnect) {
- printf("?Need to be connected first.\n");
- printf("'send ?' for help\n");
+ printf("?Need to be connected first.\r\n");
+ printf("'send ?' for help\r\n");
return 0;
}
/* Now, do we have enough room? */
if (NETROOM() < count) {
- printf("There is not enough room in the buffer TO the network\n");
- printf("to process your request. Nothing will be done.\n");
- printf("('send synch' will throw away most data in the network\n");
- printf("buffer, if this might help.)\n");
+ printf("There is not enough room in the buffer TO the network\r\n");
+ printf("to process your request. Nothing will be done.\r\n");
+ printf("('send synch' will throw away most data in the network\r\n");
+ printf("buffer, if this might help.)\r\n");
return 0;
}
/* OK, they are all OK, now go through again and actually send */
count = 0;
for (i = 1; i < argc; i++) {
if ((s = GETSEND(argv[i])) == 0) {
- fprintf(stderr, "Telnet 'send' error - argument disappeared!\n");
+ fprintf(stderr, "Telnet 'send' error - argument disappeared!\r\n");
(void) quit();
/*NOTREACHED*/
}
@@ -413,6 +353,9 @@ sendcmd(argc, argv)
return (count == success);
}
+ static int
+send_tncmd(void (*func)(), char *cmd, char *name);
+
static int
send_esc()
{
@@ -455,29 +398,29 @@ send_tncmd(func, cmd, name)
extern char *telopts[];
register int val = 0;
- if (isprefix(name, "?")) {
+ if (isprefix(name, "help") || isprefix(name, "?")) {
register int col, len;
- printf("Usage: send %s <value|option>\n", cmd);
- printf("\"value\" must be from 0 to 255\n");
- printf("Valid options are:\n\t");
+ printf("Usage: send %s <value|option>\r\n", cmd);
+ printf("\"value\" must be from 0 to 255\r\n");
+ printf("Valid options are:\r\n\t");
col = 8;
for (cpp = telopts; *cpp; cpp++) {
len = strlen(*cpp) + 3;
if (col + len > 65) {
- printf("\n\t");
+ printf("\r\n\t");
col = 8;
}
printf(" \"%s\"", *cpp);
col += len;
}
- printf("\n");
+ printf("\r\n");
return 0;
}
cpp = (char **)genget(name, telopts, sizeof(char *));
if (Ambiguous(cpp)) {
- fprintf(stderr,"'%s': ambiguous argument ('send %s ?' for help).\n",
+ fprintf(stderr,"'%s': ambiguous argument ('send %s ?' for help).\r\n",
name, cmd);
return 0;
}
@@ -492,17 +435,17 @@ send_tncmd(func, cmd, name)
cp++;
}
if (*cp != 0) {
- fprintf(stderr, "'%s': unknown argument ('send %s ?' for help).\n",
+ fprintf(stderr, "'%s': unknown argument ('send %s ?' for help).\r\n",
name, cmd);
return 0;
} else if (val < 0 || val > 255) {
- fprintf(stderr, "'%s': bad value ('send %s ?' for help).\n",
+ fprintf(stderr, "'%s': bad value ('send %s ?' for help).\r\n",
name, cmd);
return 0;
}
}
if (!connected) {
- printf("?Need to be connected first.\n");
+ printf("?Need to be connected first.\r\n");
return 0;
}
(*func)(val, 1);
@@ -515,7 +458,7 @@ send_help()
struct sendlist *s; /* pointer to current command */
for (s = Sendlist; s->name; s++) {
if (s->help)
- printf("%-15s %s\n", s->name, s->help);
+ printf("%-15s %s\r\n", s->name, s->help);
}
return(0);
}
@@ -542,10 +485,10 @@ togdebug()
}
#else /* NOT43 */
if (debug) {
- if (net > 0 && SetSockOpt(net, SOL_SOCKET, SO_DEBUG, 1) < 0)
+ if (net > 0 && SetSockOpt(net, SOL_SOCKET, SO_DEBUG, 0, 0) < 0)
perror("setsockopt (SO_DEBUG)");
} else
- printf("Cannot turn off socket debugging\n");
+ printf("Cannot turn off socket debugging\r\n");
#endif /* NOT43 */
return 1;
}
@@ -555,9 +498,9 @@ togdebug()
togcrlf()
{
if (crlf) {
- printf("Will send carriage returns as telnet <CR><LF>.\n");
+ printf("Will send carriage returns as telnet <CR><LF>.\r\n");
} else {
- printf("Will send carriage returns as telnet <CR><NUL>.\n");
+ printf("Will send carriage returns as telnet <CR><NUL>.\r\n");
}
return 1;
}
@@ -586,17 +529,17 @@ togbinary(val)
if (val == 1) {
if (my_want_state_is_will(TELOPT_BINARY) &&
my_want_state_is_do(TELOPT_BINARY)) {
- printf("Already operating in binary mode with remote host.\n");
+ printf("Already operating in binary mode with remote host.\r\n");
} else {
- printf("Negotiating binary mode with remote host.\n");
+ printf("Negotiating binary mode with remote host.\r\n");
tel_enter_binary(3);
}
} else {
if (my_want_state_is_wont(TELOPT_BINARY) &&
my_want_state_is_dont(TELOPT_BINARY)) {
- printf("Already in network ascii mode with remote host.\n");
+ printf("Already in network ascii mode with remote host.\r\n");
} else {
- printf("Negotiating network ascii mode with remote host.\n");
+ printf("Negotiating network ascii mode with remote host.\r\n");
tel_leave_binary(3);
}
}
@@ -614,16 +557,16 @@ togrbinary(val)
if (val == 1) {
if (my_want_state_is_do(TELOPT_BINARY)) {
- printf("Already receiving in binary mode.\n");
+ printf("Already receiving in binary mode.\r\n");
} else {
- printf("Negotiating binary mode on input.\n");
+ printf("Negotiating binary mode on input.\r\n");
tel_enter_binary(1);
}
} else {
if (my_want_state_is_dont(TELOPT_BINARY)) {
- printf("Already receiving in network ascii mode.\n");
+ printf("Already receiving in network ascii mode.\r\n");
} else {
- printf("Negotiating network ascii mode on input.\n");
+ printf("Negotiating network ascii mode on input.\r\n");
tel_leave_binary(1);
}
}
@@ -641,16 +584,16 @@ togxbinary(val)
if (val == 1) {
if (my_want_state_is_will(TELOPT_BINARY)) {
- printf("Already transmitting in binary mode.\n");
+ printf("Already transmitting in binary mode.\r\n");
} else {
- printf("Negotiating binary mode on output.\n");
+ printf("Negotiating binary mode on output.\r\n");
tel_enter_binary(2);
}
} else {
if (my_want_state_is_wont(TELOPT_BINARY)) {
- printf("Already transmitting in network ascii mode.\n");
+ printf("Already transmitting in network ascii mode.\r\n");
} else {
- printf("Negotiating network ascii mode on output.\n");
+ printf("Negotiating network ascii mode on output.\r\n");
tel_leave_binary(2);
}
}
@@ -662,6 +605,13 @@ static int togglehelp P((void));
#if defined(AUTHENTICATION)
extern int auth_togdebug P((int));
#endif
+#if defined(ENCRYPTION)
+extern int EncryptAutoEnc P((int));
+extern int EncryptAutoDec P((int));
+extern int EncryptDebug P((int));
+extern int EncryptVerbose P((int));
+#endif
+
struct togglelist {
char *name; /* name of toggle */
@@ -677,59 +627,81 @@ static struct togglelist Togglelist[] = {
"flushing of output when sending interrupt characters",
0,
&autoflush,
- "flush output when sending interrupt characters", 0 },
+ "flush output when sending interrupt characters" },
{ "autosynch",
"automatic sending of interrupt characters in urgent mode",
0,
&autosynch,
- "send interrupt characters in urgent mode", 0 },
+ "send interrupt characters in urgent mode" },
#if defined(AUTHENTICATION)
{ "autologin",
"automatic sending of login and/or authentication info",
0,
&autologin,
- "send login name and/or authentication information", 0 },
+ "send login name and/or authentication information" },
{ "authdebug",
"Toggle authentication debugging",
auth_togdebug,
0,
- "print authentication debugging information", 0 },
+ "print authentication debugging information" },
+#endif
+#if defined(ENCRYPTION)
+ { "autoencrypt",
+ "automatic encryption of data stream",
+ EncryptAutoEnc,
+ 0,
+ "automatically encrypt output" },
+ { "autodecrypt",
+ "automatic decryption of data stream",
+ EncryptAutoDec,
+ 0,
+ "automatically decrypt input" },
+ { "verbose_encrypt",
+ "Toggle verbose encryption output",
+ EncryptVerbose,
+ 0,
+ "print verbose encryption output" },
+ { "encdebug",
+ "Toggle encryption debugging",
+ EncryptDebug,
+ 0,
+ "print encryption debugging information" },
#endif
{ "skiprc",
"don't read ~/.telnetrc file",
0,
&skiprc,
- "skip reading of ~/.telnetrc file", 0 },
+ "skip reading of ~/.telnetrc file" },
{ "binary",
"sending and receiving of binary data",
togbinary,
0,
- 0, 1 },
+ 0 },
{ "inbinary",
"receiving of binary data",
togrbinary,
0,
- 0, 1 },
+ 0 },
{ "outbinary",
"sending of binary data",
togxbinary,
0,
- 0, 1 },
+ 0 },
{ "crlf",
"sending carriage returns as telnet <CR><LF>",
togcrlf,
&crlf,
- 0, 0 },
+ 0 },
{ "crmod",
"mapping of received carriage returns",
0,
&crmod,
- "map carriage return on output", 0 },
+ "map carriage return on output" },
{ "localchars",
"local recognition of certain control characters",
lclchars,
&localchars,
- "recognize certain control characters", 0 },
+ "recognize certain control characters" },
{ " ", "", 0, 0 }, /* empty line */
#if defined(unix) && defined(TN3270)
{ "apitrace",
@@ -747,35 +719,35 @@ static struct togglelist Togglelist[] = {
"debugging",
togdebug,
&debug,
- "turn on socket level debugging", 0 },
+ "turn on socket level debugging" },
{ "netdata",
"printing of hexadecimal network data (debugging)",
0,
&netdata,
- "print hexadecimal representation of network traffic", 0 },
+ "print hexadecimal representation of network traffic" },
{ "prettydump",
"output of \"netdata\" to user readable format (debugging)",
0,
&prettydump,
- "print user readable output for \"netdata\"", 0 },
+ "print user readable output for \"netdata\"" },
{ "options",
"viewing of options processing (debugging)",
0,
&showoptions,
- "show option processing", 0 },
+ "show option processing" },
#if defined(unix)
{ "termdata",
"(debugging) toggle printing of hexadecimal terminal data",
0,
&termdata,
- "print hexadecimal representation of terminal traffic", 0 },
+ "print hexadecimal representation of terminal traffic" },
#endif /* defined(unix) */
{ "?",
0,
- togglehelp, 0 },
+ togglehelp },
{ "help",
0,
- togglehelp, 0 },
+ togglehelp },
{ 0 }
};
@@ -787,13 +759,13 @@ togglehelp()
for (c = Togglelist; c->name; c++) {
if (c->help) {
if (*c->help)
- printf("%-15s toggle %s\n", c->name, c->help);
+ printf("%-15s toggle %s\r\n", c->name, c->help);
else
- printf("\n");
+ printf("\r\n");
}
}
- printf("\n");
- printf("%-15s %s\n", "?", "display help information");
+ printf("\r\n");
+ printf("%-15s %s\r\n", "?", "display help information");
return 0;
}
@@ -806,10 +778,10 @@ settogglehelp(set)
for (c = Togglelist; c->name; c++) {
if (c->help) {
if (*c->help)
- printf("%-15s %s %s\n", c->name, set ? "enable" : "disable",
+ printf("%-15s %s %s\r\n", c->name, set ? "enable" : "disable",
c->help);
else
- printf("\n");
+ printf("\r\n");
}
}
}
@@ -828,7 +800,7 @@ toggle(argc, argv)
if (argc < 2) {
fprintf(stderr,
- "Need an argument to 'toggle' command. 'toggle ?' for help.\n");
+ "Need an argument to 'toggle' command. 'toggle ?' for help.\r\n");
return 0;
}
argc--;
@@ -837,22 +809,22 @@ toggle(argc, argv)
name = *argv++;
c = GETTOGGLE(name);
if (Ambiguous(c)) {
- fprintf(stderr, "'%s': ambiguous argument ('toggle ?' for help).\n",
+ fprintf(stderr, "'%s': ambiguous argument ('toggle ?' for help).\r\n",
name);
return 0;
} else if (c == 0) {
- fprintf(stderr, "'%s': unknown argument ('toggle ?' for help).\n",
+ fprintf(stderr, "'%s': unknown argument ('toggle ?' for help).\r\n",
name);
return 0;
} else if (!connected && c->needconnect) {
- printf("?Need to be connected first.\n");
- printf("'send ?' for help\n");
+ printf("?Need to be connected first.\r\n");
+ printf("'send ?' for help\r\n");
return 0;
} else {
if (c->variable) {
*c->variable = !*c->variable; /* invert it */
if (c->actionexplanation) {
- printf("%s %s.\n", *c->variable? "Will" : "Won't",
+ printf("%s %s.\r\n", *c->variable? "Will" : "Won't",
c->actionexplanation);
}
}
@@ -869,7 +841,7 @@ toggle(argc, argv)
*/
#ifdef USE_TERMIO
-struct termio new_tc = { 0 };
+struct termios new_tc = { 0 };
#endif
struct setlist {
@@ -888,55 +860,26 @@ static struct setlist Setlist[] = {
{ "tracefile", "file to write trace information to", SetNetTrace, (cc_t *)NetTraceFile},
{ " ", "" },
{ " ", "The following need 'localchars' to be toggled true", 0, 0 },
- { "flushoutput", "character to cause an Abort Output", 0, termFlushCharp },
- { "interrupt", "character to cause an Interrupt Process", 0, termIntCharp },
- { "quit", "character to cause an Abort process", 0, termQuitCharp },
- { "eof", "character to cause an EOF ", 0, termEofCharp },
+ { "flushoutput", "character to cause an Abort Output", 0, &termFlushChar },
+ { "interrupt", "character to cause an Interrupt Process", 0, &termIntChar },
+ { "quit", "character to cause an Abort process", 0, &termQuitChar },
+ { "eof", "character to cause an EOF ", 0, &termEofChar },
{ " ", "" },
{ " ", "The following are for local editing in linemode", 0, 0 },
- { "erase", "character to use to erase a character", 0, termEraseCharp },
- { "kill", "character to use to erase a line", 0, termKillCharp },
- { "lnext", "character to use for literal next", 0, termLiteralNextCharp },
- { "susp", "character to cause a Suspend Process", 0, termSuspCharp },
- { "reprint", "character to use for line reprint", 0, termRprntCharp },
- { "worderase", "character to use to erase a word", 0, termWerasCharp },
- { "start", "character to use for XON", 0, termStartCharp },
- { "stop", "character to use for XOFF", 0, termStopCharp },
- { "forw1", "alternate end of line character", 0, termForw1Charp },
- { "forw2", "alternate end of line character", 0, termForw2Charp },
- { "ayt", "alternate AYT character", 0, termAytCharp },
+ { "erase", "character to use to erase a character", 0, &termEraseChar },
+ { "kill", "character to use to erase a line", 0, &termKillChar },
+ { "lnext", "character to use for literal next", 0, &termLiteralNextChar },
+ { "susp", "character to cause a Suspend Process", 0, &termSuspChar },
+ { "reprint", "character to use for line reprint", 0, &termRprntChar },
+ { "worderase", "character to use to erase a word", 0, &termWerasChar },
+ { "start", "character to use for XON", 0, &termStartChar },
+ { "stop", "character to use for XOFF", 0, &termStopChar },
+ { "forw1", "alternate end of line character", 0, &termForw1Char },
+ { "forw2", "alternate end of line character", 0, &termForw2Char },
+ { "ayt", "alternate AYT character", 0, &termAytChar },
{ 0 }
};
-#if defined(CRAY) && !defined(__STDC__)
-/* Work around compiler bug in pcc 4.1.5 */
- void
-_setlist_init()
-{
-#ifndef KLUDGELINEMODE
-#define N 5
-#else
-#define N 6
-#endif
- Setlist[N+0].charp = &termFlushChar;
- Setlist[N+1].charp = &termIntChar;
- Setlist[N+2].charp = &termQuitChar;
- Setlist[N+3].charp = &termEofChar;
- Setlist[N+6].charp = &termEraseChar;
- Setlist[N+7].charp = &termKillChar;
- Setlist[N+8].charp = &termLiteralNextChar;
- Setlist[N+9].charp = &termSuspChar;
- Setlist[N+10].charp = &termRprntChar;
- Setlist[N+11].charp = &termWerasChar;
- Setlist[N+12].charp = &termStartChar;
- Setlist[N+13].charp = &termStopChar;
- Setlist[N+14].charp = &termForw1Char;
- Setlist[N+15].charp = &termForw2Char;
- Setlist[N+16].charp = &termAytChar;
-#undef N
-}
-#endif /* defined(CRAY) && !defined(__STDC__) */
-
static struct setlist *
getset(name)
char *name;
@@ -951,11 +894,11 @@ set_escape_char(s)
{
if (rlogin != _POSIX_VDISABLE) {
rlogin = (s && *s) ? special(s) : _POSIX_VDISABLE;
- printf("Telnet rlogin escape character is '%s'.\n",
+ printf("Telnet rlogin escape character is '%s'.\r\n",
control(rlogin));
} else {
escape = (s && *s) ? special(s) : _POSIX_VDISABLE;
- printf("Telnet escape character is '%s'.\n", control(escape));
+ printf("Telnet escape character is '%s'.\r\n", control(escape));
}
}
@@ -969,15 +912,15 @@ setcmd(argc, argv)
struct togglelist *c;
if (argc < 2 || argc > 3) {
- printf("Format is 'set Name Value'\n'set ?' for help.\n");
+ printf("Format is 'set Name Value'\r\n'set ?' for help.\r\n");
return 0;
}
if ((argc == 2) && (isprefix(argv[1], "?") || isprefix(argv[1], "help"))) {
for (ct = Setlist; ct->name; ct++)
- printf("%-15s %s\n", ct->name, ct->help);
- printf("\n");
+ printf("%-15s %s\r\n", ct->name, ct->help);
+ printf("\r\n");
settogglehelp(1);
- printf("%-15s %s\n", "?", "display help information");
+ printf("%-15s %s\r\n", "?", "display help information");
return 0;
}
@@ -985,16 +928,16 @@ setcmd(argc, argv)
if (ct == 0) {
c = GETTOGGLE(argv[1]);
if (c == 0) {
- fprintf(stderr, "'%s': unknown argument ('set ?' for help).\n",
+ fprintf(stderr, "'%s': unknown argument ('set ?' for help).\r\n",
argv[1]);
return 0;
} else if (Ambiguous(c)) {
- fprintf(stderr, "'%s': ambiguous argument ('set ?' for help).\n",
+ fprintf(stderr, "'%s': ambiguous argument ('set ?' for help).\r\n",
argv[1]);
return 0;
} else if (!connected && c->needconnect) {
- printf("?Need to be connected first.\n");
- printf("'send ?' for help\n");
+ printf("?Need to be connected first.\r\n");
+ printf("'send ?' for help\r\n");
return 0;
}
@@ -1004,26 +947,26 @@ setcmd(argc, argv)
else if (strcmp("off", argv[2]) == 0)
*c->variable = 0;
else {
- printf("Format is 'set togglename [on|off]'\n'set ?' for help.\n");
+ printf("Format is 'set togglename [on|off]'\r\n'set ?' for help.\r\n");
return 0;
}
if (c->actionexplanation) {
- printf("%s %s.\n", *c->variable? "Will" : "Won't",
+ printf("%s %s.\r\n", *c->variable? "Will" : "Won't",
c->actionexplanation);
}
}
if (c->handler)
(*c->handler)(1);
} else if (argc != 3) {
- printf("Format is 'set Name Value'\n'set ?' for help.\n");
+ printf("Format is 'set Name Value'\r\n'set ?' for help.\r\n");
return 0;
} else if (Ambiguous(ct)) {
- fprintf(stderr, "'%s': ambiguous argument ('set ?' for help).\n",
+ fprintf(stderr, "'%s': ambiguous argument ('set ?' for help).\r\n",
argv[1]);
return 0;
} else if (ct->handler) {
(*ct->handler)(argv[2]);
- printf("%s set to \"%s\".\n", ct->name, (char *)ct->charp);
+ printf("%s set to \"%s\".\r\n", ct->name, (char *)ct->charp);
} else {
if (strcmp("off", argv[2])) {
value = special(argv[2]);
@@ -1031,7 +974,7 @@ setcmd(argc, argv)
value = _POSIX_VDISABLE;
}
*(ct->charp) = (cc_t)value;
- printf("%s character is '%s'.\n", ct->name, control(*(ct->charp)));
+ printf("%s character is '%s'.\r\n", ct->name, control(*(ct->charp)));
}
slc_check();
return 1;
@@ -1048,15 +991,15 @@ unsetcmd(argc, argv)
if (argc < 2) {
fprintf(stderr,
- "Need an argument to 'unset' command. 'unset ?' for help.\n");
+ "Need an argument to 'unset' command. 'unset ?' for help.\r\n");
return 0;
}
if (isprefix(argv[1], "?") || isprefix(argv[1], "help")) {
for (ct = Setlist; ct->name; ct++)
- printf("%-15s %s\n", ct->name, ct->help);
- printf("\n");
+ printf("%-15s %s\r\n", ct->name, ct->help);
+ printf("\r\n");
settogglehelp(0);
- printf("%-15s %s\n", "?", "display help information");
+ printf("%-15s %s\r\n", "?", "display help information");
return 0;
}
@@ -1068,33 +1011,33 @@ unsetcmd(argc, argv)
if (ct == 0) {
c = GETTOGGLE(name);
if (c == 0) {
- fprintf(stderr, "'%s': unknown argument ('unset ?' for help).\n",
+ fprintf(stderr, "'%s': unknown argument ('unset ?' for help).\r\n",
name);
return 0;
} else if (Ambiguous(c)) {
- fprintf(stderr, "'%s': ambiguous argument ('unset ?' for help).\n",
+ fprintf(stderr, "'%s': ambiguous argument ('unset ?' for help).\r\n",
name);
return 0;
}
if (c->variable) {
*c->variable = 0;
if (c->actionexplanation) {
- printf("%s %s.\n", *c->variable? "Will" : "Won't",
+ printf("%s %s.\r\n", *c->variable? "Will" : "Won't",
c->actionexplanation);
}
}
if (c->handler)
(*c->handler)(0);
} else if (Ambiguous(ct)) {
- fprintf(stderr, "'%s': ambiguous argument ('unset ?' for help).\n",
+ fprintf(stderr, "'%s': ambiguous argument ('unset ?' for help).\r\n",
name);
return 0;
} else if (ct->handler) {
(*ct->handler)(0);
- printf("%s reset to \"%s\".\n", ct->name, (char *)ct->charp);
+ printf("%s reset to \"%s\".\r\n", ct->name, (char *)ct->charp);
} else {
*(ct->charp) = _POSIX_VDISABLE;
- printf("%s character is '%s'.\n", ct->name, control(*(ct->charp)));
+ printf("%s character is '%s'.\r\n", ct->name, control(*(ct->charp)));
}
}
return 1;
@@ -1114,6 +1057,7 @@ dokludgemode()
send_wont(TELOPT_LINEMODE, 1);
send_dont(TELOPT_SGA, 1);
send_dont(TELOPT_ECHO, 1);
+ return 1;
}
#endif
@@ -1150,8 +1094,8 @@ dolmmode(bit, on)
extern int linemode;
if (my_want_state_is_wont(TELOPT_LINEMODE)) {
- printf("?Need to have LINEMODE option enabled first.\n");
- printf("'mode ?' for help.\n");
+ printf("?Need to have LINEMODE option enabled first.\r\n");
+ printf("'mode ?' for help.\r\n");
return 0;
}
@@ -1164,13 +1108,13 @@ dolmmode(bit, on)
}
int
-setmode(bit)
+tn_setmode(bit)
{
return dolmmode(bit, 1);
}
int
-clearmode(bit)
+tn_clearmode(bit)
{
return dolmmode(bit, 0);
}
@@ -1183,7 +1127,7 @@ struct modelist {
int arg1;
};
-extern int modehelp();
+static int modehelp __P((void));
static struct modelist ModeList[] = {
{ "character", "Disable LINEMODE option", docharmode, 1 },
@@ -1196,18 +1140,18 @@ static struct modelist ModeList[] = {
#endif
{ "", "", 0 },
{ "", "These require the LINEMODE option to be enabled", 0 },
- { "isig", "Enable signal trapping", setmode, 1, MODE_TRAPSIG },
- { "+isig", 0, setmode, 1, MODE_TRAPSIG },
- { "-isig", "Disable signal trapping", clearmode, 1, MODE_TRAPSIG },
- { "edit", "Enable character editing", setmode, 1, MODE_EDIT },
- { "+edit", 0, setmode, 1, MODE_EDIT },
- { "-edit", "Disable character editing", clearmode, 1, MODE_EDIT },
- { "softtabs", "Enable tab expansion", setmode, 1, MODE_SOFT_TAB },
- { "+softtabs", 0, setmode, 1, MODE_SOFT_TAB },
- { "-softtabs", "Disable character editing", clearmode, 1, MODE_SOFT_TAB },
- { "litecho", "Enable literal character echo", setmode, 1, MODE_LIT_ECHO },
- { "+litecho", 0, setmode, 1, MODE_LIT_ECHO },
- { "-litecho", "Disable literal character echo", clearmode, 1, MODE_LIT_ECHO },
+ { "isig", "Enable signal trapping", tn_setmode, 1, MODE_TRAPSIG },
+ { "+isig", 0, tn_setmode, 1, MODE_TRAPSIG },
+ { "-isig", "Disable signal trapping", tn_clearmode, 1, MODE_TRAPSIG },
+ { "edit", "Enable character editing", tn_setmode, 1, MODE_EDIT },
+ { "+edit", 0, tn_setmode, 1, MODE_EDIT },
+ { "-edit", "Disable character editing", tn_clearmode, 1, MODE_EDIT },
+ { "softtabs", "Enable tab expansion", tn_setmode, 1, MODE_SOFT_TAB },
+ { "+softtabs", 0, tn_setmode, 1, MODE_SOFT_TAB },
+ { "-softtabs", "Disable character editing", tn_clearmode, 1, MODE_SOFT_TAB },
+ { "litecho", "Enable literal character echo", tn_setmode, 1, MODE_LIT_ECHO },
+ { "+litecho", 0, tn_setmode, 1, MODE_LIT_ECHO },
+ { "-litecho", "Disable literal character echo", tn_clearmode, 1, MODE_LIT_ECHO },
{ "help", 0, modehelp, 0 },
#ifdef KLUDGELINEMODE
{ "kludgeline", 0, dokludgemode, 1 },
@@ -1218,18 +1162,18 @@ static struct modelist ModeList[] = {
};
- int
+ static int
modehelp()
{
struct modelist *mt;
- printf("format is: 'mode Mode', where 'Mode' is one of:\n\n");
+ printf("format is: 'mode Mode', where 'Mode' is one of:\r\n\r\n");
for (mt = ModeList; mt->name; mt++) {
if (mt->help) {
if (*mt->help)
- printf("%-15s %s\n", mt->name, mt->help);
+ printf("%-15s %s\r\n", mt->name, mt->help);
else
- printf("\n");
+ printf("\r\n");
}
}
return 0;
@@ -1246,15 +1190,15 @@ modecmd(argc, argv)
struct modelist *mt;
if (argc != 2) {
- printf("'mode' command requires an argument\n");
- printf("'mode ?' for help.\n");
+ printf("'mode' command requires an argument\r\n");
+ printf("'mode ?' for help.\r\n");
} else if ((mt = GETMODECMD(argv[1])) == 0) {
- fprintf(stderr, "Unknown mode '%s' ('mode ?' for help).\n", argv[1]);
+ fprintf(stderr, "Unknown mode '%s' ('mode ?' for help).\r\n", argv[1]);
} else if (Ambiguous(mt)) {
- fprintf(stderr, "Ambiguous mode '%s' ('mode ?' for help).\n", argv[1]);
+ fprintf(stderr, "Ambiguous mode '%s' ('mode ?' for help).\r\n", argv[1]);
} else if (mt->needconnect && !connected) {
- printf("?Need to be connected first.\n");
- printf("'mode ?' for help.\n");
+ printf("?Need to be connected first.\r\n");
+ printf("'mode ?' for help.\r\n");
} else if (mt->handler) {
return (*mt->handler)(mt->arg1);
}
@@ -1280,21 +1224,21 @@ display(argc, argv)
} else { \
printf("won't"); \
} \
- printf(" %s.\n", tl->actionexplanation); \
+ printf(" %s.\r\n", tl->actionexplanation); \
}
#define doset(sl) if (sl->name && *sl->name != ' ') { \
if (sl->handler == 0) \
- printf("%-15s [%s]\n", sl->name, control(*sl->charp)); \
+ printf("%-15s [%s]\r\n", sl->name, control(*sl->charp)); \
else \
- printf("%-15s \"%s\"\n", sl->name, (char *)sl->charp); \
+ printf("%-15s \"%s\"\r\n", sl->name, (char *)sl->charp); \
}
if (argc == 1) {
for (tl = Togglelist; tl->name; tl++) {
dotog(tl);
}
- printf("\n");
+ printf("\r\n");
for (sl = Setlist; sl->name; sl++) {
doset(sl);
}
@@ -1305,10 +1249,10 @@ display(argc, argv)
sl = getset(argv[i]);
tl = GETTOGGLE(argv[i]);
if (Ambiguous(sl) || Ambiguous(tl)) {
- printf("?Ambiguous argument '%s'.\n", argv[i]);
+ printf("?Ambiguous argument '%s'.\r\n", argv[i]);
return 0;
} else if (!sl && !tl) {
- printf("?Unknown argument '%s'.\n", argv[i]);
+ printf("?Unknown argument '%s'.\r\n", argv[i]);
return 0;
} else {
if (tl) {
@@ -1321,11 +1265,14 @@ display(argc, argv)
}
}
/*@*/optionstatus();
+#if defined(ENCRYPTION)
+ EncryptStatus();
+#endif
return 1;
#undef doset
#undef dotog
}
-
+
/*
* The following are the data structures, and many of the routines,
* relating to command processing.
@@ -1343,7 +1290,7 @@ setescape(argc, argv)
char buf[50];
printf(
- "Deprecated usage - please use 'set escape%s%s' in the future.\n",
+ "Deprecated usage - please use 'set escape%s%s' in the future.\r\n",
(argc > 2)? " ":"", (argc > 2)? argv[1]: "");
if (argc > 2)
arg = argv[1];
@@ -1355,7 +1302,7 @@ setescape(argc, argv)
if (arg[0] != '\0')
escape = arg[0];
if (!In3270) {
- printf("Escape character is '%s'.\n", control(escape));
+ printf("Escape character is '%s'.\r\n", control(escape));
}
(void) fflush(stdout);
return 1;
@@ -1366,15 +1313,15 @@ setescape(argc, argv)
togcrmod()
{
crmod = !crmod;
- printf("Deprecated usage - please use 'toggle crmod' in the future.\n");
- printf("%s map carriage return on output.\n", crmod ? "Will" : "Won't");
+ printf("Deprecated usage - please use 'toggle crmod' in the future.\r\n");
+ printf("%s map carriage return on output.\r\n", crmod ? "Will" : "Won't");
(void) fflush(stdout);
return 1;
}
/*VARARGS*/
- int
-suspend()
+ static int
+telnetsuspend()
{
#ifdef SIGTSTP
setcommandmode();
@@ -1397,7 +1344,7 @@ suspend()
TerminalSaveState();
setconnmode(0);
#else
- printf("Suspend is not supported. Try the '!' command instead\n");
+ printf("Suspend is not supported. Try the '!' command instead\r\n");
#endif
return 1;
}
@@ -1416,7 +1363,7 @@ shell(argc, argv)
err = (TerminalWindowSize(&oldrows, &oldcols) == 0) ? 1 : 0;
switch(vfork()) {
case -1:
- perror("Fork failed\n");
+ perror("Fork failed\r\n");
break;
case 0:
@@ -1425,7 +1372,6 @@ shell(argc, argv)
* Fire up the shell in the child.
*/
register char *shellp, *shellname;
- extern char *strrchr();
shellp = getenv("SHELL");
if (shellp == NULL)
@@ -1466,11 +1412,11 @@ bye(argc, argv)
if (connected) {
(void) shutdown(net, 2);
- printf("Connection closed.\n");
+ printf("Connection closed.\r\n");
(void) NetClose(net);
connected = 0;
resettermname = 1;
-#if defined(AUTHENTICATION)
+#if defined(AUTHENTICATION) || defined(ENCRYPTION)
auth_encrypt_connect(connected);
#endif /* defined(AUTHENTICATION) */
/* reset options */
@@ -1483,19 +1429,20 @@ bye(argc, argv)
longjmp(toplevel, 1);
/* NOTREACHED */
}
- return 1; /* Keep lint, etc., happy */
+ return 0; /* NOTREACHED */
}
/*VARARGS*/
+ int
quit()
{
(void) call(bye, "bye", "fromquit", 0);
Exit(0);
- /*NOTREACHED*/
+ return 0; /*NOTREACHED*/
}
/*VARARGS*/
- int
+ static int
logout()
{
send_do(TELOPT_LOGOUT, 1);
@@ -1537,9 +1484,9 @@ slc_help()
for (c = SlcList; c->name; c++) {
if (c->help) {
if (*c->help)
- printf("%-15s %s\n", c->name, c->help);
+ printf("%-15s %s\r\n", c->name, c->help);
else
- printf("\n");
+ printf("\r\n");
}
}
}
@@ -1561,17 +1508,17 @@ slccmd(argc, argv)
if (argc != 2) {
fprintf(stderr,
- "Need an argument to 'slc' command. 'slc ?' for help.\n");
+ "Need an argument to 'slc' command. 'slc ?' for help.\r\n");
return 0;
}
c = getslc(argv[1]);
if (c == 0) {
- fprintf(stderr, "'%s': unknown argument ('slc ?' for help).\n",
+ fprintf(stderr, "'%s': unknown argument ('slc ?' for help).\r\n",
argv[1]);
return 0;
}
if (Ambiguous(c)) {
- fprintf(stderr, "'%s': ambiguous argument ('slc ?' for help).\n",
+ fprintf(stderr, "'%s': ambiguous argument ('slc ?' for help).\r\n",
argv[1]);
return 0;
}
@@ -1591,19 +1538,7 @@ struct envlist {
int narg;
};
-extern struct env_lst *
- env_define P((unsigned char *, unsigned char *));
-extern void
- env_undefine P((unsigned char *)),
- env_export P((unsigned char *)),
- env_unexport P((unsigned char *)),
- env_send P((unsigned char *)),
-#if defined(OLD_ENVIRON) && defined(ENV_HACK)
- env_varval P((unsigned char *)),
-#endif
- env_list P((void));
-static void
- env_help P((void));
+static void env_help P((void));
struct envlist EnvList[] = {
{ "define", "Define an environment variable",
@@ -1634,9 +1569,9 @@ env_help()
for (c = EnvList; c->name; c++) {
if (c->help) {
if (*c->help)
- printf("%-15s %s\n", c->name, c->help);
+ printf("%-15s %s\r\n", c->name, c->help);
else
- printf("\n");
+ printf("\r\n");
}
}
}
@@ -1657,23 +1592,23 @@ env_cmd(argc, argv)
if (argc < 2) {
fprintf(stderr,
- "Need an argument to 'environ' command. 'environ ?' for help.\n");
+ "Need an argument to 'environ' command. 'environ ?' for help.\r\n");
return 0;
}
c = getenvcmd(argv[1]);
if (c == 0) {
- fprintf(stderr, "'%s': unknown argument ('environ ?' for help).\n",
+ fprintf(stderr, "'%s': unknown argument ('environ ?' for help).\r\n",
argv[1]);
return 0;
}
if (Ambiguous(c)) {
- fprintf(stderr, "'%s': ambiguous argument ('environ ?' for help).\n",
+ fprintf(stderr, "'%s': ambiguous argument ('environ ?' for help).\r\n",
argv[1]);
return 0;
}
if (c->narg + 2 != argc) {
fprintf(stderr,
- "Need %s%d argument%s to 'environ %s' command. 'environ ?' for help.\n",
+ "Need %s%d argument%s to 'environ %s' command. 'environ ?' for help.\r\n",
c->narg < argc + 2 ? "only " : "",
c->narg, c->narg == 1 ? "" : "s", c->name);
return 0;
@@ -1710,12 +1645,11 @@ env_find(var)
env_init()
{
extern char **environ;
- register char **epp, *cp;
- register struct env_lst *ep;
- extern char *strchr();
+ char **epp, *cp;
+ struct env_lst *ep;
for (epp = environ; *epp; epp++) {
- if (cp = strchr(*epp, '=')) {
+ if ((cp = strchr(*epp, '='))) {
*cp = '\0';
ep = env_define((unsigned char *)*epp,
(unsigned char *)cp+1);
@@ -1736,8 +1670,17 @@ env_init()
gethostname(hbuf, 256);
hbuf[256] = '\0';
- cp = (char *)malloc(strlen(hbuf) + strlen(cp2) + 1);
- sprintf((char *)cp, "%s%s", hbuf, cp2);
+
+ /* If this is not the full name, try to get it via DNS */
+ if (strchr(hbuf, '.') == 0) {
+ struct hostent *he = gethostbyname(hbuf);
+ if (he != 0)
+ strncpy(hbuf, he->h_name, 256);
+ hbuf[256] = '\0';
+ }
+
+ asprintf (&cp, "%s%s", hbuf, cp2);
+
free(ep->value);
ep->value = (unsigned char *)cp;
}
@@ -1752,6 +1695,7 @@ env_init()
}
env_export((unsigned char *)"DISPLAY");
env_export((unsigned char *)"PRINTER");
+ env_export((unsigned char *)"XAUTHORITY");
}
struct env_lst *
@@ -1760,7 +1704,7 @@ env_define(var, value)
{
register struct env_lst *ep;
- if (ep = env_find(var)) {
+ if ((ep = env_find(var))) {
if (ep->var)
free(ep->var);
if (ep->value)
@@ -1773,7 +1717,7 @@ env_define(var, value)
if (ep->next)
ep->next->prev = ep;
}
- ep->welldefined = opt_welldefined(var);
+ ep->welldefined = opt_welldefined((char *)var);
ep->export = 1;
ep->var = (unsigned char *)strdup((char *)var);
ep->value = (unsigned char *)strdup((char *)value);
@@ -1786,7 +1730,7 @@ env_undefine(var)
{
register struct env_lst *ep;
- if (ep = env_find(var)) {
+ if ((ep = env_find(var))) {
ep->prev->next = ep->next;
if (ep->next)
ep->next->prev = ep->prev;
@@ -1804,7 +1748,7 @@ env_export(var)
{
register struct env_lst *ep;
- if (ep = env_find(var))
+ if ((ep = env_find(var)))
ep->export = 1;
}
@@ -1830,13 +1774,13 @@ env_send(var)
#endif
) {
fprintf(stderr,
- "Cannot send '%s': Telnet ENVIRON option not enabled\n",
+ "Cannot send '%s': Telnet ENVIRON option not enabled\r\n",
var);
return;
}
ep = env_find(var);
if (ep == 0) {
- fprintf(stderr, "Cannot send '%s': variable not defined\n",
+ fprintf(stderr, "Cannot send '%s': variable not defined\r\n",
var);
return;
}
@@ -1851,7 +1795,7 @@ env_list()
register struct env_lst *ep;
for (ep = envlisthead.next; ep; ep = ep->next) {
- printf("%c %-20s %s\n", ep->export ? '*' : ' ',
+ printf("%c %-20s %s\r\n", ep->export ? '*' : ' ',
ep->var, ep->value);
}
}
@@ -1864,10 +1808,10 @@ env_default(init, welldefined)
if (init) {
nep = &envlisthead;
- return;
+ return NULL;
}
if (nep) {
- while (nep = nep->next) {
+ while ((nep = nep->next)) {
if (nep->export && (nep->welldefined == welldefined))
return(nep->var);
}
@@ -1881,7 +1825,7 @@ env_getvalue(var)
{
register struct env_lst *ep;
- if (ep = env_find(var))
+ if ((ep = env_find(var)))
return(ep->value);
return(NULL);
}
@@ -1900,11 +1844,11 @@ env_varval(what)
if (strncasecmp((char *)what, "status", len) == 0) {
if (env_auto)
printf("%s%s", "VAR and VALUE are/will be ",
- "determined automatically\n");
+ "determined automatically\r\n");
if (old_env_var == OLD_ENV_VAR)
- printf("VAR and VALUE set to correct definitions\n");
+ printf("VAR and VALUE set to correct definitions\r\n");
else
- printf("VAR and VALUE definitions are reversed\n");
+ printf("VAR and VALUE definitions are reversed\r\n");
} else if (strncasecmp((char *)what, "auto", len) == 0) {
env_auto = 1;
old_env_var = OLD_ENV_VALUE;
@@ -1919,7 +1863,7 @@ env_varval(what)
old_env_value = OLD_ENV_VAR;
} else {
unknown:
- printf("Unknown \"varval\" command. (\"auto\", \"right\", \"wrong\", \"status\")\n");
+ printf("Unknown \"varval\" command. (\"auto\", \"right\", \"wrong\", \"status\")\r\n");
}
}
#endif
@@ -1936,10 +1880,6 @@ struct authlist {
int narg;
};
-extern int
- auth_enable P((char *)),
- auth_disable P((char *)),
- auth_status P((void));
static int
auth_help P((void));
@@ -1963,9 +1903,9 @@ auth_help()
for (c = AuthList; c->name; c++) {
if (c->help) {
if (*c->help)
- printf("%-15s %s\n", c->name, c->help);
+ printf("%-15s %s\r\n", c->name, c->help);
else
- printf("\n");
+ printf("\r\n");
}
}
return 0;
@@ -1979,25 +1919,25 @@ auth_cmd(argc, argv)
if (argc < 2) {
fprintf(stderr,
- "Need an argument to 'auth' command. 'auth ?' for help.\n");
+ "Need an argument to 'auth' command. 'auth ?' for help.\r\n");
return 0;
}
c = (struct authlist *)
genget(argv[1], (char **) AuthList, sizeof(struct authlist));
if (c == 0) {
- fprintf(stderr, "'%s': unknown argument ('auth ?' for help).\n",
+ fprintf(stderr, "'%s': unknown argument ('auth ?' for help).\r\n",
argv[1]);
return 0;
}
if (Ambiguous(c)) {
- fprintf(stderr, "'%s': ambiguous argument ('auth ?' for help).\n",
+ fprintf(stderr, "'%s': ambiguous argument ('auth ?' for help).\r\n",
argv[1]);
return 0;
}
if (c->narg + 2 != argc) {
fprintf(stderr,
- "Need %s%d argument%s to 'auth %s' command. 'auth ?' for help.\n",
+ "Need %s%d argument%s to 'auth %s' command. 'auth ?' for help.\r\n",
c->narg < argc + 2 ? "only " : "",
c->narg, c->narg == 1 ? "" : "s", c->name);
return 0;
@@ -2006,6 +1946,107 @@ auth_cmd(argc, argv)
}
#endif
+#if defined(ENCRYPTION)
+/*
+ * The ENCRYPT command.
+ */
+
+struct encryptlist {
+ char *name;
+ char *help;
+ int (*handler)();
+ int needconnect;
+ int minarg;
+ int maxarg;
+};
+
+static int
+ EncryptHelp (void);
+
+struct encryptlist EncryptList[] = {
+ { "enable", "Enable encryption. ('encrypt enable ?' for more)",
+ EncryptEnable, 1, 1, 2 },
+ { "disable", "Disable encryption. ('encrypt enable ?' for more)",
+ EncryptDisable, 0, 1, 2 },
+ { "type", "Set encryptiong type. ('encrypt type ?' for more)",
+ EncryptType, 0, 1, 1 },
+ { "start", "Start encryption. ('encrypt start ?' for more)",
+ EncryptStart, 1, 0, 1 },
+ { "stop", "Stop encryption. ('encrypt stop ?' for more)",
+ EncryptStop, 1, 0, 1 },
+ { "input", "Start encrypting the input stream",
+ EncryptStartInput, 1, 0, 0 },
+ { "-input", "Stop encrypting the input stream",
+ EncryptStopInput, 1, 0, 0 },
+ { "output", "Start encrypting the output stream",
+ EncryptStartOutput, 1, 0, 0 },
+ { "-output", "Stop encrypting the output stream",
+ EncryptStopOutput, 1, 0, 0 },
+
+ { "status", "Display current status of authentication information",
+ EncryptStatus, 0, 0, 0 },
+ { "help", 0, EncryptHelp, 0, 0, 0 },
+ { "?", "Print help information", EncryptHelp, 0, 0, 0 },
+ { 0 },
+};
+
+static int
+EncryptHelp()
+{
+ struct encryptlist *c;
+
+ for (c = EncryptList; c->name; c++) {
+ if (c->help) {
+ if (*c->help)
+ printf("%-15s %s\r\n", c->name, c->help);
+ else
+ printf("\r\n");
+ }
+ }
+ return 0;
+}
+
+static int
+encrypt_cmd(int argc, char **argv)
+{
+ struct encryptlist *c;
+ c = (struct encryptlist *)
+ genget(argv[1], (char **) EncryptList, sizeof(struct encryptlist));
+ if (c == 0) {
+ fprintf(stderr, "'%s': unknown argument ('encrypt ?' for help).\r\n",
+ argv[1]);
+ return 0;
+ }
+ if (Ambiguous(c)) {
+ fprintf(stderr, "'%s': ambiguous argument ('encrypt ?' for help).\r\n",
+ argv[1]);
+ return 0;
+ }
+ argc -= 2;
+ if (argc < c->minarg || argc > c->maxarg) {
+ if (c->minarg == c->maxarg) {
+ fprintf(stderr, "Need %s%d argument%s ",
+ c->minarg < argc ? "only " : "", c->minarg,
+ c->minarg == 1 ? "" : "s");
+ } else {
+ fprintf(stderr, "Need %s%d-%d arguments ",
+ c->maxarg < argc ? "only " : "", c->minarg, c->maxarg);
+ }
+ fprintf(stderr, "to 'encrypt %s' command. 'encrypt ?' for help.\r\n",
+ c->name);
+ return 0;
+ }
+ if (c->needconnect && !connected) {
+ if (!(argc && (isprefix(argv[2], "help") || isprefix(argv[2], "?")))) {
+ printf("?Need to be connected first.\r\n");
+ return 0;
+ }
+ }
+ return ((*c->handler)(argc > 0 ? argv[2] : 0,
+ argc > 1 ? argv[3] : 0,
+ argc > 2 ? argv[4] : 0));
+}
+#endif
#if defined(unix) && defined(TN3270)
static void
@@ -2023,7 +2064,7 @@ filestuff(fd)
perror("fcntl");
return;
}
- printf("\tOwner is %d.\n", res);
+ printf("\tOwner is %d.\r\n", res);
#endif
setconnmode(0);
@@ -2035,7 +2076,7 @@ filestuff(fd)
return;
}
#ifdef notdef
- printf("\tFlags are 0x%x: %s\n", res, decodeflags(res));
+ printf("\tFlags are 0x%x: %s\r\n", res, decodeflags(res));
#endif
}
#endif /* defined(unix) && defined(TN3270) */
@@ -2050,56 +2091,59 @@ status(argc, argv)
char *argv[];
{
if (connected) {
- printf("Connected to %s.\n", hostname);
+ printf("Connected to %s.\r\n", hostname);
if ((argc < 2) || strcmp(argv[1], "notmuch")) {
int mode = getconnmode();
if (my_want_state_is_will(TELOPT_LINEMODE)) {
- printf("Operating with LINEMODE option\n");
- printf("%s line editing\n", (mode&MODE_EDIT) ? "Local" : "No");
- printf("%s catching of signals\n",
+ printf("Operating with LINEMODE option\r\n");
+ printf("%s line editing\r\n", (mode&MODE_EDIT) ? "Local" : "No");
+ printf("%s catching of signals\r\n",
(mode&MODE_TRAPSIG) ? "Local" : "No");
slcstate();
#ifdef KLUDGELINEMODE
} else if (kludgelinemode && my_want_state_is_dont(TELOPT_SGA)) {
- printf("Operating in obsolete linemode\n");
+ printf("Operating in obsolete linemode\r\n");
#endif
} else {
- printf("Operating in single character mode\n");
+ printf("Operating in single character mode\r\n");
if (localchars)
- printf("Catching signals locally\n");
+ printf("Catching signals locally\r\n");
}
- printf("%s character echo\n", (mode&MODE_ECHO) ? "Local" : "Remote");
+ printf("%s character echo\r\n", (mode&MODE_ECHO) ? "Local" : "Remote");
if (my_want_state_is_will(TELOPT_LFLOW))
- printf("%s flow control\n", (mode&MODE_FLOW) ? "Local" : "No");
+ printf("%s flow control\r\n", (mode&MODE_FLOW) ? "Local" : "No");
+#if defined(ENCRYPTION)
+ encrypt_display();
+#endif
}
} else {
- printf("No connection.\n");
+ printf("No connection.\r\n");
}
# if !defined(TN3270)
- printf("Escape character is '%s'.\n", control(escape));
+ printf("Escape character is '%s'.\r\n", control(escape));
(void) fflush(stdout);
# else /* !defined(TN3270) */
if ((!In3270) && ((argc < 2) || strcmp(argv[1], "notmuch"))) {
- printf("Escape character is '%s'.\n", control(escape));
+ printf("Escape character is '%s'.\r\n", control(escape));
}
# if defined(unix)
if ((argc >= 2) && !strcmp(argv[1], "everything")) {
- printf("SIGIO received %d time%s.\n",
+ printf("SIGIO received %d time%s.\r\n",
sigiocount, (sigiocount == 1)? "":"s");
if (In3270) {
- printf("Process ID %d, process group %d.\n",
+ printf("Process ID %d, process group %d.\r\n",
getpid(), getpgrp(getpid()));
- printf("Terminal input:\n");
+ printf("Terminal input:\r\n");
filestuff(tin);
- printf("Terminal output:\n");
+ printf("Terminal output:\r\n");
filestuff(tout);
- printf("Network socket:\n");
+ printf("Network socket:\r\n");
filestuff(net);
}
}
if (In3270 && transcom) {
- printf("Transparent mode command is '%s'.\n", transcom);
+ printf("Transparent mode command is '%s'.\r\n", transcom);
}
# endif /* defined(unix) */
(void) fflush(stdout);
@@ -2107,6 +2151,7 @@ status(argc, argv)
return 0;
}
# endif /* defined(TN3270) */
+ fflush(stdout);
return 1;
}
@@ -2114,13 +2159,93 @@ status(argc, argv)
/*
* Function that gets called when SIGINFO is received.
*/
+void
ayt_status()
{
(void) call(status, "status", "notmuch", 0);
}
#endif
-unsigned long inet_addr();
+static Command *getcmd(char *name);
+
+static void
+cmdrc(char *m1, char *m2)
+{
+ static char rcname[128];
+ Command *c;
+ FILE *rcfile;
+ int gotmachine = 0;
+ int l1 = strlen(m1);
+ int l2 = strlen(m2);
+ char m1save[64];
+
+ if (skiprc)
+ return;
+
+ strcpy(m1save, m1);
+ m1 = m1save;
+
+ if (rcname[0] == 0) {
+ char *home = getenv("HOME");
+
+ snprintf (rcname, sizeof(rcname), "%s/.telnetrc",
+ home ? home : "");
+ }
+
+ if ((rcfile = fopen(rcname, "r")) == 0) {
+ return;
+ }
+
+ for (;;) {
+ if (fgets(line, sizeof(line), rcfile) == NULL)
+ break;
+ if (line[0] == 0)
+ break;
+ if (line[0] == '#')
+ continue;
+ if (gotmachine) {
+ if (!isspace(line[0]))
+ gotmachine = 0;
+ }
+ if (gotmachine == 0) {
+ if (isspace(line[0]))
+ continue;
+ if (strncasecmp(line, m1, l1) == 0)
+ strncpy(line, &line[l1], sizeof(line) - l1);
+ else if (strncasecmp(line, m2, l2) == 0)
+ strncpy(line, &line[l2], sizeof(line) - l2);
+ else if (strncasecmp(line, "DEFAULT", 7) == 0)
+ strncpy(line, &line[7], sizeof(line) - 7);
+ else
+ continue;
+ if (line[0] != ' ' && line[0] != '\t' && line[0] != '\n')
+ continue;
+ gotmachine = 1;
+ }
+ makeargv();
+ if (margv[0] == 0)
+ continue;
+ c = getcmd(margv[0]);
+ if (Ambiguous(c)) {
+ printf("?Ambiguous command: %s\r\n", margv[0]);
+ continue;
+ }
+ if (c == 0) {
+ printf("?Invalid command: %s\r\n", margv[0]);
+ continue;
+ }
+ /*
+ * This should never happen...
+ */
+ if (c->needconnect && !connected) {
+ printf("?Need to be connected first for %s.\r\n", margv[0]);
+ continue;
+ }
+ (*c->handler)(margc, margv);
+ }
+ fclose(rcfile);
+}
+
int
tn(argc, argv)
@@ -2128,22 +2253,28 @@ tn(argc, argv)
char *argv[];
{
register struct hostent *host = 0, *alias = 0;
+#if defined(AF_INET6)
+ struct sockaddr_in6 sin6;
+#endif
struct sockaddr_in sin;
struct sockaddr_in ladr;
+ struct sockaddr *sa;
+ int sa_size;
struct servent *sp = 0;
unsigned long temp;
extern char *inet_ntoa();
#if defined(IP_OPTIONS) && defined(IPPROTO_IP)
- char *srp = 0, *strrchr();
- unsigned long sourceroute(), srlen;
+ char *srp = 0;
+ int srlen;
#endif
char *cmd, *hostp = 0, *portp = 0, *user = 0, *aliasp = 0;
+ int family, port;
/* clear the socket address prior to use */
memset((char *)&sin, 0, sizeof(sin));
if (connected) {
- printf("?Already connected to %s\n", hostname);
+ printf("?Already connected to %s\r\n", hostname);
seteuid(getuid());
setuid(getuid());
return 0;
@@ -2165,7 +2296,7 @@ tn(argc, argv)
--argc; ++argv;
if (argc == 0)
goto usage;
- user = *argv++;
+ user = strdup(*argv++);
--argc;
continue;
}
@@ -2193,7 +2324,7 @@ tn(argc, argv)
continue;
}
usage:
- printf("usage: %s [-l user] [-a] host-name [port]\n", cmd);
+ printf("usage: %s [-l user] [-a] host-name [port]\r\n", cmd);
seteuid(getuid());
setuid(getuid());
return 0;
@@ -2214,46 +2345,74 @@ tn(argc, argv)
setuid(getuid());
return 0;
} else if (temp == -1) {
- printf("Bad source route option: %s\n", hostp);
+ printf("Bad source route option: %s\r\n", hostp);
seteuid(getuid());
setuid(getuid());
return 0;
} else {
- sin.sin_addr.s_addr = temp;
- sin.sin_family = AF_INET;
+ abort();
}
} else {
#endif
- temp = inet_addr(hostp);
- if (temp != INADDR_NONE) {
- sin.sin_addr.s_addr = temp;
- sin.sin_family = AF_INET;
- host = gethostbyaddr((char *)&temp, sizeof(temp), AF_INET);
- if (host)
- (void) strcpy(_hostname, host->h_name);
- else
- (void) strcpy(_hostname, hostp);
- 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 */
- memmove((caddr_t)&sin.sin_addr,
- host->h_addr_list[0], host->h_length);
-#else /* defined(h_addr) */
- 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';
+ memset (&sin, 0, sizeof(sin));
+#if defined(HAVE_INET_PTON) && defined(AF_INET6)
+ memset (&sin6, 0, sizeof(sin6));
+
+ if(inet_pton(AF_INET6, hostp, &sin6.sin6_addr)) {
+ sin6.sin6_family = family = AF_INET6;
+ strcpy(_hostname, hostp);
+ hostname =_hostname;
+ } else
+#endif
+ if(inet_aton(hostp, &sin.sin_addr)){
+ sin.sin_family = family = AF_INET;
+ strcpy(_hostname, hostp);
hostname = _hostname;
} else {
- herror(hostp);
- seteuid(getuid());
- setuid(getuid());
- return 0;
+#ifdef HAVE_GETHOSTBYNAME2
+ host = gethostbyname2(hostp, AF_INET6);
+ if(host == NULL)
+ host = gethostbyname2(hostp, AF_INET);
+#else
+ host = gethostbyname(hostp);
+#endif
+ if (host) {
+ strncpy(_hostname, host->h_name, sizeof(_hostname));
+ family = host->h_addrtype;
+
+ switch(family) {
+ case AF_INET:
+ memset(&sin, 0, sizeof(sin));
+ sa_size = sizeof(sin);
+ sa = (struct sockaddr *)&sin;
+ sin.sin_family = family;
+ sin.sin_addr = *((struct in_addr *)(*host->h_addr_list));
+ break;
+#if defined(AF_INET6) && defined(HAVE_STRUCT_SOCKADDR_IN6)
+ case AF_INET6:
+ memset(&sin6, 0, sizeof(sin6));
+ sa_size = sizeof(sin6);
+ sa = (struct sockaddr *)&sin6;
+ sin6.sin6_family = family;
+ sin6.sin6_addr = *((struct in6_addr *)(*host->h_addr_list));
+ break;
+#endif
+ default:
+ fprintf(stderr, "Bad address family: %d\n", family);
+ return 0;
+ }
+
+ _hostname[sizeof(_hostname)-1] = '\0';
+ hostname = _hostname;
+ } else {
+ herror(hostp);
+ seteuid(getuid());
+ setuid(getuid());
+ fprintf (stderr, "%s: %s\r\n", hostp ? hostp : "",
+ "unknown error");
+ return 0;
+ }
}
- }
#if defined(IP_OPTIONS) && defined(IPPROTO_IP)
}
#endif
@@ -2263,39 +2422,62 @@ tn(argc, argv)
telnetport = 1;
} else
telnetport = 0;
- sin.sin_port = atoi(portp);
- if (sin.sin_port == 0) {
+ port = atoi(portp);
+ if (port == 0) {
sp = getservbyname(portp, "tcp");
if (sp)
- sin.sin_port = sp->s_port;
+ port = sp->s_port;
else {
- printf("%s: bad port number\n", portp);
+ printf("%s: bad port number\r\n", portp);
seteuid(getuid());
setuid(getuid());
return 0;
}
} else {
-#if !defined(htons)
- u_short htons P((unsigned short));
-#endif /* !defined(htons) */
- sin.sin_port = htons(sin.sin_port);
+ port = htons(port);
}
} else {
if (sp == 0) {
sp = getservbyname("telnet", "tcp");
if (sp == 0) {
- fprintf(stderr, "telnet: tcp/telnet: unknown service\n");
+ fprintf(stderr, "telnet: tcp/telnet: unknown service\r\n");
seteuid(getuid());
setuid(getuid());
return 0;
}
- sin.sin_port = sp->s_port;
+ port = sp->s_port;
}
telnetport = 1;
}
- printf("Trying %s...\n", inet_ntoa(sin.sin_addr));
+ switch(family) {
+ case AF_INET:
+ sin.sin_port = port;
+ printf("Trying %s...\r\n", inet_ntoa(sin.sin_addr));
+ break;
+#if defined(AF_INET6) && defined(HAVE_STRUCT_SOCKADDR_IN6)
+ case AF_INET6: {
+#ifndef INET6_ADDRSTRLEN
+#define INET6_ADDRSTRLEN 46
+#endif
+
+ char buf[INET6_ADDRSTRLEN];
+
+ sin6.sin6_port = port;
+#ifdef HAVE_INET_NTOP
+ printf("Trying %s...\r\n", inet_ntop(AF_INET6,
+ &sin6.sin6_addr,
+ buf,
+ sizeof(buf)));
+#endif
+ break;
+ }
+#endif
+ default:
+ abort();
+ }
+
do {
- net = socket(AF_INET, SOCK_STREAM, 0);
+ net = socket(family, SOCK_STREAM, 0);
seteuid(getuid());
setuid(getuid());
if (net < 0) {
@@ -2348,7 +2530,7 @@ tn(argc, argv)
tos = IPTOS_LOWDELAY; /* Low Delay bit */
if (tos
&& (setsockopt(net, IPPROTO_IP, IP_TOS,
- (char *)&tos, sizeof(int)) < 0)
+ (void *)&tos, sizeof(int)) < 0)
&& (errno != ENOPROTOOPT))
perror("telnet: setsockopt (IP_TOS) (ignored)");
}
@@ -2358,27 +2540,44 @@ tn(argc, argv)
perror("setsockopt (SO_DEBUG)");
}
- if (connect(net, (struct sockaddr *)&sin, sizeof (sin)) < 0) {
-#if defined(h_addr) /* In 4.3, this is a #define */
+ if (connect(net, sa, sa_size) < 0) {
if (host && host->h_addr_list[1]) {
int oerrno = errno;
- fprintf(stderr, "telnet: connect to address %s: ",
- inet_ntoa(sin.sin_addr));
+ switch(family) {
+ case AF_INET :
+ fprintf(stderr, "telnet: connect to address %s: ",
+ inet_ntoa(sin.sin_addr));
+ sin.sin_addr = *((struct in_addr *)(*++host->h_addr_list));
+ break;
+#if defined(AF_INET6) && defined(HAVE_STRUCT_SOCKADDR_IN6)
+ case AF_INET6: {
+ char buf[INET6_ADDRSTRLEN];
+
+ fprintf(stderr, "telnet: connect to address %s: ",
+ inet_ntop(AF_INET6, &sin6.sin6_addr, buf,
+ sizeof(buf)));
+ sin6.sin6_addr = *((struct in6_addr *)(*++host->h_addr_list));
+ break;
+ }
+#endif
+ default:
+ abort();
+ }
+
errno = oerrno;
- perror((char *)0);
+ perror(NULL);
host->h_addr_list++;
memmove((caddr_t)&sin.sin_addr,
host->h_addr_list[0], host->h_length);
(void) NetClose(net);
continue;
}
-#endif /* defined(h_addr) */
perror("telnet: Unable to connect to remote host");
return 0;
}
connected++;
-#if defined(AUTHENTICATION)
+#if defined(AUTHENTICATION) || defined(ENCRYPTION)
auth_encrypt_connect(connected);
#endif /* defined(AUTHENTICATION) */
} while (connected == 0);
@@ -2403,8 +2602,9 @@ tn(argc, argv)
if (setjmp(peerdied) == 0)
telnet(user);
(void) NetClose(net);
- ExitString("Connection closed by foreign host.\n",1);
+ ExitString("Connection closed by foreign host.\r\n",1);
/*NOTREACHED*/
+ return 0;
}
#define HELPINDENT (sizeof ("connect"))
@@ -2428,14 +2628,15 @@ static char
#if defined(AUTHENTICATION)
authhelp[] = "turn on (off) authentication ('auth ?' for more)",
#endif
-#if defined(unix)
+#if defined(ENCRYPTION)
+ encrypthelp[] = "turn on (off) encryption ('encrypt ?' for more)",
+#endif
zhelp[] = "suspend telnet",
-#endif /* defined(unix) */
shellhelp[] = "invoke a subshell",
envhelp[] = "change environment variables ('environ ?' for more)",
modestring[] = "try to enter line or character mode ('mode ?' for more)";
-static int help();
+static int help __P((int, char**));
static Command cmdtab[] = {
{ "close", closehelp, bye, 1 },
@@ -2456,9 +2657,11 @@ static Command cmdtab[] = {
#if defined(AUTHENTICATION)
{ "auth", authhelp, auth_cmd, 0 },
#endif
-#if defined(unix)
- { "z", zhelp, suspend, 0 },
-#endif /* defined(unix) */
+#if defined(ENCRYPTION)
+ { "encrypt", encrypthelp, encrypt_cmd, 0 },
+#endif
+
+ { "z", zhelp, telnetsuspend, 0 },
#if defined(TN3270)
{ "!", shellhelp, shell, 1 },
#else
@@ -2469,7 +2672,7 @@ static Command cmdtab[] = {
#if defined(SKEY)
{ "skey", NULL, skey_calc, 0 },
#endif
- 0
+ { 0, 0, 0, 0 }
};
static char crmodhelp[] = "deprecated command -- use 'toggle crmod' instead";
@@ -2479,7 +2682,7 @@ static Command cmdtab2[] = {
{ "help", 0, help, 0 },
{ "escape", escapehelp, setescape, 0 },
{ "crmod", crmodhelp, togcrmod, 0 },
- 0
+ { 0, 0, 0, 0 }
};
@@ -2488,21 +2691,15 @@ static Command cmdtab2[] = {
*/
/*VARARGS1*/
- static
-call(va_alist)
- va_dcl
+ static int
+call(intrtn_t routine, ...)
{
va_list ap;
- typedef int (*intrtn_t)();
- intrtn_t routine;
char *args[100];
int argno = 0;
- va_start(ap);
- routine = (va_arg(ap, intrtn_t));
- while ((args[argno++] = va_arg(ap, char *)) != 0) {
- ;
- }
+ va_start(ap, routine);
+ while ((args[argno++] = va_arg(ap, char *)) != 0);
va_end(ap);
return (*routine)(argno-1, args);
}
@@ -2514,7 +2711,7 @@ getcmd(name)
{
Command *cm;
- if (cm = (Command *) genget(name, (char **) cmdtab, sizeof(Command)))
+ if ((cm = (Command *) genget(name, (char **) cmdtab, sizeof(Command))))
return cm;
return (Command *) genget(name, (char **) cmdtab2, sizeof(Command));
}
@@ -2549,7 +2746,7 @@ command(top, tbuf, cnt)
goto getline;
*cp = '\0';
if (rlogin == _POSIX_VDISABLE)
- printf("%s\n", line);
+ printf("%s\r\n", line);
} else {
getline:
if (rlogin != _POSIX_VDISABLE)
@@ -2570,15 +2767,15 @@ command(top, tbuf, cnt)
}
c = getcmd(margv[0]);
if (Ambiguous(c)) {
- printf("?Ambiguous command\n");
+ printf("?Ambiguous command\r\n");
continue;
}
if (c == 0) {
- printf("?Invalid command\n");
+ printf("?Invalid command\r\n");
continue;
}
if (c->needconnect && !connected) {
- printf("?Need to be connected first.\n");
+ printf("?Need to be connected first.\r\n");
continue;
}
if ((*c->handler)(margc, margv)) {
@@ -2611,10 +2808,10 @@ help(argc, argv)
register Command *c;
if (argc == 1) {
- printf("Commands may be abbreviated. Commands are:\n\n");
+ printf("Commands may be abbreviated. Commands are:\r\n\r\n");
for (c = cmdtab; c->name; c++)
if (c->help) {
- printf("%-*s\t%s\n", HELPINDENT, c->name,
+ printf("%-*s\t%s\r\n", HELPINDENT, c->name,
c->help);
}
return 0;
@@ -2624,11 +2821,11 @@ help(argc, argv)
arg = *++argv;
c = getcmd(arg);
if (Ambiguous(c))
- printf("?Ambiguous help command %s\n", arg);
+ printf("?Ambiguous help command %s\r\n", arg);
else if (c == (Command *)0)
- printf("?Invalid help command %s\n", arg);
+ printf("?Invalid help command %s\r\n", arg);
else
- printf("%s\n", c->help);
+ printf("%s\r\n", c->help);
}
return 0;
}
@@ -2636,86 +2833,6 @@ help(argc, argv)
static char *rcname = 0;
static char rcbuf[128];
-cmdrc(m1, m2)
- char *m1, *m2;
-{
- register Command *c;
- FILE *rcfile;
- int gotmachine = 0;
- int l1 = strlen(m1);
- int l2 = strlen(m2);
- char m1save[64];
-
- if (skiprc)
- return;
-
- strcpy(m1save, m1);
- m1 = m1save;
-
- if (rcname == 0) {
- rcname = getenv("HOME");
- if (rcname && (strlen(rcname) + 10) < sizeof(rcbuf))
- strcpy(rcbuf, rcname);
- else
- rcbuf[0] = '\0';
- strcat(rcbuf, "/.telnetrc");
- rcname = rcbuf;
- }
-
- if ((rcfile = fopen(rcname, "r")) == 0) {
- return;
- }
-
- for (;;) {
- if (fgets(line, sizeof(line), rcfile) == NULL)
- break;
- if (line[0] == 0)
- break;
- if (line[0] == '#')
- continue;
- if (gotmachine) {
- if (!isspace(line[0]))
- gotmachine = 0;
- }
- if (gotmachine == 0) {
- if (isspace(line[0]))
- continue;
- if (strncasecmp(line, m1, l1) == 0)
- strncpy(line, &line[l1], sizeof(line) - l1);
- else if (strncasecmp(line, m2, l2) == 0)
- strncpy(line, &line[l2], sizeof(line) - l2);
- else if (strncasecmp(line, "DEFAULT", 7) == 0)
- strncpy(line, &line[7], sizeof(line) - 7);
- else
- continue;
- if (line[0] != ' ' && line[0] != '\t' && line[0] != '\n')
- continue;
- gotmachine = 1;
- }
- makeargv();
- if (margv[0] == 0)
- continue;
- c = getcmd(margv[0]);
- if (Ambiguous(c)) {
- printf("?Ambiguous command: %s\n", margv[0]);
- continue;
- }
- if (c == 0) {
- printf("?Invalid command: %s\n", margv[0]);
- continue;
- }
- /*
- * This should never happen...
- */
- if (c->needconnect && !connected) {
- printf("?Need to be connected first for %s.\n", margv[0]);
- continue;
- }
- (*c->handler)(margc, margv);
- }
- fclose(rcfile);
-}
-
#if defined(IP_OPTIONS) && defined(IPPROTO_IP)
/*
@@ -2829,7 +2946,7 @@ sourceroute(arg, cpp, lenp)
for (c = 0;;) {
if (c == ':')
cp2 = 0;
- else for (cp2 = cp; c = *cp2; cp2++) {
+ else for (cp2 = cp; (c = *cp2); cp2++) {
if (c == ',') {
*cp2++ = '\0';
if (*cp2 == '@')
@@ -2845,14 +2962,16 @@ sourceroute(arg, cpp, lenp)
if (!c)
cp2 = 0;
- if ((tmp = inet_addr(cp)) != INADDR_NONE) {
+ if ((tmp = inet_addr(cp)) != -1) {
sin_addr.s_addr = tmp;
- } else if (host = gethostbyname(cp)) {
+ } else if ((host = gethostbyname(cp))) {
#if defined(h_addr)
memmove((caddr_t)&sin_addr,
- host->h_addr_list[0], host->h_length);
+ host->h_addr_list[0],
+ sizeof(sin_addr));
#else
- memmove((caddr_t)&sin_addr, host->h_addr, host->h_length);
+ memmove((caddr_t)&sin_addr, host->h_addr,
+ sizeof(sin_addr));
#endif
} else {
*cpp = cp;
diff --git a/usr.bin/telnet/defines.h b/usr.bin/telnet/defines.h
index b1367794d86..0203991dd24 100644
--- a/usr.bin/telnet/defines.h
+++ b/usr.bin/telnet/defines.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: defines.h,v 1.2 1996/03/27 19:33:00 niklas Exp $ */
+/* $OpenBSD: defines.h,v 1.3 1998/03/12 04:57:30 art Exp $ */
/* $NetBSD: defines.h,v 1.5 1996/02/28 21:03:55 thorpej Exp $ */
/*
@@ -62,3 +62,7 @@
#define MODE_COMMAND_LINE(m) ((m)==-1)
#define CONTROL(x) ((x)&0x1f) /* CTRL(x) is not portable */
+
+#define MODE_OUT8 0x8000 /* binary mode sans -opost */
+
+
diff --git a/usr.bin/telnet/externs.h b/usr.bin/telnet/externs.h
index 52c5cbd02a4..de15608e0d7 100644
--- a/usr.bin/telnet/externs.h
+++ b/usr.bin/telnet/externs.h
@@ -1,5 +1,5 @@
-/* $OpenBSD: externs.h,v 1.2 1996/03/27 19:33:01 niklas Exp $ */
-/* $NetBSD: externs.h,v 1.8 1996/02/28 21:03:58 thorpej Exp $ */
+/* $OpenBSD: externs.h,v 1.3 1998/03/12 04:57:31 art Exp $ */
+/* $KTH: externs.h,v 1.16 1997/11/29 02:28:35 joda Exp $ */
/*
* Copyright (c) 1988, 1990, 1993
@@ -33,64 +33,13 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * from: @(#)externs.h 8.3 (Berkeley) 5/30/95
+ * @(#)externs.h 8.3 (Berkeley) 5/30/95
*/
#ifndef BSD
# define BSD 43
#endif
-/*
- * ucb stdio.h defines BSD as something wierd
- */
-#if defined(sun) && defined(__svr4__)
-#define BSD 43
-#endif
-
-#ifndef USE_TERMIO
-# if BSD > 43 || defined(SYSV_TERMIO)
-# define USE_TERMIO
-# endif
-#endif
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <setjmp.h>
-#if defined(CRAY) && !defined(NO_BSD_SETJMP)
-#include <bsdsetjmp.h>
-#endif
-#ifndef FILIO_H
-#include <sys/ioctl.h>
-#else
-#include <sys/filio.h>
-#endif
-#ifdef CRAY
-# include <errno.h>
-#endif /* CRAY */
-#ifdef USE_TERMIO
-# ifndef VINTR
-# ifdef SYSV_TERMIO
-# include <sys/termio.h>
-# else
-# include <sys/termios.h>
-# define termio termios
-# endif
-# endif
-#endif
-#if defined(NO_CC_T) || !defined(USE_TERMIO)
-# if !defined(USE_TERMIO)
-typedef char cc_t;
-# else
-typedef unsigned char cc_t;
-# endif
-#endif
-
-#ifndef NO_STRING_H
-#include <string.h>
-#else
-#include <strings.h>
-#endif
-
#ifndef _POSIX_VDISABLE
# ifdef sun
# include <sys/param.h> /* pick up VDISABLE definition, mayby */
@@ -104,22 +53,16 @@ typedef unsigned char cc_t;
#define SUBBUFSIZE 256
-#ifndef CRAY
-extern int errno; /* outside this world */
-#endif /* !CRAY */
-
-#include <sys/cdefs.h>
-#define P __P
-
extern int
autologin, /* Autologin enabled */
skiprc, /* Don't process the ~/.telnetrc file */
eight, /* use eight bit mode (binary in and/or out */
+ binary,
flushout, /* flush output */
connected, /* Are we connected to the other side? */
globalmode, /* Mode tty should be in */
- In3270, /* Are we in 3270 mode? */
telnetport, /* Are we connected to the telnet port? */
+ In3270, /* Are we in 3270 mode? */
localflow, /* Flow control handled locally */
restartany, /* If flow control, restart output on any character */
localchars, /* we recognize interrupt/quit */
@@ -137,15 +80,8 @@ extern int
crmod,
netdata, /* Print out network data flow */
prettydump, /* Print "netdata" output in user readable format */
-#if defined(unix)
-#if defined(TN3270)
- cursesdata, /* Print out curses data flow */
- apitrace, /* Trace API transactions */
-#endif /* defined(TN3270) */
termdata, /* Print out terminal data flow */
-#endif /* defined(unix) */
- debug, /* Debug level */
- clienteof; /* Client received EOF */
+ debug; /* Debug level */
extern cc_t escape; /* Escape to command mode */
extern cc_t rlogin; /* Rlogin mode escape character */
@@ -163,6 +99,10 @@ extern char
wont[],
options[], /* All the little options */
*hostname; /* Who are we connected to? */
+#if defined(ENCRYPTION)
+extern void (*encrypt_output) (unsigned char *, int);
+extern int (*decrypt_input) (int);
+#endif
/*
* We keep track of each side of the option negotiation.
@@ -232,121 +172,194 @@ extern FILE
extern unsigned char
NetTraceFile[]; /* Name of file where debugging output goes */
extern void
- SetNetTrace P((char *)); /* Function to change where debugging goes */
+ SetNetTrace (char *); /* Function to change where debugging goes */
extern jmp_buf
peerdied,
toplevel; /* For error conditions. */
-extern void
- command P((int, char *, int)),
- Dump P((int, unsigned char *, int)),
- init_3270 P((void)),
- printoption P((char *, int, int)),
- printsub P((int, unsigned char *, int)),
- sendnaws P((void)),
- setconnmode P((int)),
- setcommandmode P((void)),
- setneturg P((void)),
- sys_telnet_init P((void)),
- telnet P((char *)),
- tel_enter_binary P((int)),
- TerminalFlushOutput P((void)),
- TerminalNewMode P((int)),
- TerminalRestoreState P((void)),
- TerminalSaveState P((void)),
- tninit P((void)),
- upcase P((char *)),
- willoption P((int)),
- wontoption P((int));
-
-extern void
- send_do P((int, int)),
- send_dont P((int, int)),
- send_will P((int, int)),
- send_wont P((int, int));
+/* authenc.c */
-extern void
- lm_will P((unsigned char *, int)),
- lm_wont P((unsigned char *, int)),
- lm_do P((unsigned char *, int)),
- lm_dont P((unsigned char *, int)),
- lm_mode P((unsigned char *, int, int));
-
-extern void
- slc_init P((void)),
- slcstate P((void)),
- slc_mode_export P((void)),
- slc_mode_import P((int)),
- slc_import P((int)),
- slc_export P((void)),
- slc P((unsigned char *, int)),
- slc_check P((void)),
- slc_start_reply P((void)),
- slc_add_reply P((int, int, int)),
- slc_end_reply P((void));
-extern int
- slc_update P((void));
-
-extern void
- env_opt P((unsigned char *, int)),
- env_opt_start P((void)),
- env_opt_start_info P((void)),
- env_opt_add P((unsigned char *)),
- env_opt_end P((int));
-
-extern unsigned char
- *env_default P((int, int)),
- *env_getvalue P((unsigned char *));
-
-extern int
- get_status P((void)),
- dosynch P((void));
-
-extern cc_t
- *tcval P((int));
-
-#ifndef USE_TERMIO
-
-extern struct tchars ntc;
-extern struct ltchars nltc;
-extern struct sgttyb nttyb;
-
-# define termEofChar ntc.t_eofc
-# define termEraseChar nttyb.sg_erase
-# define termFlushChar nltc.t_flushc
-# define termIntChar ntc.t_intrc
-# define termKillChar nttyb.sg_kill
-# define termLiteralNextChar nltc.t_lnextc
-# define termQuitChar ntc.t_quitc
-# define termSuspChar nltc.t_suspc
-# define termRprntChar nltc.t_rprntc
-# define termWerasChar nltc.t_werasc
-# define termStartChar ntc.t_startc
-# define termStopChar ntc.t_stopc
-# define termForw1Char ntc.t_brkc
-extern cc_t termForw2Char;
-extern cc_t termAytChar;
+#if defined(AUTHENTICATION) || defined(ENCRYPTION)
+int net_write(unsigned char *str, int len);
+void net_encrypt(void);
+int telnet_spin(void);
+char *telnet_getenv(char *val);
+char *telnet_gets(char *prompt, char *result, int length, int echo);
+#endif
-# define termEofCharp (cc_t *)&ntc.t_eofc
-# define termEraseCharp (cc_t *)&nttyb.sg_erase
-# define termFlushCharp (cc_t *)&nltc.t_flushc
-# define termIntCharp (cc_t *)&ntc.t_intrc
-# define termKillCharp (cc_t *)&nttyb.sg_kill
-# define termLiteralNextCharp (cc_t *)&nltc.t_lnextc
-# define termQuitCharp (cc_t *)&ntc.t_quitc
-# define termSuspCharp (cc_t *)&nltc.t_suspc
-# define termRprntCharp (cc_t *)&nltc.t_rprntc
-# define termWerasCharp (cc_t *)&nltc.t_werasc
-# define termStartCharp (cc_t *)&ntc.t_startc
-# define termStopCharp (cc_t *)&ntc.t_stopc
-# define termForw1Charp (cc_t *)&ntc.t_brkc
-# define termForw2Charp (cc_t *)&termForw2Char
-# define termAytCharp (cc_t *)&termAytChar
+/* commands.c */
+
+struct env_lst *env_define (unsigned char *, unsigned char *);
+struct env_lst *env_find(unsigned char *var);
+void env_init (void);
+void env_undefine (unsigned char *);
+void env_export (unsigned char *);
+void env_unexport (unsigned char *);
+void env_send (unsigned char *);
+void env_list (void);
+unsigned char * env_default(int init, int welldefined);
+unsigned char * env_getvalue(unsigned char *var);
+
+void set_escape_char(char *s);
+unsigned long sourceroute(char *arg, char **cpp, int *lenp);
+
+#if defined(AUTHENTICATION)
+int auth_enable (char *);
+int auth_disable (char *);
+int auth_status (void);
+#endif
-# else
+#if defined(ENCRYPTION)
+int EncryptEnable (char *, char *);
+int EncryptDisable (char *, char *);
+int EncryptType (char *, char *);
+int EncryptStart (char *);
+int EncryptStartInput (void);
+int EncryptStartOutput (void);
+int EncryptStop (char *);
+int EncryptStopInput (void);
+int EncryptStopOutput (void);
+int EncryptStatus (void);
+#endif
-extern struct termio new_tc;
+#ifdef SIGINFO
+void ayt_status(void);
+#endif
+int tn(int argc, char **argv);
+void command(int top, char *tbuf, int cnt);
+
+/* main.c */
+
+void tninit(void);
+void usage(void);
+
+/* network.c */
+
+void init_network(void);
+int stilloob(void);
+void setneturg(void);
+int netflush(void);
+
+/* sys_bsd.c */
+
+void init_sys(void);
+int TerminalWrite(char *buf, int n);
+int TerminalRead(unsigned char *buf, int n);
+int TerminalAutoFlush(void);
+int TerminalSpecialChars(int c);
+void TerminalFlushOutput(void);
+void TerminalSaveState(void);
+void TerminalDefaultChars(void);
+void TerminalNewMode(int f);
+cc_t *tcval(int func);
+void TerminalSpeeds(long *input_speed, long *output_speed);
+int TerminalWindowSize(long *rows, long *cols);
+int NetClose(int fd);
+void NetNonblockingIO(int fd, int onoff);
+int process_rings(int netin, int netout, int netex, int ttyin, int ttyout,
+ int poll);
+
+/* telnet.c */
+
+void init_telnet(void);
+
+void tel_leave_binary(int rw);
+void tel_enter_binary(int rw);
+int opt_welldefined(char *ep);
+int telrcv(void);
+int rlogin_susp(void);
+void intp(void);
+void sendbrk(void);
+void sendabort(void);
+void sendsusp(void);
+void sendeof(void);
+void sendayt(void);
+
+void xmitAO(void);
+void xmitEL(void);
+void xmitEC(void);
+
+
+void Dump (char, unsigned char *, int);
+void printoption (char *, int, int);
+void printsub (char, unsigned char *, int);
+void sendnaws (void);
+void setconnmode (int);
+void setcommandmode (void);
+void setneturg (void);
+void sys_telnet_init (void);
+void telnet (char *);
+void tel_enter_binary (int);
+void TerminalFlushOutput (void);
+void TerminalNewMode (int);
+void TerminalRestoreState (void);
+void TerminalSaveState (void);
+void tninit (void);
+void willoption (int);
+void wontoption (int);
+
+
+void send_do (int, int);
+void send_dont (int, int);
+void send_will (int, int);
+void send_wont (int, int);
+
+void lm_will (unsigned char *, int);
+void lm_wont (unsigned char *, int);
+void lm_do (unsigned char *, int);
+void lm_dont (unsigned char *, int);
+void lm_mode (unsigned char *, int, int);
+
+void slc_init (void);
+void slcstate (void);
+void slc_mode_export (void);
+void slc_mode_import (int);
+void slc_import (int);
+void slc_export (void);
+void slc (unsigned char *, int);
+void slc_check (void);
+void slc_start_reply (void);
+void slc_add_reply (unsigned char, unsigned char, cc_t);
+void slc_end_reply (void);
+int slc_update (void);
+
+void env_opt (unsigned char *, int);
+void env_opt_start (void);
+void env_opt_start_info (void);
+void env_opt_add (unsigned char *);
+void env_opt_end (int);
+
+unsigned char *env_default (int, int);
+unsigned char *env_getvalue (unsigned char *);
+
+int get_status (void);
+int dosynch (void);
+
+cc_t *tcval (int);
+
+int quit (void);
+
+/* terminal.c */
+
+void init_terminal(void);
+int ttyflush(int drop);
+int getconnmode(void);
+
+/* utilities.c */
+
+int SetSockOpt(int fd, int level, int option, int yesno);
+void SetNetTrace(char *file);
+void Dump(char direction, unsigned char *buffer, int length);
+void printoption(char *direction, int cmd, int option);
+void optionstatus(void);
+void printsub(char direction, unsigned char *pointer, int length);
+void EmptyTerminal(void);
+void SetForExit(void);
+void Exit(int returnCode);
+void ExitString(char *string, int returnCode);
+
+extern struct termios new_tc;
# define termEofChar new_tc.c_cc[VEOF]
# define termEraseChar new_tc.c_cc[VERASE]
@@ -408,43 +421,6 @@ extern cc_t termAytChar;
# define termAytChar new_tc.c_cc[VSTATUS]
#endif
-# if !defined(CRAY) || defined(__STDC__)
-# define termEofCharp &termEofChar
-# define termEraseCharp &termEraseChar
-# define termIntCharp &termIntChar
-# define termKillCharp &termKillChar
-# define termQuitCharp &termQuitChar
-# define termSuspCharp &termSuspChar
-# define termFlushCharp &termFlushChar
-# define termWerasCharp &termWerasChar
-# define termRprntCharp &termRprntChar
-# define termLiteralNextCharp &termLiteralNextChar
-# define termStartCharp &termStartChar
-# define termStopCharp &termStopChar
-# define termForw1Charp &termForw1Char
-# define termForw2Charp &termForw2Char
-# define termAytCharp &termAytChar
-# else
- /* Work around a compiler bug */
-# define termEofCharp 0
-# define termEraseCharp 0
-# define termIntCharp 0
-# define termKillCharp 0
-# define termQuitCharp 0
-# define termSuspCharp 0
-# define termFlushCharp 0
-# define termWerasCharp 0
-# define termRprntCharp 0
-# define termLiteralNextCharp 0
-# define termStartCharp 0
-# define termStopCharp 0
-# define termForw1Charp 0
-# define termForw2Charp 0
-# define termAytCharp 0
-# endif
-#endif
-
-
/* Ring buffer structures which are shared */
extern Ring
@@ -453,26 +429,3 @@ extern Ring
ttyoring,
ttyiring;
-/* Tn3270 section */
-#if defined(TN3270)
-
-extern int
- HaveInput, /* Whether an asynchronous I/O indication came in */
- noasynchtty, /* Don't do signals on I/O (SIGURG, SIGIO) */
- noasynchnet, /* Don't do signals on I/O (SIGURG, SIGIO) */
- sigiocount, /* Count of SIGIO receptions */
- shell_active; /* Subshell is active */
-
-extern char
- *Ibackp, /* Oldest byte of 3270 data */
- Ibuf[], /* 3270 buffer */
- *Ifrontp, /* Where next 3270 byte goes */
- tline[],
- *transcom; /* Transparent command */
-
-extern int
- settranscom P((int, char**));
-
-extern void
- inputAvailable P((int));
-#endif /* defined(TN3270) */
diff --git a/usr.bin/telnet/fdset.h b/usr.bin/telnet/fdset.h
deleted file mode 100644
index 72f9655a096..00000000000
--- a/usr.bin/telnet/fdset.h
+++ /dev/null
@@ -1,52 +0,0 @@
-/* $OpenBSD: fdset.h,v 1.2 1996/03/27 19:33:02 niklas Exp $ */
-/* $NetBSD: fdset.h,v 1.5 1996/02/28 21:04:00 thorpej Exp $ */
-
-/*
- * Copyright (c) 1988, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * from: @(#)fdset.h 8.1 (Berkeley) 6/6/93
- */
-
-/*
- * The following is defined just in case someone should want to run
- * this telnet on a 4.2 system.
- *
- */
-
-#ifndef FD_SETSIZE
-
-#define FD_SET(n, p) ((p)->fds_bits[0] |= (1<<(n)))
-#define FD_CLR(n, p) ((p)->fds_bits[0] &= ~(1<<(n)))
-#define FD_ISSET(n, p) ((p)->fds_bits[0] & (1<<(n)))
-#define FD_ZERO(p) ((p)->fds_bits[0] = 0)
-
-#endif
diff --git a/usr.bin/telnet/general.h b/usr.bin/telnet/general.h
deleted file mode 100644
index f1a71404263..00000000000
--- a/usr.bin/telnet/general.h
+++ /dev/null
@@ -1,48 +0,0 @@
-/* $OpenBSD: general.h,v 1.2 1996/03/27 19:33:03 niklas Exp $ */
-/* $NetBSD: general.h,v 1.5 1996/02/28 21:04:02 thorpej Exp $ */
-
-/*
- * Copyright (c) 1988, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * from: @(#)general.h 8.1 (Berkeley) 6/6/93
- */
-
-/*
- * Some general definitions.
- */
-
-
-#define numberof(x) (sizeof x/sizeof x[0])
-#define highestof(x) (numberof(x)-1)
-
-#define ClearElement(x) memset((char *)&x, 0, sizeof x)
-#define ClearArray(x) memset((char *)x, 0, sizeof x)
diff --git a/usr.bin/telnet/main.c b/usr.bin/telnet/main.c
index 5b148382922..6c167c4735c 100644
--- a/usr.bin/telnet/main.c
+++ b/usr.bin/telnet/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.4 1997/01/15 23:43:20 millert Exp $ */
+/* $OpenBSD: main.c,v 1.5 1998/03/12 04:57:35 art Exp $ */
/* $NetBSD: main.c,v 1.5 1996/02/28 21:04:05 thorpej Exp $ */
/*
@@ -40,27 +40,14 @@ static char copyright[] =
The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#)main.c 8.3 (Berkeley) 5/30/95";
-static char rcsid[] = "$NetBSD: main.c,v 1.5 1996/02/28 21:04:05 thorpej Exp $";
-#else
-static char rcsid[] = "$OpenBSD: main.c,v 1.4 1997/01/15 23:43:20 millert Exp $";
-#endif
-#endif /* not lint */
-
-#include <sys/types.h>
-
-#include "ring.h"
-#include "externs.h"
-#include "defines.h"
+#include "telnet_locl.h"
/* These values need to be the same as defined in libtelnet/kerberos5.c */
/* Either define them in both places, or put in some common header file. */
#define OPTS_FORWARD_CREDS 0x00000002
#define OPTS_FORWARDABLE_CREDS 0x00000001
-#if 0
+#if KRB5
#define FORWARD
#endif
@@ -104,7 +91,12 @@ usage()
#else
"[-r] ",
#endif
+#ifdef ENCRYPTION
+ "[-x] [host-name [port]]"
+#else
+
"[host-name [port]]"
+#endif
);
exit(1);
}
@@ -121,19 +113,16 @@ main(argc, argv)
extern char *optarg;
extern int optind;
int ch;
- char *user, *alias, *strrchr();
+ char *user, *alias;
#ifdef FORWARD
extern int forward_flags;
#endif /* FORWARD */
tninit(); /* Clear out things */
-#if defined(CRAY) && !defined(__STDC__)
- _setlist_init(); /* Work around compiler bug */
-#endif
TerminalSaveState();
- if (prompt = strrchr(argv[0], '/'))
+ if ((prompt = strrchr(argv[0], '/')))
++prompt;
else
prompt = argv[0];
@@ -141,13 +130,30 @@ main(argc, argv)
user = alias = NULL;
rlogin = (strncmp(prompt, "rlog", 4) == 0) ? '~' : _POSIX_VDISABLE;
+
+ /*
+ * if AUTHENTICATION and ENCRYPTION is set autologin will be
+ * set to true after the getopt switch; unless the -K option is
+ * passed
+ */
autologin = -1;
- while ((ch = getopt(argc, argv, "8EKLS:X:ab:cde:fFk:l:n:rt:x")) != -1) {
+ while ((ch = getopt(argc, argv, "78DEKLS:X:ab:cde:fFk:l:n:rt:x")) != -1) {
switch(ch) {
case '8':
eight = 3; /* binary output and input */
break;
+ case '7':
+ eight = 0;
+ break;
+ case 'D': {
+ /* sometimes we don't want a mangled display */
+ char *p;
+ if((p = getenv("DISPLAY")))
+ env_define("DISPLAY", (unsigned char*)p);
+ break;
+ }
+
case 'E':
rlogin = escape = _POSIX_VDISABLE;
break;
@@ -227,7 +233,8 @@ main(argc, argv)
case 'k':
#if defined(AUTHENTICATION) && defined(KRB4)
{
- extern char *dest_realm, dst_realm_buf[], dst_realm_sz;
+ extern char *dest_realm, dst_realm_buf[];
+ extern int dst_realm_sz;
dest_realm = dst_realm_buf;
(void)strncpy(dest_realm, optarg, dst_realm_sz);
}
@@ -238,7 +245,12 @@ main(argc, argv)
#endif
break;
case 'l':
- autologin = 1;
+ if(autologin == 0){
+ fprintf(stderr, "%s: Warning: -K ignored\n",
+ prompt);
+ autologin = -1;
+ }
+
user = optarg;
break;
case 'b':
@@ -274,9 +286,15 @@ main(argc, argv)
#endif
break;
case 'x':
+#ifdef ENCRYPTION
+ encrypt_auto(1);
+ decrypt_auto(1);
+ EncryptVerbose(1);
+#else
fprintf(stderr,
"%s: Warning: -x ignored, no ENCRYPT support.\n",
prompt);
+#endif
break;
case '?':
default:
@@ -284,6 +302,17 @@ main(argc, argv)
/* NOTREACHED */
}
}
+
+ if (autologin == -1) { /* esc@magic.fi; force */
+#if defined(AUTHENTICATION)
+ autologin = 1;
+#endif
+#if defined(ENCRYPTION)
+ encrypt_auto(1);
+ decrypt_auto(1);
+#endif
+ }
+
if (autologin == -1)
autologin = (rlogin == _POSIX_VDISABLE) ? 0 : 1;
diff --git a/usr.bin/telnet/network.c b/usr.bin/telnet/network.c
index e7f3d94ffb0..4d7ff6d56f0 100644
--- a/usr.bin/telnet/network.c
+++ b/usr.bin/telnet/network.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: network.c,v 1.4 1997/12/16 22:07:38 deraadt Exp $ */
+/* $OpenBSD: network.c,v 1.5 1998/03/12 04:57:36 art Exp $ */
/* $NetBSD: network.c,v 1.5 1996/02/28 21:04:06 thorpej Exp $ */
/*
@@ -34,28 +34,7 @@
* SUCH DAMAGE.
*/
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#)network.c 8.2 (Berkeley) 12/15/93";
-static char rcsid[] = "$NetBSD: network.c,v 1.5 1996/02/28 21:04:06 thorpej Exp $";
-#else
-static char rcsid[] = "$OpenBSD: network.c,v 1.4 1997/12/16 22:07:38 deraadt Exp $";
-#endif
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/time.h>
-#include <unistd.h>
-#include <errno.h>
-
-#include <arpa/telnet.h>
-
-#include "ring.h"
-
-#include "defines.h"
-#include "externs.h"
-#include "fdset.h"
+#include "telnet_locl.h"
Ring netoring, netiring;
unsigned char netobuf[2*BUFSIZ], netibuf[BUFSIZ];
@@ -110,7 +89,7 @@ stilloob()
free(fdsp);
return 1;
} else {
- free(fdsp);
+ free(fdsp);
return 0;
}
}
@@ -144,6 +123,10 @@ netflush()
{
register int n, n1;
+#if defined(ENCRYPTION)
+ if (encrypt_output)
+ ring_encrypt(&netoring, encrypt_output);
+#endif
if ((n1 = n = ring_full_consecutive(&netoring)) > 0) {
if (!ring_at_mark(&netoring)) {
n = send(net, (char *)netoring.consume, n, 0); /* normal write */
diff --git a/usr.bin/telnet/ring.c b/usr.bin/telnet/ring.c
index 56588d18dbd..469ec1ea39d 100644
--- a/usr.bin/telnet/ring.c
+++ b/usr.bin/telnet/ring.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ring.c,v 1.2 1996/03/27 19:33:05 niklas Exp $ */
+/* $OpenBSD: ring.c,v 1.3 1998/03/12 04:57:38 art Exp $ */
/* $NetBSD: ring.c,v 1.7 1996/02/28 21:04:07 thorpej Exp $ */
/*
@@ -34,14 +34,7 @@
* SUCH DAMAGE.
*/
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#)ring.c 8.2 (Berkeley) 5/30/95";
-static char rcsid[] = "$NetBSD: ring.c,v 1.7 1996/02/28 21:04:07 thorpej Exp $";
-#else
-static char rcsid[] = "$OpenBSD: ring.c,v 1.2 1996/03/27 19:33:05 niklas Exp $";
-#endif
-#endif /* not lint */
+#include "telnet_locl.h"
/*
* This defines a structure for a ring buffer.
@@ -54,26 +47,6 @@ static char rcsid[] = "$OpenBSD: ring.c,v 1.2 1996/03/27 19:33:05 niklas Exp $";
*
*/
-#include <stdio.h>
-#ifndef NO_STRING_H
-#include <string.h>
-#endif
-#include <strings.h>
-#include <errno.h>
-
-#ifdef size_t
-#undef size_t
-#endif
-
-#include <sys/types.h>
-#ifndef FILIO_H
-#include <sys/ioctl.h>
-#endif
-#include <sys/socket.h>
-
-#include "ring.h"
-#include "general.h"
-
/* Internal macros */
#if !defined(MIN)
@@ -124,6 +97,9 @@ Ring *ring;
ring->top = ring->bottom+ring->size;
+#if defined(ENCRYPTION)
+ ring->clearto = 0;
+#endif
return 1;
}
@@ -194,6 +170,15 @@ ring_consumed(ring, count)
(ring_subtract(ring, ring->mark, ring->consume) < count)) {
ring->mark = 0;
}
+#if defined(ENCRYPTION)
+ if (ring->consume < ring->clearto &&
+ ring->clearto <= ring->consume + count)
+ ring->clearto = 0;
+ else if (ring->consume + count > ring->top &&
+ ring->bottom <= ring->clearto &&
+ ring->bottom + ((ring->consume + count) - ring->top))
+ ring->clearto = 0;
+#endif
ring->consume = ring_increment(ring, ring->consume, count);
ring->consumetime = ++ring_clock;
/*
@@ -325,3 +310,36 @@ ring_consume_data(ring, buffer, count)
}
#endif
+#if defined(ENCRYPTION)
+void
+ring_encrypt(Ring *ring, void (*encryptor)())
+{
+ unsigned char *s, *c;
+
+ if (ring_empty(ring) || ring->clearto == ring->supply)
+ return;
+
+ if (!(c = ring->clearto))
+ c = ring->consume;
+
+ s = ring->supply;
+
+ if (s <= c) {
+ (*encryptor)(c, ring->top - c);
+ (*encryptor)(ring->bottom, s - ring->bottom);
+ } else
+ (*encryptor)(c, s - c);
+
+ ring->clearto = ring->supply;
+}
+
+void
+ring_clearto(Ring *ring)
+{
+ if (!ring_empty(ring))
+ ring->clearto = ring->supply;
+ else
+ ring->clearto = 0;
+}
+#endif
+
diff --git a/usr.bin/telnet/ring.h b/usr.bin/telnet/ring.h
index 6898afbc198..a512ef968ab 100644
--- a/usr.bin/telnet/ring.h
+++ b/usr.bin/telnet/ring.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: ring.h,v 1.2 1996/03/27 19:33:06 niklas Exp $ */
+/* $OpenBSD: ring.h,v 1.3 1998/03/12 04:57:39 art Exp $ */
/* $NetBSD: ring.h,v 1.5 1996/02/28 21:04:09 thorpej Exp $ */
/*
@@ -55,6 +55,10 @@ typedef struct {
*bottom, /* lowest address in buffer */
*top, /* highest address+1 in buffer */
*mark; /* marker (user defined) */
+#if defined(ENCRYPTION)
+ unsigned char *clearto; /* Data to this point is clear text */
+ unsigned char *encryyptedto; /* Data is encrypted to here */
+#endif
int size; /* size in bytes of buffer */
u_long consumetime, /* help us keep straight full, empty, etc. */
supplytime;
@@ -86,7 +90,13 @@ extern int
ring_full_count P((Ring *ring)),
ring_full_consecutive P((Ring *ring));
+#if defined(ENCRYPTION)
+extern void
+ ring_encrypt (Ring *ring, void (*func)()),
+ ring_clearto (Ring *ring);
+#endif
+
extern void
- ring_clear_mark(),
- ring_mark();
+ ring_clear_mark P((Ring *)),
+ ring_mark P((Ring *));
diff --git a/usr.bin/telnet/sys_bsd.c b/usr.bin/telnet/sys_bsd.c
index c7b199f6b86..01d9b0425e3 100644
--- a/usr.bin/telnet/sys_bsd.c
+++ b/usr.bin/telnet/sys_bsd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sys_bsd.c,v 1.4 1996/12/11 17:14:22 robin Exp $ */
+/* $OpenBSD: sys_bsd.c,v 1.5 1998/03/12 04:57:40 art Exp $ */
/* $NetBSD: sys_bsd.c,v 1.11 1996/02/28 21:04:10 thorpej Exp $ */
/*
@@ -34,48 +34,13 @@
* SUCH DAMAGE.
*/
-#ifndef lint
-#if 0
-from: static char sccsid[] = "@(#)sys_bsd.c 8.4 (Berkeley) 5/30/95";
-static char rcsid[] = "$NetBSD: sys_bsd.c,v 1.11 1996/02/28 21:04:10 thorpej Exp $";
-#else
-static char rcsid[] = "$OpenBSD: sys_bsd.c,v 1.4 1996/12/11 17:14:22 robin Exp $";
-#endif
-#endif /* not lint */
+#include "telnet_locl.h"
/*
* The following routines try to encapsulate what is system dependent
* (at least between 4.x and dos) which is used in telnet.c.
*/
-
-#include <fcntl.h>
-#include <sys/types.h>
-#include <sys/time.h>
-#include <sys/socket.h>
-#include <signal.h>
-#include <errno.h>
-#include <arpa/telnet.h>
-#include <unistd.h>
-
-#include "ring.h"
-
-#include "fdset.h"
-
-#include "defines.h"
-#include "externs.h"
-#include "types.h"
-
-#if defined(CRAY) || (defined(USE_TERMIO) && !defined(SYSV_TERMIO))
-#define SIG_FUNC_RET void
-#else
-#define SIG_FUNC_RET int
-#endif
-
-#ifdef SIGINFO
-extern SIG_FUNC_RET ayt_status();
-#endif
-
int
tout, /* Output file descriptor */
tin, /* Input file descriptor */
@@ -91,8 +56,8 @@ int olmode = 0;
# define old_tc ottyb
#else /* USE_TERMIO */
-struct termio old_tc = { 0 };
-extern struct termio new_tc;
+struct termios old_tc = { 0 };
+extern struct termios new_tc;
# ifndef TCSANOW
# ifdef TCSETS
@@ -391,6 +356,12 @@ TerminalRestoreState()
* local/no signal mapping
*/
+#ifdef SIGTSTP
+static void susp();
+#endif /* SIGTSTP */
+#ifdef SIGINFO
+static void ayt();
+#endif
void
TerminalNewMode(f)
@@ -403,7 +374,7 @@ TerminalNewMode(f)
struct sgttyb sb;
int lmode;
#else /* USE_TERMIO */
- struct termio tmp_tc;
+ struct termios tmp_tc;
#endif /* USE_TERMIO */
int onoff;
int old;
@@ -603,10 +574,14 @@ TerminalNewMode(f)
tmp_tc.c_iflag &= ~ISTRIP;
else
tmp_tc.c_iflag |= ISTRIP;
- if (f & MODE_OUTBIN) {
+ if ((f & MODE_OUTBIN) || (f & MODE_OUT8)) {
tmp_tc.c_cflag &= ~(CSIZE|PARENB);
tmp_tc.c_cflag |= CS8;
- tmp_tc.c_oflag &= ~OPOST;
+ if(f & MODE_OUTBIN)
+ tmp_tc.c_oflag &= ~OPOST;
+ else
+ tmp_tc.c_oflag |= OPOST;
+
} else {
tmp_tc.c_cflag &= ~(CSIZE|PARENB);
tmp_tc.c_cflag |= old_tc.c_cflag & (CSIZE|PARENB);
@@ -618,13 +593,6 @@ TerminalNewMode(f)
if (f != -1) {
#ifdef SIGTSTP
- SIG_FUNC_RET susp();
-#endif /* SIGTSTP */
-#ifdef SIGINFO
- SIG_FUNC_RET ayt();
-#endif
-
-#ifdef SIGTSTP
(void) signal(SIGTSTP, susp);
#endif /* SIGTSTP */
#ifdef SIGINFO
@@ -670,9 +638,9 @@ TerminalNewMode(f)
#endif
} else {
#ifdef SIGINFO
- SIG_FUNC_RET ayt_status();
+ void ayt_status();
- (void) signal(SIGINFO, ayt_status);
+ (void) signal(SIGINFO, (void (*)(int))ayt_status);
#endif
#ifdef SIGTSTP
(void) signal(SIGTSTP, SIG_DFL);
@@ -868,7 +836,7 @@ NetSetPgrp(fd)
*/
/* ARGSUSED */
- SIG_FUNC_RET
+ void
deadpeer(sig)
int sig;
{
@@ -877,7 +845,7 @@ deadpeer(sig)
}
/* ARGSUSED */
- SIG_FUNC_RET
+ void
intr(sig)
int sig;
{
@@ -890,7 +858,7 @@ intr(sig)
}
/* ARGSUSED */
- SIG_FUNC_RET
+ void
intr2(sig)
int sig;
{
@@ -907,7 +875,7 @@ intr2(sig)
#ifdef SIGTSTP
/* ARGSUSED */
- SIG_FUNC_RET
+ void
susp(sig)
int sig;
{
@@ -920,7 +888,7 @@ susp(sig)
#ifdef SIGWINCH
/* ARGSUSED */
- SIG_FUNC_RET
+ void
sendwin(sig)
int sig;
{
@@ -932,7 +900,7 @@ sendwin(sig)
#ifdef SIGINFO
/* ARGSUSED */
- SIG_FUNC_RET
+ void
ayt(sig)
int sig;
{
@@ -1197,19 +1165,14 @@ process_rings(netin, netout, netex, ttyin, ttyout, poll)
if (c < 0 && errno == EWOULDBLOCK) {
c = 0;
} else {
- if (c < 0) {
- return -1;
- }
- if (c == 0) {
+ /* EOF detection for line mode!!!! */
+ if ((c == 0) && MODE_LOCAL_CHARS(globalmode) && isatty(tin)) {
/* must be an EOF... */
- if (MODE_LOCAL_CHARS(globalmode) && isatty(tin)) {
- *ttyiring.supply = termEofChar;
- c = 1;
- } else {
- clienteof = 1;
- shutdown(net, 1);
- return 0;
- }
+ *ttyiring.supply = termEofChar;
+ c = 1;
+ }
+ if (c <= 0) {
+ return -1;
}
if (termdata) {
Dump('<', ttyiring.supply, c);
diff --git a/usr.bin/telnet/telnet.1 b/usr.bin/telnet/telnet.1
index 8d8cca5bb45..ce62f8c6b41 100644
--- a/usr.bin/telnet/telnet.1
+++ b/usr.bin/telnet/telnet.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: telnet.1,v 1.9 1997/12/25 00:29:26 deraadt Exp $
+.\" $OpenBSD: telnet.1,v 1.10 1998/03/12 04:57:42 art Exp $
.\" $NetBSD: telnet.1,v 1.5 1996/02/28 21:04:12 thorpej Exp $
.\"
.\" Copyright (c) 1983, 1990, 1993
@@ -201,9 +201,7 @@ unless modified by the
.Fl e
option.
.It Fl x
-Turns on encryption of the data stream if possible. This
-option is not available outside of the United States and
-Canada.
+Turns on encryption of the data stream if possible.
.It Ar host
Indicates the official name, an alias, or the Internet address
of a remote host.
@@ -353,11 +351,7 @@ values (see below).
The encrypt command manipulates the information sent through the
.Dv TELNET ENCRYPT
option.
-.Pp
-Note: Because of export controls, the
-.Dv TELNET ENCRYPT
-option is not supported outside of the United States and Canada.
-.Pp
+..Pp
Valid arguments for the encrypt command are as follows:
.Bl -tag -width Ar
.It Ic disable Ar type Ic [input|output]
@@ -1138,9 +1132,6 @@ stream does not start automatically. The autoencrypt
output (input) stream should be enabled as soon as
possible.
.Pp
-Note: Because of export controls, the
-.Dv TELNET ENCRYPT
-option is not supported outside the United States and Canada.
.It Ic autologin
If the remote side supports the
.Dv TELNET AUTHENTICATION
@@ -1327,8 +1318,6 @@ toggle is
prints out a message each time encryption is enabled or
disabled. The initial value for this toggle is
.Dv FALSE.
-Note: Because of export controls, data encryption
-is not supported outside of the United States and Canada.
.It Ic \&?
Displays the legal
.Ic toggle
diff --git a/usr.bin/telnet/telnet.c b/usr.bin/telnet/telnet.c
index a66cc315846..4da88cb6d39 100644
--- a/usr.bin/telnet/telnet.c
+++ b/usr.bin/telnet/telnet.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: telnet.c,v 1.3 1997/06/05 01:07:39 deraadt Exp $ */
+/* $OpenBSD: telnet.c,v 1.4 1998/03/12 04:57:43 art Exp $ */
/* $NetBSD: telnet.c,v 1.7 1996/02/28 21:04:15 thorpej Exp $ */
/*
@@ -34,38 +34,9 @@
* SUCH DAMAGE.
*/
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#)telnet.c 8.4 (Berkeley) 5/30/95";
-static char rcsid[] = "$NetBSD: telnet.c,v 1.7 1996/02/28 21:04:15 thorpej Exp $";
-#else
-static char rcsid[] = "$OpenBSD: telnet.c,v 1.3 1997/06/05 01:07:39 deraadt Exp $";
-#endif
-#endif /* not lint */
-
-#include <sys/types.h>
-
-#if defined(unix)
-#include <signal.h>
-/* By the way, we need to include curses.h before telnet.h since,
- * among other things, telnet.h #defines 'DO', which is a variable
- * declared in curses.h.
- */
-#endif /* defined(unix) */
-
-#include <arpa/telnet.h>
-
-#include <ctype.h>
-
-#include "ring.h"
+#include "telnet_locl.h"
-#include "defines.h"
-#include "externs.h"
-#include "types.h"
-#include "general.h"
-
-
-#define strip(x) ((my_want_state_is_wont(TELOPT_BINARY)) ? ((x)&0x7f) : (x))
+#define strip(x) (eight ? (x) : ((x) & 0x7f))
static unsigned char subbuffer[SUBBUFSIZE],
*subpointer, *subend; /* buffer for sub-options */
@@ -85,7 +56,8 @@ char do_dont_resp[256];
char will_wont_resp[256];
int
- eight = 0,
+ eight = 3,
+ binary = 0,
autologin = 0, /* Autologin anyone? */
skiprc = 0,
connected,
@@ -159,18 +131,6 @@ int kludgelinemode = 1;
*/
Clocks clocks;
-
-#ifdef notdef
-Modelist modelist[] = {
- { "telnet command mode", COMMAND_LINE },
- { "character-at-a-time mode", 0 },
- { "character-at-a-time mode (local echo)", LOCAL_ECHO|LOCAL_CHARS },
- { "line-by-line mode (remote echo)", LINE | LOCAL_CHARS },
- { "line-by-line mode", LINE | LOCAL_ECHO | LOCAL_CHARS },
- { "line-by-line mode (local echoing suppressed)", LINE | LOCAL_CHARS },
- { "3270 mode", 0 },
-};
-#endif
/*
@@ -183,12 +143,12 @@ init_telnet()
env_init();
SB_CLEAR();
- ClearArray(options);
+ memset((char *)options, 0, sizeof options);
connected = In3270 = ISend = localflow = donebinarytoggle = 0;
-#if defined(AUTHENTICATION)
+#if defined(AUTHENTICATION) || defined(ENCRYPTION)
auth_encrypt_connect(connected);
-#endif /* defined(AUTHENTICATION) */
+#endif /* defined(AUTHENTICATION) || defined(ENCRYPTION) */
restartany = -1;
SYNCHing = 0;
@@ -206,56 +166,6 @@ init_telnet()
}
-#ifdef notdef
-#include <varargs.h>
-
- /*VARARGS*/
- static void
-printring(va_alist)
- va_dcl
-{
- va_list ap;
- char buffer[100]; /* where things go */
- char *ptr;
- char *format;
- char *string;
- Ring *ring;
- int i;
-
- va_start(ap);
-
- ring = va_arg(ap, Ring *);
- format = va_arg(ap, char *);
- ptr = buffer;
-
- while ((i = *format++) != 0) {
- if (i == '%') {
- i = *format++;
- switch (i) {
- case 'c':
- *ptr++ = va_arg(ap, int);
- break;
- case 's':
- string = va_arg(ap, char *);
- ring_supply_data(ring, buffer, ptr-buffer);
- ring_supply_data(ring, string, strlen(string));
- ptr = buffer;
- break;
- case 0:
- ExitString("printring: trailing %%.\n", 1);
- /*NOTREACHED*/
- default:
- ExitString("printring: unknown format character.\n", 1);
- /*NOTREACHED*/
- }
- } else {
- *ptr++ = i;
- }
- }
- ring_supply_data(ring, buffer, ptr-buffer);
-}
-#endif
-
/*
* These routines are in charge of sending option negotiations
* to the other side.
@@ -378,6 +288,9 @@ willoption(option)
#if defined(AUTHENTICATION)
case TELOPT_AUTHENTICATION:
#endif
+#if defined(ENCRYPTION)
+ case TELOPT_ENCRYPT:
+#endif
new_state_ok = 1;
break;
@@ -407,6 +320,11 @@ willoption(option)
}
}
set_my_state_do(option);
+#if defined(ENCRYPTION)
+ if (option == TELOPT_ENCRYPT)
+ encrypt_send_support();
+#endif
+
}
void
@@ -440,6 +358,11 @@ wontoption(option)
set_my_state_dont(option);
return; /* Never reply to TM will's/wont's */
+#ifdef ENCRYPTION
+ case TELOPT_ENCRYPT:
+ encrypt_not();
+ break;
+#endif
default:
break;
}
@@ -494,6 +417,9 @@ dooption(option)
case TELOPT_LFLOW: /* local flow control */
case TELOPT_TTYPE: /* terminal type option */
case TELOPT_SGA: /* no big deal */
+#if defined(ENCRYPTION)
+ case TELOPT_ENCRYPT: /* encryption variable option */
+#endif
new_state_ok = 1;
break;
@@ -683,7 +609,8 @@ mklist(buf, name)
* Skip entries with spaces or non-ascii values.
* Convert lower case letters to upper case.
*/
- if ((c == ' ') || !isascii(c))
+#define ISASCII(c) (!((c)&0x80))
+ if ((c == ' ') || !ISASCII(c))
n = 1;
else if (islower(c))
*cp = toupper(c);
@@ -739,12 +666,11 @@ is_unique(name, as, ae)
return (1);
}
-#ifdef TERMCAP
-char termbuf[1024];
+static char termbuf[1024];
/*ARGSUSED*/
int
-setupterm(tname, fd, errp)
+telnet_setupterm(tname, fd, errp)
char *tname;
int fd, *errp;
{
@@ -758,10 +684,6 @@ setupterm(tname, fd, errp)
*errp = 0;
return(-1);
}
-#else
-#define termbuf ttytype
-extern char ttytype[];
-#endif
int resettermname = 1;
@@ -778,7 +700,7 @@ gettermname()
if (tnamep && tnamep != unknown)
free(tnamep);
if ((tname = (char *)env_getvalue((unsigned char *)"TERM")) &&
- (setupterm(tname, 1, &err) == 0)) {
+ (telnet_setupterm(tname, 1, &err) == 0)) {
tnamep = mklist(termbuf, tname);
} else {
if (tname && ((int)strlen(tname) <= 40)) {
@@ -833,8 +755,9 @@ suboption()
name = gettermname();
len = strlen(name) + 4 + 2;
if (len < NETROOM()) {
- sprintf((char *)temp, "%c%c%c%c%s%c%c", IAC, SB, TELOPT_TTYPE,
- TELQUAL_IS, name, IAC, SE);
+ snprintf((char *)temp, sizeof(temp),
+ "%c%c%c%c%s%c%c", IAC, SB, TELOPT_TTYPE,
+ TELQUAL_IS, name, IAC, SE);
ring_supply_data(&netoring, temp, len);
printsub('>', &temp[2], len-2);
} else {
@@ -855,8 +778,9 @@ suboption()
TerminalSpeeds(&ispeed, &ospeed);
- sprintf((char *)temp, "%c%c%c%c%d,%d%c%c", IAC, SB, TELOPT_TSPEED,
- TELQUAL_IS, ospeed, ispeed, IAC, SE);
+ snprintf((char *)temp, sizeof(temp),
+ "%c%c%c%c%d,%d%c%c", IAC, SB, TELOPT_TSPEED,
+ TELQUAL_IS, ospeed, ispeed, IAC, SE);
len = strlen((char *)temp+4) + 4; /* temp[3] is 0 ... */
if (len < NETROOM()) {
@@ -960,7 +884,8 @@ suboption()
send_wont(TELOPT_XDISPLOC, 1);
break;
}
- sprintf((char *)temp, "%c%c%c%c%s%c%c", IAC, SB, TELOPT_XDISPLOC,
+ snprintf((char *)temp, sizeof(temp),
+ "%c%c%c%c%s%c%c", IAC, SB, TELOPT_XDISPLOC,
TELQUAL_IS, dp, IAC, SE);
len = strlen((char *)temp+4) + 4; /* temp[3] is 0 ... */
@@ -1003,6 +928,67 @@ suboption()
}
break;
#endif
+#if defined(ENCRYPTION)
+ case TELOPT_ENCRYPT:
+ if (SB_EOF())
+ return;
+ switch(SB_GET()) {
+ case ENCRYPT_START:
+ if (my_want_state_is_dont(TELOPT_ENCRYPT))
+ return;
+ encrypt_start(subpointer, SB_LEN());
+ break;
+ case ENCRYPT_END:
+ if (my_want_state_is_dont(TELOPT_ENCRYPT))
+ return;
+ encrypt_end();
+ break;
+ case ENCRYPT_SUPPORT:
+ if (my_want_state_is_wont(TELOPT_ENCRYPT))
+ return;
+ encrypt_support(subpointer, SB_LEN());
+ break;
+ case ENCRYPT_REQSTART:
+ if (my_want_state_is_wont(TELOPT_ENCRYPT))
+ return;
+ encrypt_request_start(subpointer, SB_LEN());
+ break;
+ case ENCRYPT_REQEND:
+ if (my_want_state_is_wont(TELOPT_ENCRYPT))
+ return;
+ /*
+ * We can always send an REQEND so that we cannot
+ * get stuck encrypting. We should only get this
+ * if we have been able to get in the correct mode
+ * anyhow.
+ */
+ encrypt_request_end();
+ break;
+ case ENCRYPT_IS:
+ if (my_want_state_is_dont(TELOPT_ENCRYPT))
+ return;
+ encrypt_is(subpointer, SB_LEN());
+ break;
+ case ENCRYPT_REPLY:
+ if (my_want_state_is_wont(TELOPT_ENCRYPT))
+ return;
+ encrypt_reply(subpointer, SB_LEN());
+ break;
+ case ENCRYPT_ENC_KEYID:
+ if (my_want_state_is_dont(TELOPT_ENCRYPT))
+ return;
+ encrypt_enc_keyid(subpointer, SB_LEN());
+ break;
+ case ENCRYPT_DEC_KEYID:
+ if (my_want_state_is_wont(TELOPT_ENCRYPT))
+ return;
+ encrypt_dec_keyid(subpointer, SB_LEN());
+ break;
+ default:
+ break;
+ }
+ break;
+#endif
default:
break;
}
@@ -1150,7 +1136,7 @@ slc_init()
#define initfunc(func, flags) { \
spcp = &spc_data[func]; \
- if (spcp->valp = tcval(func)) { \
+ if ((spcp->valp = tcval(func))) { \
spcp->val = *spcp->valp; \
spcp->mylevel = SLC_VARIABLE|flags; \
} else { \
@@ -1558,12 +1544,12 @@ env_opt_add(ep)
if (ep == NULL || *ep == '\0') {
/* Send user defined variables first. */
env_default(1, 0);
- while (ep = env_default(0, 0))
+ while ((ep = env_default(0, 0)))
env_opt_add(ep);
/* Now add the list of well know variables. */
env_default(1, 1);
- while (ep = env_default(0, 1))
+ while ((ep = env_default(0, 1)))
env_opt_add(ep);
return;
}
@@ -1583,7 +1569,7 @@ env_opt_add(ep)
opt_replyp = opt_reply + len - (opt_replyend - opt_replyp);
opt_replyend = opt_reply + len;
}
- if (opt_welldefined(ep))
+ if (opt_welldefined((char *)ep))
#ifdef OLD_ENVIRON
if (telopt_environ == TELOPT_OLD_ENVIRON)
*opt_replyp++ = old_env_var;
@@ -1593,7 +1579,7 @@ env_opt_add(ep)
else
*opt_replyp++ = ENV_USERVAR;
for (;;) {
- while (c = *ep++) {
+ while ((c = *ep++)) {
switch(c&0xff) {
case IAC:
*opt_replyp++ = IAC;
@@ -1607,7 +1593,7 @@ env_opt_add(ep)
}
*opt_replyp++ = c;
}
- if (ep = vp) {
+ if ((ep = vp)) {
#ifdef OLD_ENVIRON
if (telopt_environ == TELOPT_OLD_ENVIRON)
*opt_replyp++ = old_env_value;
@@ -1684,6 +1670,10 @@ telrcv()
}
c = *sbp++ & 0xff, scc--; count++;
+#if defined(ENCRYPTION)
+ if (decrypt_input)
+ c = (*decrypt_input)(c);
+#endif
switch (telrcv_state) {
@@ -1718,7 +1708,7 @@ telrcv()
# endif /* defined(TN3270) */
/*
* The 'crmod' hack (see following) is needed
- * since we can't * set CRMOD on output only.
+ * since we can't set CRMOD on output only.
* Machines like MULTICS like to send \r without
* \n; since we must turn off CRMOD to get proper
* input, the mapping is done here (sigh).
@@ -1726,6 +1716,10 @@ telrcv()
if ((c == '\r') && my_want_state_is_dont(TELOPT_BINARY)) {
if (scc > 0) {
c = *sbp&0xff;
+#if defined(ENCRYPTION)
+ if (decrypt_input)
+ c = (*decrypt_input)(c);
+#endif
if (c == 0) {
sbp++, scc--; count++;
/* a "true" CR */
@@ -1735,7 +1729,10 @@ telrcv()
sbp++, scc--; count++;
TTYADD('\n');
} else {
-
+#if defined(ENCRYPTION)
+ if (decrypt_input)
+ (*decrypt_input)(-1);
+#endif
TTYADD('\r');
if (crmod) {
TTYADD('\n');
@@ -2171,7 +2168,7 @@ telnet(user)
{
sys_telnet_init();
-#if defined(AUTHENTICATION)
+#if defined(AUTHENTICATION) || defined(ENCRYPTION)
{
static char local_host[256] = { 0 };
@@ -2182,13 +2179,17 @@ telnet(user)
auth_encrypt_init(local_host, hostname, "TELNET", 0);
auth_encrypt_user(user);
}
-#endif /* defined(AUTHENTICATION) */
+#endif /* defined(AUTHENTICATION) || defined(ENCRYPTION) */
# if !defined(TN3270)
if (telnetport) {
#if defined(AUTHENTICATION)
if (autologin)
send_will(TELOPT_AUTHENTICATION, 1);
#endif
+#if defined(ENCRYPTION)
+ send_do(TELOPT_ENCRYPT, 1);
+ send_will(TELOPT_ENCRYPT, 1);
+#endif
send_do(TELOPT_SGA, 1);
send_will(TELOPT_TTYPE, 1);
send_will(TELOPT_NAWS, 1);
@@ -2199,8 +2200,8 @@ telnet(user)
send_do(TELOPT_STATUS, 1);
if (env_getvalue((unsigned char *)"DISPLAY"))
send_will(TELOPT_XDISPLOC, 1);
- if (eight)
- tel_enter_binary(eight);
+ if (binary)
+ tel_enter_binary(binary);
}
# endif /* !defined(TN3270) */
diff --git a/usr.bin/telnet/telnet_locl.h b/usr.bin/telnet/telnet_locl.h
new file mode 100644
index 00000000000..bbb39ed00ba
--- /dev/null
+++ b/usr.bin/telnet/telnet_locl.h
@@ -0,0 +1,92 @@
+/* $OpenBSD: telnet_locl.h,v 1.1 1998/03/12 04:57:44 art Exp $ */
+/* $KTH: telnet_locl.h,v 1.13 1997/11/03 21:37:55 assar Exp $ */
+
+/*
+ * Copyright (c) 1995, 1996, 1997 Kungliga Tekniska Högskolan
+ * (Royal Institute of Technology, Stockholm, Sweden).
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the Kungliga Tekniska
+ * Högskolan and its contributors.
+ *
+ * 4. Neither the name of the Institute nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <string.h>
+#include <ctype.h>
+#include <signal.h>
+#include <errno.h>
+#include <setjmp.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+/* termios.h *must* be included before curses.h */
+#include <termios.h>
+#include <fcntl.h>
+#include <netdb.h>
+#include <pwd.h>
+#include <sys/select.h>
+#include <sys/time.h>
+#include <time.h>
+#include <sys/param.h>
+#include <sys/ioctl.h>
+#include <sys/resource.h>
+#include <sys/wait.h>
+#include <sys/file.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netinet/in_systm.h>
+#include <netinet/ip.h>
+#include <arpa/inet.h>
+
+#include <arpa/telnet.h>
+
+#if defined(AUTHENTICATION) || defined(ENCRYPTION)
+#include <libtelnet/auth.h>
+#include <libtelnet/encrypt.h>
+#endif
+#include <libtelnet/misc.h>
+#include <libtelnet/misc-proto.h>
+
+#define LINEMODE
+
+#include "ring.h"
+#include "externs.h"
+#include "defines.h"
+#include "types.h"
+
+#undef AF_INET6 /* XXX - it has not been tested and it doesn't exist yet */
+
+/* prototypes */
+
diff --git a/usr.bin/telnet/terminal.c b/usr.bin/telnet/terminal.c
index 6d1108f009f..a9d201c8b38 100644
--- a/usr.bin/telnet/terminal.c
+++ b/usr.bin/telnet/terminal.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: terminal.c,v 1.2 1996/03/27 19:33:11 niklas Exp $ */
+/* $OpenBSD: terminal.c,v 1.3 1998/03/12 04:57:45 art Exp $ */
/* $NetBSD: terminal.c,v 1.5 1996/02/28 21:04:17 thorpej Exp $ */
/*
@@ -34,22 +34,7 @@
* SUCH DAMAGE.
*/
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#)terminal.c 8.2 (Berkeley) 2/16/95";
-static char rcsid[] = "$NetBSD: terminal.c,v 1.5 1996/02/28 21:04:17 thorpej Exp $";
-#else
-static char rcsid[] = "$OpenBSD: terminal.c,v 1.2 1996/03/27 19:33:11 niklas Exp $";
-#endif
-#endif /* not lint */
-
-#include <arpa/telnet.h>
-#include <sys/types.h>
-
-#include "ring.h"
-
-#include "externs.h"
-#include "types.h"
+#include "telnet_locl.h"
Ring ttyoring, ttyiring;
unsigned char ttyobuf[2*BUFSIZ], ttyibuf[BUFSIZ];
@@ -132,7 +117,7 @@ ttyflush(drop)
TerminalFlushOutput();
/* we leave 'n' alone! */
} else {
- n = TerminalWrite(ttyoring.consume, n);
+ n = TerminalWrite((char *)ttyoring.consume, n);
}
}
if (n > 0) {
@@ -188,9 +173,11 @@ getconnmode()
if (localflow)
mode |= MODE_FLOW;
- if (my_want_state_is_will(TELOPT_BINARY))
+ if ((eight & 1) || my_want_state_is_will(TELOPT_BINARY))
mode |= MODE_INBIN;
+ if (eight & 2)
+ mode |= MODE_OUT8;
if (his_want_state_is_will(TELOPT_BINARY))
mode |= MODE_OUTBIN;
@@ -215,11 +202,28 @@ setconnmode(force)
int force;
{
register int newmode;
+#ifdef ENCRYPTION
+ static int enc_passwd = 0;
+#endif
newmode = getconnmode()|(force?MODE_FORCE:0);
TerminalNewMode(newmode);
+#ifdef ENCRYPTION
+ if ((newmode & (MODE_ECHO|MODE_EDIT)) == MODE_EDIT) {
+ if (my_want_state_is_will(TELOPT_ENCRYPT)
+ && (enc_passwd == 0) && !encrypt_output) {
+ encrypt_request_start(0, 0);
+ enc_passwd = 1;
+ }
+ } else {
+ if (enc_passwd) {
+ encrypt_request_end();
+ enc_passwd = 0;
+ }
+ }
+#endif
}
diff --git a/usr.bin/telnet/tn3270.c b/usr.bin/telnet/tn3270.c
index c170a993c0a..c814d1da64b 100644
--- a/usr.bin/telnet/tn3270.c
+++ b/usr.bin/telnet/tn3270.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tn3270.c,v 1.2 1996/03/27 19:33:12 niklas Exp $ */
+/* $OpenBSD: tn3270.c,v 1.3 1998/03/12 04:57:46 art Exp $ */
/* $NetBSD: tn3270.c,v 1.5 1996/02/28 21:04:18 thorpej Exp $ */
/*
@@ -34,24 +34,7 @@
* SUCH DAMAGE.
*/
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#)tn3270.c 8.2 (Berkeley) 5/30/95";
-static char rcsid[] = "$NetBSD: tn3270.c,v 1.5 1996/02/28 21:04:18 thorpej Exp $";
-#else
-static char rcsid[] = "$OpenBSD: tn3270.c,v 1.2 1996/03/27 19:33:12 niklas Exp $";
-#endif
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <arpa/telnet.h>
-
-#include "general.h"
-
-#include "defines.h"
-#include "ring.h"
-#include "externs.h"
-#include "fdset.h"
+#include "telnet_locl.h"
#if defined(TN3270)
diff --git a/usr.bin/telnet/utilities.c b/usr.bin/telnet/utilities.c
index 4f3f15105b7..aa6b01dcf87 100644
--- a/usr.bin/telnet/utilities.c
+++ b/usr.bin/telnet/utilities.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: utilities.c,v 1.4 1998/02/16 04:59:04 jason Exp $ */
+/* $OpenBSD: utilities.c,v 1.5 1998/03/12 04:57:47 art Exp $ */
/* $NetBSD: utilities.c,v 1.5 1996/02/28 21:04:21 thorpej Exp $ */
/*
@@ -34,34 +34,11 @@
* SUCH DAMAGE.
*/
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#)utilities.c 8.3 (Berkeley) 5/30/95";
-static char rcsid[] = "$NetBSD: utilities.c,v 1.5 1996/02/28 21:04:21 thorpej Exp $";
-#else
-static char rcsid[] = "$OpenBSD: utilities.c,v 1.4 1998/02/16 04:59:04 jason Exp $";
-#endif
-#endif /* not lint */
-
#define TELOPTS
#define TELCMDS
#define SLC_NAMES
-#include <arpa/telnet.h>
-#include <sys/types.h>
-#include <sys/time.h>
-#include <sys/socket.h>
-#include <unistd.h>
-#include <ctype.h>
-
-#include "general.h"
-
-#include "fdset.h"
-
-#include "ring.h"
-#include "defines.h"
-
-#include "externs.h"
+#include "telnet_locl.h"
FILE *NetTrace = 0; /* Not in bss, since needs to stay */
int prettydump;
@@ -98,7 +75,7 @@ SetSockOpt(fd, level, option, yesno)
{
#ifndef NOT43
return setsockopt(fd, level, option,
- (char *)&yesno, sizeof yesno);
+ (void *)&yesno, sizeof yesno);
#else /* NOT43 */
if (yesno == 0) { /* Can't do that in 4.2! */
fprintf(stderr, "Error: attempt to turn off an option 0x%x.\n",
@@ -494,6 +471,77 @@ printsub(direction, pointer, length)
break;
#endif
+#if defined(ENCRYPTION)
+ case TELOPT_ENCRYPT:
+ fprintf(NetTrace, "ENCRYPT");
+ if (length < 2) {
+ fprintf(NetTrace, " (empty suboption?)");
+ break;
+ }
+ switch (pointer[1]) {
+ case ENCRYPT_START:
+ fprintf(NetTrace, " START");
+ break;
+
+ case ENCRYPT_END:
+ fprintf(NetTrace, " END");
+ break;
+
+ case ENCRYPT_REQSTART:
+ fprintf(NetTrace, " REQUEST-START");
+ break;
+
+ case ENCRYPT_REQEND:
+ fprintf(NetTrace, " REQUEST-END");
+ break;
+
+ case ENCRYPT_IS:
+ case ENCRYPT_REPLY:
+ fprintf(NetTrace, " %s ", (pointer[1] == ENCRYPT_IS) ?
+ "IS" : "REPLY");
+ if (length < 3) {
+ fprintf(NetTrace, " (partial suboption?)");
+ break;
+ }
+ if (ENCTYPE_NAME_OK(pointer[2]))
+ fprintf(NetTrace, "%s ", ENCTYPE_NAME(pointer[2]));
+ else
+ fprintf(NetTrace, " %d (unknown)", pointer[2]);
+
+ encrypt_printsub(&pointer[1], length - 1, buf, sizeof(buf));
+ fprintf(NetTrace, "%s", buf);
+ break;
+
+ case ENCRYPT_SUPPORT:
+ i = 2;
+ fprintf(NetTrace, " SUPPORT ");
+ while (i < length) {
+ if (ENCTYPE_NAME_OK(pointer[i]))
+ fprintf(NetTrace, "%s ", ENCTYPE_NAME(pointer[i]));
+ else
+ fprintf(NetTrace, "%d ", pointer[i]);
+ i++;
+ }
+ break;
+
+ case ENCRYPT_ENC_KEYID:
+ fprintf(NetTrace, " ENC_KEYID ");
+ goto encommon;
+
+ case ENCRYPT_DEC_KEYID:
+ fprintf(NetTrace, " DEC_KEYID ");
+ goto encommon;
+
+ default:
+ fprintf(NetTrace, " %d (unknown)", pointer[1]);
+ encommon:
+ for (i = 2; i < length; i++)
+ fprintf(NetTrace, " %d", pointer[i]);
+ break;
+ }
+ break;
+#endif
+
case TELOPT_LINEMODE:
fprintf(NetTrace, "LINEMODE ");
@@ -573,12 +621,13 @@ printsub(direction, pointer, length)
}
{
char tbuf[64];
- sprintf(tbuf, "%s%s%s%s%s",
- pointer[2]&MODE_EDIT ? "|EDIT" : "",
- pointer[2]&MODE_TRAPSIG ? "|TRAPSIG" : "",
- pointer[2]&MODE_SOFT_TAB ? "|SOFT_TAB" : "",
- pointer[2]&MODE_LIT_ECHO ? "|LIT_ECHO" : "",
- pointer[2]&MODE_ACK ? "|ACK" : "");
+ snprintf(tbuf, sizeof(tbuf),
+ "%s%s%s%s%s",
+ pointer[2]&MODE_EDIT ? "|EDIT" : "",
+ pointer[2]&MODE_TRAPSIG ? "|TRAPSIG" : "",
+ pointer[2]&MODE_SOFT_TAB ? "|SOFT_TAB" : "",
+ pointer[2]&MODE_LIT_ECHO ? "|LIT_ECHO" : "",
+ pointer[2]&MODE_ACK ? "|ACK" : "");
fprintf(NetTrace, "%s", tbuf[1] ? &tbuf[1] : "0");
}
if (pointer[2]&~(MODE_MASK))
@@ -807,23 +856,24 @@ printsub(direction, pointer, length)
EmptyTerminal()
{
#if defined(unix)
- fd_set o;
+ fd_set outs;
- FD_ZERO(&o);
+ FD_ZERO(&outs);
#endif /* defined(unix) */
if (TTYBYTES() == 0) {
#if defined(unix)
- FD_SET(tout, &o);
- (void) select(tout+1, (fd_set *) 0, &o, (fd_set *) 0,
+ FD_SET(tout, &outs);
+ (void) select(tout+1, (fd_set *) 0, &outs, (fd_set *) 0,
(struct timeval *) 0); /* wait for TTLOWAT */
#endif /* defined(unix) */
} else {
while (TTYBYTES()) {
(void) ttyflush(0);
#if defined(unix)
- FD_SET(tout, &o);
- (void) select(tout+1, (fd_set *) 0, &o, (fd_set *) 0,
+ ttyflush(0);
+ FD_SET(tout, &outs);
+ (void) select(tout+1, (fd_set *) 0, &outs, (fd_set *) 0,
(struct timeval *) 0); /* wait for TTLOWAT */
#endif /* defined(unix) */
}