From 087ba077337abeca1c67d9e61c6c630754fb0497 Mon Sep 17 00:00:00 2001 From: "Simon L." Date: Tue, 14 May 2024 12:22:39 +0200 Subject: [PATCH] feat: allow to configure config.owner Signed-off-by: Simon L --- config/config.sample.php | 9 +++++++++ console.php | 5 ++++- cron.php | 5 ++++- 3 files changed, 17 insertions(+), 2 deletions(-) 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..b65a1dde12eb2 100644 --- a/console.php +++ b/console.php @@ -42,13 +42,16 @@ function exceptionHandler($exception) { } $user = posix_getuid(); + $userName = posix_getpwuid($user)['name']; $configUser = fileowner(OC::$configDir . 'config.php'); - if ($user !== $configUser) { + $configuredUser = $config->getSystemValueString('php.user', ''); + if ($user !== $configUser && $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..e9a766ecac444 100644 --- a/cron.php +++ b/cron.php @@ -130,11 +130,14 @@ } $user = posix_getuid(); + $userName = posix_getpwuid($user)['name']; $configUser = fileowner(OC::$configDir . 'config.php'); - if ($user !== $configUser) { + $configuredUser = $config->getSystemValueString('php.user', ''); + if ($user !== $configUser && $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); }