From a032668d6ff969b150c41cbcba510db8e545b734 Mon Sep 17 00:00:00 2001
From: Christian Mollekopf <mollekopf@apheleia-it.ch>
Date: Fri, 28 Apr 2023 12:01:26 +0200
Subject: [PATCH] On centos 7 we need to pass the host/port combination
 slightly differently.

---
 lib/Net/LDAP3.php | 48 +++++++++++++++++++++++++++++++++--------------
 1 file changed, 34 insertions(+), 14 deletions(-)

diff --git a/lib/Net/LDAP3.php b/lib/Net/LDAP3.php
index 0056b10..ac4fa59 100644
--- a/lib/Net/LDAP3.php
+++ b/lib/Net/LDAP3.php
@@ -785,20 +785,40 @@ class Net_LDAP3
         }
 
         $output = array();
-        $command = Array(
-                $moz_ldapsearch,
-                '-x',
-                '-h',
-                $this->_current_host,
-                '-b',
-                escapeshellarg($entry_dn),
-                '-s',
-                'base',
-                '-D',
-                escapeshellarg($this->_current_bind_dn),
-                '-w',
-                escapeshellarg($this->_current_bind_pw)
-            );
+
+        if ($moz_ldapsearch == "/usr/bin/ldapsearch") {
+            $command = Array(
+                    $moz_ldapsearch,
+                    '-x',
+                    '-h',
+                    $this->_current_host,
+                    '-b',
+                    escapeshellarg($entry_dn),
+                    '-s',
+                    'base',
+                    '-D',
+                    escapeshellarg($this->_current_bind_dn),
+                    '-w',
+                    escapeshellarg($this->_current_bind_pw)
+                );
+        } else {
+            $command = Array(
+                    $moz_ldapsearch,
+                    '-x',
+                    '-h',
+                    preg_replace('|^[a-z]+://|i', '', $this->_current_host),
+                    '-p',
+                    $this->config_get('port', 389),
+                    '-b',
+                    escapeshellarg($entry_dn),
+                    '-s',
+                    'base',
+                    '-D',
+                    escapeshellarg($this->_current_bind_dn),
+                    '-w',
+                    escapeshellarg($this->_current_bind_pw)
+                );
+        }
 
         if ($this->vendor_name() == "Oracle Corporation") {
             // For Oracle DSEE
-- 
GitLab