2007-11-15 19:07:24 +01:00
|
|
|
<?php
|
|
|
|
/*******************************************************************************
|
|
|
|
* Copyright (C) 2007 Easter-eggs
|
|
|
|
* http://ldapsaisie.labs.libre-entreprise.org
|
|
|
|
*
|
|
|
|
* Author: See AUTHORS file in top-level directory.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License version 2
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
|
|
|
******************************************************************************/
|
|
|
|
|
2009-01-12 11:57:27 +01:00
|
|
|
// Messages d'erreur
|
|
|
|
|
|
|
|
// Support
|
2009-01-25 15:37:03 +01:00
|
|
|
LSerror :: defineError('SAMBA_SUPPORT_01',
|
2009-03-13 22:32:08 +01:00
|
|
|
_("SAMBA Support : Unable to load smbHash class.")
|
2009-01-12 11:57:27 +01:00
|
|
|
);
|
2009-01-25 15:37:03 +01:00
|
|
|
LSerror :: defineError('SAMBA_SUPPORT_02',
|
2009-02-14 00:06:58 +01:00
|
|
|
_("SAMBA Support : The constant %{const} is not defined.")
|
2009-01-12 11:57:27 +01:00
|
|
|
);
|
|
|
|
|
2009-01-25 15:37:03 +01:00
|
|
|
LSerror :: defineError('SAMBA_SUPPORT_03',
|
2009-03-15 22:06:18 +01:00
|
|
|
_("SAMBA Support : The constants LS_SAMBA_SID_BASE_USER and LS_SAMBA_SID_BASE_GROUP must'nt have the same parity to keep SambaSID's unicity.")
|
2009-01-12 11:57:27 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
// Autres erreurs
|
2009-01-25 15:37:03 +01:00
|
|
|
LSerror :: defineError('SAMBA_01',
|
2009-04-15 16:06:11 +02:00
|
|
|
_("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.")
|
2009-01-12 11:57:27 +01:00
|
|
|
);
|
2007-11-15 19:07:24 +01:00
|
|
|
|
2009-12-24 15:02:30 +01:00
|
|
|
// CONSTANTES
|
|
|
|
|
|
|
|
// Le temps infini au sens NT
|
|
|
|
define('LS_SAMBA_INFINITY_TIME',2147483647);
|
|
|
|
|
2008-05-15 12:56:55 +02:00
|
|
|
/**
|
2007-11-15 19:07:24 +01:00
|
|
|
* Verification du support Samba par ldapSaisie
|
2008-02-12 18:59:44 +01:00
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* @retval boolean true si Samba est pleinement supporté, false sinon
|
2008-02-12 18:59:44 +01:00
|
|
|
*/
|
|
|
|
function LSaddon_samba_support() {
|
|
|
|
|
|
|
|
$retval=true;
|
|
|
|
|
|
|
|
// Dependance de librairie
|
|
|
|
if ( !class_exists('smbHash') ) {
|
2009-01-21 18:08:09 +01:00
|
|
|
if ( !LSsession::includeFile(LS_LIB_DIR . 'class.smbHash.php') ) {
|
2009-01-24 18:45:14 +01:00
|
|
|
LSerror :: addErrorCode('SAMBA_SUPPORT_01');
|
2008-02-12 18:59:44 +01:00
|
|
|
$retval=false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$MUST_DEFINE_CONST= array(
|
|
|
|
'LS_SAMBA_DOMAIN_SID',
|
2010-11-10 12:03:12 +01:00
|
|
|
'LS_SAMBA_DOMAIN_NAME',
|
2010-11-15 15:06:06 +01:00
|
|
|
'LS_SAMBA_HOME_PATH_FORMAT',
|
2009-04-15 16:06:11 +02:00
|
|
|
'LS_SAMBA_DOMAIN_OBJECT_DN',
|
2008-02-12 18:59:44 +01:00
|
|
|
'LS_SAMBA_SID_BASE_USER',
|
|
|
|
'LS_SAMBA_SID_BASE_GROUP',
|
|
|
|
'LS_SAMBA_UIDNUMBER_ATTR',
|
|
|
|
'LS_SAMBA_GIDNUMBER_ATTR',
|
|
|
|
'LS_SAMBA_USERPASSWORD_ATTR'
|
|
|
|
);
|
|
|
|
|
|
|
|
foreach($MUST_DEFINE_CONST as $const) {
|
2009-01-12 11:57:27 +01:00
|
|
|
if ( (!defined($const)) || (constant($const) == "")) {
|
2009-01-24 18:45:14 +01:00
|
|
|
LSerror :: addErrorCode('SAMBA_SUPPORT_02',$const);
|
2008-02-12 18:59:44 +01:00
|
|
|
$retval=false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-25 16:09:27 +02:00
|
|
|
// Pour l'intégrité des SID
|
2008-02-12 18:59:44 +01:00
|
|
|
if ( (LS_SAMBA_SID_BASE_USER % 2) == (LS_SAMBA_SID_BASE_GROUP % 2) ) {
|
2009-01-24 18:45:14 +01:00
|
|
|
LSerror :: addErrorCode('SAMBA_SUPPORT_03');
|
2008-02-12 18:59:44 +01:00
|
|
|
$retval=false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $retval;
|
|
|
|
}
|
2007-11-15 19:07:24 +01:00
|
|
|
|
2008-05-15 12:56:55 +02:00
|
|
|
/**
|
2008-12-05 19:46:31 +01:00
|
|
|
* Generation de sambaSID d'un utilisateur
|
2008-02-12 18:59:44 +01:00
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
|
|
|
* Number = LS_SAMBA_UIDNUMBER_ATTR * 2 + LS_SAMBA_SID_BASE_USER
|
|
|
|
* sambaSID = LS_SAMBA_DOMAIN_SID-Number
|
|
|
|
*
|
|
|
|
* @param[in] $ldapObject L'objet ldap
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* @retval string SambaSID ou false si il y a un problème durant la génération
|
2008-02-12 18:59:44 +01:00
|
|
|
*/
|
2008-12-05 19:46:31 +01:00
|
|
|
function generate_sambaUserSID($ldapObject) {
|
2008-02-12 18:59:44 +01:00
|
|
|
if ( get_class($ldapObject -> attrs[ LS_SAMBA_UIDNUMBER_ATTR ]) != 'LSattribute' ) {
|
2009-01-24 18:45:14 +01:00
|
|
|
LSerror :: addErrorCode('SAMBA_01',array('dependency' => LS_SAMBA_UIDNUMBER_ATTR, 'attr' => 'sambaSID'));
|
2008-02-12 18:59:44 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-05-15 12:56:55 +02:00
|
|
|
$uidnumber_attr_val = $ldapObject -> attrs[ LS_SAMBA_UIDNUMBER_ATTR ] -> getValue();
|
|
|
|
$uidnumber_attr_val = $uidnumber_attr_val[0];
|
2008-05-05 16:39:41 +02:00
|
|
|
$uidNumber = $uidnumber_attr_val * 2 + LS_SAMBA_SID_BASE_USER;
|
2008-02-12 18:59:44 +01:00
|
|
|
$sambaSID = LS_SAMBA_DOMAIN_SID . '-' . $uidNumber;
|
|
|
|
|
|
|
|
return ($sambaSID);
|
|
|
|
}
|
2008-12-05 19:46:31 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Generation de sambaSID d'un groupe
|
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
|
|
|
* Number = LS_SAMBA_GIDNUMBER_ATTR * 2 + LS_SAMBA_SID_BASE_GROUP
|
|
|
|
* sambaSID = LS_SAMBA_DOMAIN_SID-Number
|
|
|
|
*
|
|
|
|
* @param[in] $ldapObject L'objet ldap
|
|
|
|
*
|
|
|
|
* @retval string SambaSID ou false si il y a un problème durant la génération
|
|
|
|
*/
|
|
|
|
function generate_sambaGroupSID($ldapObject) {
|
|
|
|
if ( get_class($ldapObject -> attrs[ LS_SAMBA_GIDNUMBER_ATTR ]) != 'LSattribute' ) {
|
2009-01-24 18:45:14 +01:00
|
|
|
LSerror :: addErrorCode('SAMBA_01',array('dependency' => LS_SAMBA_GIDNUMBER_ATTR, 'attr' => 'sambaSID'));
|
2008-12-05 19:46:31 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$gidnumber_attr_val = $ldapObject -> attrs[ LS_SAMBA_GIDNUMBER_ATTR ] -> getValue();
|
|
|
|
$gidnumber_attr_val = $gidnumber_attr_val[0];
|
|
|
|
$gidNumber = $gidnumber_attr_val * 2 + LS_SAMBA_SID_BASE_GROUP;
|
|
|
|
$sambaSID = LS_SAMBA_DOMAIN_SID . '-' . $gidNumber;
|
|
|
|
|
|
|
|
return ($sambaSID);
|
|
|
|
}
|
2007-11-15 19:07:24 +01:00
|
|
|
|
2008-05-15 12:56:55 +02:00
|
|
|
/**
|
2008-02-12 18:59:44 +01:00
|
|
|
* Generation de sambaPrimaryGroupSID
|
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
|
|
|
* Number = LS_SAMBA_GIDNUMBER_ATTR * 2 + LS_SAMBA_SID_BASE_GROUP
|
|
|
|
* sambaSID = LS_SAMBA_DOMAIN_SID-Number
|
|
|
|
*
|
|
|
|
* @param[in] $ldapObject L'objet ldap
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* @retval string sambaPrimaryGroupSID ou false si il y a un problème durant la génération
|
2008-02-12 18:59:44 +01:00
|
|
|
*/
|
|
|
|
function generate_sambaPrimaryGroupSID($ldapObject) {
|
|
|
|
if ( get_class($ldapObject -> attrs[ LS_SAMBA_GIDNUMBER_ATTR ]) != 'LSattribute' ) {
|
2009-04-15 16:06:11 +02:00
|
|
|
LSerror :: addErrorCode('SAMBA_01',array('dependency' => LS_SAMBA_GIDNUMBER_ATTR, 'attr' => 'sambaPrimaryGroupSID'));
|
2008-02-12 18:59:44 +01:00
|
|
|
return;
|
|
|
|
}
|
2008-07-31 11:16:25 +02:00
|
|
|
|
|
|
|
$gidNumber = $ldapObject -> attrs[ LS_SAMBA_GIDNUMBER_ATTR ] -> getValue();
|
|
|
|
$gidNumber = $gidNumber[0] * 2 + LS_SAMBA_SID_BASE_GROUP;
|
2008-02-12 18:59:44 +01:00
|
|
|
$sambaPrimaryGroupSID = LS_SAMBA_DOMAIN_SID . '-' . $gidNumber;
|
|
|
|
|
|
|
|
return ($sambaPrimaryGroupSID);
|
|
|
|
}
|
2007-11-15 19:07:24 +01:00
|
|
|
|
2008-05-15 12:56:55 +02:00
|
|
|
/**
|
2008-02-12 18:59:44 +01:00
|
|
|
* Generation de sambaNTPassword
|
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
|
|
|
* @param[in] $ldapObject L'objet ldap
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* @retval string sambaNTPassword ou false si il y a un problème durant la génération
|
2008-02-12 18:59:44 +01:00
|
|
|
*/
|
|
|
|
function generate_sambaNTPassword($ldapObject) {
|
2007-11-15 19:07:24 +01:00
|
|
|
if ( get_class($ldapObject -> attrs[ LS_SAMBA_USERPASSWORD_ATTR ]) != 'LSattribute' ) {
|
2009-04-15 16:06:11 +02:00
|
|
|
LSerror :: addErrorCode('SAMBA_01',array('dependency' => LS_SAMBA_USERPASSWORD_ATTR, 'attr' => 'sambaNTPassword'));
|
2007-11-15 19:07:24 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-02-12 18:59:44 +01:00
|
|
|
$password = $ldapObject -> attrs[ LS_SAMBA_USERPASSWORD_ATTR ] -> ldap -> getClearPassword();
|
|
|
|
$sambapassword = new smbHash;
|
|
|
|
$sambaNTPassword = $sambapassword -> nthash($password);
|
2007-11-15 19:07:24 +01:00
|
|
|
|
2008-02-12 18:59:44 +01:00
|
|
|
if($sambaNTPassword == '') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
return $sambaNTPassword;
|
|
|
|
}
|
2007-11-15 19:07:24 +01:00
|
|
|
|
2008-05-15 12:56:55 +02:00
|
|
|
/**
|
2008-02-12 18:59:44 +01:00
|
|
|
* Generation de sambaLMPassword
|
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
|
|
|
* @param[in] $ldapObject L'objet ldap
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* @retval string sambaLMPassword ou false si il y a un problème durant la génération
|
2008-02-12 18:59:44 +01:00
|
|
|
*/
|
|
|
|
function generate_sambaLMPassword($ldapObject) {
|
2007-11-15 19:07:24 +01:00
|
|
|
if ( get_class($ldapObject -> attrs[ LS_SAMBA_USERPASSWORD_ATTR ]) != 'LSattribute' ) {
|
2009-04-15 16:06:11 +02:00
|
|
|
LSerror :: addErrorCode('SAMBA_01',array('dependency' => LS_SAMBA_USERPASSWORD_ATTR, 'attr' => 'sambaLMPassword'));
|
2007-11-15 19:07:24 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-02-12 18:59:44 +01:00
|
|
|
$password = $ldapObject -> attrs[ LS_SAMBA_USERPASSWORD_ATTR ] -> ldap -> getClearPassword();
|
|
|
|
$sambapassword = new smbHash;
|
|
|
|
$sambaLMPassword = $sambapassword -> lmhash($password);
|
2007-11-15 19:07:24 +01:00
|
|
|
|
2008-02-12 18:59:44 +01:00
|
|
|
if($sambaLMPassword == '') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
return $sambaLMPassword;
|
|
|
|
}
|
2007-11-15 19:07:24 +01:00
|
|
|
|
2009-04-15 16:06:11 +02:00
|
|
|
/**
|
|
|
|
* Generation de uidNumber en utilisant l'objet sambaDomain
|
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
|
|
|
* @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 <brenard@easter-eggs.com>
|
|
|
|
*
|
|
|
|
* @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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-24 15:02:30 +01:00
|
|
|
/**
|
|
|
|
* Retourne le temps infini au sens NT
|
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
|
|
|
* @param[in] $ldapObject L'objet ldap
|
|
|
|
*
|
|
|
|
* @retval integer le temps infinie au sens NT
|
|
|
|
*/
|
|
|
|
function return_sambaInfinityTime($ldapObject) {
|
|
|
|
return LS_SAMBA_INFINITY_TIME;
|
|
|
|
}
|
|
|
|
|
2010-02-16 17:48:45 +01:00
|
|
|
/**
|
|
|
|
* Generation de l'attribut sambaPwdLastSet
|
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
|
|
|
* @param[in] $ldapObject L'objet ldap
|
|
|
|
*
|
|
|
|
* @retval string sambaPwdLastSet
|
|
|
|
*/
|
|
|
|
function generate_sambaPwdLastSet($ldapObject) {
|
|
|
|
return time();
|
|
|
|
}
|
|
|
|
|
2010-11-10 12:03:12 +01:00
|
|
|
/**
|
|
|
|
* Generation du sambaDomainName
|
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
|
|
|
* @retval string Le sambaDomainName
|
|
|
|
*/
|
|
|
|
function generate_sambaDomainName($ldapObject) {
|
|
|
|
return LS_SAMBA_DOMAIN_NAME;
|
|
|
|
}
|
|
|
|
|
2010-11-10 17:45:03 +01:00
|
|
|
/**
|
|
|
|
* Generation du sambaHomePath
|
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
|
|
|
* @retval string Le sambaHomePath
|
|
|
|
*/
|
|
|
|
function generate_sambaHomePath($ldapObject) {
|
|
|
|
return $ldapObject -> getFData(LS_SAMBA_HOME_PATH_FORMAT);
|
|
|
|
}
|
|
|
|
|
2007-11-15 19:07:24 +01:00
|
|
|
?>
|