From a934f999e98e5573ca7286af26b0e675a86bb7ef Mon Sep 17 00:00:00 2001 From: Lars Kneschke Date: Sat, 28 Oct 2006 08:38:17 +0000 Subject: [PATCH] restructured ldap connect function - we bind now as ldap admin account to read the info about the ldap server - we now try to use ldap v3 be default and fall back to ldap v2 when v3 fails --- phpgwapi/inc/class.ldap.inc.php | 40 +++++++++++++-------------------- 1 file changed, 16 insertions(+), 24 deletions(-) diff --git a/phpgwapi/inc/class.ldap.inc.php b/phpgwapi/inc/class.ldap.inc.php index 86d120b88f..c723578539 100644 --- a/phpgwapi/inc/class.ldap.inc.php +++ b/phpgwapi/inc/class.ldap.inc.php @@ -128,29 +128,24 @@ return False; } + if(ldap_set_option($this->ds, LDAP_OPT_PROTOCOL_VERSION, 3)) { + $supportedLDAPVersion = 3; + } else { + $supportedLDAPVersion = 2; + } + if(!isset($this->ldapServerInfo[$host])) { - //print "no ldap server info found
"; - if (!($ldapbind = @ldap_bind($this->ds, '', ''))) - { - // try with version 3 ;-) - ldap_set_option($this->ds, LDAP_OPT_PROTOCOL_VERSION, 3); - $ldapbind = ldap_bind($this->ds, '', ''); - } + //error_log("no ldap server info found"); + $ldapbind = ldap_bind($this->ds, $GLOBALS['egw_info']['server']['ldap_root_dn'], $GLOBALS['egw_info']['server']['ldap_root_pw']); + $filter='(objectclass=*)'; $justthese = array('structuralObjectClass','namingContexts','supportedLDAPVersion','subschemaSubentry'); if(($sr = @ldap_read($this->ds, '', $filter, $justthese))) { if($info = ldap_get_entries($this->ds, $sr)) { - $ldapServerInfo = new ldapserverinfo(); - // check for supported ldap version - if($info[0]['supportedldapversion']) { - for($i=0; $i<$info[0]['supportedldapversion']['count']; $i++) { - $supportedVersion = ($supportedVersion < $info[0]['supportedldapversion'][$i] ? $info[0]['supportedldapversion'][$i] : $supportedVersion); - } - $ldapServerInfo->setVersion($supportedVersion); - } + $ldapServerInfo->setVersion($supportedLDAPVersion); // check for naming contexts if($info[0]['namingcontexts']) { @@ -178,7 +173,7 @@ $subschemasubentry = $info[0]['subschemasubentry'][0]; $ldapServerInfo->setSubSchemaEntry($subschemasubentry); } - + // create list of supported objetclasses if(!empty($subschemasubentry)) { $filter='(objectclass=*)'; @@ -190,16 +185,19 @@ for($i=0; $i<$info[0]['objectclasses']['count']; $i++) { $pattern = '/^\( (.*) NAME \'(\w*)\' /'; if(preg_match($pattern, $info[0]['objectclasses'][$i], $matches)) { + #_debug_array($matches); if(count($matches) == 3) { $supportedObjectClasses[$matches[1]] = strtolower($matches[2]); } } } + $ldapServerInfo->setSupportedObjectClasses($supportedObjectClasses); } } } } + $this->ldapServerInfo[$host] = $ldapServerInfo; } } else { @@ -210,14 +208,8 @@ $ldapServerInfo = $this->ldapServerInfo[$host]; } - if(is_a($ldapServerInfo, 'ldapserverinfo') && $ldapServerInfo->getVersion() > 2) { - ldap_set_option($this->ds, LDAP_OPT_PROTOCOL_VERSION, 3); - } - - if(!ldap_bind($this->ds,$dn,$passwd)) - { - if(is_object($GLOBALS['egw']->log)) - { + if(!ldap_bind($this->ds, $dn, $passwd)) { + if(is_object($GLOBALS['egw']->log)) { $GLOBALS['egw']->log->message('F-Abort, Failed binding to LDAP server'); $GLOBALS['egw']->log->commit(); }