From fe1386fa2d26ccf28f6fcf36a15db65f33cdd2cb Mon Sep 17 00:00:00 2001 From: w3houde Date: Wed, 15 Jul 2026 05:41:18 +0700 Subject: [PATCH] Fix #38860 build valid ldap:// URI for scheme-less host on PHP 8.3+ (#39167) Since PHP 8.3 ldap_connect() takes a single URI argument. connectBind() concatenated host and port as "host:port", which is a malformed URI for a scheme-less host (localhost, 192.168.0.2) since the host is then parsed as the URI scheme, so the following bind returns false. It also appended ":port" to an already qualified ldaps:// URI. Prefix scheme-less hosts with ldap:// and leave ldap(s):// URIs untouched. Signed-off-by: Dolicraft --- htdocs/core/class/ldap.class.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/htdocs/core/class/ldap.class.php b/htdocs/core/class/ldap.class.php index 9b76c34da1f..295554b2d93 100644 --- a/htdocs/core/class/ldap.class.php +++ b/htdocs/core/class/ldap.class.php @@ -358,7 +358,10 @@ class Ldap dol_syslog(get_class($this)."::connectBind serverPing true, we try ldap_connect to ".$host, LOG_DEBUG); } if (version_compare(PHP_VERSION, '8.3.0', '>=')) { - $uri = $host.':'.$this->serverPort; + // Since PHP 8.3, ldap_connect() expects a single URI argument. A scheme-less + // host (ex: localhost, 192.168.0.2) must be turned into a valid ldap:// URI, + // otherwise the host is parsed as the URI scheme and the later bind fails. + $uri = preg_match('/^ldaps?:\/\//i', $host) ? $host : 'ldap://'.$host.':'.$this->serverPort; $this->connection = ldap_connect($uri); } else { $this->connection = ldap_connect($host, $this->serverPort); @@ -371,7 +374,7 @@ class Ldap dol_syslog(get_class($this)."::connectBind serverPing false, we try ldap_connect to ".$host, LOG_DEBUG); } if (version_compare(PHP_VERSION, '8.3.0', '>=')) { - $uri = $host.':'.$this->serverPort; + $uri = preg_match('/^ldaps?:\/\//i', $host) ? $host : 'ldap://'.$host.':'.$this->serverPort; $this->connection = ldap_connect($uri); } else { $this->connection = ldap_connect($host, $this->serverPort);