fixed search_units() if no OUs are in the suffix

This commit is contained in:
Roland Gruber 2003-06-28 08:05:58 +00:00
parent 9f84b6b225
commit 733240f369
1 changed files with 11 additions and 10 deletions

View File

@ -9,12 +9,12 @@ $Id$
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or the Free Software Foundation; either version 2 of the License, or
(at your option) any later version. (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
@ -29,7 +29,7 @@ class Ldap{
// object of Config to access preferences // object of Config to access preferences
var $conf; var $conf;
// server handle // server handle
var $server; var $server;
@ -134,6 +134,7 @@ class Ldap{
// returns an array with all organizational units under the given suffix // returns an array with all organizational units under the given suffix
function search_units($suffix) { function search_units($suffix) {
$units = array();
$sr = @ldap_search($_SESSION["ldap"]->server(), $suffix, "objectClass=organizationalunit", array("DN")); $sr = @ldap_search($_SESSION["ldap"]->server(), $suffix, "objectClass=organizationalunit", array("DN"));
if ($sr) { if ($sr) {
$units = ldap_get_entries($_SESSION["ldap"]->server, $sr); $units = ldap_get_entries($_SESSION["ldap"]->server, $sr);
@ -141,10 +142,10 @@ class Ldap{
array_shift($units); array_shift($units);
// remove sub arrays // remove sub arrays
for ($i = 0; $i < sizeof($units); $i++) $units[$i] = $units[$i]['dn']; for ($i = 0; $i < sizeof($units); $i++) $units[$i] = $units[$i]['dn'];
// add root suffix if needed }
if (!in_array($suffix, $units)) { // add root suffix if needed
array_push($units, $suffix); if (!in_array($suffix, $units)) {
} array_push($units, $suffix);
} }
return $units; return $units;
} }
@ -153,20 +154,20 @@ class Ldap{
function server() { function server() {
return $this->server; return $this->server;
} }
// closes connection to LDAP server before serialization // closes connection to LDAP server before serialization
function __sleep() { function __sleep() {
$this->close(); $this->close();
// define which attributes to save // define which attributes to save
return array("conf", "username", "password", "ldapUserAttributes", "ldapGroupAttributes", "ldapHostAttributes"); return array("conf", "username", "password", "ldapUserAttributes", "ldapGroupAttributes", "ldapHostAttributes");
} }
// reconnects to LDAP server when deserialized // reconnects to LDAP server when deserialized
function __wakeup() { function __wakeup() {
$data = $this->decrypt(); $data = $this->decrypt();
$this->connect($data[0], $data[1]); $this->connect($data[0], $data[1]);
} }
// encrypts username and password // encrypts username and password
function encrypt($username, $password) { function encrypt($username, $password) {
// read key and iv from cookie // read key and iv from cookie