Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10 5/3/83; site utcsrgv.UUCP Path: utzoo!utcsrgv!dave From: dave@utcsrgv.UUCP (Dave Sherman) Newsgroups: net.bugs,net.unix-wizards Subject: Re: Usefulness of access(2) - (nf) Message-ID: <2326@utcsrgv.UUCP> Date: Sun, 25-Sep-83 01:44:15 EDT Article-I.D.: utcsrgv.2326 Posted: Sun Sep 25 01:44:15 1983 Date-Received: Sun, 25-Sep-83 05:39:02 EDT References: <172@laidbak.UUCP> Organization: The Law Society of Upper Canada, Toronto Lines: 31 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