Skip to content

Commit 0768c99

Browse files
fixup! Update occ
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
1 parent 77bfa2e commit 0768c99

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

occ

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
#!/usr/bin/env php
22
<?php
3+
34
/**
45
* SPDX-FileCopyrightText: 2014 ownCloud, Inc.
56
* SPDX-FileCopyrightText: 2014 Olivier Paroz
67
* SPDX-FileCopyrightText: 2013 Thomas Müller <thomas.mueller@tmit.eu>
78
* SPDX-License-Identifier: AGPL-3.0-only
89
*/
910

10-
// make it possible to run as root
11-
if (posix_getuid() == 0){
11+
// Drop privileges when run as root
12+
if (posix_getuid() === 0){
13+
$configPath = __DIR__ . '/config/config.php';
14+
$fallbackUser = 'www-data';
15+
$guessedUser = match (file_exists($configPath)) {
16+
true => ($ownerUid = fileowner($configPath)) ? posix_getpwuid($ownerUid)['name'] : $fallbackUser,
17+
false => $fallbackUser,
18+
};
1219
$command = implode (' ', $argv);
13-
echo(shell_exec('sudo -u www-data '.$command));
20+
echo(shell_exec("sudo -u $guessedUser php -f " . $command));
1421
exit;
22+
} else {
23+
require_once __DIR__ . '/console.php';
1524
}
16-
17-
require_once __DIR__ . '/console.php';

0 commit comments

Comments
 (0)