From bb602a52a387c4745bb1196d2275df506ff0ac29 Mon Sep 17 00:00:00 2001 From: imt-mines-albi Date: Fri, 30 Nov 2018 12:54:28 +0000 Subject: [PATCH] ldap-contacts-suggestions: Allow anonymous ldap_bind() if bind DN is not filled up in plugin config --- .../LdapContactsSuggestions.php | 17 ++++++++++++----- plugins/ldap-contacts-suggestions/VERSION | 2 +- plugins/ldap-contacts-suggestions/index.php | 6 +++--- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/plugins/ldap-contacts-suggestions/LdapContactsSuggestions.php b/plugins/ldap-contacts-suggestions/LdapContactsSuggestions.php index 9eb538678..0197becd7 100644 --- a/plugins/ldap-contacts-suggestions/LdapContactsSuggestions.php +++ b/plugins/ldap-contacts-suggestions/LdapContactsSuggestions.php @@ -15,12 +15,12 @@ class LdapContactsSuggestions implements \RainLoop\Providers\Suggestions\ISugges /** * @var string */ - private $sAccessDn = ''; + private $sAccessDn = NULL; /** * @var string */ - private $sAccessPassword = ''; + private $sAccessPassword = NULL; /** * @var string @@ -68,8 +68,11 @@ class LdapContactsSuggestions implements \RainLoop\Providers\Suggestions\ISugges { $this->sHostName = $sHostName; $this->iHostPort = $iHostPort; - $this->sAccessDn = $sAccessDn; - $this->sAccessPassword = $sAccessPassword; + if (0 < \strlen($sAccessDn)) + { + $this->sAccessDn = $sAccessDn; + $this->sAccessPassword = $sAccessPassword; + } $this->sUsersDn = $sUsersDn; $this->sObjectClass = $sObjectClass; $this->sNameField = $sNameField; @@ -181,7 +184,11 @@ class LdapContactsSuggestions implements \RainLoop\Providers\Suggestions\ISugges if (!@\ldap_bind($oCon, $this->sAccessDn, $this->sAccessPassword)) { - $this->logLdapError($oCon, 'ldap_bind'); + if ( is_null($this->sAccessDn) ) { + $this->logLdapError($oCon, 'ldap_bind (anonymous)'); + } else { + $this->logLdapError($oCon, 'ldap_bind'); + } return $aResult; } diff --git a/plugins/ldap-contacts-suggestions/VERSION b/plugins/ldap-contacts-suggestions/VERSION index 9f8e9b69a..9459d4ba2 100644 --- a/plugins/ldap-contacts-suggestions/VERSION +++ b/plugins/ldap-contacts-suggestions/VERSION @@ -1 +1 @@ -1.0 \ No newline at end of file +1.1 diff --git a/plugins/ldap-contacts-suggestions/index.php b/plugins/ldap-contacts-suggestions/index.php index b02fc1c37..bc2cade76 100644 --- a/plugins/ldap-contacts-suggestions/index.php +++ b/plugins/ldap-contacts-suggestions/index.php @@ -44,8 +44,7 @@ class LdapContactsSuggestionsPlugin extends \RainLoop\Plugins\AbstractPlugin $sNameField = \trim($this->Config()->Get('plugin', 'name_field', '')); $sEmailField = \trim($this->Config()->Get('plugin', 'mail_field', '')); - if (0 < \strlen($sAccessDn) && 0 < \strlen($sAccessPassword) && 0 < \strlen($sUsersDn) && - 0 < \strlen($sObjectClass) && 0 < \strlen($sEmailField)) + if (0 < \strlen($sUsersDn) && 0 < \strlen($sObjectClass) && 0 < \strlen($sEmailField)) { include_once __DIR__.'/LdapContactsSuggestions.php'; @@ -71,6 +70,7 @@ class LdapContactsSuggestionsPlugin extends \RainLoop\Plugins\AbstractPlugin ->SetType(\RainLoop\Enumerations\PluginPropertyType::INT) ->SetDefaultValue(389), \RainLoop\Plugins\Property::NewInstance('access_dn')->SetLabel('Access dn (login)') + ->SetDescription('LDAP bind DN to authentifcate with. If left blank, anonymous bind will be tried and Access password will be ignored') ->SetDefaultValue(''), \RainLoop\Plugins\Property::NewInstance('access_password')->SetLabel('Access password') ->SetType(\RainLoop\Enumerations\PluginPropertyType::PASSWORD) @@ -89,4 +89,4 @@ class LdapContactsSuggestionsPlugin extends \RainLoop\Plugins\AbstractPlugin ->SetDefaultValue('*') ); } -} \ No newline at end of file +}