diff --git a/lam/lib/ldap.inc b/lam/lib/ldap.inc index fa12cbd3..d6dc8881 100644 --- a/lam/lib/ldap.inc +++ b/lam/lib/ldap.inc @@ -127,38 +127,6 @@ class Ldap{ @ldap_close($this->server); } - /** - * Returns an array with all organizational units under the given suffix - * - * @param string $suffix search suffix - * @return array DNs of organizational units - */ - function search_units($suffix) { - $ret = array(); - $sr = @ldap_search($this->server(), escapeDN($suffix), "objectClass=organizationalunit", array("DN"), 0, 0, 0, LDAP_DEREF_NEVER); - if ($sr) { - $units = ldap_get_entries($this->server, $sr); - $units = cleanLDAPResult($units); - // extract Dns - for ($i = 0; $i < sizeof($units); $i++) { - if ($units[$i]['dn']) $ret[] = $units[$i]['dn']; - } - } - // add root suffix if needed - $found = false; - for ($i = 0; $i < sizeof($ret); $i++) { // search suffix case-intensitive - if (strtolower($suffix) == strtolower($ret[$i])) { - $found = true; - break; - } - } - if (!$found) { - $ret[] = $suffix; - } - usort($ret, array($this,"cmp_array")); - return $ret; - } - /** * Returns the LDAP connection handle * @@ -303,41 +271,6 @@ class Ldap{ } - /** - * Helper function to sort the unit DNs - * - * @param string $a first argument to compare - * @param string $b second argument to compare - * @return integer 0 if equal, 1 if $a is greater, -1 if $b is greater - */ - function cmp_array($a, $b) { - // split DNs - $array_a = explode(",", $a); - $array_b = explode(",", $b); - $len_a = sizeof($array_a); - $len_b = sizeof($array_b); - // check how many parts to compare - $len = min($len_a, $len_b); - // compare from last part on - for ($i = 0; $i < $len; $i++) { - // get parts to compare - $part_a = strtolower($array_a[$len_a - $i - 1]); - $part_b = strtolower($array_b[$len_b - $i - 1]); - // compare parts - if ($part_a == $part_b) { // part is identical - if ($i == ($len - 1)) { - if ($len_a > $len_b) return 1; - elseif ($len_a < $len_b) return -1; - else return 0; // DNs are identical - } - } - elseif ($part_a == max($part_a, $part_b)) return 1; - else return -1; - } - return -1; - } - - } ?> diff --git a/lam/lib/lists.inc b/lam/lib/lists.inc index c0cfc1fd..6a57758a 100644 --- a/lam/lib/lists.inc +++ b/lam/lib/lists.inc @@ -845,7 +845,8 @@ class lamList { } $this->entries = $entries; // generate list of possible suffixes - $this->possibleSuffixes = $_SESSION['ldap']->search_units($_SESSION["config"]->get_Suffix($this->type)); + $typeObj = new $this->type(); + $this->possibleSuffixes = $typeObj->getSuffixList(); } /** @@ -873,7 +874,7 @@ class lamList { * Prints the list configuration page. */ protected function listPrintConfigurationPage() { - echo "
\n"; + echo "
\n"; echo "
type . "&norefresh=true\" method=\"post\">\n"; echo '
'; diff --git a/lam/lib/modules.inc b/lam/lib/modules.inc index a1ff39b8..79743287 100644 --- a/lam/lib/modules.inc +++ b/lam/lib/modules.inc @@ -2183,7 +2183,8 @@ class accountContainer { return $this->cachedOUs; } $rootsuffix = $_SESSION['config']->get_Suffix($this->type); - $this->cachedOUs = $_SESSION['ldap']->search_units($rootsuffix); + $typeObj = new $this->type(); + $this->cachedOUs = $typeObj->getSuffixList(); return $this->cachedOUs; } diff --git a/lam/templates/ou_edit.php b/lam/templates/ou_edit.php index 3f85a976..52918c7f 100644 --- a/lam/templates/ou_edit.php +++ b/lam/templates/ou_edit.php @@ -64,7 +64,8 @@ if (isset($_POST['createOU']) || isset($_POST['deleteOU'])) { if (preg_match("/^[a-z0-9 _\\-]+$/i", $_POST['newOU'])) { // check if ou already exists $new_dn = "ou=" . $_POST['newOU'] . "," . $_POST['parentOU']; - if (!in_array($new_dn, $_SESSION['ldap']->search_units($_POST['parentOU']))) { + $found = ldapGetDN($new_dn); + if ($found == null) { // add new ou $ou = array(); $ou['objectClass'] = "organizationalunit"; @@ -167,9 +168,9 @@ function display_main($message, $error) { $options = array(); foreach ($types as $name => $title) { $elements = array(); - $units = $_SESSION['ldap']->search_units($_SESSION["config"]->get_Suffix($name)); + $units = searchLDAPByAttribute(null, null, 'organizationalunit', array('dn'), array($name)); for ($u = 0; $u < sizeof($units); $u++) { - $elements[getAbstractDN($units[$u])] = $units[$u]; + $elements[getAbstractDN($units[$u]['dn'])] = $units[$u]['dn']; } $options[$title] = $elements; } diff --git a/lam/templates/profedit/profilepage.php b/lam/templates/profedit/profilepage.php index 9cfad03d..bac04232 100644 --- a/lam/templates/profedit/profilepage.php +++ b/lam/templates/profedit/profilepage.php @@ -179,7 +179,9 @@ $dnContent->addElement(new htmlSpacer(null, '10px'), true); $rootsuffix = $_SESSION['config']->get_Suffix($type); // get subsuffixes $suffixes = array(); -foreach ($_SESSION['ldap']->search_units($rootsuffix) as $suffix) { +$typeObj = new $type(); +$possibleSuffixes = $typeObj->getSuffixList(); +foreach ($possibleSuffixes as $suffix) { $suffixes[getAbstractDN($suffix)] = $suffix; } $selectedSuffix = array();