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" );
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
-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();
}
}
-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;
}
#endif
- waitResult( msgid, timeout, NULL );
+ waitResult( msgid, NULL );
}
void PowerLDAP::simpleBind( const string& ldapbinddn, const string& ldapsecret )
{
- this->bind( ldapbinddn, ldapsecret, LDAP_AUTH_SIMPLE, 30 );
+ this->bind( ldapbinddn, ldapsecret, LDAP_AUTH_SIMPLE );
}
* 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;
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.
}
-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 );
}
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();
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 );
};