[ldap-contacts-suggestions] Add support for StartTLS

The plugin currently supports SSL (by using a ldaps:// URI as the
hostname of the LDAP server) and unencrypted LDAP. This patch
also adds StartTLS support, which is used by many LDAP servers.
This commit is contained in:
David Härdeman 2021-08-22 10:48:33 +02:00
parent c23eeb54be
commit 11294a8f8b
2 changed files with 19 additions and 2 deletions

View file

@ -12,6 +12,11 @@ class LdapContactsSuggestions implements \RainLoop\Providers\Suggestions\ISugges
*/
private $iHostPort = 389;
/**
* @var bool
*/
private $bUseStartTLS = True;
/**
* @var string
*/
@ -60,6 +65,7 @@ class LdapContactsSuggestions implements \RainLoop\Providers\Suggestions\ISugges
/**
* @param string $sHostName
* @param int $iHostPort
* @param bool $bUseStartTLS
* @param string $sAccessDn
* @param string $sAccessPassword
* @param string $sUsersDn
@ -70,10 +76,11 @@ class LdapContactsSuggestions implements \RainLoop\Providers\Suggestions\ISugges
*
* @return \LdapContactsSuggestions
*/
public function SetConfig($sHostName, $iHostPort, $sAccessDn, $sAccessPassword, $sUsersDn, $sObjectClass, $sUidField, $sNameField, $sEmailField, $sAllowedEmails)
public function SetConfig($sHostName, $iHostPort, $bUseStartTLS, $sAccessDn, $sAccessPassword, $sUsersDn, $sObjectClass, $sUidField, $sNameField, $sEmailField, $sAllowedEmails)
{
$this->sHostName = $sHostName;
$this->iHostPort = $iHostPort;
$this->bUseStartTLS = $bUseStartTLS;
if (0 < \strlen($sAccessDn))
{
$this->sAccessDn = $sAccessDn;
@ -190,6 +197,12 @@ class LdapContactsSuggestions implements \RainLoop\Providers\Suggestions\ISugges
@\ldap_set_option($oCon, LDAP_OPT_PROTOCOL_VERSION, 3);
if ($this->bUseStartTLS && !@\ldap_start_tls($oCon))
{
$this->logLdapError($oCon, 'ldap_start_tls');
return $aResult;
}
if (!@\ldap_bind($oCon, $this->sAccessDn, $this->sAccessPassword))
{
if (is_null($this->sAccessDn))