From 596aae5d7fa89a39057d7f96541f63848265bfe7 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Thu, 9 Oct 2014 16:51:00 +0200 Subject: Fix bug where user OU was not properly selected in user form if OU's DN contains non-ascii characters (#3744) --- lib/kolab_utils.php | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) (limited to 'lib/kolab_utils.php') diff --git a/lib/kolab_utils.php b/lib/kolab_utils.php index 9f064e3..e2602af 100644 --- a/lib/kolab_utils.php +++ b/lib/kolab_utils.php @@ -163,17 +163,47 @@ class kolab_utils */ public static function dn2ufn($dn) { - $name = ldap_dn2ufn($dn); + return self::decode_dn(ldap_dn2ufn($dn)); + } + + /** + * Unicode-aware ldap_explode_dn() wrapper + * + * @param string $dn LDAP DN string + * + * @return array Exploded DN (uses unicode encoding) + */ + public static function explode_dn($dn) + { + $result = ldap_explode_dn($dn, 0); + + // get rid of count + unset($result['count']); + + $result = array_map(array('kolab_utils', 'decode_dn'), $result); + + return $result; + } + + /** + * Decode \XX sequences into characters + * + * @param string $str String to decode + * + * @return string Decoded string + */ + public static function decode_dn($str) + { $pos = 0; // example: "\C3\A4" => "รค" - while (preg_match('/\\\\[0-9a-fA-F]{2}/', $name, $matches, PREG_OFFSET_CAPTURE, $pos)) { + while (preg_match('/\\\\[0-9a-fA-F]{2}/', $str, $matches, PREG_OFFSET_CAPTURE, $pos)) { $char = chr(hexdec(substr($matches[0][0], 1))); $pos = $matches[0][1]; - $name = substr_replace($name, $char, $pos, 3); + $str = substr_replace($str, $char, $pos, 3); $pos += 1; } - return $name; + return $str; } } -- cgit v1.1