question about getpass

dbj.rice%rand-relay at sri-unix.UUCP dbj.rice%rand-relay at sri-unix.UUCP
Mon Jun 13 13:12:09 AEST 1983


From:  Dave Johnson <dbj.rice at rand-relay>

        An easy way to make /dev/tty unopenable is for someone to open
        it exclusive mode.

WRONG!  You can't open /dev/tty "exclusive mode" (I assume you mean the
TIOCEXCL ioctl).  The device /dev/tty simply indirects to the specific tty
that is you control terminal (usually the one you are logged on to) and has
no struct tty of its own within the kernel.  If you TIOCEXCL /dev/tty, you
really end up setting the exclusive use bit on your own terminal, NOT on
/dev/tty itself.  This will not prevent some OTHER user from opening
/dev/tty.  It will only prevent you (or some other user or process) from
opening the specific terminal that is your control terminal.  The source for
the ioctl routine for /dev/tty from sys.c clears this question up exactly
(as looking at the source for the kernel does for so many other questions,
too; why do we have to read the kernel source rather than just putting it
all in the manual?).  This routine is called for an ioctl on /dev/tty and
just calls the ioctl routine for your control terminal, giving it the device
id for your control terminal rather than the one for /dev/tty itself.  This
routine then translates the device id to the address of the struct tty for
that terminal and sets the exclusive use bit there.

/*ARGSUSED*/
syioctl(dev, cmd, addr, flag)
caddr_t addr;
{

	if (u.u_procp->p_flag&SDETACH) {
		u.u_error = ENXIO;
		return;
	}
	(*cdevsw[major(u.u_ttyd)].d_ioctl)(u.u_ttyd, cmd, addr, flag);
}


                                        Dave Johnson
                                        Dept. of Math Science
                                        Rice University
                                        dbj.rice at Rand-Relay



More information about the Comp.unix.wizards mailing list