[evolvis-commits] r13489: Check if user/group name is not used by user/group

mirabilos at evolvis.org mirabilos at evolvis.org
Mon Feb 28 02:39:53 CET 2011


Author: mirabilos
Date: 2011-02-28 02:39:52 +0100 (Mon, 28 Feb 2011)
New Revision: 13489

Modified:
   trunk/gforge_base/evolvisforge-5.1/gforge/common/include/Group.class.php
   trunk/gforge_base/evolvisforge-5.1/gforge/common/include/System.class.php
   trunk/gforge_base/evolvisforge-5.1/gforge/common/include/User.class.php
   trunk/gforge_base/evolvisforge-5.1/gforge/common/include/account.php
   trunk/gforge_base/evolvisforge-5.1/gforge/common/include/system/pgsql.class.php
Log:
Check if user/group name is not used by user/group

Modified: trunk/gforge_base/evolvisforge-5.1/gforge/common/include/Group.class.php
===================================================================
--- trunk/gforge_base/evolvisforge-5.1/gforge/common/include/Group.class.php	2011-02-28 01:39:50 UTC (rev 13488)
+++ trunk/gforge_base/evolvisforge-5.1/gforge/common/include/Group.class.php	2011-02-28 01:39:52 UTC (rev 13489)
@@ -283,6 +283,7 @@
 	function create(&$user, $group_name, $unix_name, $description, $purpose, $unix_box='shell1', $scm_box='cvs1', $is_public=1, $send_mail=true) {
 		// $user is ignored - anyone can create pending group
 
+		global $SYS;
 		if ($this->getID()!=0) {
 			$this->setError(_('Group::create: Group object already exists'));
 			return false;
@@ -291,6 +292,9 @@
 		} else if (!account_groupnamevalid($unix_name)) {
 			$this->setError(_('Invalid Unix name'));
 			return false;
+		} else if (!$SYS->sysUseUnixName($unix_name)) {
+			$this->setError(_('Unix name already taken'));
+			return false;
 		} else if (db_numrows(db_query_params('SELECT group_id FROM groups WHERE unix_group_name=$1',
 						      array ($unix_name))) > 0) {
 			$this->setError(_('Unix name already taken'));

Modified: trunk/gforge_base/evolvisforge-5.1/gforge/common/include/System.class.php
===================================================================
--- trunk/gforge_base/evolvisforge-5.1/gforge/common/include/System.class.php	2011-02-28 01:39:50 UTC (rev 13488)
+++ trunk/gforge_base/evolvisforge-5.1/gforge/common/include/System.class.php	2011-02-28 01:39:52 UTC (rev 13489)
@@ -34,6 +34,17 @@
 		return true;
 	}
 
+	/**
+	* sysUseUnixName() - Check if user/group used the unix_name
+	*
+	* @param		string   The unix_name to check
+	* @returns true if used/false is free
+	*
+	*/
+	function sysUseUnixName($unix_name) {
+		return true;
+	}
+
 	/*
  	* User management functions
  	*/

Modified: trunk/gforge_base/evolvisforge-5.1/gforge/common/include/User.class.php
===================================================================
--- trunk/gforge_base/evolvisforge-5.1/gforge/common/include/User.class.php	2011-02-28 01:39:50 UTC (rev 13488)
+++ trunk/gforge_base/evolvisforge-5.1/gforge/common/include/User.class.php	2011-02-28 01:39:52 UTC (rev 13489)
@@ -236,6 +236,7 @@
 	function create($unix_name,$firstname,$lastname,$password1,$password2,$email,
 		$mail_site,$mail_va,$language_id,$timezone,$jabber_address,$jabber_only,$theme_id,
 		$unix_box='shell',$address='',$address2='',$phone='',$fax='',$title='',$ccode='US',$send_mail=true) {
+		global $SYS;
 		if (!$theme_id) {
 			$this->setError(_('You must supply a theme'));
 			return false;
@@ -266,6 +267,15 @@
 			$this->setError(_('Invalid Password:'));
 			return false;
 		}
+		$unix_name=strtolower($unix_name);
+		if (!account_namevalid($unix_name)) {
+			$this->setError(_('Invalid Unix Name.'));
+			return false;
+		}
+		if (!$SYS->sysUseUnixName($unix_name)) {
+			$this->setError(_('Unix name already taken'));
+			return false;
+		}
 		if (!validate_email($email)) {
 			$this->setError(_('Invalid Email Address'));
 			return false;

Modified: trunk/gforge_base/evolvisforge-5.1/gforge/common/include/account.php
===================================================================
--- trunk/gforge_base/evolvisforge-5.1/gforge/common/include/account.php	2011-02-28 01:39:50 UTC (rev 13488)
+++ trunk/gforge_base/evolvisforge-5.1/gforge/common/include/account.php	2011-02-28 01:39:52 UTC (rev 13489)
@@ -73,9 +73,15 @@
 		$GLOBALS['register_error'] = _('Name is reserved.');
 		return 0;
 	}
-	if ( exec("getent passwd $name") != "" ){
-		$GLOBALS['register_error'] = _('That username already exists.');
-		return 0;
+	if ($sys_use_shell) {
+		if ( exec("getent passwd $name") != "" ){
+			$GLOBALS['register_error'] = _('That username already exists.');
+			return 0;
+		}
+		if ( exec("getent group $name") != "" ){
+			$GLOBALS['register_error'] = _('That username already exists.');
+			return 0;
+		}
 	}
 	if (eregi("^(anoncvs_)",$name)) {
 		$GLOBALS['register_error'] = _('Name is reserved for CVS.');

Modified: trunk/gforge_base/evolvisforge-5.1/gforge/common/include/system/pgsql.class.php
===================================================================
--- trunk/gforge_base/evolvisforge-5.1/gforge/common/include/system/pgsql.class.php	2011-02-28 01:39:50 UTC (rev 13488)
+++ trunk/gforge_base/evolvisforge-5.1/gforge/common/include/system/pgsql.class.php	2011-02-28 01:39:52 UTC (rev 13489)
@@ -59,6 +59,24 @@
 		return true;
 	}
 
+	/**
+	* sysUseUnixName() - Check if user/group used the unix_name
+	*
+	* @param		string   The unix_name to check
+	* @returns true if used/false is free
+	*
+	*/
+	function sysUseUnixName($unix_name) {
+		$res1 = db_query_params ('SELECT user_id FROM users
+		                          WHERE user_name=$1',array($unix_name));
+		$res2 = db_query_params ('SELECT group_id FROM groups
+		                          WHERE unix_group_name=$1',array($unix_name));
+		if ( db_numrows($res1) == 0 && db_numrows($res2) == 0 ){
+			return true;
+		}
+		return false;
+	}
+
 	/*
  	* User management functions
  	*/



More information about the evolvis-commits mailing list