mirror of
https://github.com/sheumann/telnetd.git
synced 2024-09-27 02:54:29 +00:00
Convert telnetd(8) to use posix_openpt(2).
Some time ago I got some reports MPSAFE TTY broke telnetd(8). Even though it turned out to be a different problem within the TTY code, I spotted a small issue with telnetd(8). Instead of allocating PTY's using openpty(3) or posix_openpt(2), it used its own PTY allocation routine. This means that telnetd(8) still uses /dev/ptyXX-style devices. I've also increased the size of line[]. Even though 16 should be enough, we already use 13 bytes ("/dev/pts/999", including '\0'). 32 bytes gives us a little more freedom. Also enable -DSTREAMSPTY. Otherwise telnetd(8) strips the PTY's pathname to the latest slash instead of just removing "/dev/" (e.g. /dev/pts/0 -> 0, instead of pts/0). Reviewed by: rink git-svn-id: http://svn0.us-east.freebsd.org/base/head/contrib/telnet@184935 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
This commit is contained in:
parent
2846fec647
commit
7aa7324a8f
@ -77,7 +77,7 @@ extern char *neturg; /* one past last bye of urgent data */
|
|||||||
extern int pcc, ncc;
|
extern int pcc, ncc;
|
||||||
|
|
||||||
extern int pty, net;
|
extern int pty, net;
|
||||||
extern char line[16];
|
extern char line[32];
|
||||||
extern int SYNCHing; /* we are in TELNET SYNCH mode */
|
extern int SYNCHing; /* we are in TELNET SYNCH mode */
|
||||||
|
|
||||||
extern void
|
extern void
|
||||||
|
@ -392,46 +392,31 @@ spcset(int func, cc_t *valp, cc_t **valpp)
|
|||||||
*
|
*
|
||||||
* Returns the file descriptor of the opened pty.
|
* Returns the file descriptor of the opened pty.
|
||||||
*/
|
*/
|
||||||
char alpha[] = "0123456789abcdefghijklmnopqrstuv";
|
char line[32];
|
||||||
char line[16];
|
|
||||||
|
|
||||||
int
|
int
|
||||||
getpty(int *ptynum __unused)
|
getpty(int *ptynum __unused)
|
||||||
{
|
{
|
||||||
int p;
|
int p;
|
||||||
const char *cp;
|
const char *pn;
|
||||||
char *p1, *p2;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
(void) strcpy(line, _PATH_DEV);
|
p = posix_openpt(O_RDWR|O_NOCTTY);
|
||||||
(void) strcat(line, "ptyXX");
|
if (p < 0)
|
||||||
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);
|
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
|
#ifdef LINEMODE
|
||||||
|
Loading…
Reference in New Issue
Block a user