Code

Updated ldap special character handling
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 21 Sep 2010 07:00:00 +0000 (07:00 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 21 Sep 2010 07:00:00 +0000 (07:00 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@19777 594d385d-05f5-0310-b6e9-bd551577e9d8

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

index f955eb09a6ab56b5429d0b6fd759330ad6f19351..5c8bac1fb6b49a56af1c027932cf56f6ea8edc80 100644 (file)
@@ -117,17 +117,20 @@ class LDAP
         LDAP::$characterMapRegFrom = array("/\001CO/", "/\001OB/", "/\001CB/", "/\001SL/", "/\001DQ/");
         LDAP::$characterMapRegTo = array("\,", "(", ")", "/", '\"');
 
-        if(LDAP::$characterMap == NULL){
+        if(LDAP::$characterMap === NULL){
             LDAP::$characterMap = detectLdapSpecialCharHandling();
 
             // Check if character-detection was successfull, if it wasn't use a fallback.
-            if(LDAP::$characterMap){
+            if(LDAP::$characterMap !== NULL){
                 LDAP::$characterMapRegFrom = array();
                 LDAP::$characterMapRegTo = array();
                 foreach(LDAP::$characterMap as $from => $to){
                     LDAP::$characterMapRegFrom[] = "/{$from}/";
                     LDAP::$characterMapRegTo[] = "/{$to}/";
                 }
+            }else{
+                // To avoid querying a hundred times without any success, stop here.
+                LDAP::$characterMap = array();
             }
         }
 
@@ -148,7 +151,7 @@ class LDAP
         if (SPECIALS_OVERRIDE == TRUE){
 
             // Update the conversion instruction set.
-            if(LDAP::$characterMap == NULL) LDAP::updateSpecialCharHandling();
+            if(LDAP::$characterMap === NULL) LDAP::updateSpecialCharHandling();
 
             return (preg_replace(LDAP::$characterMapRegFrom,LDAP::$characterMapRegTo,$dn));
         } else {
index 9e0219e57c5a5821e8cafb62bdcad0b2d8f2157e..1b707a6ca01945ac443c5a79d38be109323ff592 100644 (file)
@@ -3818,7 +3818,10 @@ function detectLdapSpecialCharHandling()
         $obj['objectClass'] = array('top','organization');
         $obj['o'] = $name;
         $obj['description'] = 'GOsa character encoding test-object.';
-        ldap_add($ldapCID, $oDN, $obj);
+        if(!@ldap_add($ldapCID, $oDN, $obj)){
+            trigger_error("GOsa couldn't detect the special character handling used by your ldap!");
+            return(NULL);
+        }
     }
     
     // Read the character-handling detection entry from the ldap.
@@ -3826,7 +3829,7 @@ function detectLdapSpecialCharHandling()
             "(&(o=".$filterName.")(objectClass=organization))",
             array('dn','o'));
     $cnt = ldap_count_entries($ldapCID, $res);
-    if($cnt != 1){
+    if($cnt != 1 || !$res){
         trigger_error("GOsa couldn't detect the special character handling used by your ldap!");
         return(NULL);
     }else{