summaryrefslogtreecommitdiffstats
path: root/lib/kolab_utils.php
diff options
context:
space:
mode:
authorAleksander Machniak <machniak@kolabsys.com>2014-10-09 16:51:00 +0200
committerAleksander Machniak <machniak@kolabsys.com>2014-10-09 16:51:00 +0200
commit596aae5d7fa89a39057d7f96541f63848265bfe7 (patch)
tree4f0adf575f645506fbd9bfdfa8409e17ceaa5ccd /lib/kolab_utils.php
parent051ae9273df5ac9985188a87d8574b97b8a3c9c6 (diff)
downloadwebadmin-596aae5d7fa89a39057d7f96541f63848265bfe7.tar.gz
Fix bug where user OU was not properly selected in user form if OU's DN contains non-ascii characters (#3744)
Diffstat (limited to 'lib/kolab_utils.php')
-rw-r--r--lib/kolab_utils.php38
1 files changed, 34 insertions, 4 deletions
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;
}
}