mirror of
https://github.com/nextcloud/server.git
synced 2026-02-18 18:28:50 -05:00
fix(occ): Make it possible to run as root
Signed-off-by: Frank Karlitschek <karlitschek@users.noreply.github.com> Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at> Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
This commit is contained in:
parent
001b12c482
commit
53c083ea2a
1 changed files with 27 additions and 5 deletions
32
occ
32
occ
|
|
@ -1,11 +1,33 @@
|
|||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2014 ownCloud, Inc.
|
||||
* SPDX-FileCopyrightText: 2014 Olivier Paroz
|
||||
* SPDX-FileCopyrightText: 2013 Thomas Müller <thomas.mueller@tmit.eu>
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
//$argv = $_SERVER['argv'];
|
||||
/**
|
||||
* Drop privileges when run as root
|
||||
*/
|
||||
function dropPrivileges(): void {
|
||||
if (posix_getuid() !== 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
$configPath = __DIR__ . '/config/config.php';
|
||||
$uid = fileowner($configPath);
|
||||
if ($uid === false) {
|
||||
return;
|
||||
}
|
||||
$info = posix_getpwuid($uid);
|
||||
if ($info === false) {
|
||||
return;
|
||||
}
|
||||
posix_setuid($uid);
|
||||
posix_setgid($info['gid']);
|
||||
}
|
||||
|
||||
dropPrivileges();
|
||||
require_once __DIR__ . '/console.php';
|
||||
|
|
|
|||
Loading…
Reference in a new issue