Skip to content

Commit 8f28fa2

Browse files
authored
Merge pull request #33545 from nextcloud/occ-as-root
make it possible to run occ as root
2 parents 001b12c + 53c083e commit 8f28fa2

1 file changed

Lines changed: 27 additions & 5 deletions

File tree

occ

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,33 @@
11
#!/usr/bin/env php
22
<?php
3+
4+
declare(strict_types=1);
5+
6+
/**
7+
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
8+
* SPDX-License-Identifier: AGPL-3.0-or-later
9+
*/
10+
311
/**
4-
* SPDX-FileCopyrightText: 2014 ownCloud, Inc.
5-
* SPDX-FileCopyrightText: 2014 Olivier Paroz
6-
* SPDX-FileCopyrightText: 2013 Thomas Müller <[email protected]>
7-
* SPDX-License-Identifier: AGPL-3.0-only
12+
* Drop privileges when run as root
813
*/
14+
function dropPrivileges(): void {
15+
if (posix_getuid() !== 0) {
16+
return;
17+
}
18+
19+
$configPath = __DIR__ . '/config/config.php';
20+
$uid = fileowner($configPath);
21+
if ($uid === false) {
22+
return;
23+
}
24+
$info = posix_getpwuid($uid);
25+
if ($info === false) {
26+
return;
27+
}
28+
posix_setuid($uid);
29+
posix_setgid($info['gid']);
30+
}
931

10-
//$argv = $_SERVER['argv'];
32+
dropPrivileges();
1133
require_once __DIR__ . '/console.php';

0 commit comments

Comments
 (0)