-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33545 from nextcloud/occ-as-root
make it possible to run occ as root
- Loading branch information
Showing
1 changed file
with
27 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,11 +1,33 @@ | ||
#!/usr/bin/env php | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
/** | ||
* 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 | ||
* 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']); | ||
} | ||
|
||
//$argv = $_SERVER['argv']; | ||
dropPrivileges(); | ||
require_once __DIR__ . '/console.php'; |