Skip to content

Commit

Permalink
Zend_Ldap: always use uri syntax to connect
Browse files Browse the repository at this point in the history
  • Loading branch information
zerocrates committed Aug 29, 2023
1 parent cf11af4 commit 3cfa14e
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions application/libraries/Zend/Ldap.php
Original file line number Diff line number Diff line change
Expand Up @@ -748,20 +748,17 @@ public function connect($host = null, $port = null, $useSsl = null, $useStartTls
throw new Zend_Ldap_Exception(null, 'A host parameter is required');
}

$useUri = false;
/* Because ldap_connect doesn't really try to connect, any connect error
* will actually occur during the ldap_bind call. Therefore, we save the
* connect string here for reporting it in error handling in bind().
*/
$hosts = array();
if (preg_match_all('~ldap(?:i|s)?://~', $host, $hosts, PREG_SET_ORDER) > 0) {
if (preg_match_all('~ldap(i|s)?://~', $host, $hosts, PREG_SET_ORDER) > 0) {
$this->_connectString = $host;
$useUri = true;
$useSsl = false;
$useSsl = isset($hosts[0][1]) && $hosts[0][1] === 's' ? true : false;
} else {
if ($useSsl) {
$this->_connectString = 'ldaps://' . $host;
$useUri = true;
} else {
$this->_connectString = 'ldap://' . $host;
}
Expand All @@ -772,10 +769,8 @@ public function connect($host = null, $port = null, $useSsl = null, $useStartTls

$this->disconnect();

/* Only OpenLDAP 2.2 + supports URLs so if SSL is not requested, just
* use the old form.
*/
$resource = ($useUri) ? @ldap_connect($this->_connectString) : @ldap_connect($host, $port);
/* PHP 8.3 change: multiarg ldap_connect is deprecated so use the string always */
$resource = @ldap_connect($this->_connectString);

if ($resource) {
$this->_resource = $resource;
Expand Down

0 comments on commit 3cfa14e

Please sign in to comment.