@@ -101,6 +101,7 @@ function insert($event_name, $data) {
101101
102102
103103 if ($ app ->system ->is_user ($ data ['new ' ]['puser ' ])) {
104+
104105 // Get the UID of the parent user
105106 $ uid = intval ($ app ->system ->getuid ($ data ['new ' ]['puser ' ]));
106107 if ($ uid > $ this ->min_uid ) {
@@ -159,7 +160,6 @@ function insert($event_name, $data) {
159160 } else {
160161 $ app ->log ("Skipping insertion of user: " .$ data ['new ' ]['username ' ].", parent user " .$ data ['new ' ]['puser ' ]." does not exist. " , LOGLEVEL_WARN );
161162 }
162-
163163 }
164164
165165 //* This function is called, when a shell user is updated in the database
@@ -518,19 +518,18 @@ private function _setup_ssh_rsa() {
518518 //Generate ssh-rsa-keys
519519 $ app ->uses ('functions ' );
520520 $ app ->functions ->generate_ssh_key ($ id , $ username );
521-
522521 $ app ->log ("ssh-rsa keypair generated for " .$ username , LOGLEVEL_DEBUG );
523522 };
524523
525524 if (!file_exists ($ sshkeys )){
526525 // add root's key
527- $ app ->file ->mkdirs ($ sshdir , '0755 ' );
526+ $ app ->file ->mkdirs ($ sshdir , '0700 ' );
528527 $ authorized_keys_template = $ this ->jailkit_config ['jailkit_chroot_authorized_keys_template ' ];
529528 if (is_file ($ authorized_keys_template )) $ app ->system ->file_put_contents ($ sshkeys , $ app ->system ->file_get_contents ($ authorized_keys_template ));
530529
531530 // Remove duplicate keys
532531 $ existing_keys = @file ($ sshkeys , FILE_IGNORE_NEW_LINES );
533- $ new_keys = (!is_null ($ userkey ))?explode ("\n" , $ userkey ):'' ;
532+ $ new_keys = (!is_null ($ userkey ))?explode ("\n" , $ userkey ):array () ;
534533 if (is_array ($ existing_keys )) {
535534 $ final_keys_arr = @array_merge ($ existing_keys , $ new_keys );
536535 } else {
@@ -545,10 +544,11 @@ private function _setup_ssh_rsa() {
545544 $ final_keys = implode ("\n" , array_flip (array_flip ($ new_final_keys_arr ))) . "\n" ;
546545
547546 // add the user's key
548- file_put_contents ($ sshkeys , $ final_keys );
547+ $ app -> system -> file_put_contents ($ sshkeys , $ final_keys );
549548 $ app ->file ->remove_blank_lines ($ sshkeys );
550549 $ app ->log ("ssh-rsa authorisation keyfile created in " .$ sshkeys , LOGLEVEL_DEBUG );
551550 }
551+
552552 //* Get the keys
553553 $ existing_keys = file ($ sshkeys , FILE_IGNORE_NEW_LINES );
554554 if (!$ existing_keys ) {
@@ -589,7 +589,6 @@ private function _setup_ssh_rsa() {
589589
590590 // set proper file permissions
591591 $ app ->system ->exec_safe ("chown -R ?:? ? " , $ this ->data ['new ' ]['puser ' ], $ this ->data ['new ' ]['pgroup ' ], $ sshdir );
592- $ app ->system ->exec_safe ("chmod 700 ? " , $ sshdir );
593592 $ app ->system ->exec_safe ("chmod 600 ? " , $ sshkeys );
594593
595594 }
0 commit comments