Bugzilla Bug 276587: use stat to implement _MD_access because access is
authorwtchang%redhat.com
Wed, 12 Jan 2005 01:43:01 +0000
changeset 3243 fb9a0f04c6c41992c5ff675e2659f9614fa6d973
parent 3238 9bcbc1c1da3d07ac2e8caecb48a73e7e8a4719e9
child 3246 42c3ea8ff3a2da329eba21018f30da7afec2a853
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
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;
 }