cvs: pear-core /PEAR Registry.php
| From: | Greg Beaver | Date: | Sun, 20 Feb 2005 17:01:14 +0000 |
| Subject: | cvs: pear-core /PEAR Registry.php | ||
| Groups: | php.pear.cvs php.pear.core | ||
| Request: | Send a blank email to pear-cvs+get-29539@lists.php.net to get a copy of this message | ||
cellog Sun Feb 20 12:01:14 2005 EDT
Modified files:
/pear-core/PEAR Registry.php
Log:
add is_writeable() checks for all attempts to create dirs
or open files to write, so fatal errors are avoided
http://cvs.php.net/diff.php/pear-core/PEAR/Registry.php?r1=1.119&r2=1.120&ty=u
Index: pear-core/PEAR/Registry.php
diff -u pear-core/PEAR/Registry.php:1.119 pear-core/PEAR/Registry.php:1.120
--- pear-core/PEAR/Registry.php:1.119 Sun Feb 20 00:18:54 2005
+++ pear-core/PEAR/Registry.php Sun Feb 20 12:01:14 2005
@@ -18,7 +18,7 @@
// | |
// +----------------------------------------------------------------------+
//
-// $Id: Registry.php,v 1.119 2005/02/20 05:18:54 cellog Exp $
+// $Id: Registry.php,v 1.120 2005/02/20 17:01:14 cellog Exp $
/*
TODO:
@@ -148,6 +148,11 @@
$this->_config = false;
}
+ function hasWriteAccess()
+ {
+ return @is_writeable($this->statedir);
+ }
+
function setConfig(&$config)
{
$this->_config = &$config;
@@ -296,6 +301,9 @@
}
static $init = false;
if (!@is_dir($this->statedir)) {
+ if (!$this->hasWriteAccess()) {
+ return false;
+ }
if (!System::mkdir(array('-p', $this->statedir))) {
return $this->raiseError("could not create directory
'{$this->statedir}'");
}
@@ -349,6 +357,9 @@
$this->_initializeChannelDirs();
}
if (!@is_dir($channelDir)) {
+ if (!$this->hasWriteAccess()) {
+ return false;
+ }
if (!System::mkdir(array('-p', $channelDir))) {
return $this->raiseError("could not create directory '" .
$channelDir .
"'");
@@ -371,11 +382,17 @@
function _assertChannelDir()
{
if (!@is_dir($this->channelsdir)) {
+ if (!$this->hasWriteAccess()) {
+ return false;
+ }
if (!System::mkdir(array('-p', $this->channelsdir))) {
return $this->raiseError("could not create directory
'{$this->channelsdir}'");
}
}
if (!@is_dir($this->channelsdir . DIRECTORY_SEPARATOR . '.alias')) {
+ if (!$this->hasWriteAccess()) {
+ return false;
+ }
if (!System::mkdir(array('-p', $this->channelsdir . DIRECTORY_SEPARATOR .
'.alias'))) {
return $this->raiseError("could not create directory
'{$this->channelsdir}/.alias'");
}
@@ -513,7 +530,12 @@
function _openPackageFile($package, $mode, $channel = false)
{
- $this->_assertStateDir($channel);
+ if (!$this->_assertStateDir($channel)) {
+ return null;
+ }
+ if (!in_array($mode, array('r', 'rb')) &&
!$this->hasWriteAccess()) {
+ return null;
+ }
$file = $this->_packageFileName($package, $channel);
$fp = @fopen($file, $mode);
if (!$fp) {
@@ -535,7 +557,12 @@
function _openChannelFile($channel, $mode)
{
- $this->_assertChannelDir();
+ if (!$this->_assertChannelDir()) {
+ return null;
+ }
+ if (!in_array($mode, array('r', 'rb')) &&
!$this->hasWriteAccess()) {
+ return null;
+ }
$file = $this->_channelFileName($channel);
$fp = @fopen($file, $mode);
if (!$fp) {
@@ -600,6 +627,9 @@
}
}
$this->_assertStateDir();
+ if (!$this->hasWriteAccess()) {
+ return false;
+ }
$fp = @fopen($this->filemap, 'wb');
if (!$fp) {
return false;
@@ -775,6 +805,9 @@
$this->_getChannelFromAlias($channel->getAlias()) !=
$channel->getName()) {
$channel->setAlias($channel->getName());
}
+ if (!$this->hasWriteAccess()) {
+ return false;
+ }
$fp = @fopen($this->_getChannelAliasFileName($channel->getAlias()),
'w');
if (!$fp) {
return false;
@@ -782,6 +815,9 @@
fwrite($fp, $channel->getName());
fclose($fp);
}
+ if (!$this->hasWriteAccess()) {
+ return false;
+ }
$fp = @fopen($this->_channelFileName($channel->getName()), 'wb');
if (!$fp) {
return false;