Bugzilla Bug 276587: use stat to implement _MD_access because access is NSPRPUB_PRE_4_2_CLIENT_BRANCH
authorwtchang%redhat.com
Wed, 12 Jan 2005 01:47:32 +0000
branchNSPRPUB_PRE_4_2_CLIENT_BRANCH
changeset 3244 fd650ce6daa29e2012e1f12d16554b67c0f32f78
parent 3240 863632e76acfdb80cab9c1e98ca004468eb5f360
child 3245 7ecf3c036505d7aee1bcec59221342ecad1ea1b6
push idunknown
push userunknown
push dateunknown
bugs276587
Bugzilla Bug 276587: use stat to implement _MD_access because access is broken. The patch is contributed by tqh <thesuckiestemail@yahoo.se>. r=wtc Tag: NSPRPUB_PRE_4_2_CLIENT_BRANCH
pr/src/md/beos/bfile.c
--- a/pr/src/md/beos/bfile.c
+++ b/pr/src/md/beos/bfile.c
@@ -479,41 +479,48 @@ PRInt32
         PR_Unlock(_pr_rename_lock);
     return rv; 
 }
 
 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 = access(name, amode);
+
+	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;
+	}
 
 	if (rv < 0) {
 		err = _MD_ERRNO();
-		_PR_MD_MAP_ACCESS_ERROR(err);
+		_PR_MD_MAP_STAT_ERROR(err);
 	}
 
-done:
 	return(rv);
 }
 
 PRInt32
 _MD_stat (const char *name, struct stat *buf)
 {
     return PR_NOT_IMPLEMENTED_ERROR;
 }