Skip to content

Commit 2b36842

Browse files
authored
Merge pull request #23436 from nextcloud/fix/23158/remove-posix_getpwuid
Remove posix_getpwuid and compare only userid
2 parents a41b273 + 0a02bf4 commit 2b36842

2 files changed

Lines changed: 13 additions & 12 deletions

File tree

console.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,14 @@ function exceptionHandler($exception) {
6464
echo "The posix extensions are required - see http://php.net/manual/en/book.posix.php" . PHP_EOL;
6565
exit(1);
6666
}
67-
$user = posix_getpwuid(posix_getuid());
68-
$configUser = posix_getpwuid(fileowner(OC::$configDir . 'config.php'));
69-
if ($user['name'] !== $configUser['name']) {
67+
$user = posix_getuid();
68+
$configUser = fileowner(OC::$configDir . 'config.php');
69+
if ($user !== $configUser) {
7070
echo "Console has to be executed with the user that owns the file config/config.php" . PHP_EOL;
71-
echo "Current user: " . $user['name'] . PHP_EOL;
72-
echo "Owner of config.php: " . $configUser['name'] . PHP_EOL;
73-
echo "Try adding 'sudo -u " . $configUser['name'] . " ' to the beginning of the command (without the single quotes)" . PHP_EOL;
74-
echo "If running with 'docker exec' try adding the option '-u " . $configUser['name'] . "' to the docker command (without the single quotes)" . PHP_EOL;
71+
echo "Current user id: " . $user . PHP_EOL;
72+
echo "Owner id of config.php: " . $configUser . PHP_EOL;
73+
echo "Try adding 'sudo -u #" . $configUser . "' to the beginning of the command (without the single quotes)" . PHP_EOL;
74+
echo "If running with 'docker exec' try adding the option '-u " . $configUser . "' to the docker command (without the single quotes)" . PHP_EOL;
7575
exit(1);
7676
}
7777

cron.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,16 @@
9494
exit(1);
9595
}
9696

97-
$user = posix_getpwuid(posix_getuid());
98-
$configUser = posix_getpwuid(fileowner(OC::$configDir . 'config.php'));
99-
if ($user['name'] !== $configUser['name']) {
97+
$user = posix_getuid();
98+
$configUser = fileowner(OC::$configDir . 'config.php');
99+
if ($user !== $configUser) {
100100
echo "Console has to be executed with the user that owns the file config/config.php" . PHP_EOL;
101-
echo "Current user: " . $user['name'] . PHP_EOL;
102-
echo "Owner of config.php: " . $configUser['name'] . PHP_EOL;
101+
echo "Current user id: " . $user . PHP_EOL;
102+
echo "Owner id of config.php: " . $configUser . PHP_EOL;
103103
exit(1);
104104
}
105105

106+
106107
// We call Nextcloud from the CLI (aka cron)
107108
if ($appMode !== 'cron') {
108109
$config->setAppValue('core', 'backgroundjobs_mode', 'cron');

0 commit comments

Comments
 (0)