This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * Copyright (c) Xerox Corporation, Codendi Team, 2001-2009. All rights reserved |
||
4 | * Copyright (c) Enalean, 2014. All Rights Reserved. |
||
5 | * |
||
6 | * This file is a part of Tuleap. |
||
7 | * |
||
8 | * Tuleap is free software; you can redistribute it and/or modify |
||
9 | * it under the terms of the GNU General Public License as published by |
||
10 | * the Free Software Foundation; either version 2 of the License, or |
||
11 | * (at your option) any later version. |
||
12 | * |
||
13 | * Tuleap is distributed in the hope that it will be useful, |
||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
16 | * GNU General Public License for more details. |
||
17 | * |
||
18 | * You should have received a copy of the GNU General Public License |
||
19 | * along with Tuleap. If not, see <http://www.gnu.org/licenses/ |
||
20 | */ |
||
21 | |||
22 | /** |
||
23 | * Description of GitDriverclass |
||
24 | * @TODO Create Class exception to thro GIT messages |
||
25 | * @TODO Make this driver compliant with Apache ?? |
||
26 | * @TODO Make sure directories tree to manage forks and repo is a good choice |
||
27 | * @author gstorchi |
||
28 | */ |
||
29 | $DIR = dirname(__FILE__); |
||
30 | require_once($DIR.'/../DVCS/DVCSDriver.class.php'); |
||
31 | |||
32 | class GitDriver implements DVCSDriver { |
||
33 | |||
34 | public function __construct() { |
||
35 | } |
||
36 | |||
37 | protected function execGitAction($cmd, $action_name) { |
||
38 | $out = array(); |
||
39 | $ret = -1; |
||
40 | exec($cmd,$out,$ret); |
||
41 | if ($ret !== 0) { |
||
42 | throw new GitDriverErrorException('Git '.$action_name.' failed on '.$ret.' '.$cmd.PHP_EOL.implode(PHP_EOL, $out)); |
||
43 | } |
||
44 | |||
45 | return implode(PHP_EOL, $out); |
||
46 | } |
||
47 | |||
48 | private function checkFileExist($file) { |
||
49 | if ( !file_exists($file) ) { |
||
50 | throw new GitDriverSourceNotFoundException($file); |
||
51 | } |
||
52 | } |
||
53 | |||
54 | /** |
||
55 | * Make a clone of a source repository |
||
56 | * @param <String> $source source directory |
||
0 ignored issues
–
show
|
|||
57 | * @param <String> $destination destination directory |
||
0 ignored issues
–
show
The doc-type
<String> could not be parsed: Unknown type name "<" at position 0. (view supported doc-types)
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types. ![]() |
|||
58 | * @param <String> $option String of options. |
||
0 ignored issues
–
show
The doc-type
<String> could not be parsed: Unknown type name "<" at position 0. (view supported doc-types)
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types. ![]() |
|||
59 | * @return <boolean> |
||
0 ignored issues
–
show
The doc-type
<boolean> could not be parsed: Unknown type name "<" at position 0. (view supported doc-types)
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types. ![]() |
|||
60 | */ |
||
61 | private function cloneRepo($source, $destination, $option) { |
||
62 | $this->checkFileExist($source); |
||
63 | |||
64 | //WARNING : never use --shared/--reference options |
||
65 | $cmd = 'git clone '. $option .' --local --no-hardlinks '.escapeshellarg($source).' '.escapeshellarg($destination).' 2>&1'; |
||
66 | |||
67 | return $this->execGitAction($cmd, "clone"); |
||
68 | } |
||
69 | |||
70 | public function fork($source, $destination) { |
||
71 | $this->checkFileExist($source); |
||
72 | |||
73 | $this->cloneRepo($source, $destination, '--bare'); |
||
74 | |||
75 | return $this->setUpFreshRepository($destination); |
||
76 | } |
||
77 | |||
78 | public function cloneAtSpecifiqBranch($source, $destination, $branch) { |
||
79 | $this->checkFileExist($source); |
||
80 | |||
81 | return $this->cloneRepo($source, $destination, '--branch '.$branch); |
||
82 | } |
||
83 | |||
84 | public function changeGitUserInfo($repositoryPath, $email, $name) { |
||
85 | $this->checkFileExist($repositoryPath); |
||
86 | $cmdEmail = 'cd '. escapeshellarg($repositoryPath).' && git config --local user.email '.escapeshellarg($email).' 2>&1'; |
||
87 | $cmdName = 'cd '.escapeshellarg($repositoryPath).' && git config --local user.name '.escapeshellarg($name).' 2>&1'; |
||
88 | |||
89 | return $this->execGitAction($cmdEmail, 'change user email').' '.$this->execGitAction($cmdName, 'change user name'); |
||
90 | } |
||
91 | |||
92 | public function add($repositoryPath, $filePathFromRepository) { |
||
93 | $this->checkFileExist($repositoryPath); |
||
94 | $cmd = 'cd '.escapeshellarg($repositoryPath).' && git add '.escapeshellarg($filePathFromRepository).' 2>&1'; |
||
95 | |||
96 | return $this->execGitAction($cmd, 'add'); |
||
97 | } |
||
98 | |||
99 | public function commit($repositoryPath, $message) { |
||
100 | $this->checkFileExist($repositoryPath); |
||
101 | $cmd = 'cd '.escapeshellarg($repositoryPath).' && git commit --allow-empty -m '.escapeshellarg($message).' 2>&1'; |
||
102 | |||
103 | return $this->execGitAction($cmd, 'commit'); |
||
104 | } |
||
105 | |||
106 | public function mergeAndPush($repositoryPath, $bareURL) { |
||
107 | $this->checkFileExist($repositoryPath); |
||
108 | $cmd = 'cd '.escapeshellarg($repositoryPath).' && git pull --quiet --rebase && git push '. $bareURL .' 2>&1'; |
||
109 | |||
110 | return $this->execGitAction($cmd, 'merge and push'); |
||
111 | } |
||
112 | |||
113 | public function getInformationsAboutFile($repositoryPath, $filePathFromRepository) { |
||
114 | $this->checkFileExist($repositoryPath); |
||
115 | $cmd = 'cd '.escapeshellarg($repositoryPath).' && git ls-files --stage '.escapeshellarg($filePathFromRepository).' 2>&1'; |
||
116 | |||
117 | return $this->execGitAction($cmd, 'get informations'); |
||
118 | } |
||
119 | |||
120 | public function removeRepository($repositoryPath) { |
||
121 | $this->checkFileExist($repositoryPath); |
||
122 | $cmd = 'rm --recursive --dir --force '.escapeshellarg($repositoryPath).' 2>&1'; |
||
123 | |||
124 | return $this->execGitAction($cmd, 'rm'); |
||
125 | } |
||
126 | |||
127 | public function getGitVersion() { |
||
128 | $cmd = 'git --version'; |
||
129 | $cmd_result = $this->execGitAction($cmd, 'version'); |
||
130 | $version = split(" ", $cmd_result); |
||
131 | |||
132 | return $version[2]; |
||
133 | } |
||
134 | |||
135 | /** |
||
136 | * Initialize a repository |
||
137 | * @param Boolean $bare is a bare a repository |
||
138 | * @return Boolean |
||
139 | */ |
||
140 | public function init($bare=false) { |
||
141 | if ( $bare === false ) { |
||
142 | $cmd = 'git init'; |
||
143 | $out = array(); |
||
144 | $ret = -1; |
||
145 | exec($cmd, $out, $ret); |
||
146 | if ($ret !== 0) { |
||
147 | throw new GitDriverErrorException('Git init failed on '.$cmd.PHP_EOL.implode(PHP_EOL, $out)); |
||
148 | } |
||
149 | return true; |
||
150 | } |
||
151 | |||
152 | $cmd = 'git --bare init --shared=group 2>&1'; |
||
153 | $out = array(); |
||
154 | $ret = -1; |
||
155 | exec($cmd, $out, $ret); |
||
156 | if ( $ret !== 0 ) { |
||
157 | throw new GitDriverErrorException('Git init failed on '.$cmd.PHP_EOL.implode(PHP_EOL, $out)); |
||
158 | } |
||
159 | |||
160 | return $this->setUpFreshRepository(getcwd()); |
||
161 | } |
||
162 | |||
163 | /** |
||
164 | * Post creation/clone repository setup |
||
165 | * |
||
166 | * @param String $path Path to the repository |
||
167 | * |
||
168 | * @return Boolean |
||
169 | */ |
||
170 | protected function setUpFreshRepository($path) { |
||
171 | $cwd = getcwd(); |
||
172 | chdir($path); |
||
173 | |||
174 | $cmd = 'git update-server-info'; |
||
175 | $out = array(); |
||
176 | $ret = -1; |
||
177 | exec($cmd, $out, $ret); |
||
178 | chdir($cwd); |
||
179 | if ( $ret !== 0 ) { |
||
180 | throw new GitDriverErrorException('Git setup failed on '.$cmd.PHP_EOL.implode(PHP_EOL, $out)); |
||
181 | } |
||
182 | |||
183 | if (!$this->setDescription($path, 'Default description for this project'.PHP_EOL)) { |
||
184 | throw new GitDriverErrorException('Git setup failed on description update'); |
||
185 | } |
||
186 | |||
187 | return $this->setPermissions($path); |
||
188 | } |
||
189 | |||
190 | public function delete($path) { |
||
191 | if ( empty($path) || !is_writable($path) ) { |
||
192 | throw new GitDriverErrorException('Empty path or permission denied '.$path); |
||
193 | } |
||
194 | $rcode = 0; |
||
195 | $output = system('rm -fr '.escapeshellarg($path), $rcode); |
||
196 | if ( $rcode != 0 ) { |
||
0 ignored issues
–
show
|
|||
197 | throw new GitDriverErrorException('Unable to delete path '.$path); |
||
198 | } |
||
199 | return true; |
||
200 | } |
||
201 | |||
202 | public function activateHook($hookName, $repoPath, $uid=false, $gid=false) { |
||
203 | //newer version of git |
||
204 | $hook = $repoPath.'/hooks/'.$hookName; |
||
205 | if ( file_exists($hook.'.sample') ) { |
||
206 | //old git versions do not need this move |
||
207 | rename($hook.'.sample', $hook); |
||
208 | } |
||
209 | |||
210 | //older versions only requires +x for hook activation |
||
211 | if (!chmod($hook, 0755)) { |
||
212 | throw new GitDriverErrorException('Unable to make '.$hook.' executable'); |
||
213 | } |
||
214 | |||
215 | if ($uid !== false) { |
||
216 | if (!chown($hook, $uid)) { |
||
217 | throw new GitDriverErrorException('Unable to change '.$hook.' owner to '.$uid); |
||
218 | } |
||
219 | } |
||
220 | if ($gid !== false) { |
||
221 | if (!chgrp($hook, $gid)) { |
||
222 | throw new GitDriverErrorException('Unable to change '.$hook.' group to '.$gid); |
||
223 | } |
||
224 | } |
||
225 | return true; |
||
226 | } |
||
227 | |||
228 | public function masterExists($repoPath) { |
||
229 | if ( file_exists($repoPath.'/refs/heads/master') ) { |
||
230 | return true; |
||
231 | } |
||
232 | return false; |
||
233 | } |
||
234 | |||
235 | /** |
||
236 | * |
||
237 | * @param string $repoPath |
||
238 | * @return bool |
||
239 | */ |
||
240 | public function isRepositoryCreated($repoPath) { |
||
241 | return is_dir($repoPath.'/refs/heads'); |
||
242 | } |
||
243 | |||
244 | public function setDescription($repoPath, $description) { |
||
245 | if( ! file_put_contents($repoPath.'/description', $description) ) { |
||
246 | throw new GitDriverErrorException('Unable to set description'); |
||
247 | } |
||
248 | return true; |
||
249 | } |
||
250 | |||
251 | public function getDescription($repoPath) { |
||
252 | return file_get_contents($repoPath.'/description'); |
||
253 | } |
||
254 | |||
255 | /** |
||
256 | * Set one configuration key |
||
257 | * |
||
258 | * @param String $repoPath Path to the repository |
||
259 | * @param String $key Key to modify |
||
260 | * @param String $value Value to set |
||
261 | */ |
||
262 | public function setConfig($repoPath, $key, $value) { |
||
263 | if ($value === '') { |
||
264 | $value = "''"; |
||
265 | } else { |
||
266 | $value = escapeshellarg($value); |
||
267 | } |
||
268 | $configFile = $repoPath.'/config'; |
||
269 | $cmd = 'git config --file '.$configFile.' --replace-all '.escapeshellarg($key).' '.$value.' 2>&1'; |
||
270 | $ret = -1; |
||
271 | $out = array(); |
||
272 | exec($cmd, $out, $ret); |
||
273 | if ($ret !== 0) { |
||
274 | throw new GitDriverErrorException('Unable to set config for repository '.$repoPath.':'.PHP_EOL.implode(PHP_EOL, $out)); |
||
275 | } |
||
276 | } |
||
277 | |||
278 | /** |
||
279 | * Control who can access to a repository |
||
280 | * |
||
281 | * @param String $repoPath Path to the repository |
||
282 | * @param Integer $access Access level |
||
283 | * |
||
284 | * @return Boolean |
||
285 | */ |
||
286 | public function setRepositoryAccess($repoPath, $access) { |
||
287 | if ($access == GitRepository::PUBLIC_ACCESS) { |
||
288 | return chmod($repoPath, 042775); |
||
289 | } else { |
||
290 | return chmod($repoPath, 042770); |
||
291 | } |
||
292 | } |
||
293 | |||
294 | /** |
||
295 | * Ensure repository has the right permissions |
||
296 | * |
||
297 | * Pretty useless on repo creation (--shared option is ok for that) but |
||
298 | * Mandatory for clone as clone doesn't set the right permissions by default. |
||
299 | * |
||
300 | * @param String $path Path to the repository |
||
301 | * |
||
302 | * @return Boolean |
||
303 | */ |
||
304 | protected function setPermissions($path) { |
||
305 | $rcode = 0; |
||
306 | $cmd = 'find '.$path.' -type d | xargs chmod u+rwx,g+rwxs '.$path; |
||
307 | $output = system($cmd, $rcode); |
||
308 | if ( $rcode != 0 ) { |
||
0 ignored issues
–
show
|
|||
309 | throw new GitDriverErrorException($cmd.' -> '.$output); |
||
310 | } |
||
311 | |||
312 | if (!chmod($path.DIRECTORY_SEPARATOR.'HEAD', 0664)) { |
||
313 | throw new GitDriverErrorException('Unable to set permissions on HEAD'); |
||
314 | } |
||
315 | return true; |
||
316 | } |
||
317 | } |
||
318 | |||
319 | ?> |
||
320 |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.