Skip to content

Commit

Permalink
feat: allow to configure config.owner
Browse files Browse the repository at this point in the history
Signed-off-by: Simon L <szaimen@e.mail.de>
  • Loading branch information
szaimen committed May 21, 2024
1 parent 88648fa commit de2dbf5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
9 changes: 9 additions & 0 deletions config/config.sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
5 changes: 4 additions & 1 deletion console.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
5 changes: 4 additions & 1 deletion cron.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit de2dbf5

Please sign in to comment.