From 087ba077337abeca1c67d9e61c6c630754fb0497 Mon Sep 17 00:00:00 2001 From: "Simon L." Date: Tue, 14 May 2024 12:22:39 +0200 Subject: [PATCH 1/4] 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); } From a0d9dcac62e69d4fb763d352eb3dd4f83a4df283 Mon Sep 17 00:00:00 2001 From: "Simon L." Date: Wed, 22 May 2024 15:45:36 +0200 Subject: [PATCH 2/4] fix(posix_getpwuid): handle false return value Signed-off-by: Simon L --- console.php | 2 +- cron.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/console.php b/console.php index b65a1dde12eb2..512aaaa135686 100644 --- a/console.php +++ b/console.php @@ -42,7 +42,7 @@ function exceptionHandler($exception) { } $user = posix_getuid(); - $userName = posix_getpwuid($user)['name']; + $userName = posix_getpwuid($user) !== false ? posix_getpwuid($user)['name'] : ''; $configUser = fileowner(OC::$configDir . 'config.php'); $configuredUser = $config->getSystemValueString('php.user', ''); if ($user !== $configUser && $userName !== $configuredUser) { diff --git a/cron.php b/cron.php index e9a766ecac444..95228f826bba7 100644 --- a/cron.php +++ b/cron.php @@ -130,7 +130,7 @@ } $user = posix_getuid(); - $userName = posix_getpwuid($user)['name']; + $userName = posix_getpwuid($user) !== false ? posix_getpwuid($user)['name'] : ''; $configUser = fileowner(OC::$configDir . 'config.php'); $configuredUser = $config->getSystemValueString('php.user', ''); if ($user !== $configUser && $userName !== $configuredUser) { From 137986f30d178cf15a4ded25e906df0e130560dd Mon Sep 17 00:00:00 2001 From: "Simon L." Date: Wed, 22 May 2024 16:00:46 +0200 Subject: [PATCH 3/4] fix: address review Signed-off-by: Simon L --- console.php | 5 ++++- cron.php | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/console.php b/console.php index 512aaaa135686..355b62ca2e66a 100644 --- a/console.php +++ b/console.php @@ -42,7 +42,10 @@ function exceptionHandler($exception) { } $user = posix_getuid(); - $userName = posix_getpwuid($user) !== false ? posix_getpwuid($user)['name'] : ''; + $userNameArray = posix_getpwuid($user); + if ($userNameArray !== false) { + $userName = $userNameArray['name']; + } $configUser = fileowner(OC::$configDir . 'config.php'); $configuredUser = $config->getSystemValueString('php.user', ''); if ($user !== $configUser && $userName !== $configuredUser) { diff --git a/cron.php b/cron.php index 95228f826bba7..9f2c7288589c3 100644 --- a/cron.php +++ b/cron.php @@ -130,7 +130,10 @@ } $user = posix_getuid(); - $userName = posix_getpwuid($user) !== false ? posix_getpwuid($user)['name'] : ''; + $userNameArray = posix_getpwuid($user); + if ($userNameArray !== false)) { + $userName = $userNameArray['name']; + } $configUser = fileowner(OC::$configDir . 'config.php'); $configuredUser = $config->getSystemValueString('php.user', ''); if ($user !== $configUser && $userName !== $configuredUser) { From 1afe55bd5f68205645d16a32b56cef2af4f3bb7f Mon Sep 17 00:00:00 2001 From: "Simon L." Date: Fri, 24 May 2024 14:59:23 +0200 Subject: [PATCH 4/4] fix: address review 2 Signed-off-by: Simon L --- console.php | 3 ++- cron.php | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/console.php b/console.php index 355b62ca2e66a..b2bc50c13d063 100644 --- a/console.php +++ b/console.php @@ -43,12 +43,13 @@ function exceptionHandler($exception) { $user = posix_getuid(); $userNameArray = posix_getpwuid($user); + $username = null; if ($userNameArray !== false) { $userName = $userNameArray['name']; } $configUser = fileowner(OC::$configDir . 'config.php'); $configuredUser = $config->getSystemValueString('php.user', ''); - if ($user !== $configUser && $userName !== $configuredUser) { + 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; diff --git a/cron.php b/cron.php index 9f2c7288589c3..d36ab67c650cc 100644 --- a/cron.php +++ b/cron.php @@ -131,12 +131,13 @@ $user = posix_getuid(); $userNameArray = posix_getpwuid($user); - if ($userNameArray !== false)) { + $username = null; + if ($userNameArray !== false) { $userName = $userNameArray['name']; } $configUser = fileowner(OC::$configDir . 'config.php'); $configuredUser = $config->getSystemValueString('php.user', ''); - if ($user !== $configUser && $userName !== $configuredUser) { + 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;