From 1e73dad1168fa6d9a3473b97a139ee1d40059c4d Mon Sep 17 00:00:00 2001 From: Rudy Onfroy Date: Thu, 13 Sep 2018 15:37:20 +0200 Subject: [PATCH 1/4] ldap query minor refactoring --- .../Component/Ldap/Adapter/AbstractQuery.php | 8 +++--- .../Component/Ldap/Adapter/ExtLdap/Query.php | 25 +++++++++---------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/src/Symfony/Component/Ldap/Adapter/AbstractQuery.php b/src/Symfony/Component/Ldap/Adapter/AbstractQuery.php index 4bba5c2ebee40..25a664c24ece3 100644 --- a/src/Symfony/Component/Ldap/Adapter/AbstractQuery.php +++ b/src/Symfony/Component/Ldap/Adapter/AbstractQuery.php @@ -32,12 +32,12 @@ public function __construct(ConnectionInterface $connection, string $dn, string 'maxItems' => 0, 'sizeLimit' => 0, 'timeout' => 0, - 'deref' => static::DEREF_NEVER, + 'deref' => QueryInterface::DEREF_NEVER, 'attrsOnly' => 0, - 'scope' => static::SCOPE_SUB, + 'scope' => QueryInterface::SCOPE_SUB, )); - $resolver->setAllowedValues('deref', array(static::DEREF_ALWAYS, static::DEREF_NEVER, static::DEREF_FINDING, static::DEREF_SEARCHING)); - $resolver->setAllowedValues('scope', array(static::SCOPE_BASE, static::SCOPE_ONE, static::SCOPE_SUB)); + $resolver->setAllowedValues('deref', array(QueryInterface::DEREF_ALWAYS, QueryInterface::DEREF_NEVER, QueryInterface::DEREF_FINDING, QueryInterface::DEREF_SEARCHING)); + $resolver->setAllowedValues('scope', array(QueryInterface::SCOPE_BASE, QueryInterface::SCOPE_ONE, QueryInterface::SCOPE_SUB)); $resolver->setNormalizer('filter', function (Options $options, $value) { return \is_array($value) ? $value : array($value); diff --git a/src/Symfony/Component/Ldap/Adapter/ExtLdap/Query.php b/src/Symfony/Component/Ldap/Adapter/ExtLdap/Query.php index 05e5878bb2a48..bccc73de77901 100644 --- a/src/Symfony/Component/Ldap/Adapter/ExtLdap/Query.php +++ b/src/Symfony/Component/Ldap/Adapter/ExtLdap/Query.php @@ -12,6 +12,7 @@ namespace Symfony\Component\Ldap\Adapter\ExtLdap; use Symfony\Component\Ldap\Adapter\AbstractQuery; +use Symfony\Component\Ldap\Adapter\QueryInterface; use Symfony\Component\Ldap\Exception\LdapException; use Symfony\Component\Ldap\Exception\NotBoundException; @@ -37,7 +38,7 @@ public function __destruct() $con = $this->connection->getResource(); $this->connection = null; - if (null === $this->search || false === $this->search) { + if (\in_array($this->search, array(null, false), true)) { return; } @@ -62,20 +63,18 @@ public function execute() $con = $this->connection->getResource(); - switch ($this->options['scope']) { - case static::SCOPE_BASE: - $func = 'ldap_read'; - break; - case static::SCOPE_ONE: - $func = 'ldap_list'; - break; - case static::SCOPE_SUB: - $func = 'ldap_search'; - break; - default: - throw new LdapException(sprintf('Could not search in scope "%s".', $this->options['scope'])); + $funcMap = array( + QueryInterface::SCOPE_BASE => 'ldap_read', + QueryInterface::SCOPE_ONE => 'ldap_list', + QueryInterface::SCOPE_SUB => 'ldap_search', + ); + + if (\in_array($this->options['scope'], $funcMap, true)) { + throw new LdapException(sprintf('Could not search in scope "%s".', $this->options['scope'])); } + $func = $funcMap[$this->options['scope']]; + $this->search = @$func( $con, $this->dn, From f9413e09265e837868f9b2ebc7cbb3c34b59e7a5 Mon Sep 17 00:00:00 2001 From: Rudy Onfroy Date: Thu, 13 Sep 2018 16:40:09 +0200 Subject: [PATCH 2/4] fix --- src/Symfony/Component/Ldap/Adapter/ExtLdap/Query.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Ldap/Adapter/ExtLdap/Query.php b/src/Symfony/Component/Ldap/Adapter/ExtLdap/Query.php index bccc73de77901..06146f85279db 100644 --- a/src/Symfony/Component/Ldap/Adapter/ExtLdap/Query.php +++ b/src/Symfony/Component/Ldap/Adapter/ExtLdap/Query.php @@ -69,7 +69,7 @@ public function execute() QueryInterface::SCOPE_SUB => 'ldap_search', ); - if (\in_array($this->options['scope'], $funcMap, true)) { + if (!\array_key_exists($this->options['scope'], $funcMap)) { throw new LdapException(sprintf('Could not search in scope "%s".', $this->options['scope'])); } From 21fb39928ecbcab5b5ca87e8ba5d2a0d63fcabaa Mon Sep 17 00:00:00 2001 From: Rudy Onfroy Date: Mon, 17 Sep 2018 20:14:16 +0200 Subject: [PATCH 3/4] revert --- src/Symfony/Component/Ldap/Adapter/ExtLdap/Query.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/Ldap/Adapter/ExtLdap/Query.php b/src/Symfony/Component/Ldap/Adapter/ExtLdap/Query.php index 06146f85279db..b903a6e9fc185 100644 --- a/src/Symfony/Component/Ldap/Adapter/ExtLdap/Query.php +++ b/src/Symfony/Component/Ldap/Adapter/ExtLdap/Query.php @@ -37,8 +37,7 @@ public function __destruct() { $con = $this->connection->getResource(); $this->connection = null; - - if (\in_array($this->search, array(null, false), true)) { + if (null === $this->search || false === $this->search) { return; } @@ -69,7 +68,7 @@ public function execute() QueryInterface::SCOPE_SUB => 'ldap_search', ); - if (!\array_key_exists($this->options['scope'], $funcMap)) { + if (!isset($funcMap[$this->options['scope']])) { throw new LdapException(sprintf('Could not search in scope "%s".', $this->options['scope'])); } From 185ffd197457c512f2c4c0dcd3886a463db708c1 Mon Sep 17 00:00:00 2001 From: Rudy Onfroy Date: Mon, 17 Sep 2018 20:18:01 +0200 Subject: [PATCH 4/4] revert --- src/Symfony/Component/Ldap/Adapter/ExtLdap/Query.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Symfony/Component/Ldap/Adapter/ExtLdap/Query.php b/src/Symfony/Component/Ldap/Adapter/ExtLdap/Query.php index b903a6e9fc185..ba658663b463e 100644 --- a/src/Symfony/Component/Ldap/Adapter/ExtLdap/Query.php +++ b/src/Symfony/Component/Ldap/Adapter/ExtLdap/Query.php @@ -37,6 +37,7 @@ public function __destruct() { $con = $this->connection->getResource(); $this->connection = null; + if (null === $this->search || false === $this->search) { return; }