don't use deprecated libldap functions

This commit is contained in:
Ralf Haferkamp 2005-10-05 17:26:27 +00:00
parent ebb23234ca
commit efdd59d70d
5 changed files with 32 additions and 19 deletions

View file

@ -21,6 +21,7 @@
#include "LDAPRebind.h"
#include "LDAPRebindAuth.h"
#include "LDAPSearchRequest.h"
#include <sstream>
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<char*>(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;

View file

@ -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(){

View file

@ -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);

View file

@ -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;

View file

@ -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);