Permalink
Browse files

Merge branch 'permission' of https://github.com/voda/vfsStream

  • Loading branch information...
2 parents 09c40dd + 96699af commit 4ea158c7a101e3db1b761da9db644b0231c7fdc7 @mikey179 committed May 9, 2012
@@ -249,12 +249,18 @@ public function stream_open($path, $mode, $options, $opened_path)
) {
return false;
}
-
+
if (self::TRUNCATE === $mode) {
$this->content->openWithTruncate();
} elseif (self::APPEND === $mode) {
$this->content->openForAppend();
} else {
+ if (!$this->content->isReadable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup())) {
+ if (($options & STREAM_REPORT_ERRORS) === STREAM_REPORT_ERRORS) {
+ trigger_error('Permission denied', E_USER_WARNING);
+ }
+ return false;
+ }
$this->content->open();
}
@@ -572,23 +578,25 @@ public function rename($path_from, $path_to)
trigger_error(' No such file or directory', E_USER_WARNING);
return false;
}
-
- $dstContent = clone $srcContent;
- $dstNames = $this->splitPath($dstRealPath);
- // Renaming the filename
- $dstContent->rename($dstNames['basename']);
- // Copying to the destination
+ $dstNames = $this->splitPath($dstRealPath);
$dstParentContent = $this->getContent($dstNames['dirname']);
if (null == $dstParentContent) {
trigger_error('No such file or directory', E_USER_WARNING);
return false;
}
-
+ if (!$dstParentContent->isWritable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup())) {
+ trigger_error('Permission denied', E_USER_WARNING);
+ return false;
+ }
if ($dstParentContent->getType() !== vfsStreamContent::TYPE_DIR) {
trigger_error('Target is not a directory', E_USER_WARNING);
return false;
}
+ $dstContent = clone $srcContent;
+ // Renaming the filename
+ $dstContent->rename($dstNames['basename']);
+ // Copying to the destination
$dstParentContent->addChild($dstContent);
// Removing the source
return $this->doUnlink($srcRealPath);
@@ -439,5 +439,32 @@ public function cannotOpenExistingNonwritableFileWithModeW()
$this->baz1->chmod(0400);
$this->assertFalse(@fopen($this->baz1URL, 'w'));
}
+
+ /**
+ * @test
+ */
+ public function cannotOpenNonReadableFileWithModeR()
+ {
+ $this->baz1->chmod(0);
+ $this->assertFalse(@fopen($this->baz1URL, 'r'));
+ }
+
+ /**
+ * @test
+ */
+ public function cannotRenameToNonWritableDir()
+ {
+ $this->bar->chmod(0);
+ $this->assertFalse(@rename($this->baz2URL, vfsStream::url('foo/bar/baz3')));
+ }
+
+ /**
+ * @test
+ */
+ public function cannotReadFileFromNonReadableDir()
+ {
+ $this->bar->chmod(0);
+ $this->assertFalse(@file_get_contents($this->baz1URL));
+ }
}
?>

0 comments on commit 4ea158c

Please sign in to comment.