From 2a3cab868b81cdaca3d30e88f0550a96f298c53b Mon Sep 17 00:00:00 2001
From: tbrehm <t.brehm@ispconfig.org>
Date: Thu, 16 Sep 2010 06:20:59 -0400
Subject: [PATCH] Implemented: FS#1324 - Add new file system path splitter for large installations

---
 server/plugins-available/shelluser_base_plugin.inc.php |   39 ++++++++++++++++++++++++++++-----------
 1 files changed, 28 insertions(+), 11 deletions(-)

diff --git a/server/plugins-available/shelluser_base_plugin.inc.php b/server/plugins-available/shelluser_base_plugin.inc.php
index 151dfda..69348f5 100755
--- a/server/plugins-available/shelluser_base_plugin.inc.php
+++ b/server/plugins-available/shelluser_base_plugin.inc.php
@@ -77,20 +77,27 @@
 			$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 -L '.escapeshellcmd($data['new']['username']);
+					$command = 'usermod -s /bin/false -L '.escapeshellcmd($data['new']['username']);
 					exec($command);
 					$app->log("Disabling shelluser temporarily: ".$command,LOGLEVEL_DEBUG);
 				}
@@ -99,7 +106,7 @@
 				$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);
 		}
 	}
 	
@@ -125,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);
@@ -135,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);
 		}
 	}
 	
@@ -171,4 +188,4 @@
 
 } // end class
 
-?>
\ No newline at end of file
+?>

--
Gitblit v1.9.1