From b2145f20603b0bfdb8728cd265a5d0d61240f1f2 Mon Sep 17 00:00:00 2001 From: Matt Cockayne Date: Tue, 11 Oct 2011 01:29:37 +0100 Subject: [PATCH 1/3] made self install much harder to use added module whitelist for self install added requirement for separate autoinstall/upgrade methods This now means that in order for self install to be possible you must define all three of the following manager options enable_self_installation manifest_dir self_install_whitelist --- library/Zend/Module/Manager.php | 9 +++++--- library/Zend/Module/ManagerOptions.php | 29 ++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/library/Zend/Module/Manager.php b/library/Zend/Module/Manager.php index 2f039805491..cb6625e3875 100644 --- a/library/Zend/Module/Manager.php +++ b/library/Zend/Module/Manager.php @@ -2,6 +2,8 @@ namespace Zend\Module; +use Zend\Service\Amazon\Authentication\V1; + use Traversable, Zend\Config\Config, Zend\Config\Writer\ArrayWriter, @@ -126,7 +128,8 @@ public function loadModule($moduleName) $this->addProvision($module); $this->addDependency($module); } - if ($this->getOptions()->getEnableSelfInstallation()) { + if ($this->getOptions()->getEnableSelfInstallation() && + in_array($this->getOptions()->getSelfInstallWhitelist(), $moduleName)) { $this->installModule($module); } $this->runModuleInit($module); @@ -155,7 +158,7 @@ public function installModule($module) $this->loadInstallationManifest(); foreach ($module->getProvides() as $moduleName => $data) { if (!isset($this->manifest->{$moduleName})) { // if doesnt exist in manifest - if (is_callable(array($module, 'install'))) { + if (is_callable(array($module, 'autoInstall'))) { if ($module->install()) { $this->manifest->{$moduleName} = $data; $this->manifest->{'_dirty'} = true; @@ -166,7 +169,7 @@ public function installModule($module) } elseif (isset($this->manifest->{$moduleName}) && // does exists in manifest version_compare($this->manifest->{$moduleName}->version, $data['version']) < 0 // and manifest version is less than current version ){ - if (is_callable(array($module, 'upgrade'))) { + if (is_callable(array($module, 'autoUpgrade'))) { if ($module->upgrade($this->manifest->{$moduleName}->version)) { $this->manifest->{$moduleName} = $data; $this->manifest->{'_dirty'} = true; diff --git a/library/Zend/Module/ManagerOptions.php b/library/Zend/Module/ManagerOptions.php index b27b378e327..aa139aa1117 100644 --- a/library/Zend/Module/ManagerOptions.php +++ b/library/Zend/Module/ManagerOptions.php @@ -31,6 +31,13 @@ class ManagerOptions * @var bool */ protected $enableSelfInstallation = false; + + /** + * array of modules that have been whitelisted to allow self installation + * + * @var array + */ + protected $selfInstallWhiteList = array(); /** * Check if the config cache is enabled @@ -153,6 +160,28 @@ public function setEnableSelfInstallation($bool) return $this; } + /** + * gets if self installation is enabled + * + * @return bool + */ + public function getSelfInstallWhitelist() + { + return $this->selfInstallWhitelist; + } + +/** + * set if self installation is enabled + * + * @param bool $bool + * @return Manager + */ + public function setSelfInstallWhitelist(array $list) + { + $this->selfInstallWhitelist = $list; + return $this; + } + /** * gets if self installation is enabled * From e17635c8cf4ad0baac5b5f1c6ee47f25c25f18f9 Mon Sep 17 00:00:00 2001 From: Matt Cockayne Date: Tue, 11 Oct 2011 01:39:51 +0100 Subject: [PATCH 2/3] corrected some logic errors in self install whitelist --- library/Zend/Module/Manager.php | 2 +- library/Zend/Module/ManagerOptions.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/library/Zend/Module/Manager.php b/library/Zend/Module/Manager.php index cb6625e3875..fe834286dd7 100644 --- a/library/Zend/Module/Manager.php +++ b/library/Zend/Module/Manager.php @@ -129,7 +129,7 @@ public function loadModule($moduleName) $this->addDependency($module); } if ($this->getOptions()->getEnableSelfInstallation() && - in_array($this->getOptions()->getSelfInstallWhitelist(), $moduleName)) { + in_array($moduleName,$this->getOptions()->getSelfInstallWhitelist()->toArray())) { $this->installModule($module); } $this->runModuleInit($module); diff --git a/library/Zend/Module/ManagerOptions.php b/library/Zend/Module/ManagerOptions.php index aa139aa1117..e192e944e40 100644 --- a/library/Zend/Module/ManagerOptions.php +++ b/library/Zend/Module/ManagerOptions.php @@ -169,14 +169,14 @@ public function getSelfInstallWhitelist() { return $this->selfInstallWhitelist; } - -/** + + /** * set if self installation is enabled * * @param bool $bool * @return Manager */ - public function setSelfInstallWhitelist(array $list) + public function setSelfInstallWhitelist($list) { $this->selfInstallWhitelist = $list; return $this; From 7ec062aceaca1737f8a603e43ae2798312a8867a Mon Sep 17 00:00:00 2001 From: Matt Cockayne Date: Fri, 14 Oct 2011 10:53:12 +0100 Subject: [PATCH 3/3] corrected return on module auto loader return false causing premature exit of foreach on class loading --- library/Zend/Loader/ModuleAutoloader.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/library/Zend/Loader/ModuleAutoloader.php b/library/Zend/Loader/ModuleAutoloader.php index 530933537dd..18682e3b25a 100644 --- a/library/Zend/Loader/ModuleAutoloader.php +++ b/library/Zend/Loader/ModuleAutoloader.php @@ -99,9 +99,6 @@ public function autoload($class) // Find executable phars $matches = glob($path . '.{' . implode($this->pharExtensions, ',') . '}', GLOB_BRACE); - if (count($matches) == 0) { - return false; - } foreach ($matches as $phar) { if ($classLoaded = $this->loadModuleFromPhar($phar, $class)) { return $classLoaded;