Skip to content

Commit 8db8f3a

Browse files
committed
Fix for jailkit permissions in high security website mode.
1 parent f9492bf commit 8db8f3a

File tree

2 files changed

+44
-3
lines changed

2 files changed

+44
-3
lines changed

server/plugins-available/apache2_plugin.inc.php

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -463,13 +463,17 @@ function update($event_name,$data) {
463463
// Chown and chmod the directories below the document root
464464
exec("chown -R $username:$groupname ".escapeshellcmd($data["new"]["document_root"]));
465465

466-
// The document root itself has to be owned by root
467-
exec("chown root:root ".escapeshellcmd($data["new"]["document_root"]));
466+
// The document root itself has to be owned by root in normal level and by the web owner in security level 20
467+
if($web_config['security_level'] == 20) {
468+
exec("chown $username:$groupname ".escapeshellcmd($data["new"]["document_root"]));
469+
} else {
470+
exec("chown root:root ".escapeshellcmd($data["new"]["document_root"]));
471+
}
468472
}
469473

470474

471475

472-
// If the security level is set to high
476+
//* If the security level is set to high
473477
if($web_config['security_level'] == 20) {
474478

475479
exec("chmod 751 ".escapeshellcmd($data["new"]["document_root"]."/"));
@@ -487,11 +491,25 @@ function update($event_name,$data) {
487491
//* add the apache user to the client group
488492
$app->system->add_user_to_group($groupname, escapeshellcmd($web_config['user']));
489493

494+
/*
495+
* Workaround for jailkit: If jailkit is enabled for the site, the
496+
* website root has to be owned by the root user and we have to chmod it to 755 then
497+
*/
498+
499+
//* Check if there is a jailkit user for this site
500+
$tmp = $app->db->queryOneRecord("SELECT count(shell_user_id) as number FROM shell_user WHERE parent_domain_id = ".$data["new"]["domain_id"]." AND chroot = 'jailkit'");
501+
if($tmp['number'] > 0) {
502+
exec("chmod 755 ".escapeshellcmd($data["new"]["document_root"]."/"));
503+
exec("chown root:root ".escapeshellcmd($data["new"]["document_root"]."/"));
504+
}
505+
unset($tmp);
506+
490507
// If the security Level is set to medium
491508
} else {
492509

493510
exec("chmod 755 ".escapeshellcmd($data["new"]["document_root"]."/"));
494511
exec("chmod 755 ".escapeshellcmd($data["new"]["document_root"]."/*"));
512+
exec("chown root:root ".escapeshellcmd($data["new"]["document_root"]."/"));
495513

496514
// make temp direcory writable for the apache user and the website user
497515
exec("chmod 777 ".escapeshellcmd($data["new"]["document_root"]."/tmp"));

server/plugins-available/shelluser_jailkit_plugin.inc.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ function insert($event_name,$data) {
8484
$this->data = $data;
8585
$this->app = $app;
8686
$this->jailkit_config = $app->getconf->get_server_config($conf["server_id"], 'jailkit');
87+
88+
$this->_update_website_security_level();
8789

8890
$this->_setup_jailkit_chroot();
8991

@@ -119,6 +121,8 @@ function update($event_name,$data) {
119121
$this->data = $data;
120122
$this->app = $app;
121123
$this->jailkit_config = $app->getconf->get_server_config($conf["server_id"], 'jailkit');
124+
125+
$this->_update_website_security_level();
122126

123127
$this->_setup_jailkit_chroot();
124128
$this->_add_jailkit_user();
@@ -263,6 +267,25 @@ function _add_jailkit_user()
263267
$this->app->log("Added created jailkit parent user home in : ".$this->data['new']['dir'].$jailkit_chroot_puserhome,LOGLEVEL_DEBUG);
264268
}
265269

270+
//* Update the website root directory permissions depending on the security level
271+
function _update_website_security_level() {
272+
global $app,$conf;
273+
274+
// load the server configuration options
275+
$app->uses("getconf");
276+
$web_config = $app->getconf->get_server_config($conf["server_id"], 'web');
277+
278+
// Get the parent website of this shell user
279+
$web = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain_id = ".$this->data['new']['parent_domain_id']);
280+
281+
//* If the security level is set to high
282+
if($web_config['security_level'] == 20) {
283+
exec("chmod 755 ".escapeshellcmd($web["document_root"]."/"));
284+
exec("chown root:root ".escapeshellcmd($web["document_root"]."/"));
285+
}
286+
287+
}
288+
266289

267290

268291
} // end class

0 commit comments

Comments
 (0)