Subject: Re: standards/19209: test(1)'s -r, -w, and -x don't match POSIX for root (or 4.4BSD, or even V7)
To: NetBSD Bugs and PR posting List <netbsd-bugs@NetBSD.ORG>
From: David Laight <david@l8s.co.uk>
List: netbsd-bugs
Date: 11/30/2002 10:17:20
> > + 	euid = geteuid();
> > + 	if (euid == 0)
> 
> I don't think userspace ought to be checking for 'appropriate
> privileges' by checking uid == 0.  It is currently true for
> netbsd but isn't portably true.

It isn't true for NFS!

Additionally you have to use access() in order to detect
readonly file systems.

It is also possible that a volume (eg a CD) might be mounted
with global read permissions (useful if not supported at the
moment).  This wouldn't be covered by a simple check on the
mode bits.

So you definitely need to call access(),  whether it is
appropriate to return false when the access call succeeds
is another matter, but you can't return true if access would
fail.

FWIW if a shell wants to know the file permission bits
it can use $(stat -f '%p' file).

	David

-- 
David Laight: david@l8s.co.uk