note 35808 modified in function.ldap-explode-dn by pollita

From: Date: Mon, 15 Sep 2003 17:40:05 +0000
Subject: note 35808 modified in function.ldap-explode-dn by pollita
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-56542@lists.php.net to get a copy of this message
[ Editor's Note: The segfault has been fixed and will not occur in PHP 4.3.4 or PHP 5.0.0 when they are released. However, it is still important to escape special characters as detailed below. ] If your DN contains < or > characters, you must escape them with a backslash or ldap_explode_dn() will give you a "wrong parameter count" error or even a segmentation fault. For example, these calls will fail with a "wrong parameter count" or a seg fault: ldap_explode_dn( "cn=<bob>,dc=example,dc=com", 0 ); ldap_explode_dn( 'cn=<bob>,dc=example,dc=com', 0 ); But this will succeed ldap_explode_dn( "cn=\<bob\>,dc=example,dc=com", 0 ); Notice also that the < and > are escaped with hex codes as noted above. This function is a nice wrapper that properly formats all DNs and can safely be called with < and > characters, and UTF-8 characters: function my_explode_dn( $dn, $with_attributes=0 ) { $dn = addcslashes( $dn, "<>" ); $result = ldap_explode_dn( $dn, $with_attributes ); //translate hex code into ascii again foreach( $result as $key => $value ) $result[$key] = preg_replace("/\\\([0-9A-Fa-f]{2})/e", "''.chr(hexdec('\\1')).''", $value); return $result; } I am using php 4.3.1. Good luck! --was-- If your DN contains < or > characters, you must escape them with a backslash or ldap_explode_dn() will give you a "wrong parameter count" error or even a segmentation fault. For example, these calls will fail with a "wrong parameter count" or a seg fault: ldap_explode_dn( "cn=<bob>,dc=example,dc=com", 0 ); ldap_explode_dn( 'cn=<bob>,dc=example,dc=com', 0 ); But this will succeed ldap_explode_dn( "cn=\<bob\>,dc=example,dc=com", 0 ); Notice also that the < and > are escaped with hex codes as noted above. This function is a nice wrapper that properly formats all DNs and can safely be called with < and > characters, and UTF-8 characters: function my_explode_dn( $dn, $with_attributes=0 ) { $dn = addcslashes( $dn, "<>" ); $result = ldap_explode_dn( $dn, $with_attributes ); //translate hex code into ascii again foreach( $result as $key => $value ) $result[$key] = preg_replace("/\\\([0-9A-Fa-f]{2})/e", "''.chr(hexdec('\\1')).''", $value); return $result; } I am using php 4.3.1. Good luck! http://www.php.net/manual/en/function.ldap-explode-dn.php

« previous php.notes (#56542) next »