I really want to delete telnet entirely, but there are still occasions
when someone might want to use it on an intranet. Other telnet tools
are probably worse shape.
This adds two pledge calls.
The subshell and skey support are removed (you can use ^Z), and you
cannot start a new telnet session. Only the first session. (That is
not handled nicely yet... I'm looking into it).
Index: Makefile
===================================================================
RCS file: /cvs/src/usr.bin/telnet/Makefile,v
retrieving revision 1.33
diff -u -p -u -r1.33 Makefile
--- Makefile 20 Jul 2014 05:29:39 -0000 1.33
+++ Makefile 13 Nov 2015 08:16:12 -0000
@@ -32,7 +32,7 @@
PROG= telnet
-CFLAGS+=-DKLUDGELINEMODE -DSKEY
+CFLAGS+=-DKLUDGELINEMODE
CFLAGS+= -Wall
LDADD+= -lcurses
DPADD= ${LIBCURSES}
Index: commands.c
===================================================================
RCS file: /cvs/src/usr.bin/telnet/commands.c,v
retrieving revision 1.74
diff -u -p -u -r1.74 commands.c
--- commands.c 26 Oct 2015 00:33:03 -0000 1.74
+++ commands.c 13 Nov 2015 08:27:43 -0000
@@ -49,11 +49,6 @@
#include <unistd.h>
#include <limits.h>
-#ifdef SKEY
-#include <sys/wait.h>
-#define PATH_SKEY "/usr/bin/skey"
-#endif
-
char *hostname;
typedef struct {
@@ -64,37 +59,9 @@ typedef struct {
} Command;
static char line[256];
-static char saveline[256];
static int margc;
static char *margv[20];
-#ifdef SKEY
-int
-skey_calc(int argc, char **argv)
-{
- int status;
-
- if(argc != 3) {
- printf("usage: %s sequence challenge\n", argv[0]);
- return 0;
- }
-
- switch(fork()) {
- case 0:
- execv(PATH_SKEY, argv);
- exit (1);
- case -1:
- err(1, "fork");
- break;
- default:
- (void) wait(&status);
- if (WIFEXITED(status))
- return (WEXITSTATUS(status));
- return (0);
- }
-}
-#endif
-
static void
makeargv(void)
{
@@ -103,12 +70,6 @@ makeargv(void)
margc = 0;
cp = line;
- if (*cp == '!') { /* Special case shell escape */
- strlcpy(saveline, line, sizeof(saveline)); /* save for shell command */
- *argp++ = "!"; /* No room in string to get this */
- margc++;
- cp++;
- }
while ((c = *cp)) {
int inquote = 0;
while (isspace((unsigned char)c))
@@ -779,7 +740,6 @@ static struct setlist Setlist[] = {
#endif
{ "escape", "character to escape back to telnet command mode", 0,
&escape },
{ "rlogin", "rlogin escape character", 0, &rlogin },
- { "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, &termFlushChar },
@@ -1243,52 +1203,6 @@ telnetsuspend(int unused1, char *unused2
return 1;
}
-int
-shell(int argc, char *argv[])
-{
- long oldrows, oldcols, newrows, newcols, err;
-
- setcommandmode();
-
- err = (TerminalWindowSize(&oldrows, &oldcols) == 0) ? 1 : 0;
- switch(vfork()) {
- case -1:
- perror("Fork failed\r\n");
- break;
-
- case 0:
- {
- /*
- * Fire up the shell in the child.
- */
- char *shellp, *shellname;
-
- shellp = getenv("SHELL");
- if (shellp == NULL)
- shellp = "/bin/sh";
- if ((shellname = strrchr(shellp, '/')) == 0)
- shellname = shellp;
- else
- shellname++;
- if (argc > 1)
- execl(shellp, shellname, "-c", &saveline[1], (char *)NULL);
- else
- execl(shellp, shellname, (char *)NULL);
- perror("Execl");
- _exit(1);
- }
- default:
- (void)wait((int *)0); /* Wait for the shell to complete */
-
- if (TerminalWindowSize(&newrows, &newcols) && connected &&
- (err || ((oldrows != newrows) || (oldcols != newcols)))) {
- sendnaws();
- }
- break;
- }
- return 1;
-}
-
static void
close_connection(void)
{
@@ -2012,6 +1926,7 @@ tn(int argc, char *argv[])
connected++;
break;
}
+
freeaddrinfo(res0);
if (net < 0) {
return 0;
@@ -2029,6 +1944,7 @@ tn(int argc, char *argv[])
user = NULL;
}
}
+
if (user) {
env_define("USER", user);
env_export("USER");
@@ -2056,10 +1972,6 @@ static char
slchelp[] = "change state of special charaters ('slc ?' for more)",
displayhelp[] = "display operating parameters",
zhelp[] = "suspend telnet",
-#ifdef SKEY
- skeyhelp[] = "compute response to s/key challenge",
-#endif
- shellhelp[] = "invoke a subshell",
envhelp[] = "change environment variables ('environ ?' for more)",
modestring[] = "try to enter line or character mode ('mode ?' for
more)";
@@ -2080,12 +1992,8 @@ static Command cmdtab[] = {
{ "slc", slchelp, slccmd, 0 },
{ "z", zhelp, telnetsuspend, 0 },
- { "!", shellhelp, shell, 0 },
{ "environ", envhelp, env_cmd, 0 },
{ "?", helphelp, help, 0 },
-#ifdef SKEY
- { "skey", skeyhelp, skey_calc, 0 },
-#endif
{ 0, 0, 0, 0 }
};
Index: main.c
===================================================================
RCS file: /cvs/src/usr.bin/telnet/main.c,v
retrieving revision 1.30
diff -u -p -u -r1.30 main.c
--- main.c 22 Jul 2014 07:30:24 -0000 1.30
+++ main.c 13 Nov 2015 08:33:09 -0000
@@ -80,6 +80,11 @@ main(int argc, char *argv[])
char *user, *alias;
const char *errstr;
+ if (pledge("stdio rpath wpath inet tty", NULL) == -1) {
+ perror("pledge");
+ exit(1);
+ }
+
tninit(); /* Clear out things */
TerminalSaveState();
Index: telnet.1
===================================================================
RCS file: /cvs/src/usr.bin/telnet/telnet.1,v
retrieving revision 1.56
diff -u -p -u -r1.56 telnet.1
--- telnet.1 25 Oct 2015 14:12:55 -0000 1.56
+++ telnet.1 13 Nov 2015 08:31:47 -0000
@@ -1018,13 +1018,6 @@ Displays the legal
.Pq Ic unset
commands.
.El
-.It Ic skey Ar sequence challenge
-The
-.Ic skey
-command computes a response to the S/Key challenge.
-See
-.Xr skey 1
-for more information on the S/Key system.
.It Ic slc Ar state
The
.Ic slc
@@ -1295,13 +1288,6 @@ Suspend
.Nm telnet .
This command only works when the user is using a shell with
job control enabled.
-.It Ic \&! Op Ar command
-Execute a single command in a subshell on the local
-system.
-If
-.Ar command
-is omitted, then an interactive
-subshell is invoked.
.It Ic \&? Op Ar command
Get help.
With no arguments,
@@ -1330,7 +1316,6 @@ option.
user customized telnet startup values
.El
.Sh SEE ALSO
-.Xr skey 1 ,
.Xr ssh 1 ,
.Xr stty 1
.Sh HISTORY
Index: telnet.c
===================================================================
RCS file: /cvs/src/usr.bin/telnet/telnet.c,v
retrieving revision 1.30
diff -u -p -u -r1.30 telnet.c
--- telnet.c 9 Sep 2014 03:41:08 -0000 1.30
+++ telnet.c 13 Nov 2015 08:27:56 -0000
@@ -36,6 +36,7 @@
#include <ctype.h>
#include <curses.h>
#include <stdlib.h>
+#include <unistd.h>
#include <string.h>
#include <term.h>
@@ -1838,6 +1839,11 @@ void
telnet(char *user)
{
sys_telnet_init();
+
+ if (pledge("stdio tty", NULL) == -1) {
+ perror("pledge");
+ exit(1);
+ }
if (telnetport) {
send_do(TELOPT_SGA, 1);