Permalink
Browse files

Issue #380: Minor fixes to LDAP lib

  • Loading branch information...
1 parent 6f44d59 commit 52e7e85ccc7b48c60badf676d9c2537894d4a95a @janoszen janoszen committed Apr 10, 2012
Showing with 22 additions and 21 deletions.
  1. +8 −8 Ldap/LdapAuthenticationProvider.php
  2. +13 −13 Ldap/LdapConnection.php
  3. +1 −0 Ldap/LdapDn.php
@@ -312,10 +312,10 @@ protected function buildUserDn($username) {
'LdapAuthenticationProvider::setUserAttribute() before calling authenticateAndAuthorize()');
}
- $dn = $this->userDn;
+ $dn = clone $this->userDn;
$parts = $dn->getParts();
$firstpart = array('id' => $this->userAttribute, 'value' => $username);
- array_unshift($firstpart, $parts);
+ array_unshift($parts, $firstpart);
$dn->parseDN($parts);
return $dn;
}
@@ -335,10 +335,10 @@ protected function buildGroupDn($group) {
'LdapAuthenticationProvider::setGroupAttribute() before calling authenticateAndAuthorize()');
}
- $dn = $this->groupDn;
+ $dn = clone $this->groupDn;
$parts = $dn->getParts();
$firstpart = array('id' => $this->groupAttribute, 'value' => $group);
- array_unshift($firstpart, $parts);
+ array_unshift($parts, $firstpart);
$dn->parseDN($parts);
return $dn;
}
@@ -380,7 +380,7 @@ protected function authenticate($username, $password) {
$filterparams,
array('dn'),
LdapConnection::DEREF_NEVER,
- LdapConnection::SCOPE_ONE);
+ LdapConnection::SCOPE_SUB);
if (count($results)) {
return true;
} else {
@@ -414,15 +414,15 @@ protected function authorize($username) {
if ($this->groupAttributeOnUser) {
$base = $this->buildUserDn($username);
if ($this->groupAttributeOnUserIsDn) {
- $param = $this->buildGroupDn($this->requiredGroup);
+ $param = (string)$this->buildGroupDn($this->requiredGroup);
} else {
$param = $this->requiredGroup;
}
$filter = $this->groupAttributeOnUser;
} else if ($this->userAttributeOnGroup) {
$base = $this->buildGroupDn($this->requiredGroup);
if ($this->userAttributeOnGroupIsDn) {
- $param = $this->buildUserDn($username);
+ $param = (string)$this->buildUserDn($username);
} else {
$param = $username;
}
@@ -441,7 +441,7 @@ protected function authorize($username) {
array('param' => $param),
array('dn'),
LdapConnection::DEREF_NEVER,
- LdapConnection::SCOPE_ONE);
+ LdapConnection::SCOPE_SUB);
if (count($results)) {
return true;
View
@@ -77,11 +77,11 @@ public function __destruct() {
*/
public function connect($hostname = false, $port = false) {
if ($hostname && $port) {
- $link = ldap_connect($hostname, $port);
+ $link = @ldap_connect($hostname, $port);
} else if ($hostname) {
- $link = ldap_connect($hostname);
+ $link = @ldap_connect($hostname);
} else {
- $link = ldap_connect();
+ $link = @ldap_connect();
}
if (!$link) {
@@ -96,7 +96,7 @@ public function connect($hostname = false, $port = false) {
* Disconnects from the LDAP server.
*/
public function disconnect() {
- ldap_close($this->link);
+ @ldap_close($this->link);
$this->link = null;
}
@@ -113,16 +113,16 @@ public function bind(LdapDn $rdn = null, $password = "") {
if ($rdn) {
if ($password)
{
- $bind = ldap_bind($this->link, (string)$rdn, $password);
+ $bind = @ldap_bind($this->link, (string)$rdn, $password);
} else {
- $bind = ldap_bind($this->link, (string)$rdn);
+ $bind = @ldap_bind($this->link, (string)$rdn);
}
if (!$bind) {
throw new LdapBindException($this->link);
}
} else {
- $bind = ldap_bind();
+ $bind = @ldap_bind();
if (!$bind) {
throw new LdapBindException($this->link);
}
@@ -149,7 +149,7 @@ public function add(LdapDn $dn, LdapEntry $entry) {
$this->connect();
}
- $result = ldap_add($this->link, (string)$dn, $entry->getAsArray());
+ $result = @ldap_add($this->link, (string)$dn, $entry->getAsArray());
if (!$result) {
throw new LdapAddException($this->link);
@@ -168,7 +168,7 @@ function modify(LdapDn $dn, LdapEntry $entry)
$this->connect();
}
- $result = ldap_modify($this->link, (string)$dn, $entry->getAsArray());
+ $result = @ldap_modify($this->link, (string)$dn, $entry->getAsArray());
if (!$result) {
throw new LdapModifyException($this->link);
@@ -185,7 +185,7 @@ function delete(LdapDn $dn) {
$this->connect();
}
- $result = ldap_delete($this->link, (string)$dn);
+ $result = @ldap_delete($this->link, (string)$dn);
if (!$result) {
throw new LdapDeleteException($this->link);
@@ -246,11 +246,11 @@ public function search(LdapDn $rootdn, $filter, $filterparams = array(), $attrib
$filterparams[":_" . $key] = $value;
}
if ($scope == self::SCOPE_SUB) {
- $result = ldap_search($this->link, (string)$rootdn, strtr($filter, $filterparams), $attributes);
+ $result = @ldap_search($this->link, (string)$rootdn, strtr($filter, $filterparams), $attributes);
} else {
- $result = ldap_list($this->link, (string)$rootdn, strtr($filter, $filterparams), $attributes);
+ $result = @ldap_list($this->link, (string)$rootdn, strtr($filter, $filterparams), $attributes);
}
- $result = ldap_get_entries($this->link, $result);
+ $result = @ldap_get_entries($this->link, $result);
$result = $this->postprocess($result);
if ($result === false) {
throw new LdapSearchException($this->link);
View
@@ -37,6 +37,7 @@ public function __construct($dn = array()) {
* @param array $dn
*/
public function parseDN($dn = array()) {
+ $this->elements = array();
foreach($dn as $entry) {
if (isset($entry['id']) && isset($entry['value'])) {
$this->elements[] = array('id' => $entry['id'], 'value' => $entry['value']);

0 comments on commit 52e7e85

Please sign in to comment.