From 7569423f11028d6c668ab6aed82b6f996c6d3e46 Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 17 Jul 2018 19:59:11 +0800 Subject: [PATCH] Update functions.php Since openLDAP >=2.1.2,ldap_explode_dn turns unprintable chars (in the ASCII sense, UTF8 encoded) into \. --- lib/functions.php | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/lib/functions.php b/lib/functions.php index 7ce6b68..1883415 100644 --- a/lib/functions.php +++ b/lib/functions.php @@ -2487,6 +2487,30 @@ function draw_chooser_link($form,$element,$include_choose_text=true,$rdn='none') printf('%s',$href,$title,_('browse')); } +/** + * http://php.net/manual/en/function.ldap-explode-dn.php#34724 + * fixed for: + * Keep attention on UTF8 encoded DNs. Since openLDAP >=2.1.2 + * ldap_explode_dn turns unprintable chars (in the ASCII sense, UTF8 + * encoded) into \. + */ +function ldap_explode_dn_patch( $dn, $with_attrib ) { + $result = ldap_explode_dn( $dn, $with_attrib ); + if (! $result ) return null; + # translate hex code into ascii again + foreach ( $result as $key => $value ) { + $result[ $key ] = preg_replace_callback( + "/\\\([0-9A-Fa-f]{2})/", + function ( $matches) { + return chr( hexdec( $matches[1] ) ); + }, + $value + ); + } + return ( $result ); + +} + /** * Explode a DN into an array of its RDN parts. * @@ -2522,8 +2546,8 @@ function pla_explode_dn($dn,$with_attributes=0) { $dn = addcslashes($dn,'<>+";'); # split the dn - $result[0] = ldap_explode_dn(dn_escape($dn),0); - $result[1] = ldap_explode_dn(dn_escape($dn),1); + $result[0] = ldap_explode_dn_patch(dn_escape($dn),0); + $result[1] = ldap_explode_dn_patch(dn_escape($dn),1); if (! $result[$with_attributes]) { if (DEBUG_ENABLED) debug_log('Returning NULL - NO result.',1,0,__FILE__,__LINE__,__METHOD__);