Dear Handa,
I had a quick look at your code and I do think there is one part missing.
You are now passing an array of baseDNs to ldap_search().
The result of this is also an array of connectionIDs.
Next you have to check in an extra loop with ldap_count_entries() which of these connections is the right one to take into the next step: ldap_first_entry().
At least that is how I implemented it. And it works. See:
if ($preBindUser && $preBindPassword) {
/**
* Use case 1: Servers requiring pre-binding with admin defined
* credentials to search for the user's full DN before attempting
* to login.
* @see https://dev.wp-plugins.org/ticket/681
*/
if ( $isPreBound = wpDirAuth_bindTest($connection, $preBindUser, $preBindPassword,$baseDn) === true )
{ $connections[]=$connection;
$connections[]=$connection;
$baseDns[]=$baseDn; //DN1
$baseDns[]="EXTRA DN INFO"; //DN2
if ( ($results = @ldap_search($connections, $baseDns, $filterQuery, $returnKeys)) !== false )
{ foreach ($results as $conn)
{ if(ldap_count_entries($connection, $conn)>0)
{ $results = $conn;
break;
}
};
if ( ($userDn = @ldap_get_dn($connection, ldap_first_entry($connection, $results))) !== false )
{ if ( ($isBound = wpDirAuth_bindTest($connection, $userDn, $password,$baseDn)) === true )
{ $isLoggedIn = true; // valid server, valid login, move on
break; // valid server, valid login, move on
}
}
}
}
}
Kind regards,
Ivo