From 700090917af6dd2e27c9fd82269797b6ec5def59 Mon Sep 17 00:00:00 2001 From: Andre Klapper Date: Mon, 19 Aug 2024 21:48:17 +0200 Subject: [PATCH] Fix PHP 8.3 "Usage of ldap_connect with two arguments is deprecated" exception Summary: Per https://www.php.net/manual/en/function.ldap-connect.php the signature `$conn = @ldap_connect($host, $this->port);` is deprecated since PHP 8.3. Thus pass a full LDAP URI as the only parameter. ``` ERROR 8192: Usage of ldap_connect with two arguments is deprecated at [/var/www/html/phorge/phorge/src/applications/auth/adapter/PhutilLDAPAuthAdapter.php:308] ``` Closes T15724 Test Plan: Set up LDAP as auth provider, try to log in. Reviewers: O1 Blessed Committers, avivey Reviewed By: O1 Blessed Committers, avivey Subscribers: avivey, tobiaswiese, valerio.bozzolan, Matthew, Cigaryno Maniphest Tasks: T15724 Differential Revision: https://we.phorge.it/D25792 --- src/applications/auth/adapter/PhutilLDAPAuthAdapter.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/applications/auth/adapter/PhutilLDAPAuthAdapter.php b/src/applications/auth/adapter/PhutilLDAPAuthAdapter.php index 14047c1761..6b552dda53 100644 --- a/src/applications/auth/adapter/PhutilLDAPAuthAdapter.php +++ b/src/applications/auth/adapter/PhutilLDAPAuthAdapter.php @@ -305,7 +305,12 @@ final class PhutilLDAPAuthAdapter extends PhutilAuthAdapter { 'port' => $this->port, )); - $conn = @ldap_connect($host, $this->port); + if ($this->ldapStartTLS) { + $ldap_server_uri = 'ldaps://'.$host.':'.$this->port; + } else { + $ldap_server_uri = 'ldap://'.$host.':'.$this->port; + } + $conn = @ldap_connect($ldap_server_uri); $profiler->endServiceCall( $call_id, @@ -315,7 +320,7 @@ final class PhutilLDAPAuthAdapter extends PhutilAuthAdapter { if (!$conn) { throw new Exception( - pht('Unable to connect to LDAP server (%s:%d).', $host, $port)); + pht('Unable to connect to LDAP server (%s).', $ldap_server_uri)); } $options = array(