File tree Expand file tree Collapse file tree 1 file changed +12
-5
lines changed
Expand file tree Collapse file tree 1 file changed +12
-5
lines changed Original file line number Diff line number Diff line change 11#!/usr/bin/env php
22<?php
3+
34/**
45 * SPDX-FileCopyrightText: 2014 ownCloud, Inc.
56 * SPDX-FileCopyrightText: 2014 Olivier Paroz
67 * SPDX-FileCopyrightText: 2013 Thomas Müller <thomas.mueller@tmit.eu>
78 * SPDX-License-Identifier: AGPL-3.0-only
89 */
910
10- // make it possible to run as root
11- if (posix_getuid () == 0 ){
11+ // Drop privileges when run as root
12+ if (posix_getuid () === 0 ){
13+ $ configPath = __DIR__ . '/config/config.php ' ;
14+ $ fallbackUser = 'www-data ' ;
15+ $ guessedUser = match (file_exists ($ configPath )) {
16+ true => ($ ownerUid = fileowner ($ configPath )) ? posix_getpwuid ($ ownerUid )['name ' ] : $ fallbackUser ,
17+ false => $ fallbackUser ,
18+ };
1219 $ command = implode (' ' , $ argv );
13- echo (shell_exec (' sudo -u www-data ' . $ command ));
20+ echo (shell_exec (" sudo -u $ guessedUser php -f " . $ command ));
1421 exit ;
22+ } else {
23+ require_once __DIR__ . '/console.php ' ;
1524}
16-
17- require_once __DIR__ . '/console.php ' ;
You can’t perform that action at this time.
0 commit comments