Esempio n. 1
0
 function _validateFilelist($list = false, $allowignore = false, $dirs = '')
 {
     $iscontents = false;
     if (!$list) {
         $iscontents = true;
         $list = $this->_packageInfo['contents'];
         if (isset($this->_packageInfo['bundle'])) {
             return $this->_validateBundle($list);
         }
     }
     if ($allowignore) {
         $struc = array('*install->name->as', '*ignore->name');
     } else {
         $struc = array('*dir->name->?baseinstalldir', '*file->name->role->?baseinstalldir->?md5sum');
         // do a quick test for better error message
         if (isset($list['dir']) && isset($list['file'])) {
             $first = false;
             foreach ($list as $key => $tag) {
                 if ($key == 'attribs') {
                     continue;
                 }
                 $first = $key;
                 break;
             }
             if ($first == 'file') {
                 $this->_dirMustBeFirst($dirs);
             }
         }
     }
     if (!isset($list['attribs']) || !isset($list['attribs']['name'])) {
         $unknown = $allowignore ? '<filelist>' : '<dir name="*unknown*">';
         $dirname = $iscontents ? '<contents>' : $unknown;
     } else {
         $dirname = '<dir name="' . $list['attribs']['name'] . '">';
     }
     $res = $this->_stupidSchemaValidate($struc, $list, $dirname);
     if ($allowignore && $res) {
         $this->_pf->getFilelist();
         $fcontents = $this->_pf->getContents();
         $filelist = array();
         if (!isset($fcontents['dir']['file'][0])) {
             $fcontents['dir']['file'] = array($fcontents['dir']['file']);
         }
         foreach ($fcontents['dir']['file'] as $file) {
             $filelist[$file['attribs']['name']] = true;
         }
         if (isset($list['install'])) {
             if (!isset($list['install'][0])) {
                 $list['install'] = array($list['install']);
             }
             foreach ($list['install'] as $file) {
                 if (!isset($filelist[$file['attribs']['name']])) {
                     $this->_notInContents($file['attribs']['name'], 'install');
                 }
             }
         }
         if (isset($list['ignore'])) {
             if (!isset($list['ignore'][0])) {
                 $list['ignore'] = array($list['ignore']);
             }
             foreach ($list['ignore'] as $file) {
                 if (!isset($filelist[$file['attribs']['name']])) {
                     $this->_notInContents($file['attribs']['name'], 'ignore');
                 }
             }
         }
     }
     if (!$allowignore && isset($list['file'])) {
         if (!isset($list['file'][0])) {
             // single file
             $list['file'] = array($list['file']);
         }
         foreach ($list['file'] as $i => $file) {
             if (isset($file['attribs']) && isset($file['attribs']['role'])) {
                 if (!$this->_validateRole($file['attribs']['role'])) {
                     if (isset($this->_packageInfo['usesrole'])) {
                         $roles = $this->_packageInfo['usesrole'];
                         if (!isset($roles[0])) {
                             $roles = array($roles);
                         }
                         foreach ($roles as $role) {
                             if ($role['role'] = $file['attribs']['role']) {
                                 $msg = 'This package contains role "%role%" and requires ' . 'package "%package%" to be used';
                                 if (isset($role['uri'])) {
                                     $params = array('role' => $role['role'], 'package' => $role['uri']);
                                 } else {
                                     $params = array('role' => $role['role'], 'package' => $this->_pf->_registry->parsedPackageNameToString(array('package' => $role['package'], 'channel' => $role['channel']), true));
                                 }
                                 $this->_stack->push('_mustInstallRole', 'error', $params, $msg);
                             }
                         }
                     }
                     $this->_invalidFileRole($file['attribs']['name'], $dirname, $file['attribs']['role']);
                 }
             }
             if (!isset($file['attribs'])) {
                 continue;
             }
             $save = $file['attribs'];
             if ($dirs) {
                 $save['name'] = $dirs . '/' . $save['name'];
             }
             unset($file['attribs']);
             if (count($file) && $this->_curState != PEAR_VALIDATE_DOWNLOADING) {
                 // has tasks
                 foreach ($file as $task => $value) {
                     if ($tagClass = $this->_pf->getTask($task)) {
                         if (!is_array($value) || !isset($value[0])) {
                             $value = array($value);
                         }
                         foreach ($value as $v) {
                             $ret = call_user_func(array($tagClass, 'validateXml'), $this->_pf, $v, $this->_pf->_config, $save);
                             if (is_array($ret)) {
                                 $this->_invalidTask($task, $ret, @$save['name']);
                             }
                         }
                     } else {
                         if (isset($this->_packageInfo['usestask'])) {
                             $roles = $this->_packageInfo['usestask'];
                             if (!isset($roles[0])) {
                                 $roles = array($roles);
                             }
                             foreach ($roles as $role) {
                                 if ($role['task'] = $task) {
                                     $msg = 'This package contains task "%task%" and requires ' . 'package "%package%" to be used';
                                     if (isset($role['uri'])) {
                                         $params = array('task' => $role['task'], 'package' => $role['uri']);
                                     } else {
                                         $params = array('task' => $role['task'], 'package' => $this->_pf->_registry->parsedPackageNameToString(array('package' => $role['package'], 'channel' => $role['channel']), true));
                                     }
                                     $this->_stack->push('_mustInstallTask', 'error', $params, $msg);
                                 }
                             }
                         }
                         $this->_unknownTask($task, $save['name']);
                     }
                 }
             }
         }
     }
     if (isset($list['ignore'])) {
         if (!$allowignore) {
             $this->_ignoreNotAllowed('ignore');
         }
     }
     if (isset($list['install'])) {
         if (!$allowignore) {
             $this->_ignoreNotAllowed('install');
         }
     }
     if (isset($list['file'])) {
         if ($allowignore) {
             $this->_fileNotAllowed('file');
         }
     }
     if (isset($list['dir'])) {
         if ($allowignore) {
             $this->_fileNotAllowed('dir');
         } else {
             if (!isset($list['dir'][0])) {
                 $list['dir'] = array($list['dir']);
             }
             foreach ($list['dir'] as $dir) {
                 if (isset($dir['attribs']) && isset($dir['attribs']['name'])) {
                     if ($dir['attribs']['name'] == '/' || !isset($this->_packageInfo['contents']['dir']['dir'])) {
                         // always use nothing if the filelist has already been flattened
                         $newdirs = '';
                     } elseif ($dirs == '') {
                         $newdirs = $dir['attribs']['name'];
                     } else {
                         $newdirs = $dirs . '/' . $dir['attribs']['name'];
                     }
                 } else {
                     $newdirs = $dirs;
                 }
                 $this->_validateFilelist($dir, $allowignore, $newdirs);
             }
         }
     }
 }
Esempio n. 2
0
 function _validateFilelist($list = false, $allowignore = false, $dirs = '')
 {
     $iscontents = false;
     if (!$list) {
         $iscontents = true;
         $list = $this->_packageInfo['contents'];
         if (isset($this->_packageInfo['bundle'])) {
             return $this->_validateBundle($list);
         }
     }
     if ($allowignore) {
         $struc = array('*install->name->as', '*ignore->name');
     } else {
         $struc = array('*dir->name->?baseinstalldir', '*file->name->role->?baseinstalldir->?md5sum');
         if (isset($list['dir']) && isset($list['file'])) {
             // stave off validation errors without requiring a set order.
             $_old = $list;
             if (isset($list['attribs'])) {
                 $list = array('attribs' => $_old['attribs']);
             }
             $list['dir'] = $_old['dir'];
             $list['file'] = $_old['file'];
         }
     }
     if (!isset($list['attribs']) || !isset($list['attribs']['name'])) {
         $unknown = $allowignore ? '<filelist>' : '<dir name="*unknown*">';
         $dirname = $iscontents ? '<contents>' : $unknown;
     } else {
         $dirname = '<dir name="' . $list['attribs']['name'] . '">';
         if (preg_match('~/\\.\\.?(/|\\z)|^\\.\\.?/~', str_replace('\\', '/', $list['attribs']['name']))) {
             // file contains .. parent directory or . cur directory
             $this->_invalidDirName($list['attribs']['name']);
         }
     }
     $res = $this->_stupidSchemaValidate($struc, $list, $dirname);
     if ($allowignore && $res) {
         $ignored_or_installed = array();
         $this->_pf->getFilelist();
         $fcontents = $this->_pf->getContents();
         $filelist = array();
         if (!isset($fcontents['dir']['file'][0])) {
             $fcontents['dir']['file'] = array($fcontents['dir']['file']);
         }
         foreach ($fcontents['dir']['file'] as $file) {
             $filelist[$file['attribs']['name']] = true;
         }
         if (isset($list['install'])) {
             if (!isset($list['install'][0])) {
                 $list['install'] = array($list['install']);
             }
             foreach ($list['install'] as $file) {
                 if (!isset($filelist[$file['attribs']['name']])) {
                     $this->_notInContents($file['attribs']['name'], 'install');
                     continue;
                 }
                 if (array_key_exists($file['attribs']['name'], $ignored_or_installed)) {
                     $this->_multipleInstallAs($file['attribs']['name']);
                 }
                 if (!isset($ignored_or_installed[$file['attribs']['name']])) {
                     $ignored_or_installed[$file['attribs']['name']] = array();
                 }
                 $ignored_or_installed[$file['attribs']['name']][] = 1;
                 if (preg_match('~/\\.\\.?(/|\\z)|^\\.\\.?/~', str_replace('\\', '/', $file['attribs']['as']))) {
                     // file contains .. parent directory or . cur directory references
                     $this->_invalidFileInstallAs($file['attribs']['name'], $file['attribs']['as']);
                 }
             }
         }
         if (isset($list['ignore'])) {
             if (!isset($list['ignore'][0])) {
                 $list['ignore'] = array($list['ignore']);
             }
             foreach ($list['ignore'] as $file) {
                 if (!isset($filelist[$file['attribs']['name']])) {
                     $this->_notInContents($file['attribs']['name'], 'ignore');
                     continue;
                 }
                 if (array_key_exists($file['attribs']['name'], $ignored_or_installed)) {
                     $this->_ignoreAndInstallAs($file['attribs']['name']);
                 }
             }
         }
     }
     if (!$allowignore && isset($list['file'])) {
         if (is_string($list['file'])) {
             $this->_oldStyleFileNotAllowed();
             return false;
         }
         if (!isset($list['file'][0])) {
             // single file
             $list['file'] = array($list['file']);
         }
         foreach ($list['file'] as $i => $file) {
             if (isset($file['attribs']) && isset($file['attribs']['name'])) {
                 if ($file['attribs']['name'][0] == '.' && $file['attribs']['name'][1] == '/') {
                     // name is something like "./doc/whatever.txt"
                     $this->_invalidFileName($file['attribs']['name'], $dirname);
                 }
                 if (preg_match('~/\\.\\.?(/|\\z)|^\\.\\.?/~', str_replace('\\', '/', $file['attribs']['name']))) {
                     // file contains .. parent directory or . cur directory
                     $this->_invalidFileName($file['attribs']['name'], $dirname);
                 }
             }
             if (isset($file['attribs']) && isset($file['attribs']['role'])) {
                 if (!$this->_validateRole($file['attribs']['role'])) {
                     if (isset($this->_packageInfo['usesrole'])) {
                         $roles = $this->_packageInfo['usesrole'];
                         if (!isset($roles[0])) {
                             $roles = array($roles);
                         }
                         foreach ($roles as $role) {
                             if ($role['role'] = $file['attribs']['role']) {
                                 $msg = 'This package contains role "%role%" and requires ' . 'package "%package%" to be used';
                                 if (isset($role['uri'])) {
                                     $params = array('role' => $role['role'], 'package' => $role['uri']);
                                 } else {
                                     $params = array('role' => $role['role'], 'package' => $this->_pf->_registry->parsedPackageNameToString(array('package' => $role['package'], 'channel' => $role['channel']), true));
                                 }
                                 $this->_stack->push('_mustInstallRole', 'error', $params, $msg);
                             }
                         }
                     }
                     $this->_invalidFileRole($file['attribs']['name'], $dirname, $file['attribs']['role']);
                 }
             }
             if (!isset($file['attribs'])) {
                 continue;
             }
             $save = $file['attribs'];
             if ($dirs) {
                 $save['name'] = $dirs . '/' . $save['name'];
             }
             unset($file['attribs']);
             if (count($file) && $this->_curState != PEAR_VALIDATE_DOWNLOADING) {
                 // has tasks
                 foreach ($file as $task => $value) {
                     if ($tagClass = $this->_pf->getTask($task)) {
                         if (!is_array($value) || !isset($value[0])) {
                             $value = array($value);
                         }
                         foreach ($value as $v) {
                             $ret = call_user_func(array($tagClass, 'validateXml'), $this->_pf, $v, $this->_pf->_config, $save);
                             if (is_array($ret)) {
                                 $this->_invalidTask($task, $ret, isset($save['name']) ? $save['name'] : '');
                             }
                         }
                     } else {
                         if (isset($this->_packageInfo['usestask'])) {
                             $roles = $this->_packageInfo['usestask'];
                             if (!isset($roles[0])) {
                                 $roles = array($roles);
                             }
                             foreach ($roles as $role) {
                                 if ($role['task'] = $task) {
                                     $msg = 'This package contains task "%task%" and requires ' . 'package "%package%" to be used';
                                     if (isset($role['uri'])) {
                                         $params = array('task' => $role['task'], 'package' => $role['uri']);
                                     } else {
                                         $params = array('task' => $role['task'], 'package' => $this->_pf->_registry->parsedPackageNameToString(array('package' => $role['package'], 'channel' => $role['channel']), true));
                                     }
                                     $this->_stack->push('_mustInstallTask', 'error', $params, $msg);
                                 }
                             }
                         }
                         $this->_unknownTask($task, $save['name']);
                     }
                 }
             }
         }
     }
     if (isset($list['ignore'])) {
         if (!$allowignore) {
             $this->_ignoreNotAllowed('ignore');
         }
     }
     if (isset($list['install'])) {
         if (!$allowignore) {
             $this->_ignoreNotAllowed('install');
         }
     }
     if (isset($list['file'])) {
         if ($allowignore) {
             $this->_fileNotAllowed('file');
         }
     }
     if (isset($list['dir'])) {
         if ($allowignore) {
             $this->_fileNotAllowed('dir');
         } else {
             if (!isset($list['dir'][0])) {
                 $list['dir'] = array($list['dir']);
             }
             foreach ($list['dir'] as $dir) {
                 if (isset($dir['attribs']) && isset($dir['attribs']['name'])) {
                     if ($dir['attribs']['name'] == '/' || !isset($this->_packageInfo['contents']['dir']['dir'])) {
                         // always use nothing if the filelist has already been flattened
                         $newdirs = '';
                     } elseif ($dirs == '') {
                         $newdirs = $dir['attribs']['name'];
                     } else {
                         $newdirs = $dirs . '/' . $dir['attribs']['name'];
                     }
                 } else {
                     $newdirs = $dirs;
                 }
                 $this->_validateFilelist($dir, $allowignore, $newdirs);
             }
         }
     }
 }
Esempio n. 3
0
 function _validateFilelist($list = false, $allowignore = false, $dirs = '')
 {
     $iscontents = false;
     if (!$list) {
         $iscontents = true;
         $list = $this->_packageInfo['contents'];
         if (isset($this->_packageInfo['bundle'])) {
             return $this->_validateBundle($list);
         }
     }
     if ($allowignore) {
         $struc = array('*install->name->as', '*ignore->name');
     } else {
         $struc = array('*dir->name->?baseinstalldir', '*file->name->role->?baseinstalldir->?md5sum');
     }
     if (!isset($list['attribs']) || !isset($list['attribs']['name'])) {
         $unknown = $allowignore ? '<filelist>' : '<dir name="*unknown*">';
         $dirname = $iscontents ? '<contents>' : $unknown;
     } else {
         $dirname = '<dir name="' . $list['attribs']['name'] . '">';
     }
     $res = $this->_stupidSchemaValidate($struc, $list, $dirname);
     if ($allowignore && $res) {
         $this->_pf->getFilelist();
         $fcontents = $this->_pf->getContents();
         $filelist = array();
         if (!isset($fcontents['dir']['file'][0])) {
             $fcontents['dir']['file'] = array($fcontents['dir']['file']);
         }
         foreach ($fcontents['dir']['file'] as $file) {
             $filelist[$file['attribs']['name']] = true;
         }
         if (isset($list['install'])) {
             if (!isset($list['install'][0])) {
                 $list['install'] = array($list['install']);
             }
             foreach ($list['install'] as $file) {
                 if (!isset($filelist[$file['attribs']['name']])) {
                     $this->_notInContents($file['attribs']['name'], 'install');
                 }
             }
         }
         if (isset($list['ignore'])) {
             if (!isset($list['ignore'][0])) {
                 $list['ignore'] = array($list['ignore']);
             }
             foreach ($list['ignore'] as $file) {
                 if (!isset($filelist[$file['attribs']['name']])) {
                     $this->_notInContents($file['attribs']['name'], 'ignore');
                 }
             }
         }
     }
     if (!$allowignore && isset($list['file'])) {
         if (!isset($list['file'][0])) {
             // single file
             $list['file'] = array($list['file']);
         }
         foreach ($list['file'] as $i => $file) {
             if (isset($file['attribs']) && isset($file['attribs']['role'])) {
                 if (!$this->_validateRole($file['attribs']['role'])) {
                     $this->_invalidFileRole($file['attribs']['name'], $dirname, $file['attribs']['role']);
                 }
             }
             if (!isset($file['attribs'])) {
                 continue;
             }
             $save = $file['attribs'];
             if ($dirs) {
                 $save['name'] = $dirs . '/' . $save['name'];
             }
             unset($file['attribs']);
             if (count($file) && $this->_curState != PEAR_VALIDATE_DOWNLOADING) {
                 // has tasks
                 foreach ($file as $task => $value) {
                     if ($tagClass = $this->_pf->getTask($task)) {
                         if (!is_array($value) || !isset($value[0])) {
                             $value = array($value);
                         }
                         foreach ($value as $v) {
                             $ret = call_user_func(array($tagClass, 'validateXml'), $this->_pf, $v, $this->_pf->_config, $save);
                             if (is_array($ret)) {
                                 $this->_invalidTask($task, $ret, @$save['name']);
                             }
                         }
                     } else {
                         $this->_unknownTask($task, $save['name']);
                     }
                 }
             }
         }
     }
     if (isset($list['ignore'])) {
         if (!$allowignore) {
             $this->_ignoreNotAllowed('ignore');
         }
     }
     if (isset($list['install'])) {
         if (!$allowignore) {
             $this->_ignoreNotAllowed('install');
         }
     }
     if (isset($list['file'])) {
         if ($allowignore) {
             $this->_fileNotAllowed('file');
         }
     }
     if (isset($list['dir'])) {
         if ($allowignore) {
             $this->_fileNotAllowed('dir');
         } else {
             if (!isset($list['dir'][0])) {
                 $list['dir'] = array($list['dir']);
             }
             foreach ($list['dir'] as $dir) {
                 if (isset($dir['attribs']) && isset($dir['attribs']['name'])) {
                     if ($dir['attribs']['name'] == '/' || !isset($this->_packageInfo['contents']['dir']['dir'])) {
                         // always use nothing if the filelist has already been flattened
                         $newdirs = '';
                     } elseif ($dirs == '') {
                         $newdirs = $dir['attribs']['name'];
                     } else {
                         $newdirs = $dirs . '/' . $dir['attribs']['name'];
                     }
                 } else {
                     $newdirs = $dirs;
                 }
                 $this->_validateFilelist($dir, $allowignore, $newdirs);
             }
         }
     }
 }