function searchonelevel($ldap, $base, $filter, $attrs, $minresults = 1, $maxresults = 999999) { $results = ldap_list($ldap, $base, $filter, $attrs); $results or ldapdie($ldap, "ldap_list()"); $entries = ldap_get_entries($ldap, $results); $entries or ldapdie($ldap, "ldap_get_entries()"); $entries["count"] <= $maxresults or ldapdie($ldap, "More than {$maxresults} object(s) match \"{$filter}\""); $entries["count"] >= $minresults or ldapdie($ldap, "Could not find {$minresults} object(s) matching \"{$filter}\""); return $entries; }
function handle($ldap, &$config_space, &$faiobject, &$skiplist, $children_only) { $dn = $faiobject['dn']; if (!isset($faiobject['..'])) { $faiobject['..'] = array('dn' => substr($dn, strpos($dn, ',') + 1), 'count' => 0); // dummy parent reference } if (!$children_only) { foreach (array("FAIpartitionEntry", "FAIpartitionDisk", "FAIpartitionTable", "FAIpackageList", "FAIdebconfInfo", "FAIscriptEntry", "FAIscript", "FAItemplateEntry", "FAItemplate", "FAIvariableEntry", "FAIvariable", "FAIhookEntry", "FAIhook") as $oc) { if (in_array($oc, $faiobject['objectclass'])) { call_user_func_array($oc, array(&$config_space, &$faiobject)); break; } } } $result = ldap_list($ldap, $dn, 'objectClass=*'); $result or ldapdie($ldap, "ldap_list()"); $entries = ldap_get_entries($ldap, $result); $entries or ldapdie($ldap, "ldap_get_entries()"); for ($i = 0; $i < $entries["count"]; $i++) { $child = $entries[$i]; $rdn = substr($child["dn"], 0, strpos($child["dn"], ",")); if (isset($skiplist[$rdn])) { continue; } $skiplist[$rdn] = TRUE; if (array_key_exists("faistate", $child) and strpos($child["faistate"][0], "removed") !== FALSE) { continue; } $child['..'] = $faiobject; handle($ldap, $config_space, $child, $skiplist, FALSE); } }