-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Christoph Wurst <[email protected]>
- Loading branch information
1 parent
77bfa2e
commit 0768c99
Showing
1 changed file
with
12 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,24 @@ | ||
#!/usr/bin/env php | ||
<?php | ||
|
||
/** | ||
* SPDX-FileCopyrightText: 2014 ownCloud, Inc. | ||
* SPDX-FileCopyrightText: 2014 Olivier Paroz | ||
* SPDX-FileCopyrightText: 2013 Thomas Müller <[email protected]> | ||
* SPDX-License-Identifier: AGPL-3.0-only | ||
*/ | ||
|
||
// make it possible to run as root | ||
if (posix_getuid() == 0){ | ||
// Drop privileges when run as root | ||
if (posix_getuid() === 0){ | ||
$configPath = __DIR__ . '/config/config.php'; | ||
$fallbackUser = 'www-data'; | ||
$guessedUser = match (file_exists($configPath)) { | ||
true => ($ownerUid = fileowner($configPath)) ? posix_getpwuid($ownerUid)['name'] : $fallbackUser, | ||
false => $fallbackUser, | ||
}; | ||
$command = implode (' ', $argv); | ||
echo(shell_exec('sudo -u www-data '.$command)); | ||
echo(shell_exec("sudo -u $guessedUser php -f " . $command)); | ||
exit; | ||
} else { | ||
require_once __DIR__ . '/console.php'; | ||
} | ||
|
||
require_once __DIR__ . '/console.php'; |