/** * @group bug58072 */ public function testLockConfig() { $fileModContents = <<<EOQ <?PHP \t\$GLOBALS['sugar_config']['moduleInstaller']['test'] = true; \t\$manifest = array(); \t\$installdefs = array(); ?> EOQ; file_put_contents($this->fileLoc, $fileModContents); $ms = new MockModuleScanner(); $ms->config['test'] = false; $ms->lockConfig(); MSLoadManifest($this->fileLoc); $errors = $ms->checkConfig($this->fileLoc); $this->assertTrue(!empty($errors), "Not detected config change"); $this->assertFalse($ms->config['test'], "config was changed"); }
/** *This function will scan the Manifest for disabled actions specified in $GLOBALS['sugar_config']['moduleInstaller']['disableActions'] *if $GLOBALS['sugar_config']['moduleInstaller']['disableRestrictedCopy'] is set to false or not set it will call on scanCopy to ensure that it is not overriding files */ public function scanManifest($manifestPath) { $issues = array(); if (!file_exists($manifestPath)) { $this->issues['manifest'][$manifestPath] = translate('ML_NO_MANIFEST'); return $issues; } $fileIssues = $this->scanFile($manifestPath); //if the manifest contains malicious code do not open it if (!empty($fileIssues)) { return $fileIssues; } $this->lockConfig(); list($manifest, $installdefs) = MSLoadManifest($manifestPath); $fileIssues = $this->checkConfig($manifestPath); if (!empty($fileIssues)) { return $fileIssues; } //scan for disabled actions if (isset($this->config['disableActions'])) { foreach ($this->config['disableActions'] as $action) { if (isset($installdefs[$this->manifestMap[$action]])) { $issues[] = translate('ML_INVALID_ACTION_IN_MANIFEST') . $this->manifestMap[$action]; } } } // now lets scan for files that will override our files if (empty($this->config['disableRestrictedCopy']) && isset($installdefs['copy'])) { foreach ($installdefs['copy'] as $copy) { $from = $this->normalizePath($copy['from']); if ($from === false) { $this->issues['copy'][$copy['from']] = translate('ML_PATH_MAY_NOT_CONTAIN') . ' ".." -' . $copy['from']; continue; } $from = str_replace('<basepath>', $this->pathToModule, $from); $to = $this->normalizePath($copy['to']); if ($to === false) { $this->issues['copy'][$copy['to']] = translate('ML_PATH_MAY_NOT_CONTAIN') . ' ".." -' . $copy['to']; continue; } if ($to === '') { $to = "."; } $this->scanCopy($from, $to); } } if (!empty($issues)) { $this->issues['manifest'][$manifestPath] = $issues; } }
} } } if ($perform) { $manifest_file = extractManifest($tempFile); if (is_file($manifest_file)) { //SCAN THE MANIFEST FILE TO MAKE SURE NO COPIES OR ANYTHING ARE HAPPENING IN IT $ms = new ModuleScanner(); $ms->lockConfig(); $fileIssues = $ms->scanFile($manifest_file); if (!empty($fileIssues)) { echo '<h2>' . $mod_strings['ML_MANIFEST_ISSUE'] . '</h2><br>'; $ms->displayIssues(); die; } list($manifest, $installdefs) = MSLoadManifest($manifest_file); if ($ms->checkConfig($manifest_file)) { echo '<h2>' . $mod_strings['ML_MANIFEST_ISSUE'] . '</h2><br>'; $ms->displayIssues(); die; } validate_manifest($manifest); $upgrade_zip_type = $manifest['type']; // exclude the bad permutations if ($view == "module") { if ($upgrade_zip_type != "module" && $upgrade_zip_type != "theme" && $upgrade_zip_type != "langpack") { unlinkTempFiles(); die($mod_strings['ERR_UW_NOT_ACCEPTIBLE_TYPE']); } } elseif ($view == "default") { if ($upgrade_zip_type != "patch") {