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 1426 additions and 0 deletions
// $OpenLDAP$
/*
* Copyright 2000-2020 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;
}
// $OpenLDAP$
/*
* Copyright 2000-2020 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
#ifndef LDAP_MODIFY_REQUEST_H
#define LDAP_MODIFY_REQUEST_H
#include <LDAPRequest.h>
class LDAPMessageQueue;
class LDAPModifyRequest : LDAPRequest {
private :
std::string m_dn;
LDAPModList *m_modList;
public:
LDAPModifyRequest(const LDAPModifyRequest& mod);
LDAPModifyRequest(const std::string& dn, const LDAPModList *modList,
LDAPAsynConnection *connect, const LDAPConstraints *cons,
bool isReferral=false, const LDAPRequest* req=0);
virtual ~LDAPModifyRequest();
virtual LDAPMessageQueue* sendRequest();
virtual LDAPRequest* followReferral(LDAPMsg* refs);
};
#endif // LDAP_MODIFY_REQUEST_H
// $OpenLDAP$
/*
* Copyright 2003-2020 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
#include "debug.h"
#include "LDAPObjClass.h"
LDAPObjClass::LDAPObjClass(){
DEBUG(LDAP_DEBUG_CONSTRUCT,
"LDAPObjClass::LDAPObjClass( )" << endl);
oid = string ();
desc = string ();
names = StringList ();
must = StringList();
may = StringList();
sup = StringList();
}
LDAPObjClass::LDAPObjClass (const LDAPObjClass &oc){
DEBUG(LDAP_DEBUG_CONSTRUCT,
"LDAPObjClass::LDAPObjClass( )" << endl);
oid = oc.oid;
desc = oc.desc;
names = oc.names;
must = oc.must;
may = oc.may;
kind = oc.kind;
sup = oc.sup;
}
LDAPObjClass::LDAPObjClass (string oc_item, int flags ) {
DEBUG(LDAP_DEBUG_CONSTRUCT,
"LDAPObjClass::LDAPObjClass( )" << endl);
LDAPObjectClass *o;
int ret;
const char *errp;
o = ldap_str2objectclass ( oc_item.c_str(), &ret, &errp, flags );
if (o) {
this->setNames (o->oc_names);
this->setDesc (o->oc_desc);
this->setOid (o->oc_oid);
this->setKind (o->oc_kind);
this->setMust (o->oc_at_oids_must);
this->setMay (o->oc_at_oids_may);
this->setSup (o->oc_sup_oids);
}
// else? -> error
}
LDAPObjClass::~LDAPObjClass() {
DEBUG(LDAP_DEBUG_DESTROY,"LDAPObjClass::~LDAPObjClass()" << endl);
}
void LDAPObjClass::setKind (int oc_kind) {
kind = oc_kind;
}
void LDAPObjClass::setNames (char **oc_names) {
names = StringList (oc_names);
}
void LDAPObjClass::setMust (char **oc_must) {
must = StringList (oc_must);
}
void LDAPObjClass::setMay (char **oc_may) {
may = StringList (oc_may);
}
void LDAPObjClass::setSup (char **oc_sup) {
sup = StringList (oc_sup);
}
void LDAPObjClass::setDesc (char *oc_desc) {
desc = string ();
if (oc_desc)
desc = oc_desc;
}
void LDAPObjClass::setOid (char *oc_oid) {
oid = string ();
if (oc_oid)
oid = oc_oid;
}
string LDAPObjClass::getOid() const {
return oid;
}
string LDAPObjClass::getDesc() const {
return desc;
}
StringList LDAPObjClass::getNames() const {
return names;
}
StringList LDAPObjClass::getMust() const {
return must;
}
StringList LDAPObjClass::getMay() const {
return may;
}
StringList LDAPObjClass::getSup() const {
return sup;
}
string LDAPObjClass::getName() const {
if (names.empty())
return "";
else
return *(names.begin());
}
int LDAPObjClass::getKind() const {
return kind;
}
// $OpenLDAP$
/*
* Copyright 2003-2020 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
#ifndef LDAP_OBJCLASS_H
#define LDAP_OBJCLASS_H
#include <ldap_schema.h>
#include <string>
#include "StringList.h"
using namespace std;
/**
* Represents the Object Class (from LDAP schema)
*/
class LDAPObjClass{
private :
StringList names, must, may, sup;
string desc, oid;
int kind;
public :
/**
* Constructs an empty object.
*/
LDAPObjClass();
/**
* Copy constructor
*/
LDAPObjClass( const LDAPObjClass& oc );
/**
* Constructs new object and fills the data structure by parsing the
* argument.
* @param oc_item description of object class is string returned
* by the search command. It is in the form:
* "( SuSE.YaST.OC:5 NAME 'userTemplate' SUP objectTemplate STRUCTURAL
* DESC 'User object template' MUST ( cn ) MAY ( secondaryGroup ))"
*/
LDAPObjClass (string oc_item, int flags = LDAP_SCHEMA_ALLOW_NO_OID |
LDAP_SCHEMA_ALLOW_QUOTED);
/**
* Destructor
*/
virtual ~LDAPObjClass();
/**
* Returns object class description
*/
string getDesc() const;
/**
* Returns object class oid
*/
string getOid() const;
/**
* Returns object class name (first one if there are more of them)
*/
string getName() const;
/**
* Returns object class kind: 0=ABSTRACT, 1=STRUCTURAL, 2=AUXILIARY
*/
int getKind() const;
/**
* Returns all object class names
*/
StringList getNames() const;
/**
* Returns list of required attributes
*/
StringList getMust() const;
/**
* Returns list of allowed (and not required) attributes
*/
StringList getMay() const;
/**
* Returns list of the OIDs of the superior ObjectClasses
*/
StringList getSup() const;
void setNames (char **oc_names);
void setMay (char **oc_may);
void setMust (char **oc_must);
void setDesc (char *oc_desc);
void setOid (char *oc_oid);
void setKind (int oc_kind);
void setSup (char **oc_sup);
};
#endif // LDAP_OBJCLASS_H
// $OpenLDAP$
/*
* Copyright 2000-2020 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
#include "LDAPRebind.h"
// $OpenLDAP$
/*
* Copyright 2000-2020 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
#ifndef LDAP_REBIND_H
#define LDAP_REBIND_H
#include <string>
#include <LDAPRebindAuth.h>
/**
* Just an abstract class to provide a mechnism for rebind to another
* server when chasing referrals. Clients have to implement a class
* derived from this. To use authentication other than anonymous for
* referral chasing
*/
class LDAPRebind{
public:
virtual ~LDAPRebind() {}
virtual LDAPRebindAuth* getRebindAuth(const std::string& hostname,
int port) const = 0;
};
#endif //LDAP_REBIND_H
// $OpenLDAP$
/*
* Copyright 2000-2020 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
#include <iostream>
#include "LDAPRebindAuth.h"
#include "debug.h"
using namespace std;
LDAPRebindAuth::LDAPRebindAuth(const string& dn, const string& pwd){
DEBUG(LDAP_DEBUG_CONSTRUCT,"LDAPRebindAuth::LDAPRebindAuth()" << endl);
DEBUG(LDAP_DEBUG_CONSTRUCT | LDAP_DEBUG_PARAMETER," dn:" << dn << endl
<< " pwd:" << pwd << endl);
m_dn=dn;
m_password=pwd;
}
LDAPRebindAuth::LDAPRebindAuth(const LDAPRebindAuth& lra){
DEBUG(LDAP_DEBUG_CONSTRUCT,"LDAPRebindAuth::LDAPRebindAuth(&)" << endl);
m_dn=lra.m_dn;
m_password=lra.m_password;
}
LDAPRebindAuth::~LDAPRebindAuth(){
DEBUG(LDAP_DEBUG_DESTROY,"LDAPRebindAuth::~LDAPRebindAuth()" << endl);
}
const string& LDAPRebindAuth::getDN() const{
DEBUG(LDAP_DEBUG_TRACE,"LDAPRebindAuth::getDN()" << endl);
return m_dn;
}
const string& LDAPRebindAuth::getPassword() const{
DEBUG(LDAP_DEBUG_TRACE,"LDAPRebindAuth::getPassword()" << endl);
return m_password;
}
// $OpenLDAP$
/*
* Copyright 2000-2020 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
#ifndef LDAP_REBIND_AUTH_H
#define LDAP_REBIND_AUTH_H
#include<string>
/**
* This class represent Authenication information for the case that the
* library is chasing referrals.
*
* The LDAPRebind::getRebindAuth() method returns an object of this type.
* And the library uses it to authentication to the destination server of a
* referral.
* @note currently only SIMPLE authentication is supported by the library
*/
class LDAPRebindAuth{
public:
/**
* @param dn The DN that should be used for the authentication
* @param pwd The password that belongs to the DN
*/
LDAPRebindAuth(const std::string& dn="", const std::string& pwd="");
/**
* Copy-constructor
*/
LDAPRebindAuth(const LDAPRebindAuth& lra);
/**
* Destructor
*/
virtual ~LDAPRebindAuth();
/**
* @return The DN that was set in the constructor
*/
const std::string& getDN() const;
/**
* @return The password that was set in the constructor
*/
const std::string& getPassword() const;
private:
std::string m_dn;
std::string m_password;
};
#endif //LDAP_REBIND_AUTH_H
// $OpenLDAP$
/*
* Copyright 2000-2020 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
#include "LDAPReferenceList.h"
#include "LDAPSearchReference.h"
LDAPReferenceList::LDAPReferenceList(){
}
LDAPReferenceList::LDAPReferenceList(const LDAPReferenceList& e){
m_refs = e.m_refs;
}
LDAPReferenceList::~LDAPReferenceList(){
}
size_t LDAPReferenceList::size() const{
return m_refs.size();
}
bool LDAPReferenceList::empty() const{
return m_refs.empty();
}
LDAPReferenceList::const_iterator LDAPReferenceList::begin() const{
return m_refs.begin();
}
LDAPReferenceList::const_iterator LDAPReferenceList::end() const{
return m_refs.end();
}
void LDAPReferenceList::addReference(const LDAPSearchReference& e){
m_refs.push_back(e);
}
// $OpenLDAP$
/*
* Copyright 2000-2020 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
#ifndef LDAP_REFERENCE_LIST_H
#define LDAP_REFERENCE_LIST_H
#include <cstdio>
#include <list>
class LDAPSearchReference;
/**
* Container class for storing a list of Search References
*
* Used internally only by LDAPSearchResults
*/
class LDAPReferenceList{
typedef std::list<LDAPSearchReference> ListType;
public:
typedef ListType::const_iterator const_iterator;
/**
* Constructs an empty list.
*/
LDAPReferenceList();
/**
* Copy-constructor
*/
LDAPReferenceList(const LDAPReferenceList& rl);
/**
* Destructor
*/
~LDAPReferenceList();
/**
* @return The number of LDAPSearchReference-objects that are
* currently stored in this list.
*/
size_t size() const;
/**
* @return true if there are zero LDAPSearchReference-objects
* currently stored in this list.
*/
bool empty() const;
/**
* @return A iterator that points to the first element of the list.
*/
const_iterator begin() const;
/**
* @return A iterator that points to the element after the last
* element of the list.
*/
const_iterator end() const;
/**
* Adds one element to the end of the list.
* @param e The LDAPSearchReference to add to the list.
*/
void addReference(const LDAPSearchReference& e);
private:
ListType m_refs;
};
#endif // LDAP_REFERENCE_LIST_H
// $OpenLDAP$
/*
* Copyright 2000-2020 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
#include "debug.h"
#include "LDAPRequest.h"
using namespace std;
LDAPRequest::LDAPRequest(){
DEBUG(LDAP_DEBUG_CONSTRUCT, "LDAPRequest::LDAPRequest()" << endl);
}
LDAPRequest::LDAPRequest(const LDAPRequest& req){
DEBUG(LDAP_DEBUG_CONSTRUCT, "LDAPRequest::LDAPRequest(&)" << endl);
m_isReferral=req.m_isReferral;
m_cons = new LDAPConstraints(*(req.m_cons));
m_connection = req.m_connection;
m_parent = req.m_parent;
m_hopCount = req.m_hopCount;
m_msgID = req.m_msgID;
}
LDAPRequest::LDAPRequest(LDAPAsynConnection* con,
const LDAPConstraints* cons,bool isReferral, const LDAPRequest* parent){
DEBUG(LDAP_DEBUG_CONSTRUCT,"LDAPRequest::LDAPRequest()" << endl);
m_connection=con;
if(cons == 0){
m_cons=new LDAPConstraints( *(con->getConstraints()) );
}else{
m_cons=new LDAPConstraints( *cons);
}
m_isReferral=isReferral;
if(m_isReferral){
m_hopCount = (parent->getHopCount()+1);
m_parent= parent;
}else{
m_hopCount=0;
m_parent=0;
}
}
LDAPRequest::~LDAPRequest(){
DEBUG(LDAP_DEBUG_DESTROY,"LDAPRequest::~LDAPRequest()" << endl);
delete m_cons;
}
LDAPMsg* LDAPRequest::getNextMessage() const
{
DEBUG(LDAP_DEBUG_DESTROY,"LDAPRequest::getNextMessage()" << endl);
int res;
LDAPMessage *msg;
res=ldap_result(this->m_connection->getSessionHandle(),
this->m_msgID,0,0,&msg);
if (res <= 0){
if(msg != 0){
ldap_msgfree(msg);
}
throw LDAPException(this->m_connection);
}else{
LDAPMsg *ret=0;
//this can throw an exception (Decoding Error)
ret = LDAPMsg::create(this,msg);
ldap_msgfree(msg);
return ret;
}
}
LDAPRequest* LDAPRequest::followReferral(LDAPMsg* /*urls*/){
DEBUG(LDAP_DEBUG_TRACE,"LDAPBindRequest::followReferral()" << endl);
DEBUG(LDAP_DEBUG_TRACE,
"ReferralChasing not implemented for this operation" << endl);
return 0;
}
const LDAPConstraints* LDAPRequest::getConstraints() const{
DEBUG(LDAP_DEBUG_TRACE,"LDAPRequest::getConstraints()" << endl);
return m_cons;
}
const LDAPAsynConnection* LDAPRequest::getConnection() const{
DEBUG(LDAP_DEBUG_TRACE,"LDAPRequest::getConnection()" << endl);
return m_connection;
}
int LDAPRequest::getType() const {
DEBUG(LDAP_DEBUG_TRACE,"LDAPRequest::getType()" << endl);
return m_requestType;
}
int LDAPRequest::getMsgID() const {
DEBUG(LDAP_DEBUG_TRACE,"LDAPRequest::getMsgId()" << endl);
return m_msgID;
}
int LDAPRequest::getHopCount() const {
DEBUG(LDAP_DEBUG_TRACE,"LDAPRequest::getHopCount()" << endl);
return m_hopCount;
}
const LDAPRequest* LDAPRequest::getParent() const{
DEBUG(LDAP_DEBUG_TRACE,"LDAPRequest::getParent()" << endl);
return m_parent;
}
bool LDAPRequest::isReferral() const {
DEBUG(LDAP_DEBUG_TRACE,"LDAPRequest::isReferral()" << endl);
return m_isReferral;
}
bool LDAPRequest::equals(const LDAPRequest* req) const{
DEBUG(LDAP_DEBUG_TRACE,"LDAPRequest::equals()" << endl);
if( (this->m_requestType == req->getType()) &&
(this->m_connection->getHost() == req->m_connection->getHost()) &&
(this->m_connection->getPort() == req->m_connection->getPort())
){
return true;
}return false;
}
bool LDAPRequest::isCycle() const{
DEBUG(LDAP_DEBUG_TRACE,"LDAPRequest::isCycle()" << endl);
const LDAPRequest* parent=m_parent;
if(parent != 0){
do{
if(this->equals(parent)){
return true;
}else{
parent=parent->getParent();
}
}
while(parent != 0);
}
return false;
}
void LDAPRequest::unbind() const{
DEBUG(LDAP_DEBUG_TRACE,"LDAPRequest::unbind()" << endl);
m_connection->unbind();
}
// $OpenLDAP$
/*
* Copyright 2000-2020 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
#ifndef LDAP_REQUEST_H
#define LDAP_REQUEST_H
#include <LDAPConstraints.h>
#include <LDAPAsynConnection.h>
#include <LDAPMessageQueue.h>
class LDAPUrl;
/**
* For internal use only
*
* Each request that is sent to a LDAP-server by this library is
* represented by a special object that contains the parameters and some
* other info of the request. This virtual class is the common base classe
* for these specialized request classes.
*/
class LDAPRequest{
public :
static const int BIND=0;
static const int UNBIND=2;
static const int SEARCH=3;
static const int MODIFY=7;
static const int ADD=8;
static const int DELETE=10;
static const int COMPARE=14;
LDAPRequest(const LDAPRequest& req);
LDAPRequest(LDAPAsynConnection* conn,
const LDAPConstraints* cons, bool isReferral=false,
const LDAPRequest* parent=0);
virtual ~LDAPRequest();
const LDAPConstraints* getConstraints() const;
const LDAPAsynConnection* getConnection() const;
virtual LDAPMsg *getNextMessage() const;
int getType()const;
int getMsgID() const;
int getHopCount() const;
/**
* @return The LDAPRequest that has created this object. Or 0 if
* this object was not created by another request.
*/
const LDAPRequest* getParent() const;
/**
* @return true if this object was created during the automatic
* chasing of referrals. Otherwise false
*/
bool isReferral() const;
void unbind() const;
/**
* This method encodes the request an calls the apprpriate
* functions of the C-API to send the Request to a LDAP-Server
*/
virtual LDAPMessageQueue* sendRequest()=0;
virtual LDAPRequest* followReferral(LDAPMsg* ref);
/**
* Compare this request with another on. And returns true if they
* have the same parameters.
*/
virtual bool equals(const LDAPRequest* req) const;
bool isCycle() const;
protected :
bool m_isReferral;
int m_requestType;
LDAPConstraints *m_cons;
LDAPAsynConnection *m_connection;
const LDAPRequest* m_parent;
int m_hopCount;
int m_msgID; //the associated C-API Message ID
LDAPRequest();
};
#endif //LDAP_REQUEST_H
// $OpenLDAP$
/*
* Copyright 2000-2020 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
#include "debug.h"
#include"LDAPResult.h"
#include"LDAPAsynConnection.h"
#include "LDAPRequest.h"
#include "LDAPException.h"
#include <cstdlib>
using namespace std;
LDAPResult::LDAPResult(const LDAPRequest *req, LDAPMessage *msg) :
LDAPMsg(msg){
if(msg != 0){
DEBUG(LDAP_DEBUG_CONSTRUCT,"LDAPResult::LDAPResult()" << endl);
const LDAPAsynConnection *con=req->getConnection();
char **refs=0;
LDAPControl** srvctrls=0;
char* matchedDN=0;
char* errMsg=0;
int err=ldap_parse_result(con->getSessionHandle(),msg,&m_resCode,
&matchedDN, &errMsg,&refs,&srvctrls,0);
if(err != LDAP_SUCCESS){
ber_memvfree((void**) refs);
ldap_controls_free(srvctrls);
throw LDAPException(err);
}else{
if (refs){
m_referrals=LDAPUrlList(refs);
ber_memvfree((void**) refs);
}
if (srvctrls){
m_srvControls = LDAPControlSet(srvctrls);
m_hasControls = true;
ldap_controls_free(srvctrls);
}else{
m_hasControls = false;
}
if(matchedDN != 0){
m_matchedDN=string(matchedDN);
free(matchedDN);
}
if(errMsg != 0){
m_errMsg=string(errMsg);
free(errMsg);
}
}
}
}
LDAPResult::LDAPResult(int type, int resultCode, const std::string &msg) :
LDAPMsg(type,0), m_resCode(resultCode), m_errMsg(msg)
{}
LDAPResult::~LDAPResult(){
DEBUG(LDAP_DEBUG_DESTROY,"LDAPResult::~LDAPResult()" << endl);
}
int LDAPResult::getResultCode() const{
DEBUG(LDAP_DEBUG_TRACE,"LDAPResult::getResultCode()" << endl);
return m_resCode;
}
string LDAPResult::resToString() const{
DEBUG(LDAP_DEBUG_TRACE,"LDAPResult::resToString()" << endl);
return string(ldap_err2string(m_resCode));
}
const string& LDAPResult::getErrMsg() const{
DEBUG(LDAP_DEBUG_TRACE,"LDAPResult::getErrMsg()" << endl);
return m_errMsg;
}
const string& LDAPResult::getMatchedDN() const{
DEBUG(LDAP_DEBUG_TRACE,"LDAPResult::getMatchedDN()" << endl);
return m_matchedDN;
}
const LDAPUrlList& LDAPResult::getReferralUrls() const{
DEBUG(LDAP_DEBUG_TRACE,"LDAPResult::getReferralUrl()" << endl);
return m_referrals;
}
ostream& operator<<(ostream &s,LDAPResult &l){
return s << "Result: " << l.m_resCode << ": "
<< ldap_err2string(l.m_resCode) << endl
<< "Matched: " << l.m_matchedDN << endl << "ErrMsg: " << l.m_errMsg;
}
// $OpenLDAP$
/*
* Copyright 2000-2020 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
#ifndef LDAP_RESULT_H
#define LDAP_RESULT_H
#include<iostream>
#include<ldap.h>
#include <LDAPMessage.h>
#include <LDAPControlSet.h>
#include <LDAPUrlList.h>
class LDAPRequest;
class LDAPAsynConnection;
/**
* This class is for representing LDAP-Result-Messages.
*
* It represents all Messages that were returned
* from LDAP-Operations except for Messages of the Type
* LDAPMsg::SEARCH_ENTRY, LDAPMsg::SEARCH_REFERENCE and
* LDAPMsg::EXTENDED_RESPONSE. <BR>
* It defines a integer constant for every possible result type that can be
* returned by the server.
*/
class LDAPResult : public LDAPMsg{
public :
//Error codes from RFC 2251
static const int SUCCESS = 0;
static const int OPERATIONS_ERROR = 1;
static const int PROTOCOL_ERROR = 2;
static const int TIME_LIMIT_EXCEEDED = 3;
static const int SIZE_LIMIT_EXCEEDED = 4;
static const int COMPARE_FALSE = 5;
static const int COMPARE_TRUE = 6;
static const int AUTH_METHOD_NOT_SUPPORTED = 7;
static const int STRONG_AUTH_REQUIRED = 8;
static const int REFERRAL = 10;
static const int ADMIN_LIMIT_EXCEEDED = 11;
static const int UNAVAILABLE_CRITICAL_EXTENSION = 12;
static const int CONFIDENTIALITY_REQUIRED = 13;
static const int SASL_BIND_IN_PROGRESS = 14;
static const int NO_SUCH_ATTRIBUTE = 16;
static const int UNDEFINED_ATTRIBUTE_TYP = 17;
static const int INAPPROPRIATE_MATCHING = 18;
static const int CONSTRAINT_VIOLATION = 19;
static const int ATTRIBUTE_OR_VALUE_EXISTS = 20;
static const int INVALID_ATTRIBUTE_SYNTAX = 21;
static const int NO_SUCH_OBJECT = 32;
static const int ALIAS_PROBLEM = 33;
static const int INVALID_DN_SYNTAX = 34;
static const int ALIAS_DEREFERENCING_PROBLEM = 36;
static const int INAPPROPRIATE_AUTENTICATION = 48;
static const int INVALID_CREDENTIALS = 49;
static const int INSUFFICIENT_ACCESS = 50;
static const int BUSY = 51;
static const int UNAVAILABLE = 52;
static const int UNWILLING_TO_PERFORM = 53;
static const int LOOP_DETECT = 54;
static const int NAMING_VIOLATION = 64;
static const int OBJECT_CLASS_VIOLATION = 65;
static const int NOT_ALLOWED_ON_NONLEAF = 66;
static const int NOT_ALLOWED_ON_RDN = 67;
static const int ENTRY_ALREADY_EXISTS = 68;
static const int OBJECT_CLASS_MODS_PROHIBITED = 69;
static const int AFFECTS_MULTIPLE_DSAS = 71;
// some Errorcodes defined in the LDAP C API DRAFT
static const int OTHER = 80;
static const int SERVER_DOWN = 81;
static const int LOCAL_ERROR = 82;
static const int ENCODING_ERROR = 83;
static const int DECODING_ERROR = 84;
static const int TIMEOUT = 85;
static const int AUTH_UNKNOWN = 86;
static const int FILTER_ERROR = 87;
static const int USER_CANCELLED = 88;
static const int PARAM_ERROR = 89;
static const int NO_MEMORY = 90;
static const int CONNECT_ERROR = 91;
static const int NOT_SUPPORTED = 92;
static const int CONTROL_NOT_FOUND = 93;
static const int NO_RESULTS_RETURNED = 94;
static const int MORE_RESULTS_TO_RETURN = 95;
static const int CLIENT_LOOP = 96;
static const int REFERRAL_LIMIT_EXCEEDED = 97;
/**
* This constructor is called by the LDAPMsg::create method in
* order to parse a LDAPResult-Message
* @param req The request the result is associated with.
* @param msg The LDAPMessage-structure that contains the
* Message.
*/
LDAPResult(const LDAPRequest *req, LDAPMessage *msg);
LDAPResult(int type, int resultCode, const std::string &msg);
/**
* The destructor.
*/
virtual ~LDAPResult();
/**
* @returns The result code of the Message. Possible values are the
* integer constants defined in this class.
*/
int getResultCode() const;
/**
* This method transforms the result code to a human-readable
* result message.
* @returns A std::string containing the result message.
*/
std::string resToString() const;
/**
* In some case of error the server may return addional error
* messages.
* @returns The additional error message returned by the server.
*/
const std::string& getErrMsg() const;
/**
* For messages with a result code of: NO_SUCH_OBJECT,
* ALIAS_PROBLEM, ALIAS_DEREFERENCING_PROBLEM or INVALID_DN_SYNTAX
* the server returns the DN of deepest entry in the DIT that could
* be found for this operation.
* @returns The Matched-DN value that was returned by the server.
*/
const std::string& getMatchedDN() const;
/**
* @returns If the result code is REFERRAL this methode returns the
* URLs of the referral that was sent by the server.
*/
const LDAPUrlList& getReferralUrls() const;
private :
int m_resCode;
std::string m_matchedDN;
std::string m_errMsg;
LDAPUrlList m_referrals;
/**
* 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,LDAPResult &l);
};
#endif //LDAP_RESULT_H
// $OpenLDAP$
/*
* Copyright 2007-2020 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 "LDAPSaslBindResult.h"
using namespace std;
LDAPSaslBindResult::LDAPSaslBindResult(const LDAPRequest* req, LDAPMessage* msg) :
LDAPResult(req, msg){
DEBUG(LDAP_DEBUG_CONSTRUCT,"LDAPSaslBindResult::LDAPSaslBindResult()"
<< std::endl);
BerValue* data = 0;
LDAP* lc = req->getConnection()->getSessionHandle();
int err = ldap_parse_sasl_bind_result(lc, msg, &data, 0);
if( err != LDAP_SUCCESS && err != LDAP_SASL_BIND_IN_PROGRESS ){
ber_bvfree(data);
throw LDAPException(err);
}else{
if(data){
DEBUG(LDAP_DEBUG_TRACE, " creds present" << std::endl);
m_creds=string(data->bv_val, data->bv_len);
ber_bvfree(data);
} else {
DEBUG(LDAP_DEBUG_TRACE, " no creds present" << std::endl);
}
}
}
LDAPSaslBindResult::~LDAPSaslBindResult(){
DEBUG(LDAP_DEBUG_DESTROY,"LDAPSaslBindResult::~LDAPSaslBindResult()" << endl);
}
const string& LDAPSaslBindResult::getServerCreds() const{
return m_creds;
}
// $OpenLDAP$
/*
* Copyright 2007-2020 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
#ifndef LDAP_SASL_BIND_RESULT_H
#define LDAP_SASL_BIND_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 LDAPSaslBindResult : public LDAPResult {
public :
/**
* Constructor that creates an LDAPExtResult-object from the C-API
* structures
*/
LDAPSaslBindResult(const LDAPRequest* req, LDAPMessage* msg);
/**
* The Destructor
*/
virtual ~LDAPSaslBindResult();
/**
* @returns If the result contained data this method will return
* the data to the caller as a std::string.
*/
const std::string& getServerCreds() const;
private:
std::string m_creds;
};
#endif // LDAP_SASL_BIND_RESULT_H
// $OpenLDAP$
/*
* Copyright 2003-2020 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
#include "LDAPSchema.h"
#include <ctype.h>
#include <ldap.h>
#include "debug.h"
#include "StringList.h"
using namespace std;
LDAPSchema::LDAPSchema(){
DEBUG(LDAP_DEBUG_CONSTRUCT,
"LDAPSchema::LDAPSchema( )" << endl);
}
LDAPSchema::~LDAPSchema() {
DEBUG(LDAP_DEBUG_DESTROY,"LDAPSchema::~LDAPSchema()" << endl);
}
void LDAPSchema::setObjectClasses (const StringList &ocs) {
DEBUG(LDAP_DEBUG_TRACE,"LDAPSchema::setObjectClasses()" << endl);
// parse the stringlist and save it to global map...
StringList::const_iterator i,j;
for (i = ocs.begin(); i != ocs.end(); i++) {
LDAPObjClass oc ( (*i) );
StringList names = oc.getNames();
// there could be more names for one object...
for (j = names.begin(); j != names.end(); j++) {
string lc_name = *j;
string::iterator k;
for ( k = lc_name.begin(); k != lc_name.end(); k++ ) {
(*k) = tolower(*k);
}
object_classes [lc_name] = LDAPObjClass (oc);
}
}
}
void LDAPSchema::setAttributeTypes (const StringList &ats) {
DEBUG(LDAP_DEBUG_TRACE,"LDAPSchema::setAttributeTypes()" << endl);
// parse the stringlist and save it to global map...
StringList::const_iterator i,j;
for (i = ats.begin(); i != ats.end(); i++) {
LDAPAttrType at ( (*i) );
StringList names = at.getNames();
// there could be more names for one object...
for (j = names.begin(); j != names.end(); j++) {
string lc_name = *j;
string::iterator k;
for ( k = lc_name.begin(); k != lc_name.end(); k++ ) {
(*k) = tolower(*k);
}
attr_types [lc_name] = LDAPAttrType (at);
}
}
}
LDAPObjClass LDAPSchema::getObjectClassByName (string name) {
string lc_name = name;
string::iterator k;
for ( k = lc_name.begin(); k != lc_name.end(); k++ ) {
(*k) = tolower(*k);
}
return object_classes [lc_name];
}
LDAPAttrType LDAPSchema::getAttributeTypeByName (string name) {
string lc_name = name;
string::iterator k;
for ( k = lc_name.begin(); k != lc_name.end(); k++ ) {
(*k) = tolower(*k);
}
return attr_types [lc_name];
}
// $OpenLDAP$
/*
* Copyright 2003-2020 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
#ifndef LDAP_SCHEMA_H
#define LDAP_SCHEMA_H
#include <string>
#include <map>
#include "LDAPObjClass.h"
#include "LDAPAttrType.h"
/**
* Represents the LDAP schema
*/
class LDAPSchema{
private :
/**
* map of object classes: index is name, value is LDAPObjClass object
*/
map <string, LDAPObjClass> object_classes;
/**
* map of attribute types: index is name, value is LDAPAttrType object
*/
map <string, LDAPAttrType> attr_types;
public :
/**
* Constructs an empty object
*/
LDAPSchema();
/**
* Destructor
*/
virtual ~LDAPSchema();
/**
* Fill the object_classes map
* @param oc description of one objectclass (string returned by search
* command), in form:
* "( 1.2.3.4.5 NAME '<name>' SUP <supname> STRUCTURAL
* DESC '<description>' MUST ( <attrtype> ) MAY ( <attrtype> ))"
*/
void setObjectClasses (const StringList &oc);
/**
* Fill the attr_types map
* @param at description of one attribute type
* (string returned by search command), in form:
* "( 1.2.3.4.6 NAME ( '<name>' ) DESC '<desc>'
* EQUALITY caseExactIA5Match SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )"
*/
void setAttributeTypes (const StringList &at);
/**
* Returns object class object with given name
*/
LDAPObjClass getObjectClassByName (std::string name);
/**
* Returns attribute type object with given name
*/
LDAPAttrType getAttributeTypeByName (string name);
};
#endif // LDAP_SCHEMA_H
// $OpenLDAP$
/*
* Copyright 2000-2020 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
#include <iostream>
#include "debug.h"
#include "LDAPSearchReference.h"
#include "LDAPException.h"
#include "LDAPRequest.h"
#include "LDAPUrl.h"
using namespace std;
LDAPSearchReference::LDAPSearchReference(const LDAPRequest *req,
LDAPMessage *msg) : LDAPMsg(msg){
DEBUG(LDAP_DEBUG_CONSTRUCT,
"LDAPSearchReference::LDAPSearchReference()" << endl;)
char **ref=0;
LDAPControl** srvctrls=0;
const LDAPAsynConnection* con=req->getConnection();
int err = ldap_parse_reference(con->getSessionHandle(), msg, &ref,
&srvctrls,0);
if (err != LDAP_SUCCESS){
ber_memvfree((void**) ref);
ldap_controls_free(srvctrls);
throw LDAPException(err);
}else{
m_urlList=LDAPUrlList(ref);
ber_memvfree((void**) ref);
if (srvctrls){
m_srvControls = LDAPControlSet(srvctrls);
m_hasControls = true;
ldap_controls_free(srvctrls);
}else{
m_hasControls = false;
}
}
}
LDAPSearchReference::~LDAPSearchReference(){
DEBUG(LDAP_DEBUG_DESTROY,"LDAPSearchReference::~LDAPSearchReference()"
<< endl);
}
const LDAPUrlList& LDAPSearchReference::getUrls() const{
DEBUG(LDAP_DEBUG_TRACE,"LDAPSearchReference::getUrls()" << endl);
return m_urlList;
}
// $OpenLDAP$
/*
* Copyright 2000-2020 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
#ifndef LDAP_SEARCH_REFERENCE_H
#define LDAP_SEARCH_REFERENCE_H
#include <LDAPMessage.h>
#include <LDAPUrlList.h>
class LDAPRequest;
class LDAPUrl;
/**
* This class is used to represent Continuation References that were
* returned during a SEARCH-Operation.
*/
class LDAPSearchReference : public LDAPMsg{
public :
/**
* Constructor that create an object from the C-API structures
*/
LDAPSearchReference(const LDAPRequest* req, LDAPMessage* msg);
/**
* The Destructor
*/
~LDAPSearchReference();
/**
* @returns The destination URLs that were send with this message
*/
const LDAPUrlList& getUrls() const;
private :
LDAPUrlList m_urlList;
LDAPSearchReference();
};
#endif //LDAP_SEARCH_REFERENCE_H