index 193524d263219379ac87708c253ead23e821fedf..4dbe7995f770a073208bbc993fdc976cc4bfc2cf 100644 (file)
@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,13 +770,16 @@ 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[$key] = preg_replace("/,.*$/","",$sub_base);
+ $sub_bases = array();
+ foreach($sub_deps as $key => $sub_base){
+ if(!empty($sub_base)){
+ $sub_bases[$key] = preg_replace("/,.*$/","",$sub_base);
+ }
}
/* Check if we have enabled the sub_dir search support AND
@@ -784,22 +787,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,"get_sub_list(): Falling back to get_list(), due to empty sub_bases parameter. This may slow down GOsa.");
+ }
+ $tmp = get_list($filter, $category,$base,$attributes,$flags);
+ 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,6 +918,7 @@ function get_list($filter, $category, $base= "", $attributes= array(), $flags= G
$result= array();
while($attrs = $ldap->fetch()) {
+
$dn= $ldap->getDN();
/* Convert dn into a printable format */