Skip to content
This repository
Browse code

Issue #380: Minor fixes to LDAP lib

  • Loading branch information...
commit 52e7e85ccc7b48c60badf676d9c2537894d4a95a 1 parent 6f44d59
János Pásztor authored
16  Ldap/LdapAuthenticationProvider.php
@@ -312,10 +312,10 @@ protected function buildUserDn($username) {
312 312
 				'LdapAuthenticationProvider::setUserAttribute() before calling authenticateAndAuthorize()');
313 313
 		}
314 314
 		
315  
-		$dn = $this->userDn;
  315
+		$dn = clone $this->userDn;
316 316
 		$parts = $dn->getParts();
317 317
 		$firstpart = array('id' => $this->userAttribute, 'value' => $username);
318  
-		array_unshift($firstpart, $parts);
  318
+		array_unshift($parts, $firstpart);
319 319
 		$dn->parseDN($parts);
320 320
 		return $dn;
321 321
 	}
@@ -335,10 +335,10 @@ protected function buildGroupDn($group) {
335 335
 				'LdapAuthenticationProvider::setGroupAttribute() before calling authenticateAndAuthorize()');
336 336
 		}
337 337
 		
338  
-		$dn = $this->groupDn;
  338
+		$dn = clone $this->groupDn;
339 339
 		$parts = $dn->getParts();
340 340
 		$firstpart = array('id' => $this->groupAttribute, 'value' => $group);
341  
-		array_unshift($firstpart, $parts);
  341
+		array_unshift($parts, $firstpart);
342 342
 		$dn->parseDN($parts);
343 343
 		return $dn;
344 344
 	}
@@ -380,7 +380,7 @@ protected function authenticate($username, $password) {
380 380
 				$filterparams,
381 381
 				array('dn'),
382 382
 				LdapConnection::DEREF_NEVER,
383  
-				LdapConnection::SCOPE_ONE);
  383
+				LdapConnection::SCOPE_SUB);
384 384
 			if (count($results)) {
385 385
 				return true;
386 386
 			} else {
@@ -414,7 +414,7 @@ protected function authorize($username) {
414 414
 		if ($this->groupAttributeOnUser) {
415 415
 			$base = $this->buildUserDn($username);
416 416
 			if ($this->groupAttributeOnUserIsDn) {
417  
-				$param = $this->buildGroupDn($this->requiredGroup);
  417
+				$param = (string)$this->buildGroupDn($this->requiredGroup);
418 418
 			} else {
419 419
 				$param = $this->requiredGroup;
420 420
 			}
@@ -422,7 +422,7 @@ protected function authorize($username) {
422 422
 		} else if ($this->userAttributeOnGroup) {
423 423
 			$base = $this->buildGroupDn($this->requiredGroup);
424 424
 			if ($this->userAttributeOnGroupIsDn) {
425  
-				$param = $this->buildUserDn($username);
  425
+				$param = (string)$this->buildUserDn($username);
426 426
 			} else {
427 427
 				$param = $username;
428 428
 			}
@@ -441,7 +441,7 @@ protected function authorize($username) {
441 441
 			array('param' => $param),
442 442
 			array('dn'),
443 443
 			LdapConnection::DEREF_NEVER,
444  
-			LdapConnection::SCOPE_ONE);
  444
+			LdapConnection::SCOPE_SUB);
445 445
 		
446 446
 		if (count($results)) {
447 447
 			return true;
26  Ldap/LdapConnection.php
@@ -77,11 +77,11 @@ public function __destruct() {
77 77
 	 */
78 78
 	public function connect($hostname = false, $port = false) {
79 79
 		if ($hostname && $port) {
80  
-			$link = ldap_connect($hostname, $port);
  80
+			$link = @ldap_connect($hostname, $port);
81 81
 		} else if ($hostname) {
82  
-			$link = ldap_connect($hostname);
  82
+			$link = @ldap_connect($hostname);
83 83
 		} else {
84  
-			$link = ldap_connect();
  84
+			$link = @ldap_connect();
85 85
 		}
86 86
 
87 87
 		if (!$link) {
@@ -96,7 +96,7 @@ public function connect($hostname = false, $port = false) {
96 96
 	 * Disconnects from the LDAP server. 
97 97
 	 */
98 98
 	public function disconnect() {
99  
-		ldap_close($this->link);
  99
+		@ldap_close($this->link);
100 100
 		$this->link = null;
101 101
 	}
102 102
 
@@ -113,16 +113,16 @@ public function bind(LdapDn $rdn = null, $password = "") {
113 113
 		if ($rdn) {
114 114
 			if ($password)
115 115
 			{
116  
-				$bind = ldap_bind($this->link, (string)$rdn, $password);
  116
+				$bind = @ldap_bind($this->link, (string)$rdn, $password);
117 117
 			} else {
118  
-				$bind = ldap_bind($this->link, (string)$rdn);
  118
+				$bind = @ldap_bind($this->link, (string)$rdn);
119 119
 			}
120 120
 
121 121
 			if (!$bind) {
122 122
 				throw new LdapBindException($this->link);
123 123
 			}
124 124
 		} else {
125  
-			$bind = ldap_bind();
  125
+			$bind = @ldap_bind();
126 126
 			if (!$bind) {
127 127
 				throw new LdapBindException($this->link);
128 128
 			}
@@ -149,7 +149,7 @@ public function add(LdapDn $dn, LdapEntry $entry) {
149 149
 			$this->connect();
150 150
 		}
151 151
 
152  
-		$result = ldap_add($this->link, (string)$dn, $entry->getAsArray());
  152
+		$result = @ldap_add($this->link, (string)$dn, $entry->getAsArray());
153 153
 
154 154
 		if (!$result) {
155 155
 			throw new LdapAddException($this->link);
@@ -168,7 +168,7 @@ function modify(LdapDn $dn, LdapEntry $entry)
168 168
 			$this->connect();
169 169
 		}
170 170
 
171  
-		$result = ldap_modify($this->link, (string)$dn, $entry->getAsArray());
  171
+		$result = @ldap_modify($this->link, (string)$dn, $entry->getAsArray());
172 172
 
173 173
 		if (!$result) {
174 174
 			throw new LdapModifyException($this->link);
@@ -185,7 +185,7 @@ function delete(LdapDn $dn) {
185 185
 			$this->connect();
186 186
 		}
187 187
 
188  
-		$result = ldap_delete($this->link, (string)$dn);
  188
+		$result = @ldap_delete($this->link, (string)$dn);
189 189
 
190 190
 		if (!$result) {
191 191
 			throw new LdapDeleteException($this->link);
@@ -246,11 +246,11 @@ public function search(LdapDn $rootdn, $filter, $filterparams = array(), $attrib
246 246
 			$filterparams[":_" . $key] = $value;
247 247
 	    }
248 248
 	    if ($scope == self::SCOPE_SUB) {
249  
-			$result = ldap_search($this->link, (string)$rootdn, strtr($filter, $filterparams), $attributes);
  249
+			$result = @ldap_search($this->link, (string)$rootdn, strtr($filter, $filterparams), $attributes);
250 250
 	    } else {
251  
-			$result = ldap_list($this->link, (string)$rootdn, strtr($filter, $filterparams), $attributes);
  251
+			$result = @ldap_list($this->link, (string)$rootdn, strtr($filter, $filterparams), $attributes);
252 252
 	    }
253  
-		$result = ldap_get_entries($this->link, $result);
  253
+		$result = @ldap_get_entries($this->link, $result);
254 254
 		$result = $this->postprocess($result);
255 255
 		if ($result === false) {
256 256
 			throw new LdapSearchException($this->link);
1  Ldap/LdapDn.php
@@ -37,6 +37,7 @@ public function __construct($dn = array()) {
37 37
 	 * @param   array   $dn
38 38
 	 */
39 39
 	public function parseDN($dn = array()) {
  40
+		$this->elements = array();
40 41
 		foreach($dn as $entry) {
41 42
 			if (isset($entry['id']) && isset($entry['value'])) {
42 43
 				$this->elements[] = array('id' => $entry['id'], 'value' => $entry['value']);

0 notes on commit 52e7e85

Please sign in to comment.
Something went wrong with that request. Please try again.