Skip to content

Commit

Permalink
Merge pull request #5822 from mind04/ldap-timeout
Browse files Browse the repository at this point in the history
auth: ldapbackend, use the timeout setting in the PowerLDAP class
  • Loading branch information
aerique committed Oct 23, 2017
2 parents 4bf9281 + 22c8920 commit 8b7645d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 18 deletions.
2 changes: 1 addition & 1 deletion modules/ldapbackend/ldapbackend.cc
Expand Up @@ -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" );
Expand Down
2 changes: 1 addition & 1 deletion modules/ldapbackend/ldaputils.hh
Expand Up @@ -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
21 changes: 11 additions & 10 deletions modules/ldapbackend/powerldap.cc
Expand Up @@ -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();
}

Expand Down Expand Up @@ -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;

Expand All @@ -153,7 +154,7 @@ void PowerLDAP::bind( const string& ldapbinddn, const string& ldapsecret, int me
}
#endif

waitResult( msgid, timeout, NULL );
waitResult( msgid, NULL );
}


Expand All @@ -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 );
}


Expand Down Expand Up @@ -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;
Expand All @@ -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.
Expand Down Expand Up @@ -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 );
}
Expand Down
13 changes: 7 additions & 6 deletions modules/ldapbackend/powerldap.hh
Expand Up @@ -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();
Expand All @@ -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 );
};
Expand Down

0 comments on commit 8b7645d

Please sign in to comment.