]> granicus.if.org Git - pdns/commitdiff
auth: ldapbackend, use the timeout setting in the PowerLDAP class
authorKees Monshouwer <mind04@monshouwer.org>
Sat, 14 Oct 2017 22:13:02 +0000 (00:13 +0200)
committermind04 <mind04@monshouwer.org>
Sat, 14 Oct 2017 22:54:11 +0000 (00:54 +0200)
modules/ldapbackend/ldapbackend.cc
modules/ldapbackend/ldaputils.hh
modules/ldapbackend/powerldap.cc
modules/ldapbackend/powerldap.hh

index a85eb257d079337bfa8a37538c341ac9d8b12b65..0fa2b45d10353727ff7dad61e3250ac0696e6ba9 100644 (file)
@@ -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" );
index ff26af391e8397d5cb917f7b8589e7efa1edc0f2..83012f234f720e4ebbcd4fbed98d74e7093f9ad8 100644 (file)
@@ -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
index e7f6cc3cb7050c8da820bf67213ad290cee3606f..44e828374eef5cd6a06e3b2c5d93486cc549dba9 100644 (file)
 
 
 
-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 );
   }
index 27e2f032c0700aee949586d471da8796970d1cb9..48d5d919b292c2f4ff414b5cc024654a40d861e9 100644 (file)
@@ -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<string, vector<string> > sentry_t;
     typedef vector<sentry_t> 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 );
 };