Voting

: max(six, six)?
(Example: nine)

The Note You're Voting On

Anonymous
14 years ago
I have now spent enough time looking at this issue to say that ldap referrals, at least when trying to add, modify or delete a record on a slave server that correctly gives a referral to a master server, does not work in php. My suggestion is turn turn off ldap referrals and write your own add, modify and delete functions with built in referral handling. Something like this:

<?php
function ldap_referral_add($connection,$add_dn,$Add_entry,$bind_dn,$bind_pw)
{
$rconnection = $connection;
$loop = 10; # max number of referral hops.
# Turn off normal referrals
ldap_get_option($connection,LDAP_OPT_REFERRALS,$old_referral_setting)
do
{
$response = ldap_add($rconnection,$dn,$entry);
# We get a success message:
if ( $response )
{
ldap_unbind($rconnection);
$loop = 0; # Probably not needed
ldap_set_option($connection,LDAP_OPT_REFERRALS,$old_referral_setting);
return
true;
}
# We get a referral message:
elseif ( !$response && ldap_errno($rconnection) == 0x0a )
{
$new_server_url = $server= preg_replace('!^(ldap://[^/]+)/.*$!', '\\1', $ldap_error($rconnection)); # May need some sanity checking here
$rconnection = ldap_connect($new_server_url);
ldap_set_option($rconnection,LDAP_OPT_REFERRALS,0)
ldap_set_option($rconnection,LDAP_OPT_PROTOCOL_VERSION, 3)
ldap_bind($rconnection,$bind_dn,$bind_pw);
$loop = $loop - 1;
}
else
{
ldap_unbind($rconnection);
$loop = 0; # Probably not needed
ldap_set_option($connection,LDAP_OPT_REFERRALS,$old_referral_setting);
return
false;
}
} while (
$loop > 0);
}
?>

<< Back to user notes page

To Top