aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrank Karlitschek <karlitschek@users.noreply.github.com>2022-08-15 18:04:03 +0200
committerJoas Schilling <coding@schilljs.com>2025-02-27 20:42:09 +0100
commit53c083ea2af3a7191e7cb64f0c3ddf91aea6422e (patch)
tree892b182307e8400ded935582306ae8d5ff720d0b
parent001b12c482c24d43226afeb4164d0fc410383819 (diff)
downloadnextcloud-server-53c083ea2af3a7191e7cb64f0c3ddf91aea6422e.tar.gz
nextcloud-server-53c083ea2af3a7191e7cb64f0c3ddf91aea6422e.zip
fix(occ): Make it possible to run as rootocc-as-root
Signed-off-by: Frank Karlitschek <karlitschek@users.noreply.github.com> Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at> Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
-rwxr-xr-xocc32
1 files changed, 27 insertions, 5 deletions
diff --git a/occ b/occ
index b3fed16e82a..e4dcc80c9da 100755
--- a/occ
+++ b/occ
@@ -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';