Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!rutgers!sri-spam!mordor!lll-tis!ptsfa!hoptoad!academ!killer!jfh From: jfh@killer.UUCP (John Haugh) Newsgroups: comp.unix.questions Subject: Re: access(2) question Message-ID: <1027@killer.UUCP> Date: Mon, 22-Jun-87 11:57:02 EDT Article-I.D.: killer.1027 Posted: Mon Jun 22 11:57:02 1987 Date-Received: Sat, 4-Jul-87 22:27:40 EDT References: <530@applix.UUCP> <1341@xanth.UUCP> Organization: The Unix(tm) Connection, Dallas, Texas Lines: 33 Keywords: access permissions Summary: But you can't open for execute ... In article <1341@xanth.UUCP>, john@xanth.UUCP (John Owens) writes: > In article <530@applix.UUCP>, mark@applix.UUCP (Mark Fox) writes: > > Does anybody know why access checks file accessibility using the real [ug]id > > in place of the effective [ug]id? It seems to me that access should agree > > with open(2) as far as whether a program has write or read access to a file. > > Inside a set-uid program that assumption obviously doesn't work while > > uid != euid. > Well, the reason that access was added was to make it possible for a > set[ug]id program to be able to discern whether or not the real user > running it would have access to a certain file. Access() lets the user specify the type of access they plan on requesting, and then says wether the user himself would be allowed, regardles of setuid of setgid privileges. > > Is there a better way of implementing eaccess than using open/close, assuming > > I don't have the file already opened? > > Not really. It doesn't even change the access or update times until > you do a read or write, respectively, so as long as you don't open > O_TRUNC or O_CREAT, you'll be ok. Yes, there is. You only need use getuid(), geteuid(), stat() in order to find out if you can access a file. You only need look at st_mode to determine if the file is accessible. Should be fairly simple to write, just three if-then-else's aught to do it. - John. Disclaimer: No disclaimer. Whatcha gonna do, sue me? "It's never too late to have a happy childhood"