2007-03-29 18:10:14 +02: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.
|
|
|
|
|
|
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
|
|
/**
|
2008-04-25 16:09:27 +02:00
|
|
|
|
* Gestion de l'accès à l'annaire Ldap
|
2007-03-29 18:10:14 +02:00
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
|
* Cette classe gère l'accès à l'annuaire ldap en s'appuyant sur PEAR :: Net_LDAP2
|
2007-03-29 18:10:14 +02:00
|
|
|
|
*
|
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
|
*/
|
|
|
|
|
class LSldap {
|
|
|
|
|
|
2009-01-25 15:37:03 +01:00
|
|
|
|
private static $config;
|
|
|
|
|
private static $cnx = NULL;
|
|
|
|
|
|
2007-03-29 18:10:14 +02:00
|
|
|
|
/**
|
2009-01-25 15:37:03 +01:00
|
|
|
|
* D<EFBFBD>fini la configuration
|
2007-03-29 18:10:14 +02:00
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
|
* Cette methode définis la configuration de l'accès à l'annuaire
|
2007-03-29 18:10:14 +02:00
|
|
|
|
*
|
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
|
*
|
2008-04-25 15:48:12 +02:00
|
|
|
|
* @param[in] $config array Tableau de configuration au formar Net_LDAP2
|
2007-03-29 18:10:14 +02:00
|
|
|
|
*
|
|
|
|
|
* @retval void
|
|
|
|
|
*/
|
2009-01-25 15:37:03 +01:00
|
|
|
|
function setConfig ($config) {
|
|
|
|
|
self :: $config = $config;
|
2007-03-29 18:10:14 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Connection
|
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
|
* Cette methode établie la connexion à l'annuaire Ldap
|
2007-03-29 18:10:14 +02:00
|
|
|
|
*
|
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
2009-01-25 15:37:03 +01:00
|
|
|
|
*
|
|
|
|
|
* @param[in] $config array Tableau de configuration au formar Net_LDAP2
|
2007-03-29 18:10:14 +02:00
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
|
* @retval boolean true si la connection est établie, false sinon
|
2007-03-29 18:10:14 +02:00
|
|
|
|
*/
|
2009-01-25 15:37:03 +01:00
|
|
|
|
public static function connect($config = null) {
|
|
|
|
|
if ($config) {
|
|
|
|
|
self :: setConfig($config);
|
|
|
|
|
}
|
|
|
|
|
self :: $cnx = Net_LDAP2::connect(self :: $config);
|
|
|
|
|
if (Net_LDAP2::isError(self :: $cnx)) {
|
|
|
|
|
LSerror :: addErrorCode('LSldap_01',self :: $cnx -> getMessage());
|
|
|
|
|
self :: $cnx = NULL;
|
2007-03-29 18:10:14 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2008-04-25 16:09:27 +02:00
|
|
|
|
* Déconnection
|
2007-03-29 18:10:14 +02:00
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
|
* Cette methode clos la connexion à l'annuaire Ldap
|
2007-03-29 18:10:14 +02:00
|
|
|
|
*
|
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
|
*
|
|
|
|
|
* @retval void
|
|
|
|
|
*/
|
2009-01-25 15:37:03 +01:00
|
|
|
|
public static function close() {
|
|
|
|
|
self :: $cnx -> done();
|
2007-03-29 18:10:14 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Recherche dans l'annuaire
|
|
|
|
|
*
|
|
|
|
|
* Cette methode effectue une recherche dans l'annuaire et retourne le resultat
|
|
|
|
|
* de celle-ci sous la forme d'un tableau.
|
|
|
|
|
*
|
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
|
*
|
|
|
|
|
* @param[in] $filter [<b>required</b>] string Filtre de recherche Ldap
|
|
|
|
|
* @param[in] $basedn string DN de base pour la recherche
|
2008-04-25 16:09:27 +02:00
|
|
|
|
* @param[in] $params array Paramètres de recherche au format Net_LDAP2::search()
|
2007-03-29 18:10:14 +02:00
|
|
|
|
*
|
2008-04-25 15:48:12 +02:00
|
|
|
|
* @see Net_LDAP2::search()
|
2007-03-29 18:10:14 +02:00
|
|
|
|
*
|
|
|
|
|
* @retval array Retourne un tableau associatif contenant :
|
2008-04-25 16:09:27 +02:00
|
|
|
|
* - ['dn'] : le DN de l'entré
|
|
|
|
|
* - ['attrs'] : tableau associatif contenant les attributs (clé)
|
2007-03-29 18:10:14 +02:00
|
|
|
|
* et leur valeur (valeur).
|
|
|
|
|
*/
|
2009-01-25 15:37:03 +01:00
|
|
|
|
public static function search ($filter,$basedn=NULL,$params = array()) {
|
|
|
|
|
$ret = self :: $cnx -> search($basedn,$filter,$params);
|
2008-04-25 15:48:12 +02:00
|
|
|
|
if (Net_LDAP2::isError($ret)) {
|
2009-01-24 18:45:14 +01:00
|
|
|
|
LSerror :: addErrorCode('LSldap_02',$ret -> getMessage());
|
2007-03-29 18:10:14 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
2012-08-02 15:49:52 +02:00
|
|
|
|
LSdebug("LSldap::search() : return ".$ret->count()." objet(s)");
|
2007-03-29 18:10:14 +02:00
|
|
|
|
$retInfos=array();
|
2012-08-02 15:51:49 +02:00
|
|
|
|
foreach($ret as $dn => $entry) {
|
2012-08-02 15:26:02 +02:00
|
|
|
|
if (!$entry instanceof Net_LDAP2_Entry) {
|
|
|
|
|
LSerror :: addErrorCode('LSldap_02',"LDAP search return an ".get_class($entry).". object");
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2012-08-02 15:51:49 +02:00
|
|
|
|
$retInfos[]=array('dn' => $dn, 'attrs' => $entry -> getValues());
|
2007-03-29 18:10:14 +02:00
|
|
|
|
}
|
|
|
|
|
return $retInfos;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Compte le nombre de retour d'une recherche dans l'annuaire
|
|
|
|
|
*
|
|
|
|
|
* Cette methode effectue une recherche dans l'annuaire et retourne le nombre
|
2008-04-25 16:09:27 +02:00
|
|
|
|
* d'entrés trouvées.
|
2007-03-29 18:10:14 +02:00
|
|
|
|
*
|
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
|
*
|
|
|
|
|
* @param[in] $filter [<b>required</b>] string Filtre de recherche Ldap
|
|
|
|
|
* @param[in] $basedn string DN de base pour la recherche
|
2008-04-25 16:09:27 +02:00
|
|
|
|
* @param[in] $params array Paramètres de recherche au format Net_LDAP2::search()
|
2007-03-29 18:10:14 +02:00
|
|
|
|
*
|
2008-04-25 15:48:12 +02:00
|
|
|
|
* @see Net_LDAP2::search()
|
2007-03-29 18:10:14 +02:00
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
|
* @retval numeric Le nombre d'entré trouvées
|
2007-03-29 18:10:14 +02:00
|
|
|
|
*/
|
2009-01-25 15:37:03 +01:00
|
|
|
|
public static function getNumberResult ($filter,$basedn=NULL,$params = array() ) {
|
2007-03-29 18:10:14 +02:00
|
|
|
|
if (empty($filter))
|
|
|
|
|
$filter=NULL;
|
2009-01-25 15:37:03 +01:00
|
|
|
|
$ret = self :: $cnx -> search($basedn,$filter,$params);
|
2008-04-25 15:48:12 +02:00
|
|
|
|
if (Net_LDAP2::isError($ret)) {
|
2009-01-24 18:45:14 +01:00
|
|
|
|
LSerror :: addErrorCode('LSldap_02',$ret -> getMessage());
|
2007-03-29 18:10:14 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
return $ret -> count();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2008-04-25 16:09:27 +02:00
|
|
|
|
* Charge les valeurs des attributs d'une entré de l'annuaire
|
2007-03-29 18:10:14 +02:00
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
|
* Cette methode recupère les valeurs des attributs d'une entrée de l'annaire
|
2007-03-29 18:10:14 +02:00
|
|
|
|
* et les retournes sous la forme d'un tableau.
|
|
|
|
|
*
|
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
|
* @param[in] $dn string DN de l'entré Ldap
|
2007-03-29 18:10:14 +02:00
|
|
|
|
*
|
|
|
|
|
* @retval array Tableau associatif des valeurs des attributs avec en clef, le nom de l'attribut.
|
|
|
|
|
*/
|
2009-01-25 15:37:03 +01:00
|
|
|
|
public static function getAttrs($dn) {
|
2007-03-29 18:10:14 +02:00
|
|
|
|
$infos = ldap_explode_dn($dn,0);
|
|
|
|
|
if((!$infos)||($infos['count']==0))
|
|
|
|
|
return;
|
|
|
|
|
$basedn='';
|
|
|
|
|
for ($i=1;$i<$infos['count'];$i++) {
|
|
|
|
|
$sep=($basedn=='')?'':',';
|
|
|
|
|
$basedn.=$sep.$infos[$i];
|
|
|
|
|
}
|
2009-01-25 15:37:03 +01:00
|
|
|
|
$return=self :: search($infos[0],$basedn);
|
2007-03-29 18:10:14 +02:00
|
|
|
|
return $return[0]['attrs'];
|
|
|
|
|
}
|
2007-11-15 19:07:24 +01:00
|
|
|
|
|
|
|
|
|
/**
|
2008-04-25 16:09:27 +02:00
|
|
|
|
* Retourne une entrée existante ou nouvelle
|
2007-11-15 19:07:24 +01:00
|
|
|
|
*
|
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
|
*
|
|
|
|
|
* @param[in] $object_type string Type de l'objet Ldap
|
2008-04-25 16:09:27 +02:00
|
|
|
|
* @param[in] $dn string DN de l'entré Ldap
|
2007-11-15 19:07:24 +01:00
|
|
|
|
*
|
2008-05-05 16:39:41 +02:00
|
|
|
|
* @retval ldapentry|array Un objet ldapentry (PEAR::Net_LDAP2)
|
2008-05-15 12:01:59 +02:00
|
|
|
|
* ou un tableau (si c'est une nouvelle entr<EFBFBD>e):
|
|
|
|
|
* Array (
|
|
|
|
|
* 'entry' => ldapentry,
|
|
|
|
|
* 'new' => true
|
|
|
|
|
* )
|
2007-11-15 19:07:24 +01:00
|
|
|
|
*/
|
2009-01-25 15:37:03 +01:00
|
|
|
|
public static function getEntry($object_type,$dn) {
|
2009-03-25 18:46:48 +01:00
|
|
|
|
$obj_conf=LSconfig :: get('LSobjects.'.$object_type);
|
|
|
|
|
if(is_array($obj_conf)){
|
2009-04-15 16:04:21 +02:00
|
|
|
|
$entry = self :: getLdapEntry($dn);
|
|
|
|
|
if ($entry === false) {
|
2010-03-16 17:46:10 +01:00
|
|
|
|
$newentry = self :: getNewEntry($dn,$obj_conf['objectclass'],array());
|
2008-08-06 19:04:03 +02:00
|
|
|
|
|
|
|
|
|
if (!$newentry) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2008-05-05 16:39:41 +02:00
|
|
|
|
return array('entry' => $newentry,'new' => true);
|
2007-11-15 19:07:24 +01:00
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return $entry;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
2009-01-24 18:45:14 +01:00
|
|
|
|
LSerror :: addErrorCode('LSldap_03');
|
2007-11-15 19:07:24 +01:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-04-15 16:04:21 +02:00
|
|
|
|
/**
|
|
|
|
|
* Retourne un object NetLDAP d'une entree existante
|
|
|
|
|
*
|
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
|
*
|
|
|
|
|
* @param[in] $dn string DN de l'entré Ldap
|
|
|
|
|
*
|
|
|
|
|
* @retval ldapentry|boolean Un objet ldapentry (PEAR::Net_LDAP2) ou false en
|
|
|
|
|
* cas de probl<EFBFBD>me
|
|
|
|
|
*/
|
|
|
|
|
public static function getLdapEntry($dn) {
|
|
|
|
|
$entry = self :: $cnx -> getEntry($dn);
|
|
|
|
|
if (Net_LDAP2::isError($entry)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return $entry;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-08-06 19:04:03 +02:00
|
|
|
|
/**
|
|
|
|
|
* Retourne une nouvelle entr<EFBFBD>e
|
|
|
|
|
*
|
|
|
|
|
* @param[in] $dn string Le DN de l'objet
|
|
|
|
|
* @param[in] $objectClass array Un tableau contenant les objectClass de l'objet
|
|
|
|
|
* @param[in] $attrs array Un tabeau du type array('attr_name' => attr_value, ...)
|
|
|
|
|
*
|
|
|
|
|
* @retval mixed Le nouvelle objet en cas de succ<EFBFBD>s, false sinon
|
|
|
|
|
*/
|
2009-01-25 15:37:03 +01:00
|
|
|
|
public static function getNewEntry($dn,$objectClass,$attrs,$add=false) {
|
2008-08-06 19:04:03 +02:00
|
|
|
|
$newentry = Net_LDAP2_Entry::createFresh($dn,array_merge(array('objectclass' =>$objectClass),(array)$attrs));
|
|
|
|
|
if(Net_LDAP2::isError($newentry)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if($add) {
|
2009-01-25 15:37:03 +01:00
|
|
|
|
if(!self :: $cnx -> add($newentry)) {
|
2008-08-06 19:04:03 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return $newentry;
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-15 19:07:24 +01:00
|
|
|
|
/**
|
2008-04-25 16:09:27 +02:00
|
|
|
|
* Met à jour une entrée dans l'annuaire
|
2008-02-26 18:40:05 +01:00
|
|
|
|
*
|
|
|
|
|
* Remarque : Supprime les valeurs vides de attributs et les attributs sans valeur.
|
2007-11-15 19:07:24 +01:00
|
|
|
|
*
|
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
|
*
|
|
|
|
|
* @param[in] $object_type string Type de l'objet Ldap
|
2008-04-25 16:09:27 +02:00
|
|
|
|
* @param[in] $dn string DN de l'entré Ldap
|
|
|
|
|
* @param[in] $change array Tableau des modifications à apporter
|
2007-11-15 19:07:24 +01:00
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
|
* @retval boolean true si l'objet a bien été mis à jour, false sinon
|
2007-11-15 19:07:24 +01:00
|
|
|
|
*/
|
2009-01-25 15:37:03 +01:00
|
|
|
|
public static function update($object_type,$dn,$change) {
|
2008-09-26 20:03:56 +02:00
|
|
|
|
LSdebug($change);
|
2008-02-26 18:40:05 +01:00
|
|
|
|
$dropAttr=array();
|
2009-01-25 15:37:03 +01:00
|
|
|
|
$entry=self :: getEntry($object_type,$dn);
|
2008-05-15 12:01:59 +02:00
|
|
|
|
if (is_array($entry)) {
|
|
|
|
|
$new = $entry['new'];
|
|
|
|
|
$entry = $entry['entry'];
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$new = false;
|
|
|
|
|
}
|
2008-05-05 16:39:41 +02:00
|
|
|
|
|
|
|
|
|
if($entry) {
|
2008-02-26 18:40:05 +01:00
|
|
|
|
foreach($change as $attrName => $attrVal) {
|
|
|
|
|
$drop = true;
|
|
|
|
|
if (is_array($attrVal)) {
|
|
|
|
|
foreach($attrVal as $val) {
|
|
|
|
|
if (!empty($val)) {
|
|
|
|
|
$drop = false;
|
|
|
|
|
$changeData[$attrName][]=$val;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-04-25 15:48:12 +02:00
|
|
|
|
else {
|
|
|
|
|
if (!empty($attrVal)) {
|
|
|
|
|
$drop = false;
|
|
|
|
|
$changeData[$attrName][]=$attrVal;
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-02-26 18:40:05 +01:00
|
|
|
|
if($drop) {
|
|
|
|
|
$dropAttr[] = $attrName;
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-11-16 19:49:35 +01:00
|
|
|
|
if (isset($changeData)) {
|
|
|
|
|
$entry -> replace($changeData);
|
|
|
|
|
LSdebug('change : <pre>'.print_r($changeData,true).'</pre>');
|
|
|
|
|
LSdebug('drop : <pre>'.print_r($dropAttr,true).'</pre>');
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
LSdebug('No change');
|
|
|
|
|
}
|
2008-04-25 15:48:12 +02:00
|
|
|
|
|
2008-05-15 12:01:59 +02:00
|
|
|
|
if ($new) {
|
2008-10-14 15:02:03 +02:00
|
|
|
|
LSdebug('LSldap :: add()');
|
2009-01-25 15:37:03 +01:00
|
|
|
|
$ret = self :: $cnx -> add($entry);
|
2008-05-15 12:01:59 +02:00
|
|
|
|
}
|
|
|
|
|
else {
|
2008-10-14 15:02:03 +02:00
|
|
|
|
LSdebug('LSldap :: update()');
|
2008-05-15 12:01:59 +02:00
|
|
|
|
$ret = $entry -> update();
|
|
|
|
|
}
|
|
|
|
|
|
2008-04-25 15:48:12 +02:00
|
|
|
|
if (Net_LDAP2::isError($ret)) {
|
2009-01-24 18:45:14 +01:00
|
|
|
|
LSerror :: addErrorCode('LSldap_05',$dn);
|
|
|
|
|
LSerror :: addErrorCode(0,'NetLdap-Error : '.$ret->getMessage());
|
2007-11-15 19:07:24 +01:00
|
|
|
|
}
|
|
|
|
|
else {
|
2008-05-15 12:01:59 +02:00
|
|
|
|
if (!empty($dropAttr)) {
|
|
|
|
|
foreach($dropAttr as $attr) {
|
2011-04-22 14:24:28 +02:00
|
|
|
|
$value = $entry -> getValue($attr);
|
|
|
|
|
if(Net_LDAP2::isError($value) || empty($value)) {
|
2008-10-15 11:49:49 +02:00
|
|
|
|
// Attribut n'existe pas dans l'annuaire
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2008-10-13 13:37:34 +02:00
|
|
|
|
// M<>thode bugg<67> : suppression impossible de certain attribut
|
|
|
|
|
// exemple : jpegPhoto
|
|
|
|
|
// $entry -> delete($attr);
|
|
|
|
|
$entry -> replace(array($attr =>array()));
|
2008-05-15 12:01:59 +02:00
|
|
|
|
}
|
|
|
|
|
$ret = $entry -> update();
|
|
|
|
|
if (Net_LDAP2::isError($ret)) {
|
2009-01-24 18:45:14 +01:00
|
|
|
|
LSerror :: addErrorCode('LSldap_06');
|
|
|
|
|
LSerror :: addErrorCode(0,'NetLdap-Error : '.$ret->getMessage());
|
2008-05-15 12:01:59 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2007-11-15 19:07:24 +01:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
2009-01-24 18:45:14 +01:00
|
|
|
|
LSerror :: addErrorCode('LSldap_04');
|
2007-11-15 19:07:24 +01:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-02-05 17:11:21 +01:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test de bind
|
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
|
* Cette methode établie une connexion à l'annuaire Ldap et test un bind
|
|
|
|
|
* avec un login et un mot de passe passé en paramètre
|
2008-02-05 17:11:21 +01:00
|
|
|
|
*
|
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
|
* @retval boolean true si la connection à réussi, false sinon
|
2008-02-05 17:11:21 +01:00
|
|
|
|
*/
|
2009-01-25 15:37:03 +01:00
|
|
|
|
public static function checkBind($dn,$pwd) {
|
|
|
|
|
$config = self :: $config;
|
2008-02-12 18:59:44 +01:00
|
|
|
|
$config['binddn'] = $dn;
|
|
|
|
|
$config['bindpw'] = $pwd;
|
2008-04-25 15:48:12 +02:00
|
|
|
|
$cnx = Net_LDAP2::connect($config);
|
|
|
|
|
if (Net_LDAP2::isError($cnx)) {
|
2008-02-05 17:11:21 +01:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2008-02-12 18:59:44 +01:00
|
|
|
|
/**
|
2008-04-25 16:09:27 +02:00
|
|
|
|
* Retourne l'état de la connexion Ldap
|
2008-02-12 18:59:44 +01:00
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
|
* @retval boolean True si le serveur est connecté, false sinon.
|
2008-02-12 18:59:44 +01:00
|
|
|
|
*/
|
2009-01-25 15:37:03 +01:00
|
|
|
|
public static function isConnected() {
|
|
|
|
|
return (self :: $cnx == NULL)?false:true;
|
2008-02-12 18:59:44 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Supprime un objet de l'annuaire
|
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
|
* @param[in] string DN de l'objet à supprimer
|
2008-02-12 18:59:44 +01:00
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
|
* @retval boolean True si l'objet à été supprimé, false sinon
|
2008-02-12 18:59:44 +01:00
|
|
|
|
*/
|
2009-01-25 15:37:03 +01:00
|
|
|
|
public static function remove($dn) {
|
|
|
|
|
$ret = self :: $cnx -> delete($dn,array('recursive' => true));
|
2008-07-29 16:23:47 +02:00
|
|
|
|
if (Net_LDAP2::isError($ret)) {
|
2009-01-24 18:45:14 +01:00
|
|
|
|
LSerror :: addErrorCode(0,'NetLdap-Error : '.$ret->getMessage());
|
2008-07-29 16:23:47 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
2008-02-12 18:59:44 +01:00
|
|
|
|
}
|
2008-02-05 17:11:21 +01:00
|
|
|
|
|
2008-07-29 15:45:02 +02:00
|
|
|
|
/**
|
|
|
|
|
* D<EFBFBD>place un objet LDAP dans l'annuaire
|
|
|
|
|
*
|
|
|
|
|
* @param[in] $old string Le DN actuel
|
|
|
|
|
* @param[in] $new string Le futur DN
|
|
|
|
|
*
|
|
|
|
|
* @retval boolean True si l'objet a <EFBFBD>t<EFBFBD> d<EFBFBD>plac<EFBFBD>, false sinon
|
|
|
|
|
*/
|
2009-01-25 15:37:03 +01:00
|
|
|
|
public static function move($old,$new) {
|
|
|
|
|
$ret = self :: $cnx -> move($old,$new);
|
2008-07-29 16:23:47 +02:00
|
|
|
|
if (Net_LDAP2::isError($ret)) {
|
2009-01-24 18:45:14 +01:00
|
|
|
|
LSerror :: addErrorCode('LSldap_07');
|
|
|
|
|
LSerror :: addErrorCode(0,'NetLdap-Error : '.$ret->getMessage());
|
2008-07-29 16:23:47 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
2008-07-29 15:45:02 +02:00
|
|
|
|
}
|
2009-10-29 23:17:30 +01:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Combine LDAP Filters
|
|
|
|
|
*
|
|
|
|
|
* @params array Array of LDAP filters
|
|
|
|
|
*
|
|
|
|
|
* @retval Net_LDAP2_Filter | False The combined filter or False
|
|
|
|
|
**/
|
|
|
|
|
public static function combineFilters($op,$filters,$asStr=false) {
|
|
|
|
|
if (is_array($filters) && !empty($filters)) {
|
|
|
|
|
if (count($filters)==1) {
|
|
|
|
|
return $filters[0];
|
|
|
|
|
}
|
|
|
|
|
$filter=Net_LDAP2_Filter::combine($op,$filters);
|
|
|
|
|
if (!Net_LDAP2::isError($filter)) {
|
|
|
|
|
if ($asStr) {
|
|
|
|
|
return $filter->asString();
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return $filter;
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-02-03 03:07:30 +01:00
|
|
|
|
else {
|
|
|
|
|
LSerror :: addErrorCode(0,$filter -> getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Check LDAP Filters String
|
|
|
|
|
*
|
|
|
|
|
* @params string A LDAP filter as string
|
|
|
|
|
*
|
|
|
|
|
* @retval boolean True only if the filter could be parsed
|
|
|
|
|
**/
|
|
|
|
|
public static function isValidFilter($filter) {
|
|
|
|
|
if (is_string($filter) && !empty($filter)) {
|
|
|
|
|
$filter=Net_LDAP2_Filter::parse($filter);
|
|
|
|
|
if (!Net_LDAP2::isError($filter)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
LSerror :: addErrorCode(0,$filter -> getMessage());
|
|
|
|
|
}
|
2009-10-29 23:17:30 +01:00
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
2007-03-29 18:10:14 +02:00
|
|
|
|
}
|
|
|
|
|
|
2009-01-02 17:00:25 +01:00
|
|
|
|
/*
|
|
|
|
|
* Error Codes
|
|
|
|
|
*/
|
2009-01-25 15:37:03 +01:00
|
|
|
|
LSerror :: defineError('LSldap_01',
|
|
|
|
|
_("LSldap : Error during the LDAP server connection (%{msg}).")
|
2009-01-02 17:00:25 +01:00
|
|
|
|
);
|
2009-01-25 15:37:03 +01:00
|
|
|
|
LSerror :: defineError('LSldap_02',
|
|
|
|
|
_("LSldap : Error during the LDAP search (%{msg}).")
|
2009-01-02 17:00:25 +01:00
|
|
|
|
);
|
2009-01-25 15:37:03 +01:00
|
|
|
|
LSerror :: defineError('LSldap_03',
|
2009-02-14 00:06:58 +01:00
|
|
|
|
_("LSldap : Object type unknown.")
|
2009-01-02 17:00:25 +01:00
|
|
|
|
);
|
2009-01-25 15:37:03 +01:00
|
|
|
|
LSerror :: defineError('LSldap_04',
|
2009-02-14 00:06:58 +01:00
|
|
|
|
_("LSldap : Error while fetching the LDAP entry.")
|
2009-01-02 17:00:25 +01:00
|
|
|
|
);
|
2009-01-25 15:37:03 +01:00
|
|
|
|
LSerror :: defineError('LSldap_05',
|
2009-02-14 00:06:58 +01:00
|
|
|
|
_("LSldap : Error while changing the LDAP entry (DN : %{dn}).")
|
2009-01-02 17:00:25 +01:00
|
|
|
|
);
|
2009-01-25 15:37:03 +01:00
|
|
|
|
LSerror :: defineError('LSldap_06',
|
2009-02-14 00:06:58 +01:00
|
|
|
|
_("LSldap : Error while deleting empty attributes.")
|
2009-01-02 17:00:25 +01:00
|
|
|
|
);
|
2009-01-25 15:37:03 +01:00
|
|
|
|
LSerror :: defineError('LSldap_07',
|
2009-02-14 00:06:58 +01:00
|
|
|
|
_("LSldap : Error while changing the DN of the object.")
|
2009-01-02 17:00:25 +01:00
|
|
|
|
);
|
2007-11-15 19:07:24 +01:00
|
|
|
|
?>
|