Commit 693e4b93 authored by Anton Avramov's avatar Anton Avramov

Fix #4808 Load the existing keys without new line, so array_search can find...

Fix #4808 Load the existing keys without new line, so array_search can find the old ones. Unset a key from existing_keys only if a match is false and avoid false being treated as 0
parent 5812c6c0
......@@ -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]);
}
}
}
......
......@@ -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]);
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment