From 6f22dd091c3dba63b1bc49d585e271c148a415d1 Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Wed, 15 Apr 2009 14:06:11 +0000 Subject: [PATCH] - LSaddon::Samba : - Ajout des functions suivantes : - generate_uidNumber_withSambaDomainObject() - generate_gidNumber_withSambaDomainObject() - Correction d'utilisation de message d'erreur n'existant plus --- trunk/conf/LSaddons/config.LSaddons.samba.php | 3 + .../LSobjects/config.LSobjects.LSeegroup.php | 2 +- .../LSobjects/config.LSobjects.LSeepeople.php | 2 +- trunk/includes/addons/LSaddons.samba.php | 84 ++++++++++++++++++- 4 files changed, 85 insertions(+), 6 deletions(-) diff --git a/trunk/conf/LSaddons/config.LSaddons.samba.php b/trunk/conf/LSaddons/config.LSaddons.samba.php index 4826fbd2..e7558ec7 100644 --- a/trunk/conf/LSaddons/config.LSaddons.samba.php +++ b/trunk/conf/LSaddons/config.LSaddons.samba.php @@ -29,6 +29,9 @@ // SID du domaine Samba géré define('LS_SAMBA_DOMAIN_SID','S-1-5-21-2421470416-3566881284-3047381809'); +// Le DN de l'objet sambaDomain du domaine +define('LS_SAMBA_DOMAIN_OBJECT_DN','sambaDomainName=LS,o=ls'); + // Nombre de base pour le calcul des sambaSID Utilisateur define('LS_SAMBA_SID_BASE_USER',1000); diff --git a/trunk/conf/LSobjects/config.LSobjects.LSeegroup.php b/trunk/conf/LSobjects/config.LSobjects.LSeegroup.php index 021f01aa..edf92856 100644 --- a/trunk/conf/LSobjects/config.LSobjects.LSeegroup.php +++ b/trunk/conf/LSobjects/config.LSobjects.LSeegroup.php @@ -77,7 +77,7 @@ $GLOBALS['LSobjects']['LSeegroup'] = array ( 'ldap_type' => 'numeric', 'html_type' => 'text', 'required' => 1, - 'generate_function' => 'generate_gidNumber', + 'generate_function' => 'generate_gidNumber_withSambaDomainObject', 'validation' => array ( array ( 'filter' => 'gidNumber=%{val}', diff --git a/trunk/conf/LSobjects/config.LSobjects.LSeepeople.php b/trunk/conf/LSobjects/config.LSobjects.LSeepeople.php index c104c959..4e2dfdf3 100644 --- a/trunk/conf/LSobjects/config.LSobjects.LSeepeople.php +++ b/trunk/conf/LSobjects/config.LSobjects.LSeepeople.php @@ -169,7 +169,7 @@ $GLOBALS['LSobjects']['LSeepeople'] = array ( 'ldap_type' => 'numeric', 'html_type' => 'text', 'required' => 1, - 'generate_function' => 'generate_uidNumber', + 'generate_function' => 'generate_uidNumber_withSambaDomainObject', 'check_data' => array ( 'numeric' => array( 'msg' => "The numeric identifier must be an integer." diff --git a/trunk/includes/addons/LSaddons.samba.php b/trunk/includes/addons/LSaddons.samba.php index 5804ecec..c43510c4 100644 --- a/trunk/includes/addons/LSaddons.samba.php +++ b/trunk/includes/addons/LSaddons.samba.php @@ -36,7 +36,16 @@ LSerror :: defineError('SAMBA_SUPPORT_03', // Autres erreurs LSerror :: defineError('SAMBA_01', - _("SAMBA Support : The attribute%{dependency} is missing. Unable to forge the attribute %{attr}.") + _("SAMBA Support : The attribute %{dependency} is missing. Unable to forge the attribute %{attr}.") +); +LSerror :: defineError('SAMBA_02', + _("SAMBA Support : Can't get the sambaDomain object.") +); +LSerror :: defineError('SAMBA_03', + _("SAMBA Support : Error modifying the sambaDomain object.") +); +LSerror :: defineError('SAMBA_04', + _("SAMBA Support : The %{attr} of the sambaDomain object is incorrect.") ); /** @@ -61,6 +70,7 @@ LSerror :: defineError('SAMBA_01', $MUST_DEFINE_CONST= array( 'LS_SAMBA_DOMAIN_SID', + 'LS_SAMBA_DOMAIN_OBJECT_DN', 'LS_SAMBA_SID_BASE_USER', 'LS_SAMBA_SID_BASE_GROUP', 'LS_SAMBA_UIDNUMBER_ATTR', @@ -150,7 +160,7 @@ LSerror :: defineError('SAMBA_01', */ function generate_sambaPrimaryGroupSID($ldapObject) { if ( get_class($ldapObject -> attrs[ LS_SAMBA_GIDNUMBER_ATTR ]) != 'LSattribute' ) { - LSerror :: addErrorCode('SAMBA_02',array('dependency' => LS_SAMBA_GIDNUMBER_ATTR, 'attr' => 'sambaPrimaryGroupSID')); + LSerror :: addErrorCode('SAMBA_01',array('dependency' => LS_SAMBA_GIDNUMBER_ATTR, 'attr' => 'sambaPrimaryGroupSID')); return; } @@ -172,7 +182,7 @@ LSerror :: defineError('SAMBA_01', */ function generate_sambaNTPassword($ldapObject) { if ( get_class($ldapObject -> attrs[ LS_SAMBA_USERPASSWORD_ATTR ]) != 'LSattribute' ) { - LSerror :: addErrorCode('SAMBA_03',array('dependency' => LS_SAMBA_USERPASSWORD_ATTR, 'attr' => 'sambaNTPassword')); + LSerror :: addErrorCode('SAMBA_01',array('dependency' => LS_SAMBA_USERPASSWORD_ATTR, 'attr' => 'sambaNTPassword')); return; } @@ -197,7 +207,7 @@ LSerror :: defineError('SAMBA_01', */ function generate_sambaLMPassword($ldapObject) { if ( get_class($ldapObject -> attrs[ LS_SAMBA_USERPASSWORD_ATTR ]) != 'LSattribute' ) { - LSerror :: addErrorCode('SAMBA_04',array('dependency' => LS_SAMBA_USERPASSWORD_ATTR, 'attr' => 'sambaLMPassword')); + LSerror :: addErrorCode('SAMBA_01',array('dependency' => LS_SAMBA_USERPASSWORD_ATTR, 'attr' => 'sambaLMPassword')); return; } @@ -211,4 +221,70 @@ LSerror :: defineError('SAMBA_01', return $sambaLMPassword; } +/** + * Generation de uidNumber en utilisant l'objet sambaDomain + * + * @author Benjamin Renard + * + * @param[in] $ldapObject L'objet ldap + * + * @retval integer uidNumber ou false si il y a un problème durant la génération + */ + function generate_uidNumber_withSambaDomainObject($ldapObject) { + $sambaDomain = LSldap :: getLdapEntry ( LS_SAMBA_DOMAIN_OBJECT_DN ); + if ($sambaDomain === false) { + LSerror :: addErrorCode('SAMBA_02'); + return; + } + + $uidNumber = $sambaDomain->getValue('uidNumber','single'); + if (Net_LDAP2::isError($uidNumber) || $uidNumber==0) { + LSerror :: addErrorCode('SAMBA_04','uidNumber'); + return; + } + + $sambaDomain->replace(array('uidNumber' => ($uidNumber+1))); + $res = $sambaDomain->update(); + if(!Net_LDAP2::isError($res)) { + return $uidNumber; + } + else { + LSerror :: addErrorCode('SAMBA_03'); + return; + } + } + + /** + * Generation de gidNumber en utilisant l'objet sambaDomain + * + * @author Benjamin Renard + * + * @param[in] $ldapObject L'objet ldap + * + * @retval integer gidNumber ou false si il y a un problème durant la génération + */ + function generate_gidNumber_withSambaDomainObject($ldapObject) { + $sambaDomain = LSldap :: getLdapEntry ( LS_SAMBA_DOMAIN_OBJECT_DN ); + if ($sambaDomain === false) { + LSerror :: addErrorCode('SAMBA_02'); + return; + } + + $gidNumber = $sambaDomain->getValue('gidNumber','single'); + if (Net_LDAP2::isError($gidNumber) || $gidNumber==0) { + LSerror :: addErrorCode('SAMBA_04','gidNumber'); + return; + } + + $sambaDomain->replace(array('gidNumber' => ($gidNumber+1))); + $res = $sambaDomain->update(); + if(!Net_LDAP2::isError($res)) { + return $gidNumber; + } + else { + LSerror :: addErrorCode('SAMBA_03'); + return; + } + } + ?>