From d2212dda734bb8c4b899faab848fa1bd7c1bf66e Mon Sep 17 00:00:00 2001 From: tbrehm <t.brehm@ispconfig.org> Date: Sun, 19 Sep 2010 08:01:47 -0400 Subject: [PATCH] Fixed bug in maildirmake function: http://www.howtoforge.com/forums/showthread.php?t=48890 --- server/plugins-available/shelluser_base_plugin.inc.php | 55 +++++++++++++++++++++++++++++++++++++++++-------------- 1 files changed, 41 insertions(+), 14 deletions(-) diff --git a/server/plugins-available/shelluser_base_plugin.inc.php b/server/plugins-available/shelluser_base_plugin.inc.php index bf834c7..69348f5 100755 --- a/server/plugins-available/shelluser_base_plugin.inc.php +++ b/server/plugins-available/shelluser_base_plugin.inc.php @@ -77,22 +77,36 @@ $uid = intval($app->system->getuid($data['new']['puser'])); if($uid > $this->min_uid) { $command = 'useradd'; - $command .= ' --home '.escapeshellcmd($data['new']['dir']); - $command .= ' --gid '.escapeshellcmd($data['new']['pgroup']); - $command .= ' --non-unique '; - $command .= ' --password '.escapeshellcmd($data['new']['password']); - $command .= ' --shell '.escapeshellcmd($data['new']['shell']); - $command .= ' --uid '.escapeshellcmd($uid); + $command .= ' -d '.escapeshellcmd($data['new']['dir']); + $command .= ' -g '.escapeshellcmd($data['new']['pgroup']); + $command .= ' -o '; // non unique + if($data['new']['password'] != '') $command .= ' -p '.escapeshellcmd($data['new']['password']); + $command .= ' -s '.escapeshellcmd($data['new']['shell']); + $command .= ' -u '.escapeshellcmd($uid); $command .= ' '.escapeshellcmd($data['new']['username']); exec($command); + $app->log("Executed command: ".$command,LOGLEVEL_DEBUG); $app->log("Added shelluser: ".$data['new']['username'],LOGLEVEL_DEBUG); + + //* Create .bash_history file + touch(escapeshellcmd($data['new']['dir']).'/.bash_history'); + chmod(escapeshellcmd($data['new']['dir']).'/.bash_history', 0755); + chown(escapeshellcmd($data['new']['dir']).'/.bash_history', escapeshellcmd($data['new']['username'])); + chgrp(escapeshellcmd($data['new']['dir']).'/.bash_history', escapeshellcmd($data['new']['pgroup'])); + + //* Disable shell user temporarily if we use jailkit + if($data['new']['chroot'] == 'jailkit') { + $command = 'usermod -s /bin/false -L '.escapeshellcmd($data['new']['username']); + exec($command); + $app->log("Disabling shelluser temporarily: ".$command,LOGLEVEL_DEBUG); + } } else { $app->log("UID = $uid for shelluser:".$data['new']['username']." not allowed.",LOGLEVEL_ERROR); } } else { - $app->log("Skippung insert of user:".$data['new']['username'].", parent user ".$data['new']['puser']." does not exist.",LOGLEVEL_WARN); + $app->log("Skipping insertion of user:".$data['new']['username'].", parent user ".$data['new']['puser']." does not exist.",LOGLEVEL_WARN); } } @@ -118,8 +132,18 @@ $command .= ' '.escapeshellcmd($data['old']['username']); exec($command); - // $app->log("Updated shelluser: $command ",LOGLEVEL_DEBUG); + $app->log("Executed command: $command ",LOGLEVEL_DEBUG); $app->log("Updated shelluser: ".$data['old']['username'],LOGLEVEL_DEBUG); + + + //* Create .bash_history file + if(!is_file($data['new']['dir']).'/.bash_history') { + touch(escapeshellcmd($data['new']['dir']).'/.bash_history'); + chmod(escapeshellcmd($data['new']['dir']).'/.bash_history', 0755); + chown(escapeshellcmd($data['new']['dir']).'/.bash_history',escapeshellcmd($data['new']['username'])); + chgrp(escapeshellcmd($data['new']['dir']).'/.bash_history',escapeshellcmd($data['new']['pgroup'])); + } + } else { // The user does not exist, so we insert it now $this->insert($event_name,$data); @@ -128,7 +152,7 @@ $app->log("UID = $uid for shelluser:".$data['new']['username']." not allowed.",LOGLEVEL_ERROR); } } else { - $app->log("Skippung update for user:".$data['new']['username'].", parent user ".$data['new']['puser']." does not exist.",LOGLEVEL_WARN); + $app->log("Skipping update for user:".$data['new']['username'].", parent user ".$data['new']['puser']." does not exist.",LOGLEVEL_WARN); } } @@ -141,11 +165,14 @@ // Get the UID of the user $userid = intval($app->system->getuid($data['old']['username'])); if($userid > $this->min_uid) { - $command = 'userdel'; - $command .= ' '.escapeshellcmd($data['old']['username']); + // We delete only non jailkit users, jailkit users will be deleted by the jailkit plugin. + if ($data['old']['chroot'] != "jailkit") { + $command = 'userdel -f'; + $command .= ' '.escapeshellcmd($data['old']['username']); - exec($command); - $app->log("Deleted shelluser: ".$data['old']['username'],LOGLEVEL_DEBUG); + exec($command); + $app->log("Deleted shelluser: ".$data['old']['username'],LOGLEVEL_DEBUG); + } } else { $app->log("UID = $userid for shelluser:".$data['old']['username']." not allowed.",LOGLEVEL_ERROR); @@ -161,4 +188,4 @@ } // end class -?> \ No newline at end of file +?> -- Gitblit v1.9.1