[Fusionforge-commits] r7850 - in branches/Branch_4_8/gforge/common/include: . system

Julien HEYMAN jheyman at libremir.placard.fr.eu.org
Thu Jun 18 12:33:44 CEST 2009


Author: jheyman
Date: 2009-06-18 12:33:43 +0200 (Thu, 18 Jun 2009)
New Revision: 7850

Modified:
   branches/Branch_4_8/gforge/common/include/Group.class.php
   branches/Branch_4_8/gforge/common/include/System.class.php
   branches/Branch_4_8/gforge/common/include/User.class.php
   branches/Branch_4_8/gforge/common/include/account.php
   branches/Branch_4_8/gforge/common/include/system/pgsql.class.php
Log:
Check if user/group name is not used by user/group

Modified: branches/Branch_4_8/gforge/common/include/Group.class.php
===================================================================
--- branches/Branch_4_8/gforge/common/include/Group.class.php	2009-06-17 21:29:35 UTC (rev 7849)
+++ branches/Branch_4_8/gforge/common/include/Group.class.php	2009-06-18 10:33:43 UTC (rev 7850)
@@ -282,6 +282,7 @@
 	function create(&$user, $group_name, $unix_name, $description, $purpose, $unix_box='shell1', $scm_box='cvs1', $is_public=1) {
 		// $user is ignored - anyone can create pending group
 
+		global $SYS;
 		if ($this->getID()!=0) {
 			$this->setError(_('Group::create: Group object already exists'));
 			return false;
@@ -290,6 +291,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: branches/Branch_4_8/gforge/common/include/System.class.php
===================================================================
--- branches/Branch_4_8/gforge/common/include/System.class.php	2009-06-17 21:29:35 UTC (rev 7849)
+++ branches/Branch_4_8/gforge/common/include/System.class.php	2009-06-18 10:33:43 UTC (rev 7850)
@@ -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: branches/Branch_4_8/gforge/common/include/User.class.php
===================================================================
--- branches/Branch_4_8/gforge/common/include/User.class.php	2009-06-17 21:29:35 UTC (rev 7849)
+++ branches/Branch_4_8/gforge/common/include/User.class.php	2009-06-18 10:33:43 UTC (rev 7850)
@@ -215,6 +215,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;
@@ -248,6 +249,10 @@
 			$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: branches/Branch_4_8/gforge/common/include/account.php
===================================================================
--- branches/Branch_4_8/gforge/common/include/account.php	2009-06-17 21:29:35 UTC (rev 7849)
+++ branches/Branch_4_8/gforge/common/include/account.php	2009-06-18 10:33:43 UTC (rev 7850)
@@ -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: branches/Branch_4_8/gforge/common/include/system/pgsql.class.php
===================================================================
--- branches/Branch_4_8/gforge/common/include/system/pgsql.class.php	2009-06-17 21:29:35 UTC (rev 7849)
+++ branches/Branch_4_8/gforge/common/include/system/pgsql.class.php	2009-06-18 10:33:43 UTC (rev 7850)
@@ -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 Fusionforge-commits mailing list