From owner-svn-src-all@FreeBSD.ORG Thu Nov 13 19:05:28 2008 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 9EC33106567D; Thu, 13 Nov 2008 19:05:28 +0000 (UTC) (envelope-from ed@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 2AE458FC18; Thu, 13 Nov 2008 19:05:28 +0000 (UTC) (envelope-from ed@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id mADJ5SIw066544; Thu, 13 Nov 2008 19:05:28 GMT (envelope-from ed@svn.freebsd.org) Received: (from ed@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id mADJ5SJJ066541; Thu, 13 Nov 2008 19:05:28 GMT (envelope-from ed@svn.freebsd.org) Message-Id: <200811131905.mADJ5SJJ066541@svn.freebsd.org> From: Ed Schouten Date: Thu, 13 Nov 2008 19:05:28 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r184935 - in head: contrib/telnet/telnetd libexec/telnetd X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 13 Nov 2008 19:05:28 -0000 Author: ed Date: Thu Nov 13 19:05:27 2008 New Revision: 184935 URL: http://svn.freebsd.org/changeset/base/184935 Log: 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 Modified: head/contrib/telnet/telnetd/ext.h head/contrib/telnet/telnetd/sys_term.c head/libexec/telnetd/Makefile Modified: head/contrib/telnet/telnetd/ext.h ============================================================================== --- head/contrib/telnet/telnetd/ext.h Thu Nov 13 17:40:21 2008 (r184934) +++ head/contrib/telnet/telnetd/ext.h Thu Nov 13 19:05:27 2008 (r184935) @@ -77,7 +77,7 @@ extern char *neturg; /* one past last b 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 Modified: head/contrib/telnet/telnetd/sys_term.c ============================================================================== --- head/contrib/telnet/telnetd/sys_term.c Thu Nov 13 17:40:21 2008 (r184934) +++ head/contrib/telnet/telnetd/sys_term.c Thu Nov 13 19:05:27 2008 (r184935) @@ -392,46 +392,31 @@ spcset(int func, cc_t *valp, cc_t **valp * * 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]; + const char *pn; - for (cp = "pqrsPQRS"; *cp; cp++) { - struct stat stb; + 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); - *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 (p); } #ifdef LINEMODE Modified: head/libexec/telnetd/Makefile ============================================================================== --- head/libexec/telnetd/Makefile Thu Nov 13 17:40:21 2008 (r184934) +++ head/libexec/telnetd/Makefile Thu Nov 13 19:05:27 2008 (r184935) @@ -17,7 +17,8 @@ SRCS= global.c slc.c state.c sys_term.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