ldap_search not working with base=NULL after php7.1
Description
The following code:
<?php
$ds = ldap_connect(); // <-- URI from /etc/openldap/ldap.conf
ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
$sr = ldap_search($ds, NULL, "(uid=dab)", array("dn")); // <-- BASE from /etc/openldap/ldap.conf
$entry = ldap_first_entry($ds, $sr);
var_dump($entry);
Resulted in this output:
Warning: ldap_search(): Search: No such object in test.php on line 5
But I expected this output instead:
resource(6) of type (ldap result entry)
/etc/openldap/ldap.conf: BASE c=ru URI ldap://localhost
slapd.log: version <=php7.1 slapd[14091]: conn=4230904 op=0 SRCH base="c=ru" scope=2 deref=0 filter="(uid=dab)" version >php7.1 slapd[14091]: conn=4230791 op=0 SRCH base="" scope=2 deref=0 filter="(uid=dab)"
related bug&commit: https://bugs.php.net/bug.php?id=77958 https://github.com/php/php-src/commit/5d2fe48785b6d24102ff53e78631cba7f2aefbef
PHP Version
PHP 8.0.12
Operating System
gentoo
It seems that behavioral change happened to due to fixing https://bugs.php.net/bug.php?id=77958. It might be a good idea to make the $base parameter nullable, to at least partially restore the former behavior.
@MCMic, what do you think?
Sounds like something that worked by chance, was it ever documented anywhere? It seems normal to expect a base when searching, and 7.1 is quite old so this has been like this for a lot of versions.
I don't think that it was ever documented. The latest relevant change to the ldap_search fixed the parameter types from string to array|string.
but it worked and it's logical with default options from system configuration files another option: parse configs?
from openldap:
man 5 ldap.conf
The ldap.conf configuration file is used to set system-wide defaults to be applied when running ldap clients.
BASE
code from openldap/libraries/libldap/search.c: in function ldap_build_search_req: if ( base == NULL ) { /* no base provided, use session default base */ base = ld->ld_options.ldo_defbase;
"session default base" initialized in init.c from config files
it's this behavior openldap-specific only?
Yes I think it is openldap specific.
So should we transfer this issue to doc-en?
for ldap_search() only? or ldap_connect() also? ldap_connect(null) also not fully documented (what uri=null means?), but gets default uri from /etc/openldap/ldap.conf