Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8f4f2b1

Browse files
tatankatnicolas-grekas
authored andcommitted
[Ldap] Do not run ldap_set_option on failed connection
1 parent 7a3991d commit 8f4f2b1

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/Symfony/Component/Ldap/Adapter/ExtLdap/Connection.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,18 +159,18 @@ private function connect()
159159
}
160160
}
161161

162-
$this->connection = ldap_connect($this->config['connection_string']);
162+
if (false === $connection = ldap_connect($this->config['connection_string'])) {
163+
throw new LdapException('Invalid connection string: '.$this->config['connection_string']);
164+
} else {
165+
$this->connection = $connection;
166+
}
163167

164168
foreach ($this->config['options'] as $name => $value) {
165169
if (!\in_array(ConnectionOptions::getOption($name), self::PRECONNECT_OPTIONS, true)) {
166170
$this->setOption($name, $value);
167171
}
168172
}
169173

170-
if (false === $this->connection) {
171-
throw new LdapException('Could not connect to Ldap server: '.ldap_error($this->connection));
172-
}
173-
174174
if ('tls' === $this->config['encryption'] && false === @ldap_start_tls($this->connection)) {
175175
throw new LdapException('Could not initiate TLS connection: '.ldap_error($this->connection));
176176
}

0 commit comments

Comments
 (0)