Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • openldap/openldap
  • hyc/openldap
  • ryan/openldap
  • iboukris/openldap
  • ondra/openldap
  • sshanks-kx/openldap
  • blaggacao/openldap
  • pbrezina/openldap
  • quanah/openldap
  • dragos_h/openldap
  • lorenz/openldap
  • tsaarni/openldap
  • fei.ding/openldap
  • orent/openldap
  • arrowplum/openldap
  • barchiesi/openldap
  • jotik/openldap
  • hamano/openldap
  • ingovoss/openldap
  • henson/openldap
  • jlrine2/openldap
  • howeverAT/openldap
  • nivanova/openldap
  • orbea/openldap
  • rdubner/openldap
  • smckinney/openldap
  • jklowden/openldap
  • dpa-openldap/openldap
  • rouzier/openldap
  • orgads/openldap
  • ffontaine/openldap
  • jiaqingz/openldap
  • dcoutadeur/openldap
  • begeragus/openldap
  • pubellit/openldap
  • glandium/openldap
  • facboy/openldap
  • thesamesam/openldap
  • Johan/openldap
  • fkooman/openldap
  • gburd/openldap
  • h-homma/openldap
  • sgallagher/openldap
  • ahmed_zaki/openldap
  • gnoe/openldap
  • mid/openldap
  • clan/openldap
47 results
Show changes
Showing
with 1469 additions and 0 deletions
// $OpenLDAP$
/*
* Copyright 2000-2013 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
#ifndef LDAP_ENTRY_H
#define LDAP_ENTRY_H
#include <ldap.h>
#include <LDAPAttributeList.h>
class LDAPAsynConnection;
/**
* This class is used to store every kind of LDAP Entry.
*/
class LDAPEntry{
public :
/**
* Copy-constructor
*/
LDAPEntry(const LDAPEntry& entry);
/**
* Constructs a new entry (also used as standard constructor).
*
* @param dn The Distinguished Name for the new entry.
* @param attrs The attributes for the new entry.
*/
LDAPEntry(const std::string& dn=std::string(),
const LDAPAttributeList *attrs=0);
/**
* Used internally only.
*
* The constructor is used internally to create a LDAPEntry from
* the C-API's data structurs.
*/
LDAPEntry(const LDAPAsynConnection *ld, LDAPMessage *msg);
/**
* Destructor
*/
~LDAPEntry();
/**
* Assignment operator
*/
LDAPEntry& operator=(const LDAPEntry& from);
/**
* Sets the DN-attribute.
* @param dn: The new DN for the entry.
*/
void setDN(const std::string& dn);
/**
* Sets the attributes of the entry.
* @param attr: A pointer to a std::list of the new attributes.
*/
void setAttributes(LDAPAttributeList *attrs);
/**
* Get an Attribute by its AttributeType (simple wrapper around
* LDAPAttributeList::getAttributeByName() )
* @param name The name of the Attribute to look for
* @return a pointer to the LDAPAttribute with the AttributeType
* "name" or 0, if there is no Attribute of that Type
*/
const LDAPAttribute* getAttributeByName(const std::string& name) const;
/**
* Adds one Attribute to the List of Attributes (simple wrapper around
* LDAPAttributeList::addAttribute() ).
* @param attr The attribute to add to the list.
*/
void addAttribute(const LDAPAttribute& attr);
/**
* Deletes all values of an Attribute from the list of Attributes
* (simple wrapper around LDAPAttributeList::delAttribute() ).
* @param type The attribute to delete.
*/
void delAttribute(const std::string& type);
/**
* Replace an Attribute in the List of Attributes (simple wrapper
* around LDAPAttributeList::replaceAttribute() ).
* @param attr The attribute to add to the list.
*/
void replaceAttribute(const LDAPAttribute& attr);
/**
* @returns The current DN of the entry.
*/
const std::string& getDN() const ;
/**
* @returns A const pointer to the attributes of the entry.
*/
const LDAPAttributeList* getAttributes() const;
/**
* This method can be used to dump the data of a LDAPResult-Object.
* It is only useful for debugging purposes at the moment
*/
friend std::ostream& operator << (std::ostream& s, const LDAPEntry& le);
private :
LDAPAttributeList *m_attrs;
std::string m_dn;
};
#endif //LDAP_ENTRY_H
// $OpenLDAP$
/*
* Copyright 2000-2013 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
#include "LDAPEntryList.h"
#include "LDAPEntry.h"
LDAPEntryList::LDAPEntryList(){
}
LDAPEntryList::LDAPEntryList(const LDAPEntryList& e){
m_entries = e.m_entries;
}
LDAPEntryList::~LDAPEntryList(){
}
size_t LDAPEntryList::size() const{
return m_entries.size();
}
bool LDAPEntryList::empty() const{
return m_entries.empty();
}
LDAPEntryList::const_iterator LDAPEntryList::begin() const{
return m_entries.begin();
}
LDAPEntryList::const_iterator LDAPEntryList::end() const{
return m_entries.end();
}
void LDAPEntryList::addEntry(const LDAPEntry& e){
m_entries.push_back(e);
}
// $OpenLDAP$
/*
* Copyright 2000-2013 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
#ifndef LDAP_ENTRY_LIST_H
#define LDAP_ENTRY_LIST_H
#include <cstdio>
#include <list>
class LDAPEntry;
/**
* For internal use only.
*
* This class is used by LDAPSearchResults to store a std::list of
* LDAPEntry-Objects
*/
class LDAPEntryList{
typedef std::list<LDAPEntry> ListType;
public:
typedef ListType::const_iterator const_iterator;
/**
* Copy-Constructor
*/
LDAPEntryList(const LDAPEntryList& el);
/**
* Default-Constructor
*/
LDAPEntryList();
/**
* Destructor
*/
~LDAPEntryList();
/**
* @return The number of entries currently stored in the list.
*/
size_t size() const;
/**
* @return true if there are zero entries currently stored in the list.
*/
bool empty() const;
/**
* @return An iterator pointing to the first element of the list.
*/
const_iterator begin() const;
/**
* @return An iterator pointing to the end of the list
*/
const_iterator end() const;
/**
* Adds an Entry to the end of the list.
*/
void addEntry(const LDAPEntry& e);
private:
ListType m_entries;
};
#endif // LDAP_ENTRY_LIST_H
// $OpenLDAP$
/*
* Copyright 2000-2013 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
#include <ldap.h>
#include "config.h"
#include "LDAPException.h"
#include "LDAPAsynConnection.h"
#include "LDAPResult.h"
using namespace std;
LDAPException::LDAPException(int res_code, const string& err_string) throw()
: std::runtime_error(err_string)
{
m_res_code=res_code;
m_res_string=string(ldap_err2string(res_code));
m_err_string=err_string;
}
LDAPException::LDAPException(const LDAPAsynConnection *lc) throw()
: std::runtime_error("")
{
LDAP *l = lc->getSessionHandle();
ldap_get_option(l,LDAP_OPT_RESULT_CODE,&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;
#ifdef LDAP_OPT_DIAGNOSTIC_MESSAGE
ldap_get_option(l,LDAP_OPT_DIAGNOSTIC_MESSAGE ,&err_string);
#else
ldap_get_option(l,LDAP_OPT_ERROR_STRING,&err_string);
#endif
if ( err_string ) {
m_err_string = string(err_string);
} else {
m_err_string = "";
}
}
LDAPException::~LDAPException() throw()
{
}
int LDAPException::getResultCode() const throw()
{
return m_res_code;
}
const string& LDAPException::getResultMsg() const throw()
{
return m_res_string;
}
const string& LDAPException::getServerMsg() const throw()
{
return m_err_string;
}
const char* LDAPException::what() const throw()
{
return this->m_res_string.c_str();
}
ostream& operator << (ostream& s, LDAPException e) throw()
{
s << "Error " << e.m_res_code << ": " << e.m_res_string;
if (!e.m_err_string.empty()) {
s << endl << "additional info: " << e.m_err_string ;
}
return s;
}
LDAPReferralException::LDAPReferralException(const LDAPUrlList& urls) throw()
: LDAPException(LDAPResult::REFERRAL) , m_urlList(urls)
{
}
LDAPReferralException::~LDAPReferralException() throw()
{
}
const LDAPUrlList& LDAPReferralException::getUrls() throw()
{
return m_urlList;
}
// $OpenLDAP$
/*
* Copyright 2000-2013 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
#ifndef LDAP_EXCEPTION_H
#define LDAP_EXCEPTION_H
#include <iostream>
#include <string>
#include <stdexcept>
#include <LDAPUrlList.h>
class LDAPAsynConnection;
/**
* This class is only thrown as an Exception and used to signalize error
* conditions during LDAP-operations
*/
class LDAPException : public std::runtime_error
{
public :
/**
* Constructs a LDAPException-object from the parameters
* @param res_code A valid LDAP result code.
* @param err_string An addional error message for the error
* that happend (optional)
*/
LDAPException(int res_code,
const std::string& err_string=std::string()) throw();
/**
* Constructs a LDAPException-object from the error state of a
* LDAPAsynConnection-object
* @param lc A LDAP-Connection for that an error has happend. The
* Constructor tries to read its error state.
*/
LDAPException(const LDAPAsynConnection *lc) throw();
/**
* Destructor
*/
virtual ~LDAPException() throw();
/**
* @return The Result code of the object
*/
int getResultCode() const throw();
/**
* @return The error message that is corresponding to the result
* code .
*/
const std::string& getResultMsg() const throw();
/**
* @return The addional error message of the error (if it was set)
*/
const std::string& getServerMsg() const throw();
virtual const char* what() const throw();
/**
* This method can be used to dump the data of a LDAPResult-Object.
* It is only useful for debugging purposes at the moment
*/
friend std::ostream& operator << (std::ostream &s, LDAPException e) throw();
private :
int m_res_code;
std::string m_res_string;
std::string m_err_string;
};
/**
* This class extends LDAPException and is used to signalize Referrals
* there were received during synchronous LDAP-operations
*/
class LDAPReferralException : public LDAPException
{
public :
/**
* Creates an object that is initialized with a list of URLs
*/
LDAPReferralException(const LDAPUrlList& urls) throw();
/**
* Destructor
*/
~LDAPReferralException() throw();
/**
* @return The List of URLs of the Referral/Search Reference
*/
const LDAPUrlList& getUrls() throw();
private :
LDAPUrlList m_urlList;
};
#endif //LDAP_EXCEPTION_H
/*
* Copyright 2000-2013 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
#include <ldap.h>
#include <lber.h>
#include "debug.h"
#include "LDAPExtRequest.h"
#include "LDAPException.h"
#include "LDAPResult.h"
#include <cstdlib>
using namespace std;
LDAPExtRequest::LDAPExtRequest(const LDAPExtRequest& req) :
LDAPRequest(req){
DEBUG(LDAP_DEBUG_CONSTRUCT,"LDAPExtRequest::LDAPExtRequest(&)" << endl);
m_data=req.m_data;
m_oid=req.m_oid;
}
LDAPExtRequest::LDAPExtRequest(const string& oid, const string& data,
LDAPAsynConnection *connect, const LDAPConstraints *cons,
bool isReferral, const LDAPRequest* parent)
: LDAPRequest(connect, cons, isReferral, parent){
DEBUG(LDAP_DEBUG_CONSTRUCT, "LDAPExtRequest::LDAPExtRequest()" << endl);
DEBUG(LDAP_DEBUG_CONSTRUCT | LDAP_DEBUG_PARAMETER,
" oid:" << oid << endl);
m_oid=oid;
m_data=data;
}
LDAPExtRequest::~LDAPExtRequest(){
DEBUG(LDAP_DEBUG_DESTROY, "LDAPExtRequest::~LDAPExtRequest()" << endl);
}
LDAPMessageQueue* LDAPExtRequest::sendRequest(){
DEBUG(LDAP_DEBUG_TRACE, "LDAPExtRequest::sendRequest()" << endl);
int msgID=0;
BerValue* tmpdata=0;
if(m_data != ""){
tmpdata=(BerValue*) malloc(sizeof(BerValue));
tmpdata->bv_len = m_data.size();
tmpdata->bv_val = (char*) malloc(sizeof(char) * (m_data.size()) );
m_data.copy(tmpdata->bv_val, string::npos);
}
LDAPControl** tmpSrvCtrls=m_cons->getSrvCtrlsArray();
LDAPControl** tmpClCtrls=m_cons->getClCtrlsArray();
int err=ldap_extended_operation(m_connection->getSessionHandle(),
m_oid.c_str(), tmpdata, tmpSrvCtrls, tmpClCtrls, &msgID);
LDAPControlSet::freeLDAPControlArray(tmpSrvCtrls);
LDAPControlSet::freeLDAPControlArray(tmpClCtrls);
ber_bvfree(tmpdata);
if(err != LDAP_SUCCESS){
delete this;
throw LDAPException(err);
}else{
m_msgID=msgID;
return new LDAPMessageQueue(this);
}
}
LDAPRequest* LDAPExtRequest::followReferral(LDAPMsg* ref){
DEBUG(LDAP_DEBUG_TRACE, "LDAPExtRequest::followReferral()" << endl);
LDAPUrlList::const_iterator usedUrl;
LDAPUrlList urls = ((LDAPResult*)ref)->getReferralUrls();
LDAPAsynConnection* con = 0;
try {
con = getConnection()->referralConnect(urls,usedUrl,m_cons);
} catch(LDAPException e){
delete con;
return 0;
}
if(con != 0){
return new LDAPExtRequest(m_oid, m_data, con, m_cons,true,this);
}
return 0;
}
// $OpenLDAP$
/*
* Copyright 2000-2013 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
#ifndef LDAP_EXT_REQUEST_H
#define LDAP_EXT_REQUEST_H
#include <LDAPRequest.h>
class LDAPExtRequest : LDAPRequest {
public:
LDAPExtRequest(const LDAPExtRequest& req);
LDAPExtRequest(const std::string& oid, const std::string& data,
LDAPAsynConnection *connect, const LDAPConstraints *cons,
bool isReferral=false, const LDAPRequest* parent=0);
virtual ~LDAPExtRequest();
virtual LDAPMessageQueue* sendRequest();
virtual LDAPRequest* followReferral(LDAPMsg* urls);
private:
std::string m_oid;
std::string m_data;
};
#endif // LDAP_EXT_REQUEST_H
// $OpenLDAP$
/*
* Copyright 2000-2013 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
#include "debug.h"
#include <lber.h>
#include "LDAPRequest.h"
#include "LDAPException.h"
#include "LDAPResult.h"
#include "LDAPExtResult.h"
using namespace std;
LDAPExtResult::LDAPExtResult(const LDAPRequest* req, LDAPMessage* msg) :
LDAPResult(req, msg){
DEBUG(LDAP_DEBUG_CONSTRUCT,"LDAPExtResult::LDAPExtResult()" << endl);
char* oid = 0;
BerValue* data = 0;
LDAP* lc = req->getConnection()->getSessionHandle();
int err=ldap_parse_extended_result(lc, msg, &oid, &data, 0);
if(err != LDAP_SUCCESS){
ber_bvfree(data);
ldap_memfree(oid);
throw LDAPException(err);
}else{
m_oid=string(oid);
ldap_memfree(oid);
if(data){
m_data=string(data->bv_val, data->bv_len);
ber_bvfree(data);
}
}
}
LDAPExtResult::~LDAPExtResult(){
DEBUG(LDAP_DEBUG_DESTROY,"LDAPExtResult::~LDAPExtResult()" << endl);
}
const string& LDAPExtResult::getResponseOid() const{
return m_oid;
}
const string& LDAPExtResult::getResponse() const{
return m_data;
}
// $OpenLDAP$
/*
* Copyright 2000-2013 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
#ifndef LDAP_EXT_RESULT_H
#define LDAP_EXT_RESULT_H
#include <ldap.h>
#include <LDAPResult.h>
class LDAPRequest;
/**
* Object of this class are created by the LDAPMsg::create method if
* results for an Extended Operation were returned by a LDAP server.
*/
class LDAPExtResult : public LDAPResult {
public :
/**
* Constructor that creates an LDAPExtResult-object from the C-API
* structures
*/
LDAPExtResult(const LDAPRequest* req, LDAPMessage* msg);
/**
* The Destructor
*/
virtual ~LDAPExtResult();
/**
* @returns The OID of the Extended Operation that has returned
* this result.
*/
const std::string& getResponseOid() const;
/**
* @returns If the result contained data this method will return
* the data to the caller as a std::string.
*/
const std::string& getResponse() const;
private:
std::string m_oid;
std::string m_data;
};
#endif // LDAP_EXT_RESULT_H
// $OpenLDAP$
/*
* Copyright 2000-2013 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
#include "LDAPMessage.h"
#include "LDAPResult.h"
#include "LDAPExtResult.h"
#include "LDAPSaslBindResult.h"
#include "LDAPRequest.h"
#include "LDAPSearchResult.h"
#include "LDAPSearchReference.h"
#include "debug.h"
#include <iostream>
using namespace std;
LDAPMsg::LDAPMsg(LDAPMessage *msg){
DEBUG(LDAP_DEBUG_CONSTRUCT,"LDAPMsg::LDAPMsg()" << endl);
msgType=ldap_msgtype(msg);
m_hasControls=false;
}
LDAPMsg::LDAPMsg(int type, int id=0){
DEBUG(LDAP_DEBUG_CONSTRUCT,"LDAPMsg::LDAPMsg()" << endl);
msgType = type;
msgID = id;
m_hasControls=false;
}
LDAPMsg* LDAPMsg::create(const LDAPRequest *req, LDAPMessage *msg){
DEBUG(LDAP_DEBUG_TRACE,"LDAPMsg::create()" << endl);
switch(ldap_msgtype(msg)){
case SEARCH_ENTRY :
return new LDAPSearchResult(req,msg);
break;
case SEARCH_REFERENCE :
return new LDAPSearchReference(req, msg);
break;
case EXTENDED_RESPONSE :
return new LDAPExtResult(req,msg);
break;
case BIND_RESPONSE :
return new LDAPSaslBindResult(req,msg);
default :
return new LDAPResult(req, msg);
}
return 0;
}
int LDAPMsg::getMessageType(){
DEBUG(LDAP_DEBUG_TRACE,"LDAPMsg::getMessageType()" << endl);
return msgType;
}
int LDAPMsg::getMsgID(){
DEBUG(LDAP_DEBUG_TRACE,"LDAPMsg::getMsgID()" << endl);
return msgID;
}
bool LDAPMsg::hasControls() const{
return m_hasControls;
}
const LDAPControlSet& LDAPMsg::getSrvControls() const {
return m_srvControls;
}
// $OpenLDAP$
/*
* Copyright 2000-2013 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
#ifndef LDAP_MSG_H
#define LDAP_MSG_H
#include <ldap.h>
#include <LDAPControlSet.h>
class LDAPRequest;
/**
* This class represents any type of LDAP- Message returned
* from the server.
*
* This class is never not instantiated directly. Only
* its subclasses are used. The main feature of this class is the
* static method create() (see below)
*/
class LDAPMsg{
public:
//public Constants defining the response message types
static const int BIND_RESPONSE=LDAP_RES_BIND;
static const int SEARCH_ENTRY=LDAP_RES_SEARCH_ENTRY;
static const int SEARCH_DONE=LDAP_RES_SEARCH_RESULT;
static const int SEARCH_REFERENCE=LDAP_RES_SEARCH_REFERENCE;
static const int MODIFY_RESPONSE=LDAP_RES_MODIFY;
static const int ADD_RESPONSE=LDAP_RES_ADD;
static const int DEL_RESPONSE=LDAP_RES_DELETE;
static const int MODDN_RESPONSE=LDAP_RES_MODDN;
static const int COMPARE_RESPONSE=LDAP_RES_COMPARE;
static const int EXTENDED_RESPONSE=LDAP_RES_EXTENDED;
//public Constants defining the request message types
static const int BIND_REQUEST=LDAP_REQ_BIND;
static const int UNBIND_REQUEST=LDAP_REQ_UNBIND;
static const int SEARCH_REQUEST=LDAP_REQ_SEARCH;
static const int MODIFY_REQUEST=LDAP_REQ_MODIFY;
static const int ADD_REQUEST=LDAP_REQ_ADD;
static const int DELETE_REQUEST=LDAP_REQ_DELETE;
static const int MODRDN_REQUEST=LDAP_REQ_MODRDN;
static const int COMPARE_REQUEST=LDAP_REQ_COMPARE;
static const int ABANDON_REQUEST=LDAP_REQ_ABANDON;
static const int EXTENDED_REQUEST=LDAP_REQ_EXTENDED;
/**
* The destructor has no implemenation, because this is an abstract
* class.
*/
virtual ~LDAPMsg() {}
/**
* This method is used by the library to parse the results returned
* by the C-API.
*
* Based on msgtype-Value of the *msg-Parameter this method creates
* an Object of one of the subtypes of LDAPMsg (e.g. LDAPSearchResult
* or LDAPResult) that represents the same Message as the
* *msg-Parameter. *msg is e.g. a Message returned by the C-API's
* ldap_result call.
* @param req The LDAPRequest-object this result message is
* associated with.
* @param msg The LDAPMessage-structure from the C-API that
* contains the LDAP-message to parse.
* @return An Object of one of the subtypes of this class. It
* contains the parsed LDAP-message.
*/
static LDAPMsg* create(const LDAPRequest *req, LDAPMessage *msg);
/**
* @returns The Type of message that this object contains. Possible
* values are: <BR>
* BIND_RESPONSE <BR>
* SEARCH_ENTRY <BR>
* SEARCH_DONE <BR>
* SEARCH_REFERENCE <BR>
* MODIFY_RESPONSE <BR>
* ADD_RESPONSE <BR>
* DEL_RESPONSE <BR>
* MODDN_RESPONSE <BR>
* COMPARE_RESPONSE <BR>
* EXTENDED_REPONSE <BR>
*/
int getMessageType();
/**
* @returns The message-ID that the C-API return for the
* Result-message.
*/
int getMsgID();
/**
* @returns If any Control was sent back by the server this method
* returns true. Otherwise false is returned.
*/
bool hasControls() const;
/**
* @returns Server controls that were sent back by the server.
* @note This feature is not test well yet.
*/
const LDAPControlSet& getSrvControls() const;
protected:
/**
* This constructor make a copy of a LDAPMsg-pointer. The object
* itself (no the pointer) is copied.
* Only for internal use.
*/
LDAPMsg(LDAPMessage *msg);
LDAPMsg(int msgType, int msgID);
/**
* This attribute stores Server-Control that were returned with the
* message.
*/
LDAPControlSet m_srvControls;
bool m_hasControls;
private:
int msgType;
int msgID;
};
#endif //ifndef LDAP_MSG_H
// $OpenLDAP$
/*
* Copyright 2000-2013 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
#include "config.h"
#include "debug.h"
#include "LDAPMessageQueue.h"
#include "LDAPRequest.h"
#include "LDAPResult.h"
#include "LDAPSearchReference.h"
#include "LDAPSearchRequest.h"
#include "LDAPUrl.h"
#include "LDAPUrlList.h"
#include "LDAPException.h"
using namespace std;
// TODO: How to handle unsolicited notifications, like notice of
// disconnection
LDAPMessageQueue::LDAPMessageQueue(LDAPRequest *req){
DEBUG(LDAP_DEBUG_CONSTRUCT, "LDAPMessageQueue::LDAPMessageQueue()" << endl);
m_activeReq.push(req);
m_issuedReq.push_back(req);
}
LDAPMessageQueue::~LDAPMessageQueue(){
DEBUG(LDAP_DEBUG_DESTROY, "LDAPMessageQueue::~LDAPMessageQueue()" << endl);
for(LDAPRequestList::iterator i=m_issuedReq.begin();
i != m_issuedReq.end(); i++){
delete *i;
}
m_issuedReq.clear();
}
LDAPMsg *LDAPMessageQueue::getNext(){
DEBUG(LDAP_DEBUG_TRACE,"LDAPMessageQueue::getNext()" << endl);
if ( m_activeReq.empty() ) {
return 0;
}
LDAPRequest *req=m_activeReq.top();
LDAPMsg *ret=0;
try{
ret = req->getNextMessage();
}catch(LDAPException e){
//do some clean up
m_activeReq.pop();
throw;
}
const LDAPConstraints *constr=req->getConstraints();
switch (ret->getMessageType()) {
case LDAPMsg::SEARCH_REFERENCE :
if (constr->getReferralChase() ){
//throws Exception (limit Exceeded)
LDAPRequest *refReq=chaseReferral(ret);
if(refReq != 0){
m_activeReq.push(refReq);
m_issuedReq.push_back(refReq);
delete ret;
return getNext();
}
}
return ret;
break;
case LDAPMsg::SEARCH_ENTRY :
return ret;
break;
case LDAPMsg::SEARCH_DONE :
if(req->isReferral()){
req->unbind();
}
switch ( ((LDAPResult*)ret)->getResultCode()) {
case LDAPResult::REFERRAL :
if(constr->getReferralChase()){
//throws Exception (limit Exceeded)
LDAPRequest *refReq=chaseReferral(ret);
if(refReq != 0){
m_activeReq.pop();
m_activeReq.push(refReq);
m_issuedReq.push_back(refReq);
delete ret;
return getNext();
}
}
return ret;
break;
case LDAPResult::SUCCESS :
if(req->isReferral()){
delete ret;
m_activeReq.pop();
return getNext();
}else{
m_activeReq.pop();
return ret;
}
break;
default:
m_activeReq.pop();
return ret;
break;
}
break;
//must be some kind of LDAPResultMessage
default:
if(req->isReferral()){
req->unbind();
}
LDAPResult* res_p=(LDAPResult*)ret;
switch (res_p->getResultCode()) {
case LDAPResult::REFERRAL :
if(constr->getReferralChase()){
//throws Exception (limit Exceeded)
LDAPRequest *refReq=chaseReferral(ret);
if(refReq != 0){
m_activeReq.pop();
m_activeReq.push(refReq);
m_issuedReq.push_back(refReq);
delete ret;
return getNext();
}
}
return ret;
break;
default:
m_activeReq.pop();
return ret;
}
break;
}
}
// TODO Maybe moved to LDAPRequest::followReferral seems more reasonable
//there
LDAPRequest* LDAPMessageQueue::chaseReferral(LDAPMsg* ref){
DEBUG(LDAP_DEBUG_TRACE,"LDAPMessageQueue::chaseReferral()" << endl);
LDAPRequest *req=m_activeReq.top();
LDAPRequest *refReq=req->followReferral(ref);
if(refReq !=0){
if(refReq->getConstraints()->getHopLimit() < refReq->getHopCount()){
delete(refReq);
throw LDAPException(LDAP_REFERRAL_LIMIT_EXCEEDED);
}
if(refReq->isCycle()){
delete(refReq);
throw LDAPException(LDAP_CLIENT_LOOP);
}
try {
refReq->sendRequest();
return refReq;
}catch (LDAPException e){
DEBUG(LDAP_DEBUG_TRACE," caught exception" << endl);
return 0;
}
}else{
return 0;
}
}
LDAPRequestStack* LDAPMessageQueue::getRequestStack(){
DEBUG(LDAP_DEBUG_TRACE,"LDAPMessageQueue::getRequestStack()" << endl);
return &m_activeReq;
}
// $OpenLDAP$
/*
* Copyright 2000-2013 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
#ifndef LDAP_MESSAGE_QUEUE_H
#define LDAP_MESSAGE_QUEUE_H
#include <stack>
#include <LDAPUrlList.h>
#include <LDAPMessage.h>
class LDAPAsynConnection;
class LDAPRequest;
class LDAPSearchRequest;
class LDAPUrl;
typedef std::stack<LDAPRequest*> LDAPRequestStack;
typedef std::list<LDAPRequest*> LDAPRequestList;
/**
* This class is created for the asynchronous LDAP-operations. And can be
* used by the client to retrieve the results of an operation.
*/
class LDAPMessageQueue{
public :
/**
* This creates a new LDAPMessageQueue. For a LDAP-request
*
* @param conn The Request for that is queue can be used to get
* the results.
*/
LDAPMessageQueue(LDAPRequest *conn);
/**
* Destructor
*/
~LDAPMessageQueue();
/**
* This method reads exactly one Message from the results of a
* Request.
* @throws LDAPException
* @return A pointer to an object of one of the classes that were
* derived from LDAPMsg. The user has to cast it to the
* correct type (e.g. LDAPResult or LDAPSearchResult)
*/
LDAPMsg* getNext();
/**
* For internat use only.
*
* The method is used to start the automatic referral chasing
*/
LDAPRequest* chaseReferral(LDAPMsg* ref);
/**
* For internal use only
*
* The referral chasing algorithm needs this method to see the
* currently active requests.
*/
LDAPRequestStack* getRequestStack();
private :
LDAPRequestStack m_activeReq;
LDAPRequestList m_issuedReq;
};
#endif //ifndef LDAP_MESSAGE_QUEUE_H
// $OpenLDAP$
/*
* Copyright 2000-2013 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
#include <ldap.h>
#include "debug.h"
#include "LDAPModDNRequest.h"
#include "LDAPException.h"
#include "LDAPResult.h"
#include "LDAPUrlList.h"
using namespace std;
LDAPModDNRequest::LDAPModDNRequest(const LDAPModDNRequest& req) :
LDAPRequest(req){
DEBUG(LDAP_DEBUG_CONSTRUCT,
"LDAPModDNRequest::LDAPModDNRequest(&)" << endl);
m_dn = req.m_dn;
m_newRDN = req.m_newRDN;
m_newParentDN = req.m_newParentDN;
m_deleteOld = req.m_deleteOld;
}
LDAPModDNRequest::LDAPModDNRequest(const string& dn, const string& newRDN,
bool deleteOld, const string& newParentDN,
LDAPAsynConnection *connect,
const LDAPConstraints *cons, bool isReferral,
const LDAPRequest* parent):
LDAPRequest(connect, cons, isReferral, parent){
DEBUG(LDAP_DEBUG_CONSTRUCT,
"LDAPModDNRequest::LDAPModDNRequest(&)" << endl);
DEBUG(LDAP_DEBUG_CONSTRUCT | LDAP_DEBUG_PARAMETER,
" dn:" << dn << endl << " newRDN:" << newRDN << endl
<< " deleteOld:" << deleteOld << endl
<< " newParent:" << newParentDN << endl);
m_dn = dn;
m_newRDN = newRDN;
m_newParentDN = newParentDN;
m_deleteOld=deleteOld;
}
LDAPModDNRequest::~LDAPModDNRequest(){
DEBUG(LDAP_DEBUG_DESTROY, "LDAPModDNRequest::~LDAPModDNRequest()" << endl);
}
LDAPMessageQueue* LDAPModDNRequest::sendRequest(){
DEBUG(LDAP_DEBUG_TRACE, "LDAPModDNRequest::sendRequest()" << endl);
int msg_id;
const char* newRDN = (m_newRDN == "" ? 0 :m_newRDN.c_str());
const char* newParentDN = (m_newParentDN == "" ?
0 :
m_newParentDN.c_str());
LDAPControl** tmpSrvCtrls=m_cons->getSrvCtrlsArray();
LDAPControl** tmpClCtrls=m_cons->getClCtrlsArray();
int err=ldap_rename(m_connection->getSessionHandle(),m_dn.c_str(),newRDN,
newParentDN,m_deleteOld ? 1 : 0, tmpSrvCtrls, tmpClCtrls,&msg_id);
LDAPControlSet::freeLDAPControlArray(tmpSrvCtrls);
LDAPControlSet::freeLDAPControlArray(tmpClCtrls);
if(err!=LDAP_SUCCESS){
throw LDAPException(err);
}else{
m_msgID=msg_id;
return new LDAPMessageQueue(this);
}
}
LDAPRequest* LDAPModDNRequest::followReferral(LDAPMsg* ref){
DEBUG(LDAP_DEBUG_TRACE, "LDAPModifyRequest::followReferral()" << endl);
LDAPUrlList::const_iterator usedUrl;
LDAPUrlList urls = ((LDAPResult*)ref)->getReferralUrls();
LDAPAsynConnection* con = 0;
try {
con = getConnection()->referralConnect(urls,usedUrl,m_cons);
} catch(LDAPException e){
delete con;
return 0;
}
if(con != 0){
return new LDAPModDNRequest(m_dn, m_newRDN, m_deleteOld, m_newParentDN,
con, m_cons,true,this);
}
return 0;
}
// $OpenLDAP$
/*
* Copyright 2000-2013 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
#ifndef LDAP_MOD_DN_REQUEST_H
#define LDAP_MOD_DN_REQUEST_H
#include <LDAPRequest.h>
class LDAPModDNRequest : LDAPRequest {
public:
LDAPModDNRequest(const LDAPModDNRequest& req);
LDAPModDNRequest(const std::string& dn, const std::string& newRDN,
bool deleteOld, const std::string& newParentDN,
LDAPAsynConnection *connect, const LDAPConstraints *cons,
bool isReferral=false, const LDAPRequest* parent=0);
virtual ~LDAPModDNRequest();
virtual LDAPMessageQueue* sendRequest();
virtual LDAPRequest* followReferral(LDAPMsg* urls);
private:
std::string m_dn;
std::string m_newRDN;
std::string m_newParentDN;
bool m_deleteOld;
};
#endif // LDAP_MOD_DN_REQUEST_H
// $OpenLDAP$
/*
* Copyright 2000-2013 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
#include "LDAPModList.h"
#include "debug.h"
#include <cstdlib>
using namespace std;
LDAPModList::LDAPModList(){
DEBUG(LDAP_DEBUG_CONSTRUCT,"LDAPModList::LDAPModList()" << endl);
}
LDAPModList::LDAPModList(const LDAPModList& ml){
DEBUG(LDAP_DEBUG_CONSTRUCT,"LDAPModList::LDAPModList(&)" << endl);
m_modList=ml.m_modList;
}
void LDAPModList::addModification(const LDAPModification &mod){
DEBUG(LDAP_DEBUG_TRACE,"LDAPModList::addModification()" << endl);
m_modList.push_back(mod);
}
LDAPMod** LDAPModList::toLDAPModArray(){
DEBUG(LDAP_DEBUG_TRACE,"LDAPModList::toLDAPModArray()" << endl);
LDAPMod **ret = (LDAPMod**) malloc(
(m_modList.size()+1) * sizeof(LDAPMod*));
ret[m_modList.size()]=0;
LDAPModList::ListType::const_iterator i;
int j=0;
for (i=m_modList.begin(); i != m_modList.end(); i++ , j++){
ret[j]=i->toLDAPMod();
}
return ret;
}
bool LDAPModList::empty() const {
return m_modList.empty();
}
unsigned int LDAPModList::size() const {
return m_modList.size();
}
// $OpenLDAP$
/*
* Copyright 2000-2013 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
#ifndef LDAP_MOD_LIST_H
#define LDAP_MOD_LIST_H
#include <ldap.h>
#include <list>
#include <LDAPModification.h>
/**
* This container class is used to store multiple LDAPModification-objects.
*/
class LDAPModList{
typedef std::list<LDAPModification> ListType;
public :
/**
* Constructs an empty list.
*/
LDAPModList();
/**
* Copy-constructor
*/
LDAPModList(const LDAPModList&);
/**
* Adds one element to the end of the list.
* @param mod The LDAPModification to add to the std::list.
*/
void addModification(const LDAPModification &mod);
/**
* Translates the list to a 0-terminated array of
* LDAPMod-structures as needed by the C-API
*/
LDAPMod** toLDAPModArray();
/**
* @returns true, if the ModList contains no Operations
*/
bool empty() const;
/**
* @returns number of Modifications in the ModList
*/
unsigned int size() const;
private :
ListType m_modList;
};
#endif //LDAP_MOD_LIST_H
// $OpenLDAP$
/*
* Copyright 2000-2013 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
#include "LDAPModification.h"
#include "debug.h"
using namespace std;
LDAPModification::LDAPModification(const LDAPAttribute& attr, mod_op op){
DEBUG(LDAP_DEBUG_CONSTRUCT,"LDAPModification::LDAPModification()" << endl);
DEBUG(LDAP_DEBUG_CONSTRUCT | LDAP_DEBUG_PARAMETER,
" attr:" << attr << endl);
m_attr = attr;
m_mod_op = op;
}
LDAPMod* LDAPModification::toLDAPMod() const {
DEBUG(LDAP_DEBUG_TRACE,"LDAPModification::toLDAPMod()" << endl);
LDAPMod* ret=m_attr.toLDAPMod();
//The mod_op value of the LDAPMod-struct needs to be ORed with the right
// LDAP_MOD_* constant to preserve the BIN-flag (see CAPI-draft for
// explanation of the LDAPMod struct)
switch (m_mod_op){
case OP_ADD :
ret->mod_op |= LDAP_MOD_ADD;
break;
case OP_DELETE :
ret->mod_op |= LDAP_MOD_DELETE;
break;
case OP_REPLACE :
ret->mod_op |= LDAP_MOD_REPLACE;
break;
}
return ret;
}
const LDAPAttribute* LDAPModification::getAttribute() const {
return &m_attr;
}
LDAPModification::mod_op LDAPModification::getOperation() const {
return m_mod_op;
}
// $OpenLDAP$
/*
* Copyright 2000-2013 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
#ifndef LDAP_MODIFICATION_H
#define LDAP_MODIFICATION_H
#include <ldap.h>
#include <LDAPAttribute.h>
class LDAPModification{
public:
enum mod_op {OP_ADD, OP_DELETE, OP_REPLACE};
LDAPModification(const LDAPAttribute& attr, mod_op op);
LDAPMod *toLDAPMod() const;
const LDAPAttribute* getAttribute() const;
mod_op getOperation() const;
private:
LDAPAttribute m_attr;
mod_op m_mod_op;
};
#endif //LDAP_MODIFICATION_H
// $OpenLDAP$
/*
* Copyright 2000-2013 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
#include <ldap.h>
#include "debug.h"
#include "LDAPModifyRequest.h"
#include "LDAPException.h"
#include "LDAPMessageQueue.h"
#include "LDAPResult.h"
using namespace std;
LDAPModifyRequest::LDAPModifyRequest(const LDAPModifyRequest& req) :
LDAPRequest(req){
DEBUG(LDAP_DEBUG_CONSTRUCT,
"LDAPModifyRequest::LDAPModifyRequest(&)" << endl);
m_modList = new LDAPModList(*(req.m_modList));
m_dn = req.m_dn;
}
LDAPModifyRequest::LDAPModifyRequest(const string& dn,
const LDAPModList *modList, LDAPAsynConnection *connect,
const LDAPConstraints *cons, bool isReferral,
const LDAPRequest* parent) :
LDAPRequest(connect, cons, isReferral, parent){
DEBUG(LDAP_DEBUG_CONSTRUCT,
"LDAPModifyRequest::LDAPModifyRequest(&)" << endl);
DEBUG(LDAP_DEBUG_CONSTRUCT | LDAP_DEBUG_PARAMETER,
" dn:" << dn << endl);
m_dn = dn;
m_modList = new LDAPModList(*modList);
}
LDAPModifyRequest::~LDAPModifyRequest(){
DEBUG(LDAP_DEBUG_DESTROY,
"LDAPModifyRequest::~LDAPModifyRequest()" << endl);
delete m_modList;
}
LDAPMessageQueue* LDAPModifyRequest::sendRequest(){
DEBUG(LDAP_DEBUG_TRACE, "LDAPModifyRequest::sendRequest()" << endl);
int msgID=0;
LDAPControl** tmpSrvCtrls=m_cons->getSrvCtrlsArray();
LDAPControl** tmpClCtrls=m_cons->getClCtrlsArray();
LDAPMod** tmpMods=m_modList->toLDAPModArray();
int err=ldap_modify_ext(m_connection->getSessionHandle(),m_dn.c_str(),
tmpMods, tmpSrvCtrls, tmpClCtrls,&msgID);
LDAPControlSet::freeLDAPControlArray(tmpSrvCtrls);
LDAPControlSet::freeLDAPControlArray(tmpClCtrls);
ldap_mods_free(tmpMods,1);
if(err != LDAP_SUCCESS){
throw LDAPException(err);
}else{
m_msgID=msgID;
return new LDAPMessageQueue(this);
}
}
LDAPRequest* LDAPModifyRequest::followReferral(LDAPMsg* ref){
DEBUG(LDAP_DEBUG_TRACE, "LDAPModifyRequest::followReferral()" << endl);
LDAPUrlList::const_iterator usedUrl;
LDAPUrlList urls = ((LDAPResult*)ref)->getReferralUrls();
LDAPAsynConnection* con = 0;
try {
con = getConnection()->referralConnect(urls,usedUrl,m_cons);
} catch(LDAPException e){
delete con;
return 0;
}
if(con != 0){
return new LDAPModifyRequest(m_dn, m_modList, con, m_cons,true,this);
}
return 0;
}