Skip to content

Commit ddfb4a8

Browse files
bug #46325 [Ldap] Fix LDAP connection options (buffcode)
This PR was merged into the 4.4 branch. Discussion ---------- [Ldap] Fix LDAP connection options | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | License | MIT This PR adds support for the [`LDAP_OPT_X_TLS_CACERTFILE`](https://www.php.net/manual/de/ldap.constants.php#constant.ldap-opt-x-tls-cacertfile) option in order to specify a CA file which should be used. It is available since the same PHP version [as the other options](https://www.php.net/manual/de/function.ldap-set-option.php) and may just have been forgotten. Furthermore the connection options need to be applied at different stages in order to be effective. Connection options are tagged to be preconnect-options and are executed before `ldap_connect`, all other options continue to be applied between `ldap_connect` and `ldap_bind`. Be aware that [there is no LDAP documentation](https://www.openldap.org/software/man.cgi?query=ldap_get_option&apropos=0&sektion=0&manpath=OpenLDAP+2.6-Release&arch=default&format=html) about which option is global and thus not requiring a connection and which needs one. The preconnect options from this PR come from trial-and-error testing and mailing list entries at OpenLDAP. Maybe also relevant: - https://bugs.php.net/bug.php?id=73558 - https://bugs.php.net/bug.php?id=78029 Commits ------- 78a9c59 Fix LDAP connection options
2 parents a6f405a + 78a9c59 commit ddfb4a8

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ class Connection extends AbstractConnection
2929
private const LDAP_INVALID_CREDENTIALS = 0x31;
3030
private const LDAP_TIMEOUT = 0x55;
3131
private const LDAP_ALREADY_EXISTS = 0x44;
32+
private const PRECONNECT_OPTIONS = [
33+
ConnectionOptions::DEBUG_LEVEL,
34+
ConnectionOptions::X_TLS_CACERTDIR,
35+
ConnectionOptions::X_TLS_CACERTFILE,
36+
ConnectionOptions::X_TLS_REQUIRE_CERT,
37+
];
3238

3339
/** @var bool */
3440
private $bound = false;
@@ -147,10 +153,18 @@ private function connect()
147153
return;
148154
}
149155

156+
foreach ($this->config['options'] as $name => $value) {
157+
if (\in_array(ConnectionOptions::getOption($name), self::PRECONNECT_OPTIONS, true)) {
158+
$this->setOption($name, $value);
159+
}
160+
}
161+
150162
$this->connection = ldap_connect($this->config['connection_string']);
151163

152164
foreach ($this->config['options'] as $name => $value) {
153-
$this->setOption($name, $value);
165+
if (!\in_array(ConnectionOptions::getOption($name), self::PRECONNECT_OPTIONS, true)) {
166+
$this->setOption($name, $value);
167+
}
154168
}
155169

156170
if (false === $this->connection) {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ final class ConnectionOptions
4040
public const DEBUG_LEVEL = 0x5001;
4141
public const TIMEOUT = 0x5002;
4242
public const NETWORK_TIMEOUT = 0x5005;
43+
public const X_TLS_CACERTFILE = 0x6002;
4344
public const X_TLS_CACERTDIR = 0x6003;
4445
public const X_TLS_CERTFILE = 0x6004;
4546
public const X_TLS_CRL_ALL = 0x02;

0 commit comments

Comments
 (0)