Code

Updated functions.inc
[gosa.git] / gosa-core / include / functions.inc
index dfb6486e125037fefc4f1fb92d5eb4ab78ed1080..1da4e832c9b95fead61c302f443836260335dc7a 100644 (file)
@@ -755,7 +755,7 @@ function get_multiple_locks($objects)
     @param $attributes Array The attributes we search for.
     @param $flags     Long   A set of Flags
  */
-function get_sub_list($filter, $category,$sub_bases, $base= "", $attributes= array(), $flags= GL_SUBSEARCH)
+function get_sub_list($filter, $category,$sub_deps, $base= "", $attributes= array(), $flags= GL_SUBSEARCH)
 {
   global $config, $ui;
 
@@ -770,12 +770,13 @@ function get_sub_list($filter, $category,$sub_bases, $base= "", $attributes= arr
   }
 
   /* Ensure we have an array as department list */
-  if(is_string($sub_bases)){
-    $sub_bases = array($sub_bases);
+  if(is_string($sub_deps)){
+    $sub_deps = array($sub_deps);
   }
 
   /* Remove , ("ou=1,ou=2.." => "ou=1") */
-  foreach($sub_bases as $key => $sub_base){
+  $sub_bases = array();
+  foreach($sub_deps as $key => $sub_base){
     $sub_bases[$key] = preg_replace("/,.*$/","",$sub_base);
   }
 
@@ -784,22 +785,41 @@ function get_sub_list($filter, $category,$sub_bases, $base= "", $attributes= arr
    * If not, fall back to old method, get_list().
    */
   $sub_enabled = isset($config->current['SUB_LIST_SUPPORT']) && preg_match("/true/i",$config->current['SUB_LIST_SUPPORT']);
-  if($sub_bases == "" || !$sub_enabled){
-    return(get_list($filter, $category,$base,$attributes,$flags));
+  if(!count($sub_bases) || !$sub_enabled){
+    
+    /* Log this fall back, it may be an unpredicted behaviour.
+     */
+    if(!count($sub_bases)){
+      gosa_log("debug","get_sub_list","",$attributes,sprintf("get_sub_list(): Falling back to get_list(), due to empty sub_bases parameter. This may slow down GOsa.",$src,$attrs['dn']));
+    }
+    $tmp = get_list($filter, $category,$base,$attributes,$flags | GL_SUBSEARCH);
+    return($tmp);
   }
 
   /* Get all deparments matching the given sub_bases */
   $departments = array();
-  
   $base_filter= "";
   foreach($sub_bases as $sub_base){
     $base_filter .= "(".$sub_base.")";
   }
   $base_filter = "(&(objectClass=organizationalUnit)(|".$base_filter."))";
-
   $ldap->search($base_filter,array("dn"));
   while($attrs = $ldap->fetch()){
-    $departments[$attrs['dn']] = $attrs['dn'];
+    foreach($sub_deps as $sub_dep){
+
+      /* Only add those departments that match the reuested list of departments.
+       *
+       * e.g.   sub_deps = array("ou=servers,ou=systems,");
+       *  
+       * In this case we have search for "ou=servers" and we may have also fetched 
+       *  departments like this "ou=servers,ou=blafasel,..."
+       * Here we filter out those blafasel departments.
+       */
+      if(preg_match("/".normalizePreg($sub_dep)."/",$attrs['dn'])){
+        $departments[$attrs['dn']] = $attrs['dn'];
+        break;
+      }
+    }
   }
 
   $result= array();
@@ -896,33 +916,36 @@ function get_list($filter, $category, $base= "", $attributes= array(), $flags= G
   $result= array();
 
   while($attrs = $ldap->fetch()) {
+
     $dn= $ldap->getDN();
 
-    /* Sort in every value that fits the permissions */
-    if (is_array($category)){
-      foreach ($category as $o){
-        if ($ui->get_category_permissions($dn, $o) != ""){
-          if ($flags & GL_CONVERT){
-            $attrs["dn"]= convert_department_dn($dn);
-          } else {
-            $attrs["dn"]= $dn;
+    /* Convert dn into a printable format */
+    if ($flags & GL_CONVERT){
+      $attrs["dn"]= convert_department_dn($dn);
+    } else {
+      $attrs["dn"]= $dn;
+    }
+
+    if($flags & GL_NO_ACL_CHECK){
+      $result[]= $attrs;
+    }else{
+
+      /* Sort in every value that fits the permissions */
+      if (is_array($category)){
+        foreach ($category as $o){
+          if ($ui->get_category_permissions($dn, $o) != ""){
+
+            /* We found what we were looking for, break speeds things up */
+            $result[]= $attrs;
           }
+        }
+      } else {
+        if ($ui->get_category_permissions($dn, $category) != ""){
 
           /* We found what we were looking for, break speeds things up */
           $result[]= $attrs;
         }
       }
-    } else {
-      if ($ui->get_category_permissions($dn, $category) != ""){
-        if ($flags & GL_CONVERT){
-          $attrs["dn"]= convert_department_dn($dn);
-        } else {
-          $attrs["dn"]= $dn;
-        }
-
-        /* We found what we were looking for, break speeds things up */
-        $result[]= $attrs;
-      }
     }
   }