diff --git a/lam/lib/account.inc b/lam/lib/account.inc index e040dbe5..8c69963a 100644 --- a/lam/lib/account.inc +++ b/lam/lib/account.inc @@ -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. diff --git a/lam/lib/cache.inc b/lam/lib/cache.inc index 3a1d226c..eb7d5736 100644 --- a/lam/lib/cache.inc +++ b/lam/lib/cache.inc @@ -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); diff --git a/lam/lib/lists.inc b/lam/lib/lists.inc index 3f8e0fdd..f19f7355 100644 --- a/lam/lib/lists.inc +++ b/lam/lib/lists.inc @@ -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)); } diff --git a/lam/lib/modules/fixed_ip.inc b/lam/lib/modules/fixed_ip.inc index 12eb3030..df2e8b64 100644 --- a/lam/lib/modules/fixed_ip.inc +++ b/lam/lib/modules/fixed_ip.inc @@ -192,21 +192,16 @@ 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++) { - $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])); - - $this->orig_ips[$i]['cn'] = $entries[$i]['cn'][0]; - $this->orig_ips[$i]['mac'] = array_pop(explode(" ", $entries[$i]['dhcphwaddress'][0])); - $this->orig_ips[$i]['ip'] = array_pop(explode(" ", $entries[$i]['dhcpstatements'][0])); - } - } - } + $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])); + + $this->orig_ips[$i]['cn'] = $entries[$i]['cn'][0]; + $this->orig_ips[$i]['mac'] = array_pop(explode(" ", $entries[$i]['dhcphwaddress'][0])); + $this->orig_ips[$i]['ip'] = array_pop(explode(" ", $entries[$i]['dhcpstatements'][0])); + } } } diff --git a/lam/lib/modules/kolabUser.inc b/lam/lib/modules/kolabUser.inc index 19cca6be..d51827c3 100644 --- a/lam/lib/modules/kolabUser.inc +++ b/lam/lib/modules/kolabUser.inc @@ -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); diff --git a/lam/lib/types/dhcp.inc b/lam/lib/types/dhcp.inc index c8a3ba52..fd809059 100644 --- a/lam/lib/types/dhcp.inc +++ b/lam/lib/types/dhcp.inc @@ -134,30 +134,21 @@ 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 ""; - $this->fixed_ips = array(); - if (isset($get)) { - foreach($get AS $id=>$arr) { - if (is_numeric($id)) { - echo ""; - echo ""; - echo ""; - echo ""; - echo ""; - } - } - } - echo "
".array_pop(explode(" ",$get[$id]['dhcpstatements'][0]))."".array_pop(explode(" ",$get[$id]['dhcphwaddress'][0]))."".$get[$id]['cn'][0]."
"; - } + for ($i = 0; $i < sizeof($entries); $i++) { + echo ""; + echo "".array_pop(explode(" ",$entries[$i]['dhcpstatements'][0])).""; + echo "".array_pop(explode(" ",$entries[$i]['dhcphwaddress'][0])).""; + echo "".$entries[$i]['cn'][0].""; + echo ""; + } + echo ""; + } } // fixed ip address elseif ($attribute=="dhcpstatements") { diff --git a/lam/templates/delete.php b/lam/templates/delete.php index 68a8802a..86c1c6cb 100644 --- a/lam/templates/delete.php +++ b/lam/templates/delete.php @@ -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); } /**