2000-09-01 14:46:32 -04:00
|
|
|
/*
|
|
|
|
|
* Copyright 2000, OpenLDAP Foundation, All Rights Reserved.
|
|
|
|
|
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <ldap.h>
|
|
|
|
|
|
|
|
|
|
#include "debug.h"
|
|
|
|
|
|
|
|
|
|
#include "LDAPBindRequest.h"
|
|
|
|
|
#include "LDAPException.h"
|
|
|
|
|
|
2001-09-28 12:39:58 -04:00
|
|
|
using namespace std;
|
|
|
|
|
|
2000-09-01 14:46:32 -04:00
|
|
|
LDAPBindRequest::LDAPBindRequest(const LDAPBindRequest& req) :
|
|
|
|
|
LDAPRequest(req){
|
2000-10-03 14:25:34 -04:00
|
|
|
DEBUG(LDAP_DEBUG_CONSTRUCT, "LDAPBindRequest::LDAPBindRequest(&)" << endl);
|
|
|
|
|
m_dn=req.m_dn;
|
|
|
|
|
m_cred=req.m_cred;
|
|
|
|
|
m_mech=req.m_mech;
|
2000-09-01 14:46:32 -04:00
|
|
|
}
|
|
|
|
|
|
2000-10-03 14:25:34 -04:00
|
|
|
LDAPBindRequest::LDAPBindRequest(const string& dn,const string& passwd,
|
|
|
|
|
LDAPAsynConnection *connect, const LDAPConstraints *cons,
|
2002-04-08 07:51:22 -04:00
|
|
|
bool isReferral) : LDAPRequest(connect, cons, isReferral){
|
2000-10-03 14:25:34 -04:00
|
|
|
DEBUG(LDAP_DEBUG_CONSTRUCT,"LDAPBindRequest::LDAPBindRequest()" << endl);
|
|
|
|
|
DEBUG(LDAP_DEBUG_CONSTRUCT | LDAP_DEBUG_PARAMETER, " dn:" << dn << endl
|
2000-09-01 14:46:32 -04:00
|
|
|
<< " passwd:" << passwd << endl);
|
2000-10-03 14:25:34 -04:00
|
|
|
m_dn = dn;
|
|
|
|
|
m_cred = passwd;
|
|
|
|
|
m_mech = "";
|
2000-09-01 14:46:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LDAPBindRequest::~LDAPBindRequest(){
|
2000-10-03 14:25:34 -04:00
|
|
|
DEBUG(LDAP_DEBUG_DESTROY,"LDAPBindRequest::~LDAPBindRequest()" << endl);
|
2000-09-01 14:46:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LDAPMessageQueue* LDAPBindRequest::sendRequest(){
|
|
|
|
|
DEBUG(LDAP_DEBUG_TRACE,"LDAPBindRequest::sendRequest()" << endl);
|
|
|
|
|
int msgID=0;
|
2000-10-03 14:25:34 -04:00
|
|
|
|
|
|
|
|
const char* mech = (m_mech == "" ? 0 : m_mech.c_str());
|
|
|
|
|
BerValue* tmpcred=0;
|
|
|
|
|
if(m_cred != ""){
|
2001-11-14 12:33:54 -05:00
|
|
|
char* tmppwd = (char*) malloc( (m_cred.size()+1) * sizeof(char));
|
2000-10-03 14:25:34 -04:00
|
|
|
m_cred.copy(tmppwd,string::npos);
|
|
|
|
|
tmppwd[m_cred.size()]=0;
|
|
|
|
|
tmpcred=ber_bvstr(tmppwd);
|
|
|
|
|
}else{
|
2001-11-14 12:33:54 -05:00
|
|
|
tmpcred=(BerValue*) malloc(sizeof(BerValue));
|
2000-10-03 14:25:34 -04:00
|
|
|
tmpcred->bv_len=0;
|
|
|
|
|
tmpcred->bv_val=0;
|
|
|
|
|
}
|
|
|
|
|
const char* dn = 0;
|
|
|
|
|
if(m_dn != ""){
|
|
|
|
|
dn = m_dn.c_str();
|
|
|
|
|
}
|
|
|
|
|
LDAPControl** tmpSrvCtrls=m_cons->getSrvCtrlsArray();
|
|
|
|
|
LDAPControl** tmpClCtrls=m_cons->getClCtrlsArray();
|
|
|
|
|
int err=ldap_sasl_bind(m_connection->getSessionHandle(),dn,
|
|
|
|
|
mech, tmpcred, tmpSrvCtrls, tmpClCtrls, &msgID);
|
2001-11-14 12:33:54 -05:00
|
|
|
LDAPControlSet::freeLDAPControlArray(tmpSrvCtrls);
|
|
|
|
|
LDAPControlSet::freeLDAPControlArray(tmpClCtrls);
|
2000-10-03 14:25:34 -04:00
|
|
|
ber_bvfree(tmpcred);
|
|
|
|
|
|
2000-09-01 14:46:32 -04:00
|
|
|
if(err != LDAP_SUCCESS){
|
|
|
|
|
throw LDAPException(err);
|
|
|
|
|
}else{
|
|
|
|
|
m_msgID=msgID;
|
|
|
|
|
return new LDAPMessageQueue(this);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2001-09-28 12:39:58 -04:00
|
|
|
LDAPRequest* LDAPBindRequest::followReferral(LDAPMsg* /*urls*/){
|
2000-09-01 14:46:32 -04:00
|
|
|
DEBUG(LDAP_DEBUG_TRACE,"LDAPBindRequest::followReferral()" << endl);
|
2000-10-05 10:16:16 -04:00
|
|
|
DEBUG(LDAP_DEBUG_TRACE,
|
|
|
|
|
"ReferralChasing for bind-operation not implemented yet" << endl);
|
2000-09-01 14:46:32 -04:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|