Code

Prepared ldap special character conversion
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 20 Sep 2010 13:01:41 +0000 (13:01 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 20 Sep 2010 13:01:41 +0000 (13:01 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@19769 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-core/include/class_ldap.inc
gosa-core/include/class_ldapMultiplexer.inc
gosa-core/include/functions.inc

index 68a94658d8d8f606ded0db5fac0cedcc191fae88..b87a228fd85bf527c3cf9fbde8f6219af94eb3e8 100644 (file)
@@ -327,6 +327,11 @@ class LDAP{
     }
   }
 
+    function getSearchResultHandle($srp)
+    {
+        return($this->sr[$srp]);
+    }
+
   function fetch($srp)
   {
     $att= array();
index fbd6d91b47d47168cfb579ecd57596f8ebde0b66..557bc7dfb5145b24f0fc75964e08259790c748d9 100644 (file)
@@ -39,7 +39,7 @@ class ldapMultiplexer {
  
   public function __call($methodName, $parameters) {
     /* Add resource pointer if the mentioned methods are used */
-    if (preg_match('/^(search|ls|cat|fetch|clearResult|resetResult|count|getDN|recursive_remove|rmdir_recursive|gen_xls|create_missing_trees|import_single_entry|import_complete_ldif)$/', $methodName)){
+    if (preg_match('/^(search|ls|cat|fetch|clearResult|resetResult|count|getDN|recursive_remove|rmdir_recursive|gen_xls|create_missing_trees|import_single_entry|import_complete_ldif|getSearchResultHandle)$/', $methodName)){
       array_unshift($parameters, $this->sr);
     }
 
index 8307b6e63ee5c6996ef2a3821aad4484ccd1dec5..192a0bb1b54b7858f53b6b590f18c98b0faa3bde 100644 (file)
@@ -3777,5 +3777,71 @@ function bold($str)
 }
 
 
+
+/*! \brief  Detect the special character handling for the currently used ldap database. 
+ *  @param      Config  The GOsa configuration object.
+ *  @return     Array   An array containing a character mapping the use.
+ */
+function detectLdapSpecialCharHandling()
+{
+    // The list of chars to test for
+    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}_";
+    }
+
+    // Create the target dn
+    $oDN = "o=".LDAP::convert($dnName).",".$config->current['BASE'];
+
+    // Create the object on demand.
+    $ldap = $config->get_ldap_link();
+    $ldap->cd($config->current['BASE']);
+    if(!$ldap->dn_exists($oDN)){
+        $obj = array();
+        $obj['objectClass'] = array('top','organization');
+        $obj['o'] = $name;
+        $obj['description'] = 'GOsa character encoding test-object.';
+        $ldap->cd($oDN);
+        $ldap->add($obj);
+    }
+
+    // Read the encoding instruction set.
+    $ldap->cd($config->current['BASE']);
+    $ldap->ls("(&(o={$name})(objectClass=organization))");
+
+    
+    if(!$ldap->count() == 1){
+        trigger_error("GOsa couldn't detect the special character encoding used by your ldap!");
+        return(NULL);
+    }else{
+
+        $re = ldap_first_entry($ldap->cid, $ldap->getSearchResultHandle());
+        $attrs= ldap_get_attributes($ldap->cid, $re);
+        $attrs['dn']= trim(ldap_get_dn($ldap->cid, $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);
+        $mapDN = preg_split("/_/", $mapDNstr,0, PREG_SPLIT_NO_EMPTY);
+
+        $map = array();
+        foreach($mapO as $key => $entry){
+            $map[$entry] = $mapDN[$key];
+            $map[$mapDN[$key]] = $entry;
+        }
+        return($map);
+    }
+    return(NULL);
+}
+
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
 ?>