Skip to content
Snippets Groups Projects
Unverified Commit 1c7bd3d2 authored by Tim van Dijen's avatar Tim van Dijen Committed by GitHub
Browse files

Make sure $value is of type Array (Part 2)

parent 4a634f74
No related branches found
No related tags found
No related merge requests found
...@@ -53,10 +53,8 @@ class SimpleSAML_Auth_LDAP ...@@ -53,10 +53,8 @@ class SimpleSAML_Auth_LDAP
* @param int $port * @param int $port
* @param bool $referrals * @param bool $referrals
*/ */
// TODO: Flesh out documentation
public function __construct($hostname, $enable_tls = true, $debug = false, $timeout = 0, $port = 389, $referrals = true) public function __construct($hostname, $enable_tls = true, $debug = false, $timeout = 0, $port = 389, $referrals = true)
{ {
// Debug // Debug
SimpleSAML\Logger::debug('Library - LDAP __construct(): Setup LDAP with ' . SimpleSAML\Logger::debug('Library - LDAP __construct(): Setup LDAP with ' .
'host=\'' . $hostname . 'host=\'' . $hostname .
...@@ -207,8 +205,7 @@ class SimpleSAML_Auth_LDAP ...@@ -207,8 +205,7 @@ class SimpleSAML_Auth_LDAP
{ {
// Create the search filter // Create the search filter
$attribute = self::escape_filter_value($attribute, false); $attribute = self::escape_filter_value($attribute, false);
$value = \SimpleSAML\Utils\Arrays::Arrayize($value); $value = self::escape_filter_value($value, true);
$value = self::escape_filter_value($value);
$filter = ''; $filter = '';
foreach ($attribute as $attr) { foreach ($attribute as $attr) {
$filter .= '(' . $attr . '=' . $value. ')'; $filter .= '(' . $attr . '=' . $value. ')';
...@@ -222,8 +219,7 @@ class SimpleSAML_Auth_LDAP ...@@ -222,8 +219,7 @@ class SimpleSAML_Auth_LDAP
// Search using generated filter // Search using generated filter
SimpleSAML\Logger::debug('Library - LDAP search(): Searching base \'' . $base . '\' for \'' . $filter . '\''); SimpleSAML\Logger::debug('Library - LDAP search(): Searching base \'' . $base . '\' for \'' . $filter . '\'');
// TODO: Should aliases be dereferenced? $result = @ldap_search($this->ldap, $base, $filter, array(), 0, 0, $this->timeout, LDAP_DEREF_NEVER);
$result = @ldap_search($this->ldap, $base, $filter, array(), 0, 0, $this->timeout);
if ($result === false) { if ($result === false) {
throw $this->makeException('Library - LDAP search(): Failed search on base \'' . $base . '\' for \'' . $filter . '\''); throw $this->makeException('Library - LDAP search(): Failed search on base \'' . $base . '\' for \'' . $filter . '\'');
} }
...@@ -250,7 +246,6 @@ class SimpleSAML_Auth_LDAP ...@@ -250,7 +246,6 @@ class SimpleSAML_Auth_LDAP
if ($dn === false) { if ($dn === false) {
throw $this->makeException('Library - LDAP search(): Unable to get DN after searching base \'' . $base . '\' for \'' . $filter . '\''); throw $this->makeException('Library - LDAP search(): Unable to get DN after searching base \'' . $base . '\' for \'' . $filter . '\'');
} }
// FIXME: Are we now sure, if no excepton has been thrown, that we are returning a DN?
return $dn; return $dn;
} }
...@@ -598,7 +593,6 @@ class SimpleSAML_Auth_LDAP ...@@ -598,7 +593,6 @@ class SimpleSAML_Auth_LDAP
* @param string $password * @param string $password
* @return array|bool * @return array|bool
*/ */
// TODO: Documentation; only cleared up exception/log messages
public function validate($config, $username, $password = null) public function validate($config, $username, $password = null)
{ {
/* Escape any characters with a special meaning in LDAP. The following /* Escape any characters with a special meaning in LDAP. The following
...@@ -644,15 +638,13 @@ class SimpleSAML_Auth_LDAP ...@@ -644,15 +638,13 @@ class SimpleSAML_Auth_LDAP
* backslash followed by two hex digits representing the hexadecimal value of the character. * backslash followed by two hex digits representing the hexadecimal value of the character.
* *
* @static * @static
* @param array $values Array of values to escape * @param string|array $values Array of values to escape
* @return array Array $values, but escaped * @return array Array $values, but escaped
*/ */
public static function escape_filter_value($values = array(), $singleValue = true) public static function escape_filter_value($values = array(), $singleValue = true)
{ {
// Parameter validation // Parameter validation
if (!is_array($values)) { $values = \SimpleSAML\Utils\Arrays::arrayize($values);
$values = array($values);
}
foreach ($values as $key => $val) { foreach ($values as $key => $val) {
// Escaping of filter meta characters // Escaping of filter meta characters
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment