0
0
Fork 0
mirror of https://github.com/nextcloud/server.git synced 2025-05-01 12:30:27 +00:00
nextcloud_server/occ
provokateurin 48a1997bc6 fix(occ): Suppress errors when checking config.php fileowner
Signed-off-by: provokateurin <kate@provokateurin.de>
2025-03-26 09:14:32 +00:00

33 lines
596 B
PHP
Executable file

#!/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
*/
/**
* 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';