Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 2.2.0

Bug #14240 dnExists() fails
Submitted: 2008-06-25 20:57 UTC
From: wesleys Assigned: beni
Status: Bogus Package: Net_LDAP2 (version 2.0.0RC3)
PHP Version: 5.1.5 OS: Solaris 9
Roadmaps: (Not assigned)    
Subscription  


 [2008-06-25 20:57 UTC] wesleys (Wesley Schwengle)
Description: ------------ function _get_manager($dn) { if ($dn ) { $res = $this->ldap->dnExists($dn); if ($res instanceof Net_LDAP2_Error) { printf("%s failed due to %s\n", __FUNCTION__, "bloody hell!"); } elseif ($res === true) { $entry = $this->ldap->getEntry($dn, array('displayName')); if ($entry instanceof Net_LDAP2_Entry) { return $entry->getValue('displayName'); } } } return "UNKNOWN"; } On Ubuntu 7.04 this works fine (PHP 5.2.1). Same code on php 5.1.5 I suddenly I get an Net_LDAP_Error. Test script: --------------- function _get_manager($dn) { if ($dn ) { $res = $this->ldap->dnExists($dn); if ($res instanceof Net_LDAP2_Error) { printf("%s failed due to %s\n", __FUNCTION__, "bloody hell!"); } elseif ($res === true) { $entry = $this->ldap->getEntry($dn, array('displayName')); if ($entry instanceof Net_LDAP2_Entry) { return $entry->getValue('displayName'); } } } return "UNKNOWN"; } Expected result: ---------------- I expect the following, all elements of the array are fetched from LDAP. The manager entry is a DN which I want to retreive with the _get_manager function. So I know the calls to LDAP are working, however the dnExists() claims otherwise.. # Ubuntu 7.04/PHP 5.2.1 User 'xxx' found, details are: Array ( [username] => xxx [name] => xxx [phone] => +31 20 xxxxxx [gsm] => +31 6 xxxxxx [title] => xxxxx [info] => Armed and dangerous [url] => http://xxxxx/ [email] => xxxxx@xxxxx [manager] => xxxxxx ) # Same call on Solaris 9/PHP 5.1.5 _get_manager failed due to bloody hell! User 'xxx' found, details are: Array ( [username] => xxx [name] => xxx [phone] => +31 20 xxxxxx [gsm] => +31 6 xxxxxx [title] => xxxxx [info] => Armed and dangerous [url] => http://xxxxx/ [email] => xxxxx@xxxxx [manager] => UNKNOWN

Comments

 [2008-06-26 05:56 UTC] beni (Benedikt Hallinger)
Hello and thank you for your bug report! Well "bloody hell" is not really an exact error message. Please replace the line printf("%s failed due to %s\n", __FUNCTION__, "bloody hell!"); with printf("%s failed due to %s\n", __FUNCTION__, $res->getMessage()); to recieve an meaningful error message from the error dropped by dnExists(). I cant reproduce this here with PHP 5.2.5 (Debian; package version: 5.2.5-3), so this might be an error inside the ldap extension of PHP which is fixed in 5.2.
 [2008-06-26 06:01 UTC] beni (Benedikt Hallinger)
dnExists() uses ldap_list() from PHPs ldap extension, just for your information. Maybe the DN you pass to test is somehow corrupted. Please also mention the DN you want to test.
 [2008-06-26 08:51 UTC] wesleys (Wesley Schwengle)
Hello, yeah, sorry for that (I was a bit anoyed when I first produced the bug). I already replaced the code block you mentioned. $res->getMessage returns LDAP SERVER DOWN. But I know this is not true since I can retreive information with the same LDAP sessions just seconds after. A example DN (users might have different ones, depending on who their manager is): CN=michielvdb,OU=USERS,OU=NEWCO,DC=broadband,DC=lan The code change produces this error message: _get_manager failed due to Can't contact LDAP server: LDAP_SERVER_DOWN
 [2008-06-26 09:27 UTC] wesleys (Wesley Schwengle)
Mmm, the plot thickens.. While I was able to reuse my LDAP connection previously, the same test script cannot reuse the LDAP connection. Eventhough I'm not disconnection ($this->ldap = null - hope this is correct btw, couldn't find a disconnect function in Net_LDAP2). function connect() { if ($this->ldap) { #print_r($this->ldap); if (Net_LDAP2::isError($this->ldap)) { die(sprintf("Could not connect to LDAP-server: %s\n", $this->ldap->getMessage())); } return; } # More code here } When I uncomment the print_r statement, I get the Net_LDAP2 object and it has a link: [_link:protected] => Resource id #25 Yet I have to call connect() before every LDAP call, otherwise I get LDAP SERVER down messages. If you want I will upload my test script, so you can have a closer look at what I'm doing.
 [2008-06-26 10:22 UTC] beni (Benedikt Hallinger)
Which LDAP server do you use? This code: if ($this->ldap) { is true as long as there is any object stored inside that variable. This doesn't neccesary mea that there is a valid ldap link. If you need to fetch the ldap link, you should use $ldap->getLink(). This returns the link from the ldap connection and allows you to test for it: if (!is_resource($ldap->getLink())) { echo "no link"; } However, unless your ldap server or network is buggy, once you establish the ldap link using the Net_LDAP2::connect() method, you SHOULD have a valid link or a Net_LDAP2_Error object. For the disconnecting-part: $this->ldap = null; just erases the ldap object instance. The ldap link used by this object however remains open! Use $ldap->done() to close the link. For further convinience, i just added a disconnect() method that aliases done() in CVS. Do you test on a local installed ldap server? Does Solaris+PHP 5.2. work?
 [2008-06-26 11:20 UTC] wesleys (Wesley Schwengle)
I'm connecting to the same LDAP server (MS 2003 Active directory) on both the Solaris and Ubuntu (and FreeBSD) box(es). I could test wheter this problem also occurs when I will use a OpenLDAP server. I don't think the server or my connection is buggy, on different servers within the same network running php 5.2.x everything works as expected. I think this bug might have something to do with your comment about 5.1.x having bugs in the PHP LDAP API. Solaris 9 + php 5.2.x I cannot test. I don't know wheter we have other webservers running Solaris 9 with PHP. The bug is not present on a FreeBSD 7 server with PHP 5.2.6 with Suhosin-Patch 0.9.6.2. That I can verify. Thanks for the is_resource code snipplet and the done method, will include it ASAP.
 [2008-06-26 11:32 UTC] beni (Benedikt Hallinger)
Thank you for taking the time to report a problem with PHP. Unfortunately you are not using a current version of PHP -- the problem might already be fixed. Please download a new PHP version from http://www.php.net/downloads.php If you are able to reproduce the bug with one of the latest versions of PHP, please change the PHP version on this bug report to the version you tested and change the status back to "Open". Again, thank you for your continued support of PEAR. Ok, then i will close this bug with status "new php version" since the problem is not to be reproduced in the latest php versions. Additionally, i was not able to detect any bug in the affected Net_LDAP code and since your code runs well under the later php versions, it is most likely that it is the php ldap extension that produces the error. Anyway, thank you for your bug report and your continued investigation.
 [2008-06-26 11:47 UTC] wesleys (Wesley Schwengle)
function is_open() { if ($this->ldap) { return is_resource($this->ldap->getLink()); } return false; } function close() { if ($this->ldap) { $this->ldap->done(); $this->ldap = null; } } function connect() { if ($this->is_open()) return; # more code here } I've changed the code, and I'm calling connect() just before every LDAP call, but on 5.1.5 this approach doesn't work.