Usefulness of access(2) - (nf)

Dave Sherman dave at utcsrgv.UUCP
Sun Sep 25 15:44:15 AEST 1983


Pardon me, but surely open(2) will do fine when you want to find out
whether the *effective* UID has permission to get to a file?!!!

I recently ran into a case where I wanted a setUID-root program,
which flips my phone line from originate to answer mode, to check
whether anyone (e.g., cu or uucico) has the line open with TIOCEXCL.
The driver allows root to stomp in on top of a TIOCEXCL. The suggested
access(2) using the real UID would have worked. But who needs a new
system call? I just did:

	if((pid=fork())==0)
	{
		setuid(1);
		if(open(line,1) < 0)
			exit(1);
		exit(0);
	}
	wait(&status);
	if(status)
	{
		/* do whatever you'd do if you couldn't open the line */
	}

Sure it's a little ugly, and requires a fork, but it's a heckuva lot
better than a new system call! (This is on v7 on an 11/23, by the way.)
[Of course, I have to fork since after the setuid(1) you can't setuid
back to 0 to do the work of changing the line status.]

Dave Sherman
-- 
 {cornell,decvax,ihnp4,linus,utzoo,uw-beaver}!utcsrgv!lsuc!dave



More information about the Comp.unix.wizards mailing list