#include "LDAPRebind.h"
#include "LDAPRebindAuth.h"
#include "LDAPSearchRequest.h"
+#include <sstream>
using namespace std;
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;
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;
}
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(){
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);
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;
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);