You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
596 B

  1. #!/usr/bin/env php
  2. <?php
  3. declare(strict_types=1);
  4. /**
  5. * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
  6. * SPDX-License-Identifier: AGPL-3.0-or-later
  7. */
  8. /**
  9. * Drop privileges when run as root
  10. */
  11. function dropPrivileges(): void {
  12. if (posix_getuid() !== 0) {
  13. return;
  14. }
  15. $configPath = __DIR__ . '/config/config.php';
  16. $uid = @fileowner($configPath);
  17. if ($uid === false) {
  18. return;
  19. }
  20. $info = posix_getpwuid($uid);
  21. if ($info === false) {
  22. return;
  23. }
  24. posix_setuid($uid);
  25. posix_setgid($info['gid']);
  26. }
  27. dropPrivileges();
  28. require_once __DIR__ . '/console.php';