Skip to content

Commit 7ddeb2a

Browse files
author
Marius Burkard
committed
- backported !653, Fix #4808
1 parent 98a5b58 commit 7ddeb2a

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

server/plugins-available/shelluser_base_plugin.inc.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ private function _setup_ssh_rsa() {
461461
if(is_file('/root/.ssh/authorized_keys')) $app->system->file_put_contents($sshkeys, $app->system->file_get_contents('/root/.ssh/authorized_keys'));
462462

463463
// Remove duplicate keys
464-
$existing_keys = @file($sshkeys);
464+
$existing_keys = @file($sshkeys, FILE_IGNORE_NEW_LINES);
465465
$new_keys = explode("\n", $userkey);
466466
$final_keys_arr = @array_merge($existing_keys, $new_keys);
467467
$new_final_keys_arr = array();
@@ -479,15 +479,17 @@ private function _setup_ssh_rsa() {
479479
}
480480

481481
//* Get the keys
482-
$existing_keys = file($sshkeys);
482+
$existing_keys = file($sshkeys, FILE_IGNORE_NEW_LINES);
483483
$new_keys = explode("\n", $sshrsa);
484484
$old_keys = explode("\n", $this->data['old']['ssh_rsa']);
485485

486486
//* Remove all old keys
487487
if(is_array($old_keys)) {
488488
foreach($old_keys as $key => $val) {
489489
$k = array_search(trim($val), $existing_keys);
490-
unset($existing_keys[$k]);
490+
if ($k !== false) {
491+
unset($existing_keys[$k]);
492+
}
491493
}
492494
}
493495

server/plugins-available/shelluser_jailkit_plugin.inc.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ private function _setup_ssh_rsa() {
480480
if(is_file('/root/.ssh/authorized_keys')) $app->system->file_put_contents($sshkeys, $app->system->file_get_contents('/root/.ssh/authorized_keys'));
481481

482482
// Remove duplicate keys
483-
$existing_keys = @file($sshkeys);
483+
$existing_keys = @file($sshkeys, FILE_IGNORE_NEW_LINES);
484484
$new_keys = explode("\n", $userkey);
485485
$final_keys_arr = @array_merge($existing_keys, $new_keys);
486486
$new_final_keys_arr = array();
@@ -497,15 +497,17 @@ private function _setup_ssh_rsa() {
497497
$this->app->log("ssh-rsa authorisation keyfile created in ".$sshkeys, LOGLEVEL_DEBUG);
498498
}
499499
//* Get the keys
500-
$existing_keys = file($sshkeys);
500+
$existing_keys = file($sshkeys, FILE_IGNORE_NEW_LINES);
501501
$new_keys = explode("\n", $sshrsa);
502502
$old_keys = explode("\n", $this->data['old']['ssh_rsa']);
503503

504504
//* Remove all old keys
505505
if(is_array($old_keys)) {
506506
foreach($old_keys as $key => $val) {
507507
$k = array_search(trim($val), $existing_keys);
508-
unset($existing_keys[$k]);
508+
if ($k !== false) {
509+
unset($existing_keys[$k]);
510+
}
509511
}
510512
}
511513

0 commit comments

Comments
 (0)