X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=gosa-core%2Finclude%2Fclass_filterLDAP.inc;h=34aff04a8e5652b6c00a9e61cb5bdb8df7dbb459;hb=c9bd6c4d92532063a9dd8df3cfd20740d43e5841;hp=f0f8ca740881a3574c67d49140cbc96ee3d4e650;hpb=e9feb085c421af65246962bf60757aba9ce8e944;p=gosa.git diff --git a/gosa-core/include/class_filterLDAP.inc b/gosa-core/include/class_filterLDAP.inc index f0f8ca740..34aff04a8 100644 --- a/gosa-core/include/class_filterLDAP.inc +++ b/gosa-core/include/class_filterLDAP.inc @@ -2,7 +2,7 @@ class filterLDAP { - static function query($base, $scope, $filter, $attributes, $category, $objectStorage= "") + static function query($base, $scope, $filter, $attributes, $category, $objectStorage= array("")) { $config= session::global_get('config'); $ldap= $config->get_ldap_link(TRUE); @@ -14,42 +14,45 @@ class filterLDAP { static function get_list($base, $filter, $attributes, $category, $objectStorage, $flags= GL_SUBSEARCH) { - global $ui; - global $config; + $ui= session::global_get('ui'); + $config= session::global_get('config'); // Move to arrays for category and objectStorage if (!is_array($category)) { $category= array($category); } - if (!is_array($objectStorage)) { - $objectStorage= array($objectStorage); - } + + // Store in base - i.e. is a rdn value empty? + $storeOnBase= count($objectStorage) == 1 && empty($objectStorage[0]); + + $method= ($storeOnBase && !($flags & GL_SUBSEARCH))?"ls":"search"; // Initialize search bases $bases= array(); - // Get list of sub bases to search on and fill dn components to search for - $components= array(); - foreach ($objectStorage as $oc) { - $oc= preg_replace('/,$/', '', $oc); - $tmp= split(',', $oc); - if (count($tmp) == 1) { - preg_match('/([^=]+)=(.*)$/', $oc, $m); - $components[]= $m[1].":dn:=".$m[2]; - if ($flags & GL_SUBSEARCH) { - $bases[$base][]= $m[1].":dn:=".$m[2]; - } else { - $bases["$oc,$base"][]= $m[1].":dn:=".$m[2]; - } - } else { - // No, there's no \, in pre defined RDN values - preg_match('/^([^,]+),(.*)$/', $oc, $matches); - preg_match('/([^=]+)=(.*)$/', $matches[1], $m); - $components[]= $m[1].":dn:=".$m[2]; - if ($flags & GL_SUBSEARCH) { - $bases[$base][]= $m[1].":dn:=".$m[2]; + // Get list of sub bases to search on + if ($storeOnBase) { + $bases[$base]= ""; + } else { + foreach ($objectStorage as $oc) { + $oc= preg_replace('/,$/', '', $oc); + $tmp= explode(',', $oc); + if (count($tmp) == 1) { + preg_match('/([^=]+)=(.*)$/', $oc, $m); + if ($flags & GL_SUBSEARCH) { + $bases[$base][]= $m[1].":dn:=".$m[2]; + } else { + $bases["$oc,$base"][]= $m[1].":dn:=".$m[2]; + } } else { - $bases[$matches[2].",$base"][]= $m[1].":dn:=".$m[2]; + // No, there's no \, in pre defined RDN values + preg_match('/^([^,]+),(.*)$/', $oc, $matches); + preg_match('/([^=]+)=(.*)$/', $matches[1], $m); + if ($flags & GL_SUBSEARCH) { + $bases[$base][]= $m[1].":dn:=".$m[2]; + } else { + $bases[$matches[2].",$base"][]= $m[1].":dn:=".$m[2]; + } } } } @@ -68,13 +71,21 @@ class filterLDAP { } // Switch to new base and search + if (is_array($dnFilters)){ + $dnFilter= "(|"; + foreach ($dnFilters as $df) { + $dnFilter.= "($df)"; + } + $dnFilter.= ")"; + } else { + $dnFilter= ""; + } $ldap->cd($base); - $dnFilter= "(|"; - foreach ($dnFilters as $df) { - $dnFilter.= "($df)"; + if ($method == "ls") { + $ldap->ls("(&$filter$dnFilter)", $base, $attributes); + } else { + $ldap->search("(&$filter$dnFilter)", $attributes); } - $dnFilter.= ")"; - $ldap->search ("(&$filter$dnFilter)", $attributes); // Check for size limit exceeded messages for GUI feedback if (preg_match("/size limit/i", $ldap->get_error())){