summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2018-05-09 16:19:46 +0300
committerAndras Timar <andras.timar@collabora.com>2018-05-09 22:58:19 +0200
commit1e6f6234ff9a6d8473549b2d6f08cca8f19a9dcd (patch)
treebb7d98d0b777d35a49490a3f5f6fe531a7f82852
parent5fb29ca1f9da72641d2647fca100c8b269eeb07e (diff)
Don't throw in LdapUserProfileBe ctor on LDAP misconfiguration
Otherwise LO crashes e.g. at opening Expert Configuration dialog. Instead, log the event, create an empty backend, and return empty values. Reviewed-on: https://gerrit.libreoffice.org/53958 Reviewed-by: Stephan Bergmann <sbergman@redhat.com> Tested-by: Jenkins <ci@libreoffice.org> (cherry picked from commit 5ed889e80805daf8471054786c1e424a73744ad3) Change-Id: I433fc89c003e7886dfc5242a4ef8defa46d643d3 Reviewed-on: https://gerrit.libreoffice.org/54042 Reviewed-by: Andras Timar <andras.timar@collabora.com> Tested-by: Andras Timar <andras.timar@collabora.com>
-rw-r--r--extensions/Library_ldapbe2.mk1
-rw-r--r--extensions/source/config/ldap/ldapuserprofilebe.cxx41
2 files changed, 21 insertions, 21 deletions
diff --git a/extensions/Library_ldapbe2.mk b/extensions/Library_ldapbe2.mk
index 0364d58e8bd1..5ea5a9597101 100644
--- a/extensions/Library_ldapbe2.mk
+++ b/extensions/Library_ldapbe2.mk
@@ -28,6 +28,7 @@ $(eval $(call gb_Library_add_exception_objects,ldapbe2,\
))
$(eval $(call gb_Library_use_libraries,ldapbe2,\
+ comphelper \
cppuhelper \
cppu \
salhelper \
diff --git a/extensions/source/config/ldap/ldapuserprofilebe.cxx b/extensions/source/config/ldap/ldapuserprofilebe.cxx
index daabc23c09ed..5d49d677887f 100644
--- a/extensions/source/config/ldap/ldapuserprofilebe.cxx
+++ b/extensions/source/config/ldap/ldapuserprofilebe.cxx
@@ -30,6 +30,7 @@
#include <com/sun/star/beans/NamedValue.hpp>
#include <com/sun/star/beans/Optional.hpp>
#include <com/sun/star/configuration/theDefaultProvider.hpp>
+#include <comphelper/scopeguard.hxx>
#include <cppuhelper/supportsservice.hxx>
#include <osl/security.hxx>
@@ -42,6 +43,8 @@ LdapUserProfileBe::LdapUserProfileBe( const uno::Reference<uno::XComponentContex
{
LdapDefinition aDefinition;
OUString loggedOnUser;
+ // true initially to handle reentrant call; will become false if readLdapConfiguration fails
+ bool bHaveLdapConfiguration = true;
// This whole rigmarole is to prevent an infinite recursion where reading
// the configuration for the backend would create another instance of the
@@ -55,30 +58,26 @@ LdapUserProfileBe::LdapUserProfileBe( const uno::Reference<uno::XComponentContex
if (!bReentrantCall)
{
- try
- {
- bReentrantCall = true ;
- if (!readLdapConfiguration(
- xContext, &aDefinition, &loggedOnUser))
- {
- throw css::uno::RuntimeException(
- OUString("LdapUserProfileBe- LDAP not configured"),
- nullptr);
- }
-
- bReentrantCall = false ;
- }
- catch (...)
- {
- bReentrantCall = false;
- throw;
- }
+ bReentrantCall = true ;
+ comphelper::ScopeGuard aReentrantCallGuard([]() { bReentrantCall = false; });
+ // Don't throw on fail: this will crash if LDAP is misconfigured, and user opens
+ // Expert Configuration dialog. Instead, just don't fill data_, which will make the
+ // backend return empty values. This happens in SvtUserOptions::Impl::GetValue_Impl
+ // anyway even in throwing scenario, but doing it here also improves performance
+ // because of avoiding repeated attempts to create the backend.
+ bHaveLdapConfiguration = readLdapConfiguration(
+ xContext, &aDefinition, &loggedOnUser);
+ if (!bHaveLdapConfiguration)
+ SAL_WARN("extensions.config", "LdapUserProfileBackend: LDAP not configured");
}
}
- LdapConnection connection;
- connection.connectSimple(aDefinition);
- connection.getUserProfile(loggedOnUser, &data_);
+ if (bHaveLdapConfiguration)
+ {
+ LdapConnection connection;
+ connection.connectSimple(aDefinition);
+ connection.getUserProfile(loggedOnUser, &data_);
+ }
}
LdapUserProfileBe::~LdapUserProfileBe()