Merge pull request #33545 from nextcloud/occ-as-root

make it possible to run occ as root
This commit is contained in:
Ferdinand Thiessen 2025-02-27 22:21:30 +01:00 committed by GitHub
commit 8f28fa232a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

32
occ
View file

@ -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';