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
This commit is contained in:
Lars Kneschke 2006-10-28 08:38:17 +00:00
parent c431575d69
commit a934f999e9

View File

@ -128,29 +128,24 @@
return False; return False;
} }
if(!isset($this->ldapServerInfo[$host])) { if(ldap_set_option($this->ds, LDAP_OPT_PROTOCOL_VERSION, 3)) {
//print "no ldap server info found<br>"; $supportedLDAPVersion = 3;
if (!($ldapbind = @ldap_bind($this->ds, '', ''))) } else {
{ $supportedLDAPVersion = 2;
// try with version 3 ;-)
ldap_set_option($this->ds, LDAP_OPT_PROTOCOL_VERSION, 3);
$ldapbind = ldap_bind($this->ds, '', '');
} }
if(!isset($this->ldapServerInfo[$host])) {
//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=*)'; $filter='(objectclass=*)';
$justthese = array('structuralObjectClass','namingContexts','supportedLDAPVersion','subschemaSubentry'); $justthese = array('structuralObjectClass','namingContexts','supportedLDAPVersion','subschemaSubentry');
if(($sr = @ldap_read($this->ds, '', $filter, $justthese))) { if(($sr = @ldap_read($this->ds, '', $filter, $justthese))) {
if($info = ldap_get_entries($this->ds, $sr)) { if($info = ldap_get_entries($this->ds, $sr)) {
$ldapServerInfo = new ldapserverinfo(); $ldapServerInfo = new ldapserverinfo();
// check for supported ldap version $ldapServerInfo->setVersion($supportedLDAPVersion);
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);
}
// check for naming contexts // check for naming contexts
if($info[0]['namingcontexts']) { if($info[0]['namingcontexts']) {
@ -190,16 +185,19 @@
for($i=0; $i<$info[0]['objectclasses']['count']; $i++) { for($i=0; $i<$info[0]['objectclasses']['count']; $i++) {
$pattern = '/^\( (.*) NAME \'(\w*)\' /'; $pattern = '/^\( (.*) NAME \'(\w*)\' /';
if(preg_match($pattern, $info[0]['objectclasses'][$i], $matches)) { if(preg_match($pattern, $info[0]['objectclasses'][$i], $matches)) {
#_debug_array($matches);
if(count($matches) == 3) { if(count($matches) == 3) {
$supportedObjectClasses[$matches[1]] = strtolower($matches[2]); $supportedObjectClasses[$matches[1]] = strtolower($matches[2]);
} }
} }
} }
$ldapServerInfo->setSupportedObjectClasses($supportedObjectClasses); $ldapServerInfo->setSupportedObjectClasses($supportedObjectClasses);
} }
} }
} }
} }
$this->ldapServerInfo[$host] = $ldapServerInfo; $this->ldapServerInfo[$host] = $ldapServerInfo;
} }
} else { } else {
@ -210,14 +208,8 @@
$ldapServerInfo = $this->ldapServerInfo[$host]; $ldapServerInfo = $this->ldapServerInfo[$host];
} }
if(is_a($ldapServerInfo, 'ldapserverinfo') && $ldapServerInfo->getVersion() > 2) { if(!ldap_bind($this->ds, $dn, $passwd)) {
ldap_set_option($this->ds, LDAP_OPT_PROTOCOL_VERSION, 3); 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->message('F-Abort, Failed binding to LDAP server');
$GLOBALS['egw']->log->commit(); $GLOBALS['egw']->log->commit();
} }