From d991ec578c79c91fe1a76d26e181c29146ad3db9 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Sat, 9 Nov 2019 14:25:06 +0100 Subject: [PATCH] fixed saving accounts with Windows escaping --- lam/lib/account.inc | 14 ++++++++++++++ lam/lib/modules.inc | 4 ++-- lam/tests/lib/accountTest.php | 9 ++++++++- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/lam/lib/account.inc b/lam/lib/account.inc index 982adb6a..b29baf12 100644 --- a/lam/lib/account.inc +++ b/lam/lib/account.inc @@ -692,6 +692,19 @@ function escapeRDN($rdn) { $rdn); } +/** + * Converts the comma escaping from Windows to OpenLDAP style. + * + * @param string $dn DN + * @return string DN + */ +function convertCommaEscaping($dn) { + return str_replace( + array('\\,'), + array('\\2C'), + $dn); +} + /** * Connects to an LDAP server using the given URL. * @@ -1213,6 +1226,7 @@ function extractDNSuffix($dn) { if ($dn == null) { return null; } + $dn = convertCommaEscaping($dn); return substr($dn, strpos($dn, ',')+1); } diff --git a/lam/lib/modules.inc b/lam/lib/modules.inc index 288a0391..60ac11f9 100644 --- a/lam/lib/modules.inc +++ b/lam/lib/modules.inc @@ -1937,9 +1937,9 @@ class accountContainer { } // Set to true if an real error has happened $stopprocessing = false; - if (strtolower($this->finalDN) != strtolower($this->dn_orig)) { + if (strtolower($this->finalDN) != convertCommaEscaping(strtolower($this->dn_orig))) { // move existing DN - if ($this->dn_orig!='') { + if ($this->dn_orig != '') { $removeOldRDN = false; if (isset($attributes[$this->finalDN]['modify'])) { $attributes[$this->finalDN]['modify'] = array_change_key_case($attributes[$this->finalDN]['modify'], CASE_LOWER); diff --git a/lam/tests/lib/accountTest.php b/lam/tests/lib/accountTest.php index 3bef321e..8790ba28 100644 --- a/lam/tests/lib/accountTest.php +++ b/lam/tests/lib/accountTest.php @@ -1,7 +1,7 @@ assertEquals('http://base/test.php', getCallingURL('http://base')); } + /** + * Tests convertCommaEscaping(). + */ + function testConvertCommaEscaping() { + $this->assertEquals('cn=test\\2C user,ou=People,o=test,c=de', convertCommaEscaping('cn=test\\, user,ou=People,o=test,c=de')); + } + }