From owner-freebsd-standards Fri Dec 27 23: 9:21 2002 Delivered-To: freebsd-standards@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 8B95337B401 for ; Fri, 27 Dec 2002 23:09:19 -0800 (PST) Received: from ncsmtp02.ogw.rr.com (ncsmtp02.ogw.rr.com [24.93.67.83]) by mx1.FreeBSD.org (Postfix) with ESMTP id DA3B443E4A for ; Fri, 27 Dec 2002 23:09:18 -0800 (PST) (envelope-from ryany@pobox.com) Received: from mail8.nc.rr.com (fe8 [24.93.67.55]) by ncsmtp02.ogw.rr.com (8.12.5/8.12.2) with ESMTP id gBS78Yup020818 for ; Sat, 28 Dec 2002 02:08:34 -0500 (EST) Received: from cheshire.mydomain.dom ([24.25.23.20]) by mail8.nc.rr.com with Microsoft SMTPSVC(5.5.1877.757.75); Sat, 28 Dec 2002 02:08:08 -0500 Content-Type: text/plain; charset="us-ascii" From: Ryan Younce To: freebsd-standards@freebsd.org Subject: submission: grantpt(), posix_openpt(), ptsname(), unlockpt() Date: Sat, 28 Dec 2002 02:19:11 -0500 User-Agent: KMail/1.4.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-Id: <200212280219.12803.ryany@pobox.com> Sender: owner-freebsd-standards@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG The first go at the PTY functions in 1003.1-2001 (grantpt(), posix_openpt(), ptsname(), and unlockpt()) can be found at http://www.tribug.org/~ryan/grantpt.tar.gz LAYOUT grantpt/patches contains patches to: src/include/stdlib.h src/lib/libc/stdlib/Makefile.inc grantpt/new contains new files: src/lib/libc/stdlib/grantpt.c src/lib/libc/stdlib/grantpt.3 src/libexec/pt_chown/Makefile src/libexec/pt_chown/pt_chown.c NOTES POSIX states grantpt() is to do the following to the slave pseudo-terminal device: * set ownership to the real user ID of the calling process * set the group to an unspecified group ID (in this implementation, it sets it to group "tty") * set permissions to S_IWUSR | S_IRUSR | S_IWGRP The only provision granted is that if the slave cannot be accessed, grantpt() fail with EACCES. Solaris and Digital Unix both rely on a helper program (in Solaris this is /usr/libexec/pt_chown) that is setuid root to actually set the user ID and the group ID of the slave device. From this perspective, I decided to also write a pt_chown program that also does this. It is rather restrictive in its operation, operating only upon its standard input file descriptor only if it is a master PTY device (therefore, the device must be open). Details behind this can be found in pt_chown.c. ADDITIONAL pt_chown.c relies on ptsname(), which is introduced in grantpt.c. If pt_chown is not committed, grantpt() will likely usually fail with EACCES. grantpt() does try to do the chown()/chmod() manually if the execution of pt_chown fails, so it's pretty much unpredictable whether or not a given call to grantpt() for a given master descriptor will succeed or not. It would succeed, for example, if the ownership of the slave was already set to the calling process, or if the calling process was root. I have tested these functions, along with pt_chown, on my system and have not run into any problems. I would greatly appreciate any comments or suggestions. Ryan Younce ryany@pobox.com To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-standards" in the body of the message