Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 28 Dec 2002 02:19:11 -0500
From:      Ryan Younce <ryany@pobox.com>
To:        freebsd-standards@freebsd.org
Subject:   submission: grantpt(), posix_openpt(), ptsname(), unlockpt()
Message-ID:  <200212280219.12803.ryany@pobox.com>

next in thread | raw e-mail | index | archive | help
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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200212280219.12803.ryany>