note 104606 added to function.ldap-set-rebind-proc
| From: | leon at leonux dot co dot za | Date: | Sat, 25 Jun 2011 10:26:58 +0000 |
| Subject: | note 104606 added to function.ldap-set-rebind-proc | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-180943@lists.php.net to get a copy of this message | ||
I finally have referrals working using the ldap_set_rebind_proc function. Don't connect to the
referral server in your callback function. This is done for you. You only have to bind. The callback
must return 0 if the bind succeeds or 1 if it fails.
Consider a master - slave LDAP setup where the slave is read-only and refers writes to the master.
For the PHP on the slave, you need something like this:
<?php
// Callback function
function rebind($ldap, $referral) {
// 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');
// The referral is of the form:
// ldaps://newhost/cn=user,ou=people,dc=example,dc=com
$refparts = explode('/', $referral);
if (count($refparts) > 2) {
// Get the bind dn from referral
$dn = $refparts[3];
// Bind to new host
if (!ldap_bind($ldap, $dn, $pass)) {
echo 'Could not bind to referral server';
return 1;
}
} else {
// Try anonymous bind
if (!ldap_bind($ldap)) {
echo 'Could not bind to referral server anonymously';
return 1;
}
}
return 0;
}
// Initial ldap connection to slave server
$ldap_host = 'localhost'
$ds = ldap_connect($ldap_host);
// ldap options
ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3)
ldap_set_option($ds, LDAP_OPT_REFERRALS, True)
// Set callback function
ldap_set_rebind_proc($ds, 'rebind'))
// bind
ldap_bind($ds, $dn, $pass)
// ldap write
ldap_modify($ds, $dn, $attr);
?>
Accessing passwords and other data from your callback is easier if you use a class method as the
callback function. The callback would be initialized like this:
<?php
ldap_set_rebind_proc($ldap, 'MyClass::rebind');
?>
----
Server IP: 69.147.83.197
Probable Submitter: 196.215.114.99
----
Manual Page -- http://www.php.net/manual/en/function.ldap-set-rebind-proc.php
Edit -- https://master.php.net/note/edit/104606
Del: integrated -- https://master.php.net/note/delete/104606/integrated
Del: useless -- https://master.php.net/note/delete/104606/useless
Del: bad code -- https://master.php.net/note/delete/104606/bad+code
Del: spam -- https://master.php.net/note/delete/104606/spam
Del: non-english -- https://master.php.net/note/delete/104606/non-english
Del: in docs -- https://master.php.net/note/delete/104606/in+docs
Del: other reasons-- https://master.php.net/note/delete/104606
Reject -- https://master.php.net/note/reject/104606
Search -- https://master.php.net/manage/user-notes.php