diff --git a/config/config.sample.php b/config/config.sample.php index 288ea7e4a9b2f..226941367d102 100644 --- a/config/config.sample.php +++ b/config/config.sample.php @@ -940,6 +940,15 @@ */ 'config_is_read_only' => false, +/** + * In certain environments it is desired to set the config.php owner to + * something else than the user that is running the php process. + * In that case in order to determine the user that the php process uses, + * you can overwrite the user with this config flag for console.php and cron.php + * Defaults to ``''`` (empty string) + */ +'php.user' => '', + /** * Logging */ diff --git a/console.php b/console.php index 693a2618a8886..b2bc50c13d063 100644 --- a/console.php +++ b/console.php @@ -42,13 +42,20 @@ function exceptionHandler($exception) { } $user = posix_getuid(); + $userNameArray = posix_getpwuid($user); + $username = null; + if ($userNameArray !== false) { + $userName = $userNameArray['name']; + } $configUser = fileowner(OC::$configDir . 'config.php'); - if ($user !== $configUser) { + $configuredUser = $config->getSystemValueString('php.user', ''); + if ($user !== $configUser && $username !== null && $userName !== $configuredUser) { echo "Console has to be executed with the user that owns the file config/config.php" . PHP_EOL; echo "Current user id: " . $user . PHP_EOL; echo "Owner id of config.php: " . $configUser . PHP_EOL; echo "Try adding 'sudo -u #" . $configUser . "' to the beginning of the command (without the single quotes)" . PHP_EOL; echo "If running with 'docker exec' try adding the option '-u " . $configUser . "' to the docker command (without the single quotes)" . PHP_EOL; + echo "Another option is to configure 'php.user' in config.php which will overwrite this check."; exit(1); } diff --git a/cron.php b/cron.php index be743664db2ba..d36ab67c650cc 100644 --- a/cron.php +++ b/cron.php @@ -130,11 +130,18 @@ } $user = posix_getuid(); + $userNameArray = posix_getpwuid($user); + $username = null; + if ($userNameArray !== false) { + $userName = $userNameArray['name']; + } $configUser = fileowner(OC::$configDir . 'config.php'); - if ($user !== $configUser) { + $configuredUser = $config->getSystemValueString('php.user', ''); + if ($user !== $configUser && $username !== null && $userName !== $configuredUser) { echo "Console has to be executed with the user that owns the file config/config.php" . PHP_EOL; echo "Current user id: " . $user . PHP_EOL; echo "Owner id of config.php: " . $configUser . PHP_EOL; + echo "Another option is to configure 'php.user' in config.php which will overwrite this check."; exit(1); }