diff options
author | Peter Powell <petpow@saberuk.com> | 2019-09-27 22:39:56 +0100 |
---|---|---|
committer | Peter Powell <petpow@saberuk.com> | 2019-09-27 22:39:56 +0100 |
commit | e96f1bb1571c864705c20a976ff64bb40d6b8d06 (patch) | |
tree | c880b9aed5e7534d5e33394ef5e84d7576a5bce3 /src/modules/extra/m_ldap.cpp | |
parent | 65f74be719bf249f4bc93e09670ee07410ecec96 (diff) |
Deduplicate code for handling with setting LDAP options.
Diffstat (limited to 'src/modules/extra/m_ldap.cpp')
-rw-r--r-- | src/modules/extra/m_ldap.cpp | 23 |
1 files changed, 13 insertions, 10 deletions
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 |