diff --git a/include/class_ldap.inc b/include/class_ldap.inc
index bf5db49ea999459febebfc535705866a205bcf99..7c218cb3dfb3109153cc7b02b687c9d2d9121858 100644
--- a/include/class_ldap.inc
+++ b/include/class_ldap.inc
@@ -952,7 +952,7 @@ class LDAP
     $admin  = escapeshellarg($this->binddn);
     $filter = escapeshellarg($filter);
 
-    $cmd = "ldapsearch -x -LLLL -D {$admin} {$filter} {$limit} {$scope} -H {$host} -b {$dn} -w {$pwd} ";
+    $cmd = 'ldapsearch'.($this->tls ? ' -ZZ' : '')." -x -LLLL -D {$admin} {$filter} {$limit} {$scope} -H {$host} -b {$dn} -w {$pwd} ";
 
     // Create list of process pipes
     $descriptorspec = array(