note 111417 modified in function.ldap-set-rebind-proc by danbrown

From: Date: Mon, 04 Mar 2013 18:04:52 +0000
Subject: note 111417 modified in function.ldap-set-rebind-proc by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-193880@lists.php.net to get a copy of this message
The $referral that is used in the callback function isn't the bind dn, but the dn of the record that was being accessed (or rather it's location on the master server, I guess, if there is a difference in the two), so you need to rebind with your existing credentials. The connection ($ldap) appears to have already been made to the new server, so it is just a rebind process, nothing else more complicated than that. There must be a loop in the underlying library that re-submits the request that prompted the referral until either a success or fail is returned. I guess if the bind dn you were using in the first place won't let you edit the record on the master, then that is an ldap rather than php issue. However, at least with the rebind procedure you have a way to modify the bind dn first. So, the rebind process is really quite simple, now that I understand how it works! I was assuming it to be way more complicated. In it's simplest form, this is all you need, assuming your bind $dn and $pass are globals <?php function rebind($ldap, $referral) { // Set ldap options ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3); ldap_set_option($ldap, LDAP_OPT_REFERRALS, True); ldap_set_rebind_proc($ldap, 'rebind'); // Rebind if (!ldap_bind($ldap, $dn, $pass)) { echo 'Could not bind to referral server'; return 1; // Yes, a 1 means a failure. } return 0; // Yes, return a 0 on success. } ?> --was-- The $referral that is used in the callback function isn't the bind dn, but the dn of the record that was being accessed (or rather it's location on the master server, I guess, if there is a difference in the two), so you need to rebind with your existing credentials. The connection ($ldap) appears to have already been made to the new server, so it is just a rebind process, nothing else more complicated than that. There must be a loop in the underlying library that re-submits the request that prompted the referral until either a success or fail is returned. I guess if the bind dn you were using in the first place won't let you edit the record on the master, then that is an ldap rather than php issue. However, at least with the rebind procedure you have a way to modify the bind dn first. So, the rebind process is really quite simple, now that I understand how it works! I was assuming it to be way more complicated. In it's simplest form, this is all you need, assuming your bind $dn and $pass are globals function rebind($ldap, $referral) { // Set ldap options ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3); ldap_set_option($ldap, LDAP_OPT_REFERRALS, True); ldap_set_rebind_proc($ldap, 'rebind'); // Rebind if (!ldap_bind($ldap, $dn, $pass)) { echo 'Could not bind to referral server'; return 1; // Yes, a 1 means a failure. } return 0; // Yes, return a 0 on success. } http://php.net/manual/en/function.ldap-set-rebind-proc.php

« previous php.notes (#193880) next »