Path: utzoo!mnetor!uunet!vsi!friedl From: friedl@vsi.UUCP (Stephen J. Friedl) Newsgroups: comp.unix.wizards Subject: Re: Writing to A NON-Existing File in "C" Message-ID: <574@vsi.UUCP> Date: 20 Apr 88 15:40:19 GMT References: <9654@jplgodo.UUCP> <14020030@hpisod2.HP.COM> Organization: V-Systems, Inc. -- Santa Ana, CA Lines: 22 Summary: *PLEASE* don't use access(2) In article <14020030@hpisod2.HP.COM>, decot@hpisod2.HP.COM (Dave Decot) writes: > Uh...I think a file's existence is independent of your user-id. > > It's perfectly acceptable to use access(2) the F_OK (0) value of amode > it to determine whether files exist. Such calls succeed exactly when > calls to stat(2) succeed. Not quite -- parent directory modes will get in the way. In the case where the real uid has no permission in a parent directory component of a file but but the effective uid does, stat(2) succeeds and access(2) fails. So, access("/tmp/secret.dir/open.file", 0); and stat("/tmp/secret.dir/open.file", &stbuf); are not guaranteed to return the same values if /tmp/secret.dir is available to the set-user-id but not to me. -- Steve Friedl V-Systems, Inc. Resident access(2) basher friedl@vsi.com {backbones}!vsi.com!friedl attmail!vsi!friedl