summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/api/kolab_api_service_form_value.php3
-rw-r--r--lib/kolab_api_service.php5
-rw-r--r--lib/kolab_utils.php38
3 files changed, 37 insertions, 9 deletions
diff --git a/lib/api/kolab_api_service_form_value.php b/lib/api/kolab_api_service_form_value.php
index 18867a4..9a9bff2 100644
--- a/lib/api/kolab_api_service_form_value.php
+++ b/lib/api/kolab_api_service_form_value.php
@@ -1028,10 +1028,9 @@ class kolab_api_service_form_value extends kolab_api_service
$subjects = $subjects->entries(true);
$subject = array_shift($subjects);
$subject_dn = key($subject);
- $subject_dn_components = ldap_explode_dn($subject_dn, 0);
+ $subject_dn_components = kolab_utils::explode_dn($subject_dn);
if ($subject_dn_components) {
- unset($subject_dn_components['count']);
array_shift($subject_dn_components);
$default = strtolower(implode(',', $subject_dn_components));
}
diff --git a/lib/kolab_api_service.php b/lib/kolab_api_service.php
index 9c55763..0049b8f 100644
--- a/lib/kolab_api_service.php
+++ b/lib/kolab_api_service.php
@@ -535,9 +535,8 @@ abstract class kolab_api_service
// add organizational unit to the result
if (empty($attrs['ou']) && isset($attributes['ou'])) {
- $dn = ldap_explode_dn($dn, 0);
- // pop the count and rdn
- unset($dn['count']);
+ $dn = kolab_utils::explode_dn($dn);
+ // pop the rdn
unset($dn[0]);
$attrs['ou'] = implode(',', $dn);
}
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;
}
}