summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--contrib/telnet/telnetd/ext.h2
-rw-r--r--contrib/telnet/telnetd/sys_term.c55
-rw-r--r--libexec/telnetd/Makefile3
3 files changed, 23 insertions, 37 deletions
diff --git a/contrib/telnet/telnetd/ext.h b/contrib/telnet/telnetd/ext.h
index 448ba68..25db496 100644
--- a/contrib/telnet/telnetd/ext.h
+++ b/contrib/telnet/telnetd/ext.h
@@ -77,7 +77,7 @@ extern char *neturg; /* one past last bye of urgent data */
extern int pcc, ncc;
extern int pty, net;
-extern char line[16];
+extern char line[32];
extern int SYNCHing; /* we are in TELNET SYNCH mode */
extern void
diff --git a/contrib/telnet/telnetd/sys_term.c b/contrib/telnet/telnetd/sys_term.c
index 151c5b4..02a7b7c 100644
--- a/contrib/telnet/telnetd/sys_term.c
+++ b/contrib/telnet/telnetd/sys_term.c
@@ -392,46 +392,31 @@ spcset(int func, cc_t *valp, cc_t **valpp)
*
* Returns the file descriptor of the opened pty.
*/
-char alpha[] = "0123456789abcdefghijklmnopqrstuv";
-char line[16];
+char line[32];
int
getpty(int *ptynum __unused)
{
int p;
- const char *cp;
- char *p1, *p2;
- int i;
-
- (void) strcpy(line, _PATH_DEV);
- (void) strcat(line, "ptyXX");
- p1 = &line[8];
- p2 = &line[9];
-
- for (cp = "pqrsPQRS"; *cp; cp++) {
- struct stat stb;
-
- *p1 = *cp;
- *p2 = '0';
- /*
- * This stat() check is just to keep us from
- * looping through all 256 combinations if there
- * aren't that many ptys available.
- */
- if (stat(line, &stb) < 0)
- break;
- for (i = 0; i < 32; i++) {
- *p2 = alpha[i];
- p = open(line, 2);
- if (p > 0) {
- line[5] = 't';
- chown(line, 0, 0);
- chmod(line, 0600);
- return(p);
- }
- }
- }
- return(-1);
+ const char *pn;
+
+ p = posix_openpt(O_RDWR|O_NOCTTY);
+ if (p < 0)
+ return (-1);
+
+ if (grantpt(p) == -1)
+ return (-1);
+
+ if (unlockpt(p) == -1)
+ return (-1);
+
+ pn = ptsname(p);
+ if (pn == NULL)
+ return (-1);
+
+ strcpy(line, pn);
+
+ return (p);
}
#ifdef LINEMODE
diff --git a/libexec/telnetd/Makefile b/libexec/telnetd/Makefile
index 3ad8a4e..dcc3398 100644
--- a/libexec/telnetd/Makefile
+++ b/libexec/telnetd/Makefile
@@ -17,7 +17,8 @@ SRCS= global.c slc.c state.c sys_term.c telnetd.c \
WARNS?= 2
WFORMAT?= 0
-CFLAGS+= -DLINEMODE -DUSE_TERMIO -DDIAGNOSTICS -DOLD_ENVIRON -DENV_HACK
+CFLAGS+= -DLINEMODE -DUSE_TERMIO -DDIAGNOSTICS -DOLD_ENVIRON \
+ -DENV_HACK -DSTREAMSPTY
.if ${MK_INET6_SUPPORT} != "no"
CFLAGS+= -DINET6
OpenPOWER on IntegriCloud