note 76562 added to function.ldap-bind

From: Date: Fri, 20 Jul 2007 14:29:12 +0000
Subject: note 76562 added to function.ldap-bind
Groups: php.notes 
Request: Send a blank email to php-notes+get-128765@lists.php.net to get a copy of this message
The OpenLDAP libraries will return error 53 (Server unwilling to perform) when trying to re-bind to a non-anonymous account if you accidentally leave the password field blank. If you want to authenticate against a different field than the dn, you have to bind to the server twice. Your code may look like the following: <? function ldapLogin($uname, $pass, $base_dn, $fname, $server, $port){ $ldc=@ldap_connect($server, $port); if (!$ldc) return ERROR_CODE; $bn='cn=anonymous-user,'.$base_dn; $pw='anonymous-pass'; $lbind=@ldap_bind($ldc, $bn, $pw); if (!$lbind) return ERROR_CODE; $ureturn=@ldap_search($ldc, $base_dn, "($fname=$uname)", array('dn', 'givenName', 'sn', 'mail')); $uent=@ldap_first_entry($ldc, $ureturn); if (!$uent) return ERROR_CODE; $bn=@ldap_get_dn($ldc, $uent); //This line should use $pass rather than $password $lbind=@ldap_bind($ldc, $bn, $password); // Now you can find the error echo ldap_error($ltc); if ($lbind) return true; else return false; ?> Hope this helps someone else running in to the same error. ---- Server IP: 64.71.164.2 Probable Submitter: 66.170.97.28 ---- Manual Page -- http://www.php.net/manual/en/function.ldap-bind.php Edit -- https://master.php.net/note/edit/76562 Del: integrated -- https://master.php.net/note/delete/76562/integrated Del: useless -- https://master.php.net/note/delete/76562/useless Del: bad code -- https://master.php.net/note/delete/76562/bad+code Del: spam -- https://master.php.net/note/delete/76562/spam Del: non-english -- https://master.php.net/note/delete/76562/non-english Del: in docs -- https://master.php.net/note/delete/76562/in+docs Del: other reasons-- https://master.php.net/note/delete/76562 Reject -- https://master.php.net/note/reject/76562 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#128765) next »