Skip to content

Commit 2bbc4c7

Browse files
committed
Add the website user and group also to the passwd and group files in chroot enviroment.
1 parent bbecbc1 commit 2bbc4c7

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

server/plugins-available/apache2_plugin.inc.php

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,13 @@ function update($event_name,$data) {
235235
$app->uses("getconf");
236236
$web_config = $app->getconf->get_server_config($conf["server_id"], 'web');
237237

238+
//* Check if this is a chrooted setup
239+
if($web_config['website_basedir'] != '' && @is_file($web_config['/var/www'].'/etc/passwd')) {
240+
$apache_chrooted = true;
241+
} else {
242+
$apache_chrooted = false;
243+
}
244+
238245
if($data["new"]["document_root"] == '') {
239246
$app->log("document_root not set",LOGLEVEL_WARN);
240247
return 0;
@@ -292,7 +299,7 @@ function update($event_name,$data) {
292299
$command .= ' '.escapeshellcmd($data["new"]["system_user"]);
293300
exec($command);
294301

295-
302+
if($apache_chrooted) exec("chroot ".escapeshellcmd($web_config['website_basedir'])." ".$command);
296303

297304

298305
}
@@ -438,12 +445,14 @@ function update($event_name,$data) {
438445
$groupname = escapeshellcmd($data["new"]["system_group"]);
439446
if($data["new"]["system_group"] != '' && !$app->system->is_group($data["new"]["system_group"])) {
440447
exec("groupadd $groupname");
448+
if($apache_chrooted) exec("chroot ".escapeshellcmd($web_config['website_basedir'])." groupadd $groupname");
441449
$app->log("Adding the group: $groupname",LOGLEVEL_DEBUG);
442450
}
443451

444452
$username = escapeshellcmd($data["new"]["system_user"]);
445453
if($data["new"]["system_user"] != '' && !$app->system->is_user($data["new"]["system_user"])) {
446454
exec("useradd -d ".escapeshellcmd($data["new"]["document_root"])." -g $groupname -G sshusers $username -s /bin/false");
455+
if($apache_chrooted) exec("chroot ".escapeshellcmd($web_config['website_basedir'])." "."useradd -d ".escapeshellcmd($data["new"]["document_root"])." -g $groupname -G sshusers $username -s /bin/false");
447456
$app->log("Adding the user: $username",LOGLEVEL_DEBUG);
448457
}
449458

@@ -487,6 +496,18 @@ function update($event_name,$data) {
487496
$command .= ' '.escapeshellcmd($data["new"]["system_user"]);
488497
$this->_exec($command);
489498

499+
//* if we have a chrooted apache enviroment
500+
if($apache_chrooted) {
501+
exec("chroot ".escapeshellcmd($web_config['website_basedir'])." ".$command);
502+
503+
//* add the apache user to the client group in the chroot enviroment
504+
$tmp_groupfile = $app->system->server_conf["group_datei"];
505+
$app->system->server_conf["group_datei"] = $web_config['website_basedir'].'/etc/group';
506+
$app->system->add_user_to_group($groupname, escapeshellcmd($web_config['user']));
507+
$app->system->server_conf["group_datei"] = $tmp_groupfile;
508+
unset($tmp_groupfile);
509+
}
510+
490511
//* add the apache user to the client group
491512
$app->system->add_user_to_group($groupname, escapeshellcmd($web_config['user']));
492513

@@ -809,6 +830,12 @@ function delete($event_name,$data) {
809830
$app->uses("getconf");
810831
$web_config = $app->getconf->get_server_config($conf["server_id"], 'web');
811832

833+
//* Check if this is a chrooted setup
834+
if($web_config['website_basedir'] != '' && @is_file($web_config['/var/www'].'/etc/passwd')) {
835+
$apache_chrooted = true;
836+
} else {
837+
$apache_chrooted = false;
838+
}
812839

813840
if($data["old"]["type"] != "vhost" && $data["old"]["parent_domain_id"] > 0) {
814841
//* This is a alias domain or subdomain, so we have to update the website instead
@@ -889,6 +916,8 @@ function delete($event_name,$data) {
889916
$command = 'userdel';
890917
$command .= ' '.$data["old"]["system_user"];
891918
exec($command);
919+
if($apache_chrooted) exec("chroot ".escapeshellcmd($web_config['website_basedir'])." ".$command);
920+
892921
}
893922
}
894923

0 commit comments

Comments
 (0)