This topic is locked
[SOLVED]

 Unexpected ldap-bind error message

1/26/2012 4:43:16 PM
PHPRunner General questions
D
drgregory author

Dear Sirs,
I have a PHPRunner 5.2 project which at the present validates its users and passwords against a table in the PostgreSQL database. Now I need to validate them from the same login page but against an Active Directory server by means of the ldap_bind() function. I've put my PHP code in Global events -> Login page -> Before login. And the passwords stored in the PostgreSQL table are equivalent to those in the AD database, there is no difference here. I begin executing the project and try to connect in the login.php page. And here is my question: If I enter a correct pair user/password, then the Before login event is first executed and the hole process of connecting to the LDAP server and binding it with ldap_bind() performs OK and the result is a correct True. But if the user I type, the password or both are wrong, I get to the typical PHPrunner error page just at the point of the ldap_bind() function call and, of course, the process is broken and I loose control over it. In other words, I don't even get the False which would be the correct answer from ldap_bind() for any of the three cases. As if the expected False from ldap_bind() were first trapped by some piece of PHPRunner code instead of returning the False I need for the message of invalid connection to be displayed.
To give you more information, I've put the hole PHP code of my Before login event in a sepparate new file and tested it as a plain new page and the ldap_bind() function returns True or False correctly, depending of the pair user/password I test, so I think there is an issue with ldap_bind() and PHPRunner at this point. ¿Can you please help me with this? Here is the Before login event code (whithout comments and debugging lines):
function BeforeLogin($username, $password, $message)

{

$prmusucodi = $username;

$prmusupass = $password;

$prmexprval = false;

$strdomisrv = "xxxxxx.sba.com.ar";

$strldapsrv = "xxxxxx.sba.com.ar";

$conldapsrv = ldap_connect($strldapsrv);

if ($conldapsrv) {

ldap_set_option($conldapsrv, LDAP_OPT_PROTOCOL_VERSION, 3);

ldap_set_option($conldapsrv, LDAP_OPT_REFERRALS, 0);

$strdomiusu = $prmusucodi . '@' . $strdomisrv;

$prmexprval = ldap_bind($conldapsrv, $strdomiusu, $prmusupass);

ldap_close($conldapsrv);

}

return $prmexprval;

}
The messages in the error page (instead the expected False) are:
Error description ldap_bind() [function.ldap-bind]: Unable to bind to server: Invalid credentials

URL srvcau/operaciones/aa/login.php?

Error file E:\Program Files\BitNami WAPPStack\apache2\htdocs\operaciones\aa\include\events.php

...
Call Stack:

0. include\events.php:45 ldap_bind ...

1. include\events.php:45 BeforeLogin ...

2. login.php:118 Global scope ...



Thank you in advance.

Best regards,
DrGregory

Buenos Aires

Argentina

Admin 1/26/2012

To the best of my understanding AD username/password are incorrect.
Try to print username/password that you send to ldap_bind function to see what is wrong.

D
drgregory author 1/26/2012

Dear admin,
As I mentioned in my post, if I type a correct username and a correct password, the result of binding with ldap_bind() is completely and correctly executed, resulting in a True, no matter what pair of correct user/password I test. The error page ONLY arises when I type an existent user and an invalid password, or viceversa, or both are wrong. Just to answer what you've asked, one of the pairs I tried was:
username = 'aviani'

password = 'argentina2012'
These are just real user/password credentials used to login everyday in a Windows workstation which belongs to the AD I try to connect with ldap_bind().
And I would like to tell you again that the same PHP code, run in a sepparate PHP page outside any PHPRunner project, functions OK: ldap_bind() ansewrs TRUE or FALSE as expected, no error messages at all.
¿Can you help me?
Thank you again for your time and dedication.
DrGregory

D
drgregory author 1/26/2012

Of course, for debugging purposes I print any data I use in the function, like this:
print 'conldapsrv = {' . $conldapsrv . '}';

print 'strdomiusu = {' . $strdomiusu . '}';

print 'prmusupass = {' . $prmusupass . '}';
which respectively show the data in the correct form. There are no errors here. Example of these printings:
conldapsrv = {Resource id #16}

strdomiusu = {aviani@xxxxxx.sba.com.ar}

prmusupass = {argentina2012}
DrGregory

Admin 1/26/2012

I guess your question is how to turn off error reporting so function can proceed further and return false, right?
In this case you can add the following line in the beginning of your code:

error_reporting(0);

D
drgregory author 1/26/2012

I've tried putting error_reporting(0); at top of the BeforeLogin function as you suggested. But the results are still the same. When the user and or password typed are wrong, error page arises and the process is aborted. If both are correct, ldap_bind() answers True and execution of login process continues as expected (looking for the same user/password in the PostgreSQL table). Any ideas?

D
drgregory author 1/26/2012

By the way, I tell you that when the error page arises, the technical information box says Error type: 2, and the rest of the info is what I wrote in my first post.

Admin 1/26/2012

To be honest, I have no idea why ldap_bind produces the error instead of simply returning false.
Try this just in case:

$prmexprval = @ldap_bind($conldapsrv, $strdomiusu, $prmusupass);


@ character is supposed to suppress error messages.

D
drgregory author 1/27/2012

OK, I've tried all of your suggestions before you tell me about using them, so I change you the question: how can I tell PHPRunner not to show that error page, at least during the login process, so as to give me the control over the results of the functions I use?

Is there any way to avoid the error page appears?
Thank you again.

Best regards,
Carlos Capriz

Admin 1/27/2012

I don't know why this happening.
Probably you can try to define your own error handler and then do nothing in that handler, simply returning the control to the main function.
More info: http://php.net/manual/en/function.set-error-handler.php