From 150aa06e65e4e07f93cd7f021c24ad2d17895e74 Mon Sep 17 00:00:00 2001 From: Jesse Norell <jesse@kci.net> Date: Thu, 17 Sep 2020 15:45:28 -0600 Subject: [PATCH] eliminate mkdir error for existing directory --- server/plugins-available/apache2_plugin.inc.php | 10 ++++++---- server/plugins-available/cron_jailkit_plugin.inc.php | 10 ++++++---- server/plugins-available/nginx_plugin.inc.php | 11 ++++++----- .../shelluser_jailkit_plugin.inc.php | 4 ++-- 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/server/plugins-available/apache2_plugin.inc.php b/server/plugins-available/apache2_plugin.inc.php index 4f7a02cf4d..8c99d4ad00 100644 --- a/server/plugins-available/apache2_plugin.inc.php +++ b/server/plugins-available/apache2_plugin.inc.php @@ -3791,7 +3791,7 @@ class apache2_plugin { // add the user to the chroot $jailkit_chroot_userhome = $this->_get_home_dir($this->website['system_user']); - if(!is_dir($this->website['document_root'].'/etc')) mkdir($this->website['document_root'].'/etc'); + if(!is_dir($this->website['document_root'].'/etc')) $app->system->mkdir($this->website['document_root'].'/etc', 0755, true); if(!is_file($this->website['document_root'].'/etc/passwd')) $app->system->exec_safe('touch ?', $this->website['document_root'].'/etc/passwd'); // IMPORTANT! @@ -3800,9 +3800,11 @@ class apache2_plugin { // and the user has FULL ACCESS to the root of the server! $app->system->create_jailkit_user($this->website['system_user'], $this->website['document_root'], $jailkit_chroot_userhome); - $app->system->mkdir($this->website['document_root'].$jailkit_chroot_userhome, 0755, true); - $app->system->chown($this->website['document_root'].$jailkit_chroot_userhome, $this->website['system_user']); - $app->system->chgrp($this->website['document_root'].$jailkit_chroot_userhome, $this->website['system_group']); + if(!is_dir($this->website['document_root'].$jailkit_chroot_userhome)) { + $app->system->mkdir($this->website['document_root'].$jailkit_chroot_userhome, 0750, true); + $app->system->chown($this->website['document_root'].$jailkit_chroot_userhome, $this->website['system_user']); + $app->system->chgrp($this->website['document_root'].$jailkit_chroot_userhome, $this->website['system_group']); + } $app->log("Added created jailkit user home in : ".$this->website['document_root'].$jailkit_chroot_userhome, LOGLEVEL_DEBUG); } diff --git a/server/plugins-available/cron_jailkit_plugin.inc.php b/server/plugins-available/cron_jailkit_plugin.inc.php index 576c363ae2..b8fa291f67 100644 --- a/server/plugins-available/cron_jailkit_plugin.inc.php +++ b/server/plugins-available/cron_jailkit_plugin.inc.php @@ -323,7 +323,7 @@ class cron_jailkit_plugin { // add the user to the chroot $jailkit_chroot_userhome = $this->_get_home_dir($this->parent_domain['system_user']); - if(!is_dir($this->parent_domain['document_root'].'/etc')) mkdir($this->parent_domain['document_root'].'/etc'); + if(!is_dir($this->parent_domain['document_root'].'/etc')) $app->system->mkdir($this->parent_domain['document_root'].'/etc', 0755, true); if(!is_file($this->parent_domain['document_root'].'/etc/passwd')) $app->system->exec_safe('touch ?', $this->parent_domain['document_root'].'/etc/passwd'); // IMPORTANT! @@ -332,9 +332,11 @@ class cron_jailkit_plugin { // and the user has FULL ACCESS to the root of the server! $app->system->create_jailkit_user($this->parent_domain['system_user'], $this->parent_domain['document_root'], $jailkit_chroot_userhome); - $app->system->mkdir($this->parent_domain['document_root'].$jailkit_chroot_userhome, 0755, true); - $app->system->chown($this->parent_domain['document_root'].$jailkit_chroot_userhome, $this->parent_domain['system_user']); - $app->system->chgrp($this->parent_domain['document_root'].$jailkit_chroot_userhome, $this->parent_domain['system_group']); + if(!is_dir($this->parent_domain['document_root'].$jailkit_chroot_userhome)) { + $app->system->mkdir($this->parent_domain['document_root'].$jailkit_chroot_userhome, 0750, true); + $app->system->chown($this->parent_domain['document_root'].$jailkit_chroot_userhome, $this->parent_domain['system_user']); + $app->system->chgrp($this->parent_domain['document_root'].$jailkit_chroot_userhome, $this->parent_domain['system_group']); + } } diff --git a/server/plugins-available/nginx_plugin.inc.php b/server/plugins-available/nginx_plugin.inc.php index cb991bcce4..4ee9b18a5d 100644 --- a/server/plugins-available/nginx_plugin.inc.php +++ b/server/plugins-available/nginx_plugin.inc.php @@ -3576,7 +3576,7 @@ class nginx_plugin { // add the user to the chroot $jailkit_chroot_userhome = $this->_get_home_dir($this->website['system_user']); - if(!is_dir($this->website['document_root'].'/etc')) mkdir($this->website['document_root'].'/etc'); + if(!is_dir($this->website['document_root'].'/etc')) $app->system->mkdir($this->website['document_root'].'/etc', 0755, true); if(!is_file($this->website['document_root'].'/etc/passwd')) $app->system->exec_safe('touch ?', $this->website['document_root'].'/etc/passwd'); // IMPORTANT! @@ -3585,10 +3585,11 @@ class nginx_plugin { // and the user has FULL ACCESS to the root of the server! $app->system->create_jailkit_user($this->website['system_user'], $this->website['document_root'], $jailkit_chroot_userhome); - $app->system->mkdir($this->website['document_root'].$jailkit_chroot_userhome, 0755, true); - $app->system->chown($this->website['document_root'].$jailkit_chroot_userhome, $this->website['system_user']); - $app->system->chgrp($this->website['document_root'].$jailkit_chroot_userhome, $this->website['system_group']); - + if(!is_dir($this->website['document_root'].$jailkit_chroot_userhome)) { + $app->system->mkdir($this->website['document_root'].$jailkit_chroot_userhome, 0750, true); + $app->system->chown($this->website['document_root'].$jailkit_chroot_userhome, $this->website['system_user']); + $app->system->chgrp($this->website['document_root'].$jailkit_chroot_userhome, $this->website['system_group']); + } $app->log("Added created jailkit user home in : ".$this->website['document_root'].$jailkit_chroot_userhome, LOGLEVEL_DEBUG); } diff --git a/server/plugins-available/shelluser_jailkit_plugin.inc.php b/server/plugins-available/shelluser_jailkit_plugin.inc.php index 57665abeeb..9fe6337cd3 100755 --- a/server/plugins-available/shelluser_jailkit_plugin.inc.php +++ b/server/plugins-available/shelluser_jailkit_plugin.inc.php @@ -398,7 +398,7 @@ class shelluser_jailkit_plugin { } $jailkit_chroot_puserhome = $this->_get_home_dir($this->data['new']['puser']); - if(!is_dir($this->data['new']['dir'].'/etc')) mkdir($this->data['new']['dir'].'/etc', 0755); + if(!is_dir($this->data['new']['dir'].'/etc')) $app->system->mkdir($this->data['new']['dir'].'/etc', 0755, true); if(!is_file($this->data['new']['dir'].'/etc/passwd')) touch($this->data['new']['dir'].'/etc/passwd', 0755); // IMPORTANT! @@ -417,7 +417,7 @@ class shelluser_jailkit_plugin { if(is_dir($this->data['old']['dir'].$jailkit_chroot_userhome_old)) { $app->system->rename($this->data['old']['dir'].$jailkit_chroot_userhome_old,$this->data['new']['dir'].$jailkit_chroot_userhome); } else { - mkdir($this->data['new']['dir'].$jailkit_chroot_userhome, 0750, true); + $app->system->mkdir($this->data['new']['dir'].$jailkit_chroot_userhome, 0750, true); } } $app->system->chown($this->data['new']['dir'].$jailkit_chroot_userhome, $this->data['new']['username']); -- GitLab