use central LDAP search and LDAP search limit
This commit is contained in:
parent
fa9edd7963
commit
55083ce3f6
|
@ -548,7 +548,8 @@ function searchLDAPByAttribute($name, $value, $objectClass, $attributes, $scopes
|
|||
}
|
||||
for ($s = 0; $s < sizeof($scopes); $s++) {
|
||||
// search LDAP
|
||||
$sr = @ldap_search($_SESSION['ldap']->server(), escapeDN($_SESSION['config']->get_Suffix($scopes[$s])), $filter, $attributes, 0, 0, 0, LDAP_DEREF_NEVER);
|
||||
$sr = @ldap_search($_SESSION['ldap']->server(), escapeDN($_SESSION['config']->get_Suffix($scopes[$s])),
|
||||
$filter, $attributes, 0, $_SESSION['config']->get_searchLimit(), 0, LDAP_DEREF_NEVER);
|
||||
if ($sr) {
|
||||
$entries = ldap_get_entries($_SESSION['ldap']->server(), $sr);
|
||||
if ($entries) {
|
||||
|
@ -566,12 +567,14 @@ function searchLDAPByAttribute($name, $value, $objectClass, $attributes, $scopes
|
|||
* @param String $filter
|
||||
* @param array $attributes list of attributes to return
|
||||
* @param array $scopes account types
|
||||
* @return array list of found entries
|
||||
*/
|
||||
function searchLDAPByFilter($filter, $attributes, $scopes) {
|
||||
$return = array();
|
||||
for ($s = 0; $s < sizeof($scopes); $s++) {
|
||||
// search LDAP
|
||||
$sr = @ldap_search($_SESSION['ldap']->server(), escapeDN($_SESSION['config']->get_Suffix($scopes[$s])), $filter, $attributes, 0, 0, 0, LDAP_DEREF_NEVER);
|
||||
$sr = @ldap_search($_SESSION['ldap']->server(), escapeDN($_SESSION['config']->get_Suffix($scopes[$s])),
|
||||
$filter, $attributes, 0, $_SESSION['config']->get_searchLimit(), 0, LDAP_DEREF_NEVER);
|
||||
if ($sr) {
|
||||
$entries = ldap_get_entries($_SESSION['ldap']->server(), $sr);
|
||||
if ($entries) {
|
||||
|
@ -583,6 +586,45 @@ function searchLDAPByFilter($filter, $attributes, $scopes) {
|
|||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs an LDAP search.
|
||||
*
|
||||
* @param String $suffix LDAP suffix
|
||||
* @param String $filter filter
|
||||
* @param array $attributes list of attributes to return
|
||||
* @return array list of found entries
|
||||
*/
|
||||
function searchLDAP($suffix, $filter, $attributes) {
|
||||
$return = array();
|
||||
$sr = @ldap_search($_SESSION['ldap']->server(), escapeDN($suffix), $filter, $attributes,
|
||||
0, $_SESSION['config']->get_searchLimit(), 0, LDAP_DEREF_NEVER);
|
||||
if ($sr) {
|
||||
$entries = ldap_get_entries($_SESSION['ldap']->server(), $sr);
|
||||
if ($entries) {
|
||||
$return = cleanLDAPResult($entries);
|
||||
}
|
||||
@ldap_free_result($sr);
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the error number of the last LDAP command.
|
||||
*
|
||||
* @return int error number (0 if all was ok)
|
||||
*/
|
||||
function getLastLDAPErrorNumber() {
|
||||
return ldap_errno($_SESSION["ldap"]->server());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the error message of the last LDAP command.
|
||||
*
|
||||
* @return String error message
|
||||
*/
|
||||
function getLastLDAPErrorMessage() {
|
||||
return ldap_error($_SESSION["ldap"]->server());
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleans the result of an LDAP search.
|
||||
|
|
|
@ -146,7 +146,8 @@ class cache {
|
|||
// Get Data from ldap
|
||||
$search = $this->attributes[$scope];
|
||||
$search[] = 'objectClass';
|
||||
$result = @ldap_search($_SESSION['ldap']->server(), escapeDN($suffix), 'objectClass=*', $search, 0, 0, 0, LDAP_DEREF_NEVER);
|
||||
$result = @ldap_search($_SESSION['ldap']->server(), escapeDN($suffix), 'objectClass=*',
|
||||
$search, 0, $_SESSION['config']->get_searchLimit(), 0, LDAP_DEREF_NEVER);
|
||||
if ($result) {
|
||||
// Write search result in array
|
||||
$entry = @ldap_first_entry($_SESSION['ldap']->server(), $result);
|
||||
|
|
|
@ -811,21 +811,14 @@ class lamList {
|
|||
$module_filter = get_ldap_filter($this->type); // basic filter is provided by modules
|
||||
$filter = "(&" . $module_filter . ")";
|
||||
$attrs = $this->attrArray;
|
||||
$sr = @ldap_search($_SESSION["ldap"]->server(), escapeDN($this->suffix), $filter, $attrs, 0, 0, 0, LDAP_DEREF_NEVER);
|
||||
if (ldap_errno($_SESSION["ldap"]->server()) == 4) {
|
||||
$entries = searchLDAP($this->suffix, $filter, $attrs);
|
||||
if (getLastLDAPErrorNumber() == 4) {
|
||||
StatusMessage("WARN", _("LDAP sizelimit exceeded, not all entries are shown."), _("See the manual for instructions to solve this problem."));
|
||||
}
|
||||
if ($sr) {
|
||||
$info = ldap_get_entries($_SESSION["ldap"]->server(), $sr);
|
||||
$info = cleanLDAPResult($info);
|
||||
ldap_free_result($sr);
|
||||
// save results
|
||||
$this->entries = $info;
|
||||
}
|
||||
else {
|
||||
$this->entries = array();
|
||||
StatusMessage("ERROR", _("LDAP search failed! Please check your preferences."));
|
||||
elseif (getLastLDAPErrorNumber() > 0) {
|
||||
StatusMessage("ERROR", _("LDAP search failed! Please check your preferences."), getLastLDAPErrorMessage());
|
||||
}
|
||||
$this->entries = $entries;
|
||||
// generate list of possible suffixes
|
||||
$this->possibleSuffixes = $_SESSION['ldap']->search_units($_SESSION["config"]->get_Suffix($this->type));
|
||||
}
|
||||
|
|
|
@ -192,11 +192,8 @@ class fixed_ip extends baseModule {
|
|||
*/
|
||||
function load_attributes($attr) {
|
||||
if ($this->getAccountContainer()->dn_orig!=$_SESSION['config']->get_suffix('dhcp')) {
|
||||
$sr = @ldap_search($_SESSION['ldap']->server(),$this->getAccountContainer()->dn_orig, '(objectClass=dhcpHost)', array(), 0, 0, 0, LDAP_DEREF_NEVER);
|
||||
if ($sr) {
|
||||
$entries = ldap_get_entries($_SESSION['ldap']->server(), $sr);
|
||||
if ($entries) {
|
||||
for ($i=0; $i < $entries["count"]; $i++) {
|
||||
$entries = searchLDAP($this->getAccountContainer()->dn_orig, '(objectClass=dhcpHost)', array('cn', 'dhcphwaddress', 'dhcpstatements'));
|
||||
for ($i=0; $i < sizeof($entries); $i++) {
|
||||
$this->fixed_ip[$i]['cn'] = $entries[$i]['cn'][0];
|
||||
$this->fixed_ip[$i]['mac'] = array_pop(explode(" ", $entries[$i]['dhcphwaddress'][0]));
|
||||
$this->fixed_ip[$i]['ip'] = array_pop(explode(" ", $entries[$i]['dhcpstatements'][0]));
|
||||
|
@ -207,8 +204,6 @@ class fixed_ip extends baseModule {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -824,9 +824,6 @@ class kolabUser extends baseModule {
|
|||
// delegates
|
||||
if (in_array('kolabDelegate', $fields)) {
|
||||
$delegates = array();
|
||||
|
||||
// $entries = searchLDAPByAttribute('mail', '*', 'inetOrgPerson', array('mail'), $this->selfServiceSettings->LDAPSuffix);
|
||||
|
||||
$sr = @ldap_search($_SESSION['ldapHandle'], escapeDN($this->selfServiceSettings->LDAPSuffix), '(&(objectClass=inetOrgPerson)(mail=*))', array('mail'), 0, 0, 0, LDAP_DEREF_NEVER);
|
||||
if ($sr) {
|
||||
$result = ldap_get_entries($_SESSION['ldapHandle'], $sr);
|
||||
|
|
|
@ -134,28 +134,19 @@ class lamDHCPList extends lamList {
|
|||
* @param string $attribute attribute name
|
||||
*/
|
||||
public function listPrintTableCellContent(&$entry, &$attribute) {
|
||||
// Fixed Ips
|
||||
// Fixed IPs
|
||||
if ($attribute=="fixed_ips") {
|
||||
// find all fixed addresses:
|
||||
$ldap = $_SESSION['ldap'];
|
||||
$sr = @ldap_search($ldap->server(),$entry['dn'],"objectClass=dhcpHost", array('dhcpstatements', 'dhcphwaddress', 'cn'), 0, 0, 0, LDAP_DEREF_NEVER);
|
||||
if ($sr) {
|
||||
$get = ldap_get_entries($ldap->server(),$sr);
|
||||
|
||||
// Now list all fixed_ips:
|
||||
$entries = searchLDAP($entry['dn'], 'objectClass=dhcpHost', array('dhcpstatements', 'dhcphwaddress', 'cn'));
|
||||
if (sizeof($entries) > 0) {
|
||||
echo "<table border=\"0\" width=\"100%\">";
|
||||
$this->fixed_ips = array();
|
||||
if (isset($get)) {
|
||||
foreach($get AS $id=>$arr) {
|
||||
if (is_numeric($id)) {
|
||||
for ($i = 0; $i < sizeof($entries); $i++) {
|
||||
echo "<tr>";
|
||||
echo "<td width=\"25%\">".array_pop(explode(" ",$get[$id]['dhcpstatements'][0]))."</td>";
|
||||
echo "<td width=\"35%\">".array_pop(explode(" ",$get[$id]['dhcphwaddress'][0]))."</td>";
|
||||
echo "<td width=\"40%\">".$get[$id]['cn'][0]."</td>";
|
||||
echo "<td width=\"25%\">".array_pop(explode(" ",$entries[$i]['dhcpstatements'][0]))."</td>";
|
||||
echo "<td width=\"35%\">".array_pop(explode(" ",$entries[$i]['dhcphwaddress'][0]))."</td>";
|
||||
echo "<td width=\"40%\">".$entries[$i]['cn'][0]."</td>";
|
||||
echo "</tr>";
|
||||
}
|
||||
}
|
||||
}
|
||||
echo "</table>";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -244,14 +244,8 @@ if ($_POST['delete']) {
|
|||
* @return interger number of childs
|
||||
*/
|
||||
function getChildCount($dn) {
|
||||
$return = 0;
|
||||
$sr = @ldap_search($_SESSION['ldap']->server(), escapeDN($dn), 'objectClass=*', array('dn'), 0, 0, 0, LDAP_DEREF_NEVER);
|
||||
if ($sr) {
|
||||
$entries = ldap_get_entries($_SESSION['ldap']->server(), $sr);
|
||||
$entries = cleanLDAPResult($entries);
|
||||
$return = sizeof($entries) - 1;
|
||||
}
|
||||
return $return;
|
||||
$entries = searchLDAP(escapeDN($dn), 'objectClass=*', array('dn'));
|
||||
return (sizeof($entries) - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue