]> git.sur5r.net Git - openldap/blob - contrib/ldapc++/src/LDAPBindRequest.cpp
28d0cf682196c7526a0d689eb87edbbdc12de184
[openldap] / contrib / ldapc++ / src / LDAPBindRequest.cpp
1 /*
2  * Copyright 2000, OpenLDAP Foundation, All Rights Reserved.
3  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
4  */
5
6 #include <ldap.h>
7
8 #include "debug.h"
9
10 #include "LDAPBindRequest.h"
11 #include "LDAPException.h"
12
13 using namespace std;
14
15 LDAPBindRequest::LDAPBindRequest(const LDAPBindRequest& req) :
16         LDAPRequest(req){
17     DEBUG(LDAP_DEBUG_CONSTRUCT, "LDAPBindRequest::LDAPBindRequest(&)" << endl);
18     m_dn=req.m_dn;
19     m_cred=req.m_cred;
20     m_mech=req.m_mech;
21 }
22
23 LDAPBindRequest::LDAPBindRequest(const string& dn,const string& passwd, 
24         LDAPAsynConnection *connect, const LDAPConstraints *cons,
25         bool isReferral=false) : LDAPRequest(connect, cons, isReferral){
26    DEBUG(LDAP_DEBUG_CONSTRUCT,"LDAPBindRequest::LDAPBindRequest()" << endl);
27    DEBUG(LDAP_DEBUG_CONSTRUCT | LDAP_DEBUG_PARAMETER, "   dn:" << dn << endl
28            << "   passwd:" << passwd << endl);
29     m_dn = dn;
30     m_cred = passwd;
31     m_mech = "";
32 }
33
34 LDAPBindRequest::~LDAPBindRequest(){
35     DEBUG(LDAP_DEBUG_DESTROY,"LDAPBindRequest::~LDAPBindRequest()" << endl);
36 }
37
38 LDAPMessageQueue* LDAPBindRequest::sendRequest(){
39     DEBUG(LDAP_DEBUG_TRACE,"LDAPBindRequest::sendRequest()" << endl);
40     int msgID=0;
41     
42     const char* mech = (m_mech == "" ? 0 : m_mech.c_str());
43     BerValue* tmpcred=0;
44     if(m_cred != ""){
45         char* tmppwd = (char*) malloc( (m_cred.size()+1) * sizeof(char));
46         m_cred.copy(tmppwd,string::npos);
47         tmppwd[m_cred.size()]=0;
48         tmpcred=ber_bvstr(tmppwd);
49     }else{
50         tmpcred=(BerValue*) malloc(sizeof(BerValue));
51         tmpcred->bv_len=0;
52         tmpcred->bv_val=0;
53     }
54     const char* dn = 0;
55     if(m_dn != ""){
56         dn = m_dn.c_str();
57     }
58     LDAPControl** tmpSrvCtrls=m_cons->getSrvCtrlsArray();
59     LDAPControl** tmpClCtrls=m_cons->getClCtrlsArray();
60     int err=ldap_sasl_bind(m_connection->getSessionHandle(),dn, 
61             mech, tmpcred, tmpSrvCtrls, tmpClCtrls, &msgID);
62     LDAPControlSet::freeLDAPControlArray(tmpSrvCtrls);
63     LDAPControlSet::freeLDAPControlArray(tmpClCtrls);
64     ber_bvfree(tmpcred);
65
66     if(err != LDAP_SUCCESS){
67         throw LDAPException(err);
68     }else{
69         m_msgID=msgID;
70         return new LDAPMessageQueue(this);
71     }
72 }
73
74 LDAPRequest* LDAPBindRequest::followReferral(LDAPMsg* /*urls*/){
75     DEBUG(LDAP_DEBUG_TRACE,"LDAPBindRequest::followReferral()" << endl);
76     DEBUG(LDAP_DEBUG_TRACE,
77             "ReferralChasing for bind-operation not implemented yet" << endl);
78     return 0;
79 }
80