1// $OpenLDAP$
2/*
3 * Copyright 2007-2021 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
5 */
6
7#include "debug.h"
8#include <lber.h>
9#include "LDAPRequest.h"
10#include "LDAPException.h"
11
12#include "LDAPResult.h"
13#include "LDAPSaslBindResult.h"
14
15using namespace std;
16
17LDAPSaslBindResult::LDAPSaslBindResult(const LDAPRequest* req, LDAPMessage* msg) :
18        LDAPResult(req, msg){
19    DEBUG(LDAP_DEBUG_CONSTRUCT,"LDAPSaslBindResult::LDAPSaslBindResult()"
20            << std::endl);
21    BerValue* data = 0;
22    LDAP* lc = req->getConnection()->getSessionHandle();
23    int err = ldap_parse_sasl_bind_result(lc, msg, &data, 0);
24    if( err != LDAP_SUCCESS && err != LDAP_SASL_BIND_IN_PROGRESS ){
25        ber_bvfree(data);
26        throw LDAPException(err);
27    }else{
28        if(data){
29            DEBUG(LDAP_DEBUG_TRACE, "   creds present" << std::endl);
30            m_creds=string(data->bv_val, data->bv_len);
31            ber_bvfree(data);
32        } else {
33            DEBUG(LDAP_DEBUG_TRACE, "   no creds present" << std::endl);
34        }
35    }
36}
37
38LDAPSaslBindResult::~LDAPSaslBindResult(){
39    DEBUG(LDAP_DEBUG_DESTROY,"LDAPSaslBindResult::~LDAPSaslBindResult()" << endl);
40}
41
42const string& LDAPSaslBindResult::getServerCreds() const{
43    return m_creds;
44}
45
46