Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix(occ): Make it possible to run as root
Signed-off-by: Frank Karlitschek <[email protected]>
Signed-off-by: Christoph Wurst <[email protected]>
Signed-off-by: Ferdinand Thiessen <[email protected]>
  • Loading branch information
karlitschek authored and backportbot[bot] committed Feb 27, 2025
commit c6bb5f102e6200a6e954b807d88ecc37d04c065a
32 changes: 27 additions & 5 deletions occ
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 <[email protected]>
* 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';
Loading