From e96f1bb1571c864705c20a976ff64bb40d6b8d06 Mon Sep 17 00:00:00 2001 From: Peter Powell Date: Fri, 27 Sep 2019 22:39:56 +0100 Subject: Deduplicate code for handling with setting LDAP options. --- src/modules/extra/m_ldap.cpp | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'src/modules') diff --git a/src/modules/extra/m_ldap.cpp b/src/modules/extra/m_ldap.cpp index 37a19fb21..70c6e7b04 100644 --- a/src/modules/extra/m_ldap.cpp +++ b/src/modules/extra/m_ldap.cpp @@ -247,6 +247,17 @@ class LDAPService : public LDAPProvider, public SocketThread Connect(); } + int SetOption(int option, void* value) + { + int ret = ldap_set_option(this->con, option, value); + if (ret != LDAP_OPT_SUCCESS) + { + ldap_unbind_ext(this->con, NULL, NULL); + this->con = NULL; + } + return ret; + } + void QueueRequest(LDAPRequest* r) { this->LockQueue(); @@ -318,22 +329,14 @@ class LDAPService : public LDAPProvider, public SocketThread throw LDAPException("Unable to connect to LDAP service " + this->name + ": " + ldap_err2string(i)); const int version = LDAP_VERSION3; - i = ldap_set_option(this->con, LDAP_OPT_PROTOCOL_VERSION, &version); + i = SetOption(LDAP_OPT_PROTOCOL_VERSION, &version); if (i != LDAP_OPT_SUCCESS) - { - ldap_unbind_ext(this->con, NULL, NULL); - this->con = NULL; throw LDAPException("Unable to set protocol version for " + this->name + ": " + ldap_err2string(i)); - } const struct timeval tv = { 0, 0 }; - i = ldap_set_option(this->con, LDAP_OPT_NETWORK_TIMEOUT, &tv); + i = SetOption(LDAP_OPT_NETWORK_TIMEOUT, &tv); if (i != LDAP_OPT_SUCCESS) - { - ldap_unbind_ext(this->con, NULL, NULL); - this->con = NULL; throw LDAPException("Unable to set timeout for " + this->name + ": " + ldap_err2string(i)); - } } void BindAsManager(LDAPInterface* i) CXX11_OVERRIDE -- cgit v1.2.3