From 2740606be13b042672be97f6765c73a22ec3709e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=B4me=20Chilliet?= <come.chilliet@fusiondirectory.org>
Date: Wed, 26 Aug 2020 14:55:08 +0200
Subject: [PATCH] :sparkles: feat(ldap) Add parameter for wrapping to
 generateLdif

Will be used by ldapmanager plugin.

issue #6105
---
 include/class_ldap.inc | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/include/class_ldap.inc b/include/class_ldap.inc
index b7c7485fa..8019ba514 100644
--- a/include/class_ldap.inc
+++ b/include/class_ldap.inc
@@ -1114,10 +1114,17 @@ class LDAP
    * \param  string $scope    'base', 'sub' .. see manpage for 'ldapmodify' for details.
    *
    * \param  int $limit       Limits the result.
+   *
+   * \param  ?int $wrap       Wraps line around this length (0 to disable).
    */
-  function generateLdif (string $dn, string $filter = '(objectClass=*)', string $scope = 'sub', int $limit = 0): string
+  function generateLdif (string $dn, string $filter = '(objectClass=*)', string $scope = 'sub', int $limit = 0, int $wrap = NULL): string
   {
-    $limit = (($limit == 0) ? '' : ' -z '.$limit);
+    $limit  = (($limit == 0) ? '' : ' -z '.$limit);
+    if ($wrap === NULL) {
+      $wrap = '';
+    } else {
+      $wrap = ' -o ldif-wrap='.($wrap ? $wrap : 'no');
+    }
 
     // Check scope values
     $scope = trim($scope);
@@ -1133,7 +1140,7 @@ class LDAP
     $admin  = escapeshellarg($this->binddn);
     $filter = escapeshellarg($filter);
 
-    $cmd = 'ldapsearch'.($this->tls ? ' -ZZ' : '')." -x -LLLL -D {$admin} {$filter} {$limit} {$scope} -H {$host} -b {$dn} -w {$pwd} ";
+    $cmd = 'ldapsearch'.($this->tls ? ' -ZZ' : '')." -x -LLLL -D {$admin} {$filter} {$limit} {$wrap} {$scope} -H {$host} -b {$dn} -w {$pwd} ";
 
     // Create list of process pipes
     $descriptorspec = [
-- 
GitLab