From 22c89200ca0ec3afa9075d6d009d22e8941299b6 Mon Sep 17 00:00:00 2001 From: Kees Monshouwer Date: Sun, 15 Oct 2017 00:13:02 +0200 Subject: [PATCH] auth: ldapbackend, use the timeout setting in the PowerLDAP class --- modules/ldapbackend/ldapbackend.cc | 2 +- modules/ldapbackend/ldaputils.hh | 2 +- modules/ldapbackend/powerldap.cc | 21 +++++++++++---------- modules/ldapbackend/powerldap.hh | 13 +++++++------ 4 files changed, 20 insertions(+), 18 deletions(-) diff --git a/modules/ldapbackend/ldapbackend.cc b/modules/ldapbackend/ldapbackend.cc index a85eb257d..0fa2b45d1 100644 --- a/modules/ldapbackend/ldapbackend.cc +++ b/modules/ldapbackend/ldapbackend.cc @@ -81,7 +81,7 @@ LdapBackend::LdapBackend( const string &suffix ) L << Logger::Info << m_myname << " LDAP servers = " << hoststr << endl; - m_pldap = new PowerLDAP( hoststr.c_str(), LDAP_PORT, mustDo( "starttls" ) ); + m_pldap = new PowerLDAP( hoststr.c_str(), LDAP_PORT, mustDo( "starttls" ), getArgAsNum( "timeout" ) ); m_pldap->setOption( LDAP_OPT_DEREF, LDAP_DEREF_ALWAYS ); string bindmethod = getArg( "bindmethod" ); diff --git a/modules/ldapbackend/ldaputils.hh b/modules/ldapbackend/ldaputils.hh index ff26af391..83012f234 100644 --- a/modules/ldapbackend/ldaputils.hh +++ b/modules/ldapbackend/ldaputils.hh @@ -31,6 +31,6 @@ void ldapGetOption( LDAP *conn, int option, void *value ); std::string ldapGetError( LDAP *conn, int code ); -int ldapWaitResult( LDAP *conn, int msgid = LDAP_RES_ANY, int timeout = 0, LDAPMessage** result = NULL ); +int ldapWaitResult( LDAP *conn, int msgid, int timeout, LDAPMessage** result = NULL ); #endif // LDAPUTILS_HH diff --git a/modules/ldapbackend/powerldap.cc b/modules/ldapbackend/powerldap.cc index e7f6cc3cb..44e828374 100644 --- a/modules/ldapbackend/powerldap.cc +++ b/modules/ldapbackend/powerldap.cc @@ -32,12 +32,13 @@ -PowerLDAP::PowerLDAP( const string& hosts, uint16_t port, bool tls ) +PowerLDAP::PowerLDAP( const string& hosts, uint16_t port, bool tls, int timeout ) { d_ld = 0; d_hosts = hosts; d_port = port; d_tls = tls; + d_timeout = timeout; ensureConnect(); } @@ -131,7 +132,7 @@ void PowerLDAP::bind( LdapAuthenticator* authenticator ) } -void PowerLDAP::bind( const string& ldapbinddn, const string& ldapsecret, int method, int timeout ) +void PowerLDAP::bind( const string& ldapbinddn, const string& ldapsecret, int method) { int msgid; @@ -153,7 +154,7 @@ void PowerLDAP::bind( const string& ldapbinddn, const string& ldapsecret, int me } #endif - waitResult( msgid, timeout, NULL ); + waitResult( msgid, NULL ); } @@ -163,7 +164,7 @@ void PowerLDAP::bind( const string& ldapbinddn, const string& ldapsecret, int me void PowerLDAP::simpleBind( const string& ldapbinddn, const string& ldapsecret ) { - this->bind( ldapbinddn, ldapsecret, LDAP_AUTH_SIMPLE, 30 ); + this->bind( ldapbinddn, ldapsecret, LDAP_AUTH_SIMPLE ); } @@ -197,13 +198,13 @@ int PowerLDAP::search( const string& base, int scope, const string& filter, cons * ldap_msgfree! */ -int PowerLDAP::waitResult( int msgid, int timeout, LDAPMessage** result ) +int PowerLDAP::waitResult( int msgid, LDAPMessage** result ) { - return ldapWaitResult( d_ld, msgid, timeout, result ); + return ldapWaitResult( d_ld, msgid, d_timeout, result ); } -bool PowerLDAP::getSearchEntry( int msgid, sentry_t& entry, bool dn, int timeout ) +bool PowerLDAP::getSearchEntry( int msgid, sentry_t& entry, bool dn ) { int i; char* attr; @@ -215,7 +216,7 @@ bool PowerLDAP::getSearchEntry( int msgid, sentry_t& entry, bool dn, int timeout bool hasResult = false; while ( !hasResult ) { - i = waitResult( msgid, timeout, &result ); + i = waitResult( msgid, &result ); // Here we deliberately ignore LDAP_RES_SEARCH_REFERENCE as we don't follow them. // Instead we get the next result. // If the function returned an error (i <= 0) we'll deal with after this loop too. @@ -287,12 +288,12 @@ bool PowerLDAP::getSearchEntry( int msgid, sentry_t& entry, bool dn, int timeout } -void PowerLDAP::getSearchResults( int msgid, sresult_t& result, bool dn, int timeout ) +void PowerLDAP::getSearchResults( int msgid, sresult_t& result, bool dn ) { sentry_t entry; result.clear(); - while( getSearchEntry( msgid, entry, dn, timeout ) ) + while( getSearchEntry( msgid, entry, dn ) ) { result.push_back( entry ); } diff --git a/modules/ldapbackend/powerldap.hh b/modules/ldapbackend/powerldap.hh index 27e2f032c..48d5d919b 100644 --- a/modules/ldapbackend/powerldap.hh +++ b/modules/ldapbackend/powerldap.hh @@ -47,16 +47,17 @@ class PowerLDAP string d_hosts; int d_port; bool d_tls; - + int d_timeout; + const string getError( int rc = -1 ); - int waitResult( int msgid = LDAP_RES_ANY, int timeout = 0, LDAPMessage** result = NULL ); + int waitResult( int msgid = LDAP_RES_ANY, LDAPMessage** result = NULL ); void ensureConnect(); public: typedef map > sentry_t; typedef vector sresult_t; - PowerLDAP( const string& hosts = "ldap://127.0.0.1/", uint16_t port = LDAP_PORT, bool tls = false ); + PowerLDAP( const string& hosts, uint16_t port, bool tls, int timeout ); ~PowerLDAP(); bool connect(); @@ -65,13 +66,13 @@ class PowerLDAP void setOption( int option, int value ); void bind( LdapAuthenticator *authenticator ); - void bind( const string& ldapbinddn = "", const string& ldapsecret = "", int method = LDAP_AUTH_SIMPLE, int timeout = 5 ); + void bind( const string& ldapbinddn = "", const string& ldapsecret = "", int method = LDAP_AUTH_SIMPLE ); void simpleBind( const string& ldapbinddn = "", const string& ldapsecret = "" ); int search( const string& base, int scope, const string& filter, const char** attr = 0 ); void modify( const string& dn, LDAPMod *mods[], LDAPControl **scontrols = 0, LDAPControl **ccontrols = 0 ); - bool getSearchEntry( int msgid, sentry_t& entry, bool dn = false, int timeout = 5 ); - void getSearchResults( int msgid, sresult_t& result, bool dn = false, int timeout = 5 ); + bool getSearchEntry( int msgid, sentry_t& entry, bool dn = false ); + void getSearchResults( int msgid, sresult_t& result, bool dn = false ); static const string escape( const string& tobe ); }; -- 2.40.0