From 5416f9bd9eca079ab5185c641cf075c02de1b1d3 Mon Sep 17 00:00:00 2001 From: "wtchang%redhat.com" Date: Wed, 12 Jan 2005 01:47:32 +0000 Subject: Bugzilla Bug 276587: use stat to implement _MD_access because access is broken. The patch is contributed by tqh . r=wtc Tag: NSPRPUB_PRE_4_2_CLIENT_BRANCH --- pr/src/md/beos/bfile.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/pr/src/md/beos/bfile.c b/pr/src/md/beos/bfile.c index 19492a42..b67c97f1 100644 --- a/pr/src/md/beos/bfile.c +++ b/pr/src/md/beos/bfile.c @@ -484,31 +484,38 @@ PRInt32 _MD_access (const char *name, PRIntn how) { PRInt32 rv, err; -int amode; +int checkFlags; +struct stat buf; switch (how) { case PR_ACCESS_WRITE_OK: - amode = W_OK; + checkFlags = S_IWUSR | S_IWGRP | S_IWOTH; break; + case PR_ACCESS_READ_OK: - amode = R_OK; + checkFlags = S_IRUSR | S_IRGRP | S_IROTH; break; + case PR_ACCESS_EXISTS: - amode = F_OK; + /* we don't need to examine st_mode. */ break; + default: PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0); - rv = -1; - goto done; + return -1; + } + + rv = stat(name, &buf); + if (rv == 0 && how != PR_ACCESS_EXISTS && (!(buf.st_mode & checkFlags))) { + PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, 0); + return -1; } - rv = access(name, amode); if (rv < 0) { err = _MD_ERRNO(); - _PR_MD_MAP_ACCESS_ERROR(err); + _PR_MD_MAP_STAT_ERROR(err); } -done: return(rv); } -- cgit v1.2.1