#33588 [NEW]: No RootDSE query possible

From: Date: Wed, 06 Jul 2005 11:55:11 +0000
Subject: #33588 [NEW]: No RootDSE query possible
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-81470@lists.php.net to get a copy of this message
From: cajus at naasa dot net Operating system: Debian GNU/Linux PHP version: 5.0.4 PHP Bug Type: LDAP related Bug description: No RootDSE query possible Description: ------------ I've found that searching the RootDSE does not work with PHP, because the base is set to NULL when no base is specified. This fact causes the LDAP library to look into the systems ldap.conf to take the base from there - which is probably not what we want. The following patch fixes the problem: --- php5-5.0.4/ext/ldap/ldap.c 2005-01-19 01:27:42.000000000 +0100 +++ php5-5.0.4/ext/ldap/ldap.c.fixed 2005-07-01 17:15:55.000000000 +0200 @@ -575,6 +575,7 @@ { zval **link, **base_dn, **filter, **attrs, **attr, **attrsonly, **sizelimit, **timelimit, **deref; char *ldap_base_dn = NULL; + char *dummy_base_dn = ""; char *ldap_filter = NULL; char **ldap_attrs = NULL; ldap_linkdata *ld; @@ -674,7 +675,7 @@ } else { nbases = 0; /* this means string, not array */ convert_to_string_ex(base_dn); - ldap_base_dn = Z_STRLEN_PP(base_dn) < 1 ? NULL : Z_STRVAL_PP(base_dn); + ldap_base_dn = Z_STRLEN_PP(base_dn) < 1 ? dummy_base_dn : Z_STRVAL_PP(base_dn); } if (Z_TYPE_PP(filter) == IS_ARRAY) { @@ -713,7 +714,7 @@ zend_hash_get_current_data(Z_ARRVAL_PP(base_dn), (void **)&entry); zend_hash_move_forward(Z_ARRVAL_PP(base_dn)); convert_to_string_ex(entry); - ldap_base_dn = Z_STRLEN_PP(entry) < 1 ? NULL : Z_STRVAL_PP(entry); + ldap_base_dn = Z_STRLEN_PP(entry) < 1 ? dummy_base_dn : Z_STRVAL_PP(entry); } if (nfilters != 0) { /* filter an array? */ zend_hash_get_current_data(Z_ARRVAL_PP(filter), (void **)&entry); @@ -756,7 +757,7 @@ /* fix to make null base_dn's work */ if (strlen(ldap_base_dn) < 1) { - ldap_base_dn = NULL; + ldap_base_dn = dummy_base_dn; } ld = (ldap_linkdata *) zend_fetch_resource(link TSRMLS_CC, -1, "ldap link", NULL, 1, le_link); Reproduce code: --------------- <?php # ldapsearch -x -b '' -s base '(objectclass=*)' namingContexts function get_naming_contexts($server, $admin, $password) { /* Build LDAP connection */ $ds= ldap_connect ($server); if (!$ds) { die ("Can't bind to LDAP. No check possible!"); } ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3); $r= ldap_bind ($ds, $admin, $password); /* Get base to look for naming contexts */ $sr = @ldap_read ($ds, "", "objectClass=*", array("namingContexts")); $attr= @ldap_get_entries($ds,$sr); print_r($attr); } get_naming_contexts("what.server.ever.org", "cn=admindn,dc=whatever,dc=org", "secret"); ?> Expected result: ---------------- Array ( [count] => 1 [0] => Array ( [namingcontexts] => Array ( [count] => 2 [0] => dc=whatever,dc=org [1] => dc=whatever,dc=shell ) [0] => namingcontexts [count] => 1 [dn] => ) ) Actual result: -------------- Array ( [count] => 1 [0] => Array ( [count] => 0 [dn] => dc=whatever,dc=org ) ) -- Edit bug report at http://bugs.php.net/?id=33588&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=33588&r=trysnapshot4 Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=33588&r=trysnapshot50 Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=33588&r=trysnapshot51 Fixed in CVS: http://bugs.php.net/fix.php?id=33588&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=33588&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=33588&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=33588&r=needscript Try newer version: http://bugs.php.net/fix.php?id=33588&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=33588&r=support Expected behavior: http://bugs.php.net/fix.php?id=33588&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=33588&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=33588&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=33588&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=33588&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=33588&r=dst IIS Stability: http://bugs.php.net/fix.php?id=33588&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=33588&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=33588&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=33588&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=33588&r=mysqlcfg

« previous php.bugs (#81470) next »