From efdd59d70d4cbf72e7992b2f2eafe817fcd06be6 Mon Sep 17 00:00:00 2001 From: Ralf Haferkamp Date: Wed, 5 Oct 2005 17:26:27 +0000 Subject: [PATCH] don't use deprecated libldap functions --- contrib/ldapc++/src/LDAPAsynConnection.cpp | 18 ++++++++++------ contrib/ldapc++/src/LDAPException.cpp | 23 ++++++++++++++------- contrib/ldapc++/src/LDAPResult.cpp | 4 ++-- contrib/ldapc++/src/LDAPSearchReference.cpp | 4 ++-- contrib/ldapc++/src/LDAPSearchRequest.cpp | 2 +- 5 files changed, 32 insertions(+), 19 deletions(-) diff --git a/contrib/ldapc++/src/LDAPAsynConnection.cpp b/contrib/ldapc++/src/LDAPAsynConnection.cpp index 58b6056576..5e192c3607 100644 --- a/contrib/ldapc++/src/LDAPAsynConnection.cpp +++ b/contrib/ldapc++/src/LDAPAsynConnection.cpp @@ -21,6 +21,7 @@ #include "LDAPRebind.h" #include "LDAPRebindAuth.h" #include "LDAPSearchRequest.h" +#include using namespace std; @@ -48,7 +49,10 @@ void LDAPAsynConnection::init(const string& hostname, int port){ DEBUG(LDAP_DEBUG_TRACE | LDAP_DEBUG_PARAMETER, " hostname:" << hostname << endl << " port:" << port << endl); - cur_session=ldap_init(hostname.c_str(),port); + std::ostringstream urlstream; + urlstream << "ldap://" + hostname << ":" << port; + std::string url = urlstream.str(); + ldap_initialize(&cur_session, url.c_str()); m_host=hostname; m_port=port; int opt=3; @@ -270,18 +274,20 @@ LDAPAsynConnection* LDAPAsynConnection::referralConnect( string dn = auth->getDN(); string passwd = auth->getPassword(); const char* c_dn=0; - const char* c_passwd=0; + struct berval c_passwd = { 0, 0 }; if(dn != ""){ c_dn = dn.c_str(); } if(passwd != ""){ - c_passwd = passwd.c_str(); + c_passwd.bv_val = const_cast(passwd.c_str()); + c_passwd.bv_len = passwd.size(); } - err = ldap_simple_bind_s(tmpConn->getSessionHandle(), c_dn, - c_passwd); + err = ldap_sasl_bind_s(tmpConn->getSessionHandle(), c_dn, + LDAP_SASL_SIMPLE, &c_passwd, NULL, NULL, NULL); } else { // Do anonymous bind - err = ldap_simple_bind_s(tmpConn->getSessionHandle(), 0,0); + err = ldap_sasl_bind_s(tmpConn->getSessionHandle(),NULL, + LDAP_SASL_SIMPLE, NULL, NULL, NULL, NULL); } if( err == LDAP_SUCCESS ){ usedUrl=conUrl; diff --git a/contrib/ldapc++/src/LDAPException.cpp b/contrib/ldapc++/src/LDAPException.cpp index 5038df613b..c7b0c5689e 100644 --- a/contrib/ldapc++/src/LDAPException.cpp +++ b/contrib/ldapc++/src/LDAPException.cpp @@ -21,14 +21,21 @@ LDAPException::LDAPException(int res_code, const string& err_string){ } LDAPException::LDAPException(const LDAPAsynConnection *lc){ - m_err_string=string(); - m_res_string=string(); - LDAP *l = lc->getSessionHandle(); - ldap_get_option(l,LDAP_OPT_ERROR_NUMBER,&m_res_code); - m_res_string=string(ldap_err2string(m_res_code)); - char* err_string; - ldap_get_option(l,LDAP_OPT_ERROR_STRING,&err_string); - m_err_string=string(err_string); + LDAP *l = lc->getSessionHandle(); + ldap_get_option(l,LDAP_OPT_ERROR_NUMBER,&m_res_code); + const char *res_cstring = ldap_err2string(m_res_code); + if ( res_cstring ) { + m_res_string = string(res_cstring); + } else { + m_res_string = ""; + } + const char* err_string; + ldap_get_option(l,LDAP_OPT_ERROR_STRING,&err_string); + if ( err_string ) { + m_res_string = string(err_string); + } else { + m_res_string = ""; + } } LDAPException::~LDAPException(){ diff --git a/contrib/ldapc++/src/LDAPResult.cpp b/contrib/ldapc++/src/LDAPResult.cpp index 598adc330a..5a3b2e48e3 100644 --- a/contrib/ldapc++/src/LDAPResult.cpp +++ b/contrib/ldapc++/src/LDAPResult.cpp @@ -24,13 +24,13 @@ LDAPResult::LDAPResult(const LDAPRequest *req, LDAPMessage *msg) : int err=ldap_parse_result(con->getSessionHandle(),msg,&m_resCode, &matchedDN, &errMsg,&refs,&srvctrls,0); if(err != LDAP_SUCCESS){ - ldap_value_free(refs); + ber_memvfree((void**) refs); ldap_controls_free(srvctrls); throw LDAPException(err); }else{ if (refs){ m_referrals=LDAPUrlList(refs); - ldap_value_free(refs); + ber_memvfree((void**) refs); } if (srvctrls){ m_srvControls = LDAPControlSet(srvctrls); diff --git a/contrib/ldapc++/src/LDAPSearchReference.cpp b/contrib/ldapc++/src/LDAPSearchReference.cpp index 7d22cea52e..a4e1b577ca 100644 --- a/contrib/ldapc++/src/LDAPSearchReference.cpp +++ b/contrib/ldapc++/src/LDAPSearchReference.cpp @@ -24,12 +24,12 @@ LDAPSearchReference::LDAPSearchReference(const LDAPRequest *req, int err = ldap_parse_reference(con->getSessionHandle(), msg, &ref, &srvctrls,0); if (err != LDAP_SUCCESS){ - ldap_value_free(ref); + ber_memvfree((void**) ref); ldap_controls_free(srvctrls); throw LDAPException(err); }else{ m_urlList=LDAPUrlList(ref); - ldap_value_free(ref); + ber_memvfree((void**) ref); if (srvctrls){ m_srvControls = LDAPControlSet(srvctrls); m_hasControls = true; diff --git a/contrib/ldapc++/src/LDAPSearchRequest.cpp b/contrib/ldapc++/src/LDAPSearchRequest.cpp index aa13cd77c9..532e86f38e 100644 --- a/contrib/ldapc++/src/LDAPSearchRequest.cpp +++ b/contrib/ldapc++/src/LDAPSearchRequest.cpp @@ -70,7 +70,7 @@ LDAPMessageQueue* LDAPSearchRequest::sendRequest(){ m_scope, m_filter.c_str(), tmpattrs, m_attrsOnly, tmpSrvCtrl, tmpClCtrl, tmptime, m_cons->getSizeLimit(), &msgID ); delete tmptime; - ldap_value_free(tmpattrs); + ber_memvfree((void**)tmpattrs); LDAPControlSet::freeLDAPControlArray(tmpSrvCtrl); LDAPControlSet::freeLDAPControlArray(tmpClCtrl); -- 2.39.5