summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: bbf7b81)
raw | patch | inline | side by side (parent: bbf7b81)
author | hickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Tue, 21 Sep 2010 05:22:11 +0000 (05:22 +0000) | ||
committer | hickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Tue, 21 Sep 2010 05:22:11 +0000 (05:22 +0000) |
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@19772 594d385d-05f5-0310-b6e9-bd551577e9d8
gosa-core/include/class_ldap.inc | patch | blob | history | |
gosa-core/include/functions.inc | patch | blob | history |
index db88defe203bc36f8b8eb1dbf2956b8b86f40137..9cdd38ec63a811d5c38e938d31bfa7d1c54b5862 100644 (file)
$this->connect();
// Get detected character mapping
- if(LDAP::$characterMap == NULL){
+ if(LDAP::$characterMap == NULL || TRUE){
LDAP::$characterMap = detectLdapSpecialCharHandling();
}
}
static function fix($dn)
{
if (SPECIALS_OVERRIDE == TRUE){
+
+ print_a(LDAP::$characterMap);
+
return (preg_replace(array("/\001CO/", "/\001OB/", "/\001CB/", "/\001SL/", "/\001DQ/"),
array("\,", "(", ")", "/", '\"'),
$dn));
index 598a41baa26ff7e49e3518b3771b6e6cef293bd2..f039e56ad8b5a01328fcb9e11c00b99b18787f52 100644 (file)
/*! \brief Detect the special character handling for the currently used ldap database.
+ * For example some convert , to \2C or " to \22.
+ *
* @param Config The GOsa configuration object.
* @return Array An array containing a character mapping the use.
*/
global $config;
if(!$config) return(NULL);
-
- $testChars = array(',','"');
-
// In the DN we've to use escaped characters, but the object name (o)
// has the be un-escaped.
- $dnName = $name = "GOsaLdapEncoding_";
- foreach($testChars as $char){
- $dnName .= "\\{$char}_";
- $name .= "{$char}_";
- }
-
+ $name = 'GOsaLdapEncoding_,_"_(_)';
+ $dnName = 'GOsaLdapEncoding_\,_\"_(_)';
+
// Create the target dn
- $oDN = "o=".LDAP::convert($dnName).",".$config->current['BASE'];
+ $oDN = "o={$dnName},".$config->current['BASE'];
// Get ldap connection and check if we've already created the character
// detection object.
- $ldapCID = @ldap_connect($config->current['SERVER']);
- @ldap_bind($ldapCID, $config->current['ADMINDN'],$config->current['ADMINPASSWORD']);
- $res = ldap_list($ldapCID, $config->current['BASE'], "(&(o={$name})(objectClass=organization))",array('dn'));
+ $ldapCID = ldap_connect($config->current['SERVER']);
+ ldap_set_option($ldapCID, LDAP_OPT_PROTOCOL_VERSION, 3);
+ ldap_bind($ldapCID, $config->current['ADMINDN'],$config->current['ADMINPASSWORD']);
+ $res = ldap_list($ldapCID, $config->current['BASE'],
+ "(&(o=".LDAP::prepare4filter($name).")(objectClass=organization))",
+ array('dn'));
+
+ // If we haven't created the character-detection object, then create it now.
$cnt = ldap_count_entries($ldapCID, $res);
if(!$cnt){
$obj = array();
$obj['objectClass'] = array('top','organization');
$obj['o'] = $name;
$obj['description'] = 'GOsa character encoding test-object.';
- ldap_add($ldapCID, $config->current['BASE'], $attrs);
+ ldap_add($ldapCID, $oDN, $obj);
}
-
- // Read the encoding instruction set.
- $res = ldap_list($ldapCID, $config->current['BASE'], "(&(o={$name})(objectClass=organization))",array('*'));
+ // Read the character-handling detection entry from the ldap.
+ $res = ldap_list($ldapCID, $config->current['BASE'],
+ "(&(o=".LDAP::prepare4filter($name).")(objectClass=organization))",
+ array('dn','o'));
$cnt = ldap_count_entries($ldapCID, $res);
if($cnt != 1){
- trigger_error("GOsa couldn't detect the special character encoding used by your ldap!");
+ trigger_error("GOsa couldn't detect the special character handling used by your ldap!");
return(NULL);
}else{
+ // Get the character handling entry from the ldap and check how the
+ // values were written. Compare them with what
+ // we've initially intended to write and create a mapping out
+ // of the results.
$re = ldap_first_entry($ldapCID, $res);
- $attrs= ldap_get_attributes($ldapCID, $re);
- $attrs['dn']= trim(ldap_get_dn($ldapCID, $re));
-
- $o = $attrs['o'][0];
- $dn = $attrs['dn'];
- $mapOstr = preg_replace("/^GOsaLdapEncoding_/","",$o);
- $mapO = preg_split("/_/", $mapOstr,0, PREG_SPLIT_NO_EMPTY);
- $mapDNstr = preg_replace("/^o=GOsaLdapEncoding_([^,]*),.*$/","\\1",$dn);
+ $attrs = ldap_get_attributes($ldapCID, $re);
+
+ // Extract the interessting characters out of the dn and the
+ // initially used $name for the entry.
+ $mapDNstr = preg_replace("/^o=GOsaLdapEncoding_([^,]*),.*$/","\\1", trim(ldap_get_dn($ldapCID, $re)));
$mapDN = preg_split("/_/", $mapDNstr,0, PREG_SPLIT_NO_EMPTY);
+ $mapNameStr = preg_replace("/^GOsaLdapEncoding_/","",$dnName);
+ $mapName = preg_split("/_/", $mapNameStr,0, PREG_SPLIT_NO_EMPTY);
+
+ // Create a mapping out of the results.
$map = array();
- foreach($mapO as $key => $entry){
- $map[$entry] = $mapDN[$key];
- $map[$mapDN[$key]] = $entry;
+ foreach($mapName as $key => $entry){
+ $map[LDAP::convert("{$entry}")] = $mapDN[$key];
}
return($map);
}