From 7ddeb2a499cbfa9e6dbdc3be84a6427259d6fde2 Mon Sep 17 00:00:00 2001 From: Marius Burkard Date: Wed, 4 Oct 2017 17:44:53 +0200 Subject: [PATCH] - backported !653, Fix #4808 --- server/plugins-available/shelluser_base_plugin.inc.php | 8 +++++--- server/plugins-available/shelluser_jailkit_plugin.inc.php | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/server/plugins-available/shelluser_base_plugin.inc.php b/server/plugins-available/shelluser_base_plugin.inc.php index d3376f10ca..74c6fa364f 100755 --- a/server/plugins-available/shelluser_base_plugin.inc.php +++ b/server/plugins-available/shelluser_base_plugin.inc.php @@ -461,7 +461,7 @@ class shelluser_base_plugin { if(is_file('/root/.ssh/authorized_keys')) $app->system->file_put_contents($sshkeys, $app->system->file_get_contents('/root/.ssh/authorized_keys')); // Remove duplicate keys - $existing_keys = @file($sshkeys); + $existing_keys = @file($sshkeys, FILE_IGNORE_NEW_LINES); $new_keys = explode("\n", $userkey); $final_keys_arr = @array_merge($existing_keys, $new_keys); $new_final_keys_arr = array(); @@ -479,7 +479,7 @@ class shelluser_base_plugin { } //* Get the keys - $existing_keys = file($sshkeys); + $existing_keys = file($sshkeys, FILE_IGNORE_NEW_LINES); $new_keys = explode("\n", $sshrsa); $old_keys = explode("\n", $this->data['old']['ssh_rsa']); @@ -487,7 +487,9 @@ class shelluser_base_plugin { if(is_array($old_keys)) { foreach($old_keys as $key => $val) { $k = array_search(trim($val), $existing_keys); - unset($existing_keys[$k]); + if ($k !== false) { + unset($existing_keys[$k]); + } } } diff --git a/server/plugins-available/shelluser_jailkit_plugin.inc.php b/server/plugins-available/shelluser_jailkit_plugin.inc.php index 291c771e6c..69a041c037 100755 --- a/server/plugins-available/shelluser_jailkit_plugin.inc.php +++ b/server/plugins-available/shelluser_jailkit_plugin.inc.php @@ -480,7 +480,7 @@ class shelluser_jailkit_plugin { if(is_file('/root/.ssh/authorized_keys')) $app->system->file_put_contents($sshkeys, $app->system->file_get_contents('/root/.ssh/authorized_keys')); // Remove duplicate keys - $existing_keys = @file($sshkeys); + $existing_keys = @file($sshkeys, FILE_IGNORE_NEW_LINES); $new_keys = explode("\n", $userkey); $final_keys_arr = @array_merge($existing_keys, $new_keys); $new_final_keys_arr = array(); @@ -497,7 +497,7 @@ class shelluser_jailkit_plugin { $this->app->log("ssh-rsa authorisation keyfile created in ".$sshkeys, LOGLEVEL_DEBUG); } //* Get the keys - $existing_keys = file($sshkeys); + $existing_keys = file($sshkeys, FILE_IGNORE_NEW_LINES); $new_keys = explode("\n", $sshrsa); $old_keys = explode("\n", $this->data['old']['ssh_rsa']); @@ -505,7 +505,9 @@ class shelluser_jailkit_plugin { if(is_array($old_keys)) { foreach($old_keys as $key => $val) { $k = array_search(trim($val), $existing_keys); - unset($existing_keys[$k]); + if ($k !== false) { + unset($existing_keys[$k]); + } } } -- GitLab