Skip to content

Commit 88c60a5

Browse files
author
Marius Burkard
committed
Merge branch '6024-jailkit_errors' into 'develop'
jailkit bugfixes Closes #6041, #6036, #6040, and #6042 See merge request ispconfig/ispconfig3!1401
2 parents eb1416d + 1070f87 commit 88c60a5

File tree

4 files changed

+20
-9
lines changed

4 files changed

+20
-9
lines changed

server/lib/classes/cron.d/600-jailkit_maintenance.inc.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ public function onRunJob() {
114114
if (is_file( $rec['document_root']."/bin/bash" )) {
115115
# test that /bin/bash functions in the jail
116116
print "chroot --userspec ".$rec['system_user'].":".$rec['system_group']." ".$rec['document_root']." /bin/bash -c true 2>/dev/null\n";
117-
if (! $app->system->exec_safe("chroot --userspec ?:? ? /bin/bash -c true 2>/dev/null", $rec['system_user'], $rec['system_group'], $rec['document_root'])) {
117+
$app->system->exec_safe("chroot --userspec ?:? ? /bin/bash -c true 2>/dev/null", $rec['system_user'], $rec['system_group'], $rec['document_root']);
118+
if ($app->system->last_exec_retcode()) { # return 0 means success
118119
print "/bin/bash test failed, forcing update\n";
119120
$options[] = 'force';
120121
# bogus hash will not match, triggering an update

server/lib/classes/system.inc.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2412,6 +2412,7 @@ public function create_jailkit_user($username, $home_dir, $user_home_dir, $shell
24122412

24132413
public function create_jailkit_chroot($home_dir, $app_sections = array(), $options = array()) {
24142414
global $app;
2415+
$app->log("create_jailkit_chroot: called for home_dir $home_dir with options: " . print_r($options, true), LOGLEVEL_DEBUG);
24152416

24162417
// Disallow operating on root directory
24172418
if(realpath($home_dir) == '/') {
@@ -2428,6 +2429,9 @@ public function create_jailkit_chroot($home_dir, $app_sections = array(), $optio
24282429
} elseif(is_string($app_sections)) {
24292430
$app_sections = preg_split('/[\s,]+/', $app_sections);
24302431
}
2432+
if(! is_array($options)) {
2433+
$options = (is_string($options) ? preg_split('/[\s,]+/', $options) : array());
2434+
}
24312435

24322436
// Change ownership of the chroot directory to root
24332437
$this->chown($home_dir, 'root');
@@ -2485,6 +2489,7 @@ public function create_jailkit_chroot($home_dir, $app_sections = array(), $optio
24852489

24862490
public function create_jailkit_programs($home_dir, $programs = array(), $options = array()) {
24872491
global $app;
2492+
$app->log("create_jailkit_programs: called for home_dir $home_dir with options: " . print_r($options, true), LOGLEVEL_DEBUG);
24882493

24892494
// Disallow operating on root directory
24902495
if(realpath($home_dir) == '/') {
@@ -2501,6 +2506,9 @@ public function create_jailkit_programs($home_dir, $programs = array(), $options
25012506
} elseif(is_string($programs)) {
25022507
$programs = preg_split('/[\s,]+/', $programs);
25032508
}
2509+
if(! is_array($options)) {
2510+
$options = (is_string($options) ? preg_split('/[\s,]+/', $options) : array());
2511+
}
25042512

25052513
# prohibit ill-advised copying paths known to be sensitive/problematic
25062514
# (easy to bypass if needed, eg. use /./etc)

server/plugins-available/apache2_plugin.inc.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -788,17 +788,18 @@ function update($event_name, $data) {
788788
$last_updated = array_unique($last_updated, SORT_REGULAR);
789789
sort($last_updated, SORT_STRING);
790790
$update_hash = hash('md5', implode(' ', $last_updated));
791+
$check_for_jailkit_updates=false;
791792

792793
// Create jailkit chroot when enabling php_fpm_chroot
793-
if($data['new']['php_fpm_chroot'] == 'y' && $data['old']['php_fpm_chroot'] != 'y') {
794+
if($data['new']['php_fpm_chroot'] == 'y' && $data['old']['php_fpm_chroot'] != 'y' && $data['new']['php'] != 'no') {
794795
$website = $app->db->queryOneRecord('SELECT * FROM web_domain WHERE domain_id = ?', $data['new']['domain_id']);
795796
$this->website = array_merge($website, $data['new'], array('new_jailkit_hash' => $update_hash));
796797
$this->jailkit_config = $jailkit_config;
797798
$this->_setup_jailkit_chroot();
798799
$this->_add_jailkit_user();
799-
$check_for_jailkit_updates=false;
800800
// else delete if unused
801-
} elseif ($data['new']['delete_unused_jailkit'] == 'y' && $data['new']['php_fpm_chroot'] != 'y') {
801+
} elseif (($data['new']['delete_unused_jailkit'] == 'y' && $data['new']['php_fpm_chroot'] != 'y') ||
802+
($data['new']['delete_unused_jailkit'] == 'y' && $data['new']['php'] == 'no')) {
802803
$check_for_jailkit_updates=false;
803804
$this->_delete_jailkit_if_unused($data['new']['domain_id']);
804805
if(is_dir($data['new']['document_root'].'/etc/jailkit')) {
@@ -3820,7 +3821,7 @@ private function _delete_jailkit_if_unused($parent_domain_id) {
38203821
}
38213822

38223823
// chroot is used by php-fpm
3823-
if (isset($parent_domain['php_fpm_chroot']) && $parent_domain['php_fpm_chroot'] == 'y') {
3824+
if (isset($parent_domain['php_fpm_chroot']) && $parent_domain['php_fpm_chroot'] == 'y' && $parent_domain['php'] != 'no') {
38243825
return;
38253826
}
38263827

server/plugins-available/nginx_plugin.inc.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -626,17 +626,18 @@ function update($event_name, $data) {
626626
$last_updated = array_unique($last_updated, SORT_REGULAR);
627627
sort($last_updated, SORT_STRING);
628628
$update_hash = hash('md5', implode(' ', $last_updated));
629+
$check_for_jailkit_updates=false;
629630

630631
// Create jailkit chroot when enabling php_fpm_chroot
631-
if($data['new']['php_fpm_chroot'] == 'y' && $data['old']['php_fpm_chroot'] != 'y') {
632+
if($data['new']['php_fpm_chroot'] == 'y' && $data['old']['php_fpm_chroot'] != 'y' && $data['new']['php'] != 'no') {
632633
$website = $app->db->queryOneRecord('SELECT * FROM web_domain WHERE domain_id = ?', $data['new']['domain_id']);
633634
$this->website = array_merge($website, $data['new'], array('new_jailkit_hash' => $update_hash));
634635
$this->jailkit_config = $jailkit_config;
635636
$this->_setup_jailkit_chroot();
636637
$this->_add_jailkit_user();
637-
$check_for_jailkit_updates=false;
638638
// else delete if unused
639-
} elseif ($data['new']['delete_unused_jailkit'] == 'y' && $data['new']['php_fpm_chroot'] != 'y') {
639+
} elseif (($data['new']['delete_unused_jailkit'] == 'y' && $data['new']['php_fpm_chroot'] != 'y') ||
640+
($data['new']['delete_unused_jailkit'] == 'y' && $data['new']['php'] == 'no')) {
640641
$check_for_jailkit_updates=false;
641642
$this->_delete_jailkit_if_unused($data['new']['domain_id']);
642643
if(is_dir($data['new']['document_root'].'/etc/jailkit')) {
@@ -3599,7 +3600,7 @@ private function _delete_jailkit_if_unused($parent_domain_id) {
35993600
}
36003601

36013602
// chroot is used by php-fpm
3602-
if (isset($parent_domain['php_fpm_chroot']) && $parent_domain['php_fpm_chroot'] == 'y') {
3603+
if (isset($parent_domain['php_fpm_chroot']) && $parent_domain['php_fpm_chroot'] == 'y' && $parent_domain['php'] != 'no') {
36033604
return;
36043605
}
36053606

0 commit comments

Comments
 (0)