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 2641 additions and 0 deletions
// $OpenLDAP$
/*
* Copyright 2003-2020 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
#include "debug.h"
#include "LDAPAttrType.h"
LDAPAttrType::LDAPAttrType(){
DEBUG(LDAP_DEBUG_CONSTRUCT,
"LDAPAttrType::LDAPAttrType( )" << endl);
oid = string ();
desc = string ();
names = StringList ();
single = false;
usage = 0;
}
LDAPAttrType::LDAPAttrType (string at_item, int flags ) {
DEBUG(LDAP_DEBUG_CONSTRUCT,
"LDAPAttrType::LDAPAttrType( )" << endl);
LDAPAttributeType *a;
int ret;
const char *errp;
a = ldap_str2attributetype (at_item.c_str(), &ret, &errp, flags);
if (a) {
this->setNames( a->at_names );
this->setDesc( a->at_desc );
this->setOid( a->at_oid );
this->setSingle( a->at_single_value );
this->setUsage( a->at_usage );
this->setSuperiorOid( a->at_sup_oid );
this->setEqualityOid( a->at_equality_oid );
this->setOrderingOid( a->at_ordering_oid );
this->setSubstringOid( a->at_substr_oid );
this->setSyntaxOid( a->at_syntax_oid );
}
// else? -> error
}
LDAPAttrType::~LDAPAttrType() {
DEBUG(LDAP_DEBUG_DESTROY,"LDAPAttrType::~LDAPAttrType()" << endl);
}
void LDAPAttrType::setSingle (int at_single) {
single = (at_single == 1);
}
void LDAPAttrType::setNames ( char **at_names ) {
names = StringList(at_names);
}
void LDAPAttrType::setDesc (const char *at_desc) {
desc = string ();
if (at_desc)
desc = at_desc;
}
void LDAPAttrType::setOid (const char *at_oid) {
oid = string ();
if (at_oid)
oid = at_oid;
}
void LDAPAttrType::setUsage (int at_usage) {
usage = at_usage;
}
void LDAPAttrType::setSuperiorOid( const char *oid ){
if ( oid )
superiorOid = oid;
}
void LDAPAttrType::setEqualityOid( const char *oid ){
if ( oid )
equalityOid = oid;
}
void LDAPAttrType::setOrderingOid( const char *oid ){
if ( oid )
orderingOid = oid;
}
void LDAPAttrType::setSubstringOid( const char *oid ){
if ( oid )
substringOid = oid;
}
void LDAPAttrType::setSyntaxOid( const char *oid ){
if ( oid )
syntaxOid = oid;
}
bool LDAPAttrType::isSingle() const {
return single;
}
string LDAPAttrType::getOid() const {
return oid;
}
string LDAPAttrType::getDesc() const {
return desc;
}
StringList LDAPAttrType::getNames() const {
return names;
}
string LDAPAttrType::getName() const {
if (names.empty())
return "";
else
return *(names.begin());
}
int LDAPAttrType::getUsage() const {
return usage;
}
std::string LDAPAttrType::getSuperiorOid() const {
return superiorOid;
}
std::string LDAPAttrType::getEqualityOid() const {
return equalityOid;
}
std::string LDAPAttrType::getOrderingOid() const {
return orderingOid;
}
std::string LDAPAttrType::getSubstringOid() const {
return substringOid;
}
std::string LDAPAttrType::getSyntaxOid() const {
return syntaxOid;
}
// $OpenLDAP$
/*
* Copyright 2003-2020 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
#ifndef LDAP_ATTRTYPE_H
#define LDAP_ATTRTYPE_H
#include <ldap_schema.h>
#include <string>
#include "StringList.h"
using namespace std;
/**
* Represents the Attribute Type (from LDAP schema)
*/
class LDAPAttrType{
private :
StringList names;
std::string desc, oid, superiorOid, equalityOid;
std::string orderingOid, substringOid, syntaxOid;
bool single;
int usage;
public :
/**
* Constructor
*/
LDAPAttrType();
/**
* Constructs new object and fills the data structure by parsing the
* argument.
* @param at_item description of attribute type is string returned
* by the search command. It is in the form:
* "( SuSE.YaST.Attr:19 NAME ( 'skelDir' ) DESC ''
* EQUALITY caseExactIA5Match SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )"
*/
LDAPAttrType (string at_item, int flags = LDAP_SCHEMA_ALLOW_NO_OID |
LDAP_SCHEMA_ALLOW_QUOTED );
/**
* Destructor
*/
virtual ~LDAPAttrType();
/**
* Returns attribute description
*/
string getDesc() const;
/**
* Returns attribute oid
*/
string getOid() const;
/**
* Returns attribute name (first one if there are more of them)
*/
string getName() const;
/**
* Returns all attribute names
*/
StringList getNames() const;
/**
* Returns true if attribute type allows only single value
*/
bool isSingle() const;
/**
* Return the 'usage' value:
* (0=userApplications, 1=directoryOperation, 2=distributedOperation,
* 3=dSAOperation)
*/
int getUsage () const;
std::string getSuperiorOid() const;
std::string getEqualityOid() const;
std::string getOrderingOid() const;
std::string getSubstringOid() const;
std::string getSyntaxOid() const;
void setNames( char **at_names);
void setDesc(const char *at_desc);
void setOid(const char *at_oid);
void setSingle(int at_single_value);
void setUsage(int at_usage );
void setSuperiorOid( const char *oid );
void setEqualityOid( const char *oid );
void setOrderingOid( const char *oid );
void setSubstringOid( const char *oid );
void setSyntaxOid( const char *oid );
};
#endif // LDAP_ATTRTYPE_H
// $OpenLDAP$
/*
* Copyright 2000-2020 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
//TODO!!!
// * some kind of iterator to step through the attribute values
// * remove values from Attribute
// * handling of subtypes (;de; and so on)
// * some documentation
#include <ldap.h>
#include <cstdlib>
#include "debug.h"
#include "StringList.h"
#include "LDAPAttribute.h"
using namespace std;
LDAPAttribute::LDAPAttribute(){
DEBUG(LDAP_DEBUG_CONSTRUCT, "LDAPAttribute::LDAPAttribute( )" << endl);
m_name=string();
}
LDAPAttribute::LDAPAttribute(const LDAPAttribute& attr){
DEBUG(LDAP_DEBUG_CONSTRUCT, "LDAPAttribute::LDAPAttribute(&)" << endl);
DEBUG(LDAP_DEBUG_CONSTRUCT | LDAP_DEBUG_PARAMETER,
" attr:" << attr << endl);
m_name=attr.m_name;
m_values=StringList(attr.m_values);
}
LDAPAttribute::LDAPAttribute(const string& name, const string& value){
DEBUG(LDAP_DEBUG_CONSTRUCT, "LDAPAttribute::LDAPAttribute()" << endl);
DEBUG(LDAP_DEBUG_CONSTRUCT | LDAP_DEBUG_PARAMETER,
" name:" << name << endl << " value:" << value << endl);
this->setName(name);
if(value != ""){
this->addValue(value);
}
}
LDAPAttribute::LDAPAttribute(const string& name, const StringList& values){
DEBUG(LDAP_DEBUG_CONSTRUCT, "LDAPAttribute::LDAPAttribute()" << endl);
DEBUG(LDAP_DEBUG_CONSTRUCT | LDAP_DEBUG_PARAMETER,
" name:" << name << endl);
m_name=name;
m_values=values;
}
LDAPAttribute::LDAPAttribute(const char *name, char **values){
DEBUG(LDAP_DEBUG_CONSTRUCT, "LDAPAttribute::LDAPAttribute()" << endl);
DEBUG(LDAP_DEBUG_CONSTRUCT | LDAP_DEBUG_PARAMETER,
" name:" << name << endl);
this->setName(name);
this->setValues(values);
}
LDAPAttribute::LDAPAttribute(const char *name, BerValue **values){
DEBUG(LDAP_DEBUG_CONSTRUCT, "LDAPAttribute::LDAPAttribute()" << endl);
DEBUG(LDAP_DEBUG_CONSTRUCT | LDAP_DEBUG_PARAMETER,
" name:" << name << endl);
this->setName(name);
this->setValues(values);
}
LDAPAttribute::~LDAPAttribute(){
DEBUG(LDAP_DEBUG_DESTROY,"LDAPAttribute::~LDAPAttribute()" << endl);
}
void LDAPAttribute::addValue(const string& value){
DEBUG(LDAP_DEBUG_TRACE,"LDAPAttribute::addValue()" << endl);
m_values.add(value);
}
int LDAPAttribute::addValue(const BerValue *value){
DEBUG(LDAP_DEBUG_TRACE,"LDAPAttribute::addValue()" << endl);
if(value!=0){
this->addValue(string(value->bv_val, value->bv_len));
return 0;
}
return -1;
}
int LDAPAttribute::setValues(char **values){
DEBUG(LDAP_DEBUG_TRACE,"LDAPAttribute::setValues()" << endl);
if(values){
m_values.clear();
for( char **i=values; *i!=0; i++){
this->addValue(*i);
}
}
return 0;
}
int LDAPAttribute::setValues(BerValue **values){
DEBUG(LDAP_DEBUG_TRACE,"LDAPAttribute::setValues()" << endl);
if(values){
m_values.clear();
for( BerValue **i=values; *i!=0; i++){
if( this->addValue(*i) ){
return -1;
}
}
}
return 0;
}
void LDAPAttribute::setValues(const StringList& values){
DEBUG(LDAP_DEBUG_TRACE,"LDAPAttribute::setValues()" << endl);
m_values=values;
}
const StringList& LDAPAttribute::getValues() const{
DEBUG(LDAP_DEBUG_TRACE,"LDAPAttribute::getValues()" << endl);
return m_values;
}
BerValue** LDAPAttribute::getBerValues() const{
DEBUG(LDAP_DEBUG_TRACE,"LDAPAttribute::getBerValues()" << endl);
size_t size=m_values.size();
if (size == 0){
return 0;
}else{
BerValue **temp = (BerValue**) malloc(sizeof(BerValue*) * (size+1));
StringList::const_iterator i;
int p=0;
for(i=m_values.begin(), p=0; i!=m_values.end(); i++,p++){
temp[p]=(BerValue*) malloc(sizeof(BerValue));
temp[p]->bv_len= i->size();
temp[p]->bv_val= (char*) malloc(sizeof(char) * (i->size()+1));
i->copy(temp[p]->bv_val,string::npos);
}
temp[size]=0;
return temp;
}
}
int LDAPAttribute::getNumValues() const{
DEBUG(LDAP_DEBUG_TRACE,"LDAPAttribute::getNumValues()" << endl);
return m_values.size();
}
const string& LDAPAttribute::getName() const {
DEBUG(LDAP_DEBUG_TRACE, "LDAPAttribute::getName()" << endl);
return m_name;
}
void LDAPAttribute::setName(const string& name){
DEBUG(LDAP_DEBUG_TRACE, "LDAPAttribute::setName()" << endl);
DEBUG(LDAP_DEBUG_TRACE | LDAP_DEBUG_PARAMETER," name:" << name << endl);
m_name.erase();
m_name=name;
}
// The bin-FLAG of the mod_op is always set to LDAP_MOD_BVALUES (0x80)
LDAPMod* LDAPAttribute::toLDAPMod() const {
DEBUG(LDAP_DEBUG_TRACE, "LDAPAttribute::toLDAPMod()" << endl);
LDAPMod* ret= (LDAPMod*) malloc(sizeof(LDAPMod));
ret->mod_op=LDAP_MOD_BVALUES; //always assume binary-Values
ret->mod_type= (char*) malloc(sizeof(char) * (m_name.size()+1));
m_name.copy(ret->mod_type,string::npos);
ret->mod_type[m_name.size()]=0;
ret->mod_bvalues=this->getBerValues();
return ret;
}
bool LDAPAttribute::isNotPrintable() const {
StringList::const_iterator i;
for(i=m_values.begin(); i!=m_values.end(); i++){
size_t len = i->size();
for(size_t j=0; j<len; j++){
if (! isprint( (i->data())[j] ) ){
return true;
}
}
}
return false;
}
ostream& operator << (ostream& s, const LDAPAttribute& attr){
s << attr.m_name << "=";
StringList::const_iterator i;
if (attr.isNotPrintable()){
s << "NOT_PRINTABLE" ;
}else{
for(i=attr.m_values.begin(); i!=attr.m_values.end(); i++){
s << *i << " ";
}
}
return s;
}
// $OpenLDAP$
/*
* Copyright 2000-2020 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
#ifndef LDAP_ATTRIBUTE_H
#define LDAP_ATTRIBUTE_H
#include<iostream>
#include<string>
#include<ldap.h>
#include<lber.h>
#include <StringList.h>
/**
* Represents the name an value(s) of an Attribute
*/
class LDAPAttribute{
public :
/**
* Default constructor.
* initializes an empty object.
*/
LDAPAttribute();
/**
* Copy constructor.
* Copies all values of an Attribute to a new one
* @param attr The Attribute that should be copied
*/
LDAPAttribute(const LDAPAttribute& attr);
/**
* Construct an Attribute with a single string value
* @param name The attribute's name (type)
* @param value The string value of the attribute, if "" the
* attribute will have no values, for LDAPv3
* this values must be UTF-8 encoded
*/
LDAPAttribute(const std::string& name, const std::string& value="");
/**
* Construct an attribute with multiple string values
* @param name The attribute's name (type)
* @param values A 0-terminated array of char*. Each char* specifies
* one value of the attribute (UTF-8 encoded)
*/
LDAPAttribute(const char* name, char **values);
/**
* Construct an attribute with multiple string values
* @param name The attribute's name (type)
* @param values A list of strings. Each element specifies
* one value of the attribute (UTF-8 or binary
* encoded)
*/
LDAPAttribute(const std::string& name, const StringList& values);
/**
* Construct an attribute with multiple binary coded values
* @param name The attribute's name (type)
* @param values 0-terminated array of binary attribute values
* The BerValue struct is declared as:<BR>
* struct berval{
* unsigned long bv_len;
* char *bv_val;
* } BerValue;
*/
LDAPAttribute(const char* name, BerValue **values);
/**
* Destructor
*/
~LDAPAttribute();
/**
* Add a single string value(bin/char) to the Attribute
* @param value Value that should be added, it is copied inside the
* object
*/
void addValue(const std::string& value);
/**
* Add a single binary value to the Attribute
* @param value The binary coded value that should be added to the
* Attribute.
* @return 0 no problem <BR>
* -1 failure (mem. allocation problem)
*/
int addValue(const BerValue *value);
/**
* Set the values of the attribute. If the object contains some values
* already, they are deleted
* @param values 0-terminated array of char*, each char*
* representing a string value to add to the entry
*
* @return 0 no problem <BR>
* -1 failure (mem. allocation problem)
*/
int setValues(char** values);
/**
* Set the values of the attribute. If the object does already contain
* some values, they will be deleted
* @param values 0-terminated array of BerValue*, each BerValue
* representing a binary value to add to the entry
*
* @return 0 no problem <BR>
* -1 failure (mem. allocation problem)
*/
int setValues(BerValue** values);
/**
* Set the values of the attribute. If the object does already contain
* some values, they will be deleted
* @param values A list of string-Objects. Each string is
* representing a string or binary value to add to
* the entry
*/
void setValues(const StringList& values);
/**
* For interal use only.
* This method is used to translate the values of the Attribute to
* 0-terminated Array of BerValue-structs as used by the C-API
* @return The Values of the Attribute as an 0-terminated Array of
* BerValue* (is dynamically allocated, delete it after usage)
* <BR>
* 0-pointer in case of error
*/
BerValue** getBerValues() const;
/**
* @return The values of the array as a list of strings
*/
const StringList& getValues() const;
/**
* @return The number of values of the attribute
*/
int getNumValues() const;
/**
* @return The name(type) of the attribute
*/
const std::string& getName() const ;
/**
* Sets the Attribute's name (type)
* @param the new name of the object
*/
void setName(const std::string& name);
/**
* For internal use only.
*
* This method translate the attribute of the object into a
* LDAPMod-Structure as used by the C-API
*/
LDAPMod* toLDAPMod() const ;
/**
* @return true If the attribute contains non-printable attributes
*/
bool isNotPrintable() const ;
private :
std::string m_name;
StringList m_values;
/**
* 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 LDAPAttribute& attr);
};
#endif //#ifndef LDAP_ATTRIBUTE_H
// $OpenLDAP$
/*
* Copyright 2000-2020 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
#include "debug.h"
#include "LDAPAttributeList.h"
#include "LDAPException.h"
#include "LDAPAttribute.h"
#include "LDAPAsynConnection.h"
#include "LDAPMessage.h"
#include <cstdlib>
using namespace std;
// little helper function for doing case insensitve string comparison
bool nocase_compare(char c1, char c2);
LDAPAttributeList::LDAPAttributeList(){
DEBUG(LDAP_DEBUG_CONSTRUCT,
"LDAPAttributeList::LDAPAttributList( )" << endl);
}
LDAPAttributeList::LDAPAttributeList(const LDAPAttributeList& al){
DEBUG(LDAP_DEBUG_CONSTRUCT,
"LDAPAttributeList::LDAPAttributList(&)" << endl);
m_attrs=al.m_attrs;
}
LDAPAttributeList::LDAPAttributeList(const LDAPAsynConnection *ld,
LDAPMessage *msg){
DEBUG(LDAP_DEBUG_CONSTRUCT,
"LDAPAttributeList::LDAPAttributList()" << endl);
BerElement *ptr=0;
char *name=ldap_first_attribute(ld->getSessionHandle(), msg, &ptr);
/*
This code was making problems if no attribute were returned
How am I supposed to find decoding errors? ldap_first/next_attribute
return 0 in case of error or if there are no more attributes. In either
case they set the LDAP* error code to 0x54 (Decoding error) ??? Strange..
There will be some changes in the new version of the C-API so that this
code should work in the future.
if(name == 0){
ber_free(ptr,0);
ldap_memfree(name);
throw LDAPException(ld);
}else{
*/ BerValue **values;
for (;name !=0;
name=ldap_next_attribute(ld->getSessionHandle(),msg,ptr) ){
values=ldap_get_values_len(ld->getSessionHandle(),
msg, name);
this->addAttribute(LDAPAttribute(name, values));
ldap_memfree(name);
ldap_value_free_len(values);
}
ber_free(ptr,0);
// }
}
LDAPAttributeList::~LDAPAttributeList(){
DEBUG(LDAP_DEBUG_DESTROY,"LDAPAttributeList::~LDAPAttributList()" << endl);
}
size_t LDAPAttributeList::size() const{
DEBUG(LDAP_DEBUG_TRACE,"LDAPAttribute::size()" << endl);
return m_attrs.size();
}
bool LDAPAttributeList::empty() const{
DEBUG(LDAP_DEBUG_TRACE,"LDAPAttribute::empty()" << endl);
return m_attrs.empty();
}
LDAPAttributeList::const_iterator LDAPAttributeList::begin() const{
DEBUG(LDAP_DEBUG_TRACE,"LDAPAttribute::begin()" << endl);
return m_attrs.begin();
}
LDAPAttributeList::const_iterator LDAPAttributeList::end() const{
DEBUG(LDAP_DEBUG_TRACE,"LDAPAttribute::end()" << endl);
return m_attrs.end();
}
const LDAPAttribute* LDAPAttributeList::getAttributeByName(
const string& name) const {
DEBUG(LDAP_DEBUG_TRACE,"LDAPAttribute::getAttributeByName()" << endl);
DEBUG(LDAP_DEBUG_TRACE | LDAP_DEBUG_PARAMETER,
" name:" << name << endl);
LDAPAttributeList::const_iterator i;
for( i = m_attrs.begin(); i != m_attrs.end(); i++){
const std::string& tmpType = i->getName();
if(name.size() == tmpType.size()){
if(equal(name.begin(), name.end(), tmpType.begin(),
nocase_compare)){
return &(*i);
DEBUG(LDAP_DEBUG_TRACE," found:" << name << endl);
}
}
}
return 0;
}
void LDAPAttributeList::addAttribute(const LDAPAttribute& attr){
DEBUG(LDAP_DEBUG_TRACE,"LDAPAttribute::addAttribute()" << endl);
DEBUG(LDAP_DEBUG_TRACE | LDAP_DEBUG_PARAMETER,
" attr:" << attr << endl);
const std::string attrType = attr.getName();
const std::string::size_type attrLen = attrType.size();
std::string::size_type tmpAttrLen = 0;
bool done=false;
LDAPAttributeList::iterator i;
for( i=m_attrs.begin(); i != m_attrs.end(); i++ ){
const std::string tmpAttrType = i->getName();
tmpAttrLen = tmpAttrType.size();
if(tmpAttrLen == attrLen){
if(equal(tmpAttrType.begin(), tmpAttrType.end(), attrType.begin(),
nocase_compare)){
const StringList& values = attr.getValues();
StringList::const_iterator j;
for(j = values.begin(); j != values.end(); j++){
i->addValue(*j);
}
DEBUG(LDAP_DEBUG_TRACE,"Attribute" << i->getName()
<< "already present" << endl);
done=true;
break; // The AttributeType was already present,
// we are done here
}
}
}
if(! done){
m_attrs.push_back(attr);
}
}
void LDAPAttributeList::delAttribute(const std::string& type)
{
DEBUG(LDAP_DEBUG_TRACE,"LDAPAttribute::replaceAttribute()" << endl);
DEBUG(LDAP_DEBUG_TRACE | LDAP_DEBUG_PARAMETER, " type: " << type << endl);
LDAPAttributeList::iterator i;
for( i = m_attrs.begin(); i != m_attrs.end(); i++){
if(type.size() == i->getName().size()){
if(equal(type.begin(), type.end(), i->getName().begin(),
nocase_compare)){
m_attrs.erase(i);
break;
}
}
}
}
void LDAPAttributeList::replaceAttribute(const LDAPAttribute& attr)
{
DEBUG(LDAP_DEBUG_TRACE,"LDAPAttribute::replaceAttribute()" << endl);
DEBUG(LDAP_DEBUG_TRACE | LDAP_DEBUG_PARAMETER,
" attr:" << attr << endl);
LDAPAttributeList::iterator i;
this->delAttribute( attr.getName() );
m_attrs.push_back(attr);
}
LDAPMod** LDAPAttributeList::toLDAPModArray() const{
DEBUG(LDAP_DEBUG_TRACE,"LDAPAttribute::toLDAPModArray()" << endl);
LDAPMod **ret = (LDAPMod**) malloc((m_attrs.size()+1) * sizeof(LDAPMod*));
LDAPAttributeList::const_iterator i;
int j=0;
for (i=m_attrs.begin(); i!= m_attrs.end(); i++, j++){
ret[j]=i->toLDAPMod();
}
ret[m_attrs.size()]=0;
return ret;
}
ostream& operator << (ostream& s, const LDAPAttributeList& al){
LDAPAttributeList::const_iterator i;
for(i=al.m_attrs.begin(); i!=al.m_attrs.end(); i++){
s << *i << "; ";
}
return s;
}
bool nocase_compare( char c1, char c2){
return toupper(c1) == toupper(c2);
}
// $OpenLDAP$
/*
* Copyright 2000-2020 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
#ifndef LDAP_ATTRIBUTE_LIST_H
#define LDAP_ATTRIBUTE_LIST_H
#include <ldap.h>
#include <list>
#include <string>
class LDAPAttribute;
class LDAPAsynConnection;
class LDAPMsg;
/**
* This container class is used to store multiple LDAPAttribute-objects.
*/
class LDAPAttributeList{
typedef std::list<LDAPAttribute> ListType;
private :
ListType m_attrs;
public :
typedef ListType::const_iterator const_iterator;
typedef ListType::iterator iterator;
/**
* Copy-constructor
*/
LDAPAttributeList(const LDAPAttributeList& al);
/**
* For internal use only
*
* This constructor is used by the library internally to create a
* list of attributes from a LDAPMessage-struct that was return by
* the C-API
*/
LDAPAttributeList(const LDAPAsynConnection *ld, LDAPMessage *msg);
/**
* Constructs an empty list.
*/
LDAPAttributeList();
/**
* Destructor
*/
virtual ~LDAPAttributeList();
/**
* @return The number of LDAPAttribute-objects that are currently
* stored in this list.
*/
size_t size() const;
/**
* @return true if there are zero LDAPAttribute-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;
/**
* Get an Attribute by its AttributeType
* @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 element to the end of the list.
* @param attr The attribute to add to the list.
*/
void addAttribute(const LDAPAttribute& attr);
/**
* Deletes all values of an Attribute for the list
* @param type The attribute type to be deleted.
*/
void delAttribute(const std::string& type);
/**
* Replace an Attribute in the List
* @param attr The attribute to add to the list.
*/
void replaceAttribute(const LDAPAttribute& attr);
/**
* Translates the list of Attributes to a 0-terminated array of
* LDAPMod-structures as needed by the C-API
*/
LDAPMod** toLDAPModArray() 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 LDAPAttributeList& al);
};
#endif // LDAP_ATTRIBUTE_LIST_H
// $OpenLDAP$
/*
* Copyright 2000-2020 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
#include <ldap.h>
#include "debug.h"
#include "LDAPBindRequest.h"
#include "LDAPException.h"
#include "SaslInteractionHandler.h"
#include "SaslInteraction.h"
#include <cstdlib>
#include <sasl/sasl.h>
using namespace std;
LDAPBindRequest::LDAPBindRequest(const LDAPBindRequest& req) :
LDAPRequest(req){
DEBUG(LDAP_DEBUG_CONSTRUCT, "LDAPBindRequest::LDAPBindRequest(&)" << endl);
m_dn=req.m_dn;
m_cred=req.m_cred;
m_mech=req.m_mech;
}
LDAPBindRequest::LDAPBindRequest(const string& dn,const string& passwd,
LDAPAsynConnection *connect, const LDAPConstraints *cons,
bool isReferral) : LDAPRequest(connect, cons, isReferral){
DEBUG(LDAP_DEBUG_CONSTRUCT,"LDAPBindRequest::LDAPBindRequest()" << endl);
DEBUG(LDAP_DEBUG_CONSTRUCT | LDAP_DEBUG_PARAMETER, " dn:" << dn << endl
<< " passwd:" << passwd << endl);
m_dn = dn;
m_cred = passwd;
m_mech = "";
}
LDAPBindRequest::~LDAPBindRequest(){
DEBUG(LDAP_DEBUG_DESTROY,"LDAPBindRequest::~LDAPBindRequest()" << endl);
}
LDAPMessageQueue* LDAPBindRequest::sendRequest(){
DEBUG(LDAP_DEBUG_TRACE,"LDAPBindRequest::sendRequest()" << endl);
int msgID=0;
const char* mech = (m_mech == "" ? 0 : m_mech.c_str());
BerValue* tmpcred=0;
if(m_cred != ""){
char* tmppwd = (char*) malloc( (m_cred.size()+1) * sizeof(char));
m_cred.copy(tmppwd,string::npos);
tmppwd[m_cred.size()]=0;
tmpcred=ber_bvstr(tmppwd);
}else{
tmpcred=(BerValue*) malloc(sizeof(BerValue));
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);
LDAPControlSet::freeLDAPControlArray(tmpSrvCtrls);
LDAPControlSet::freeLDAPControlArray(tmpClCtrls);
ber_bvfree(tmpcred);
if(err != LDAP_SUCCESS){
throw LDAPException(err);
}else{
m_msgID=msgID;
return new LDAPMessageQueue(this);
}
}
LDAPSaslBindRequest::LDAPSaslBindRequest(const std::string& mech,
const std::string& cred,
LDAPAsynConnection *connect,
const LDAPConstraints *cons,
bool isReferral) : LDAPRequest(connect, cons, isReferral),m_mech(mech), m_cred(cred) {}
LDAPMessageQueue* LDAPSaslBindRequest::sendRequest()
{
DEBUG(LDAP_DEBUG_TRACE,"LDAPSaslBindRequest::sendRequest()" << endl);
int msgID=0;
BerValue tmpcred;
tmpcred.bv_val = (char*) malloc( m_cred.size() * sizeof(char));
m_cred.copy(tmpcred.bv_val,string::npos);
tmpcred.bv_len = m_cred.size();
LDAPControl** tmpSrvCtrls=m_cons->getSrvCtrlsArray();
LDAPControl** tmpClCtrls=m_cons->getClCtrlsArray();
int err=ldap_sasl_bind(m_connection->getSessionHandle(), "", m_mech.c_str(),
&tmpcred, tmpSrvCtrls, tmpClCtrls, &msgID);
LDAPControlSet::freeLDAPControlArray(tmpSrvCtrls);
LDAPControlSet::freeLDAPControlArray(tmpClCtrls);
free(tmpcred.bv_val);
if(err != LDAP_SUCCESS){
throw LDAPException(err);
}else{
m_msgID=msgID;
return new LDAPMessageQueue(this);
}
}
LDAPSaslBindRequest::~LDAPSaslBindRequest()
{
DEBUG(LDAP_DEBUG_DESTROY,"LDAPSaslBindRequest::~LDAPSaslBindRequest()" << endl);
}
LDAPSaslInteractiveBind::LDAPSaslInteractiveBind( const std::string& mech,
int flags, SaslInteractionHandler *sih, LDAPAsynConnection *connect,
const LDAPConstraints *cons, bool isReferral) :
LDAPRequest(connect, cons, isReferral),
m_mech(mech), m_flags(flags), m_sih(sih), m_res(0)
{
}
static int my_sasl_interact(LDAP *l, unsigned flags, void *cbh, void *interact)
{
DEBUG(LDAP_DEBUG_TRACE, "LDAPSaslInteractiveBind::my_sasl_interact()"
<< std::endl );
std::list<SaslInteraction*> interactions;
sasl_interact_t *iter = (sasl_interact_t*) interact;
while ( iter->id != SASL_CB_LIST_END ) {
SaslInteraction *si = new SaslInteraction(iter);
interactions.push_back( si );
iter++;
}
((SaslInteractionHandler*)cbh)->handleInteractions(interactions);
return LDAP_SUCCESS;
}
/* This kind of fakes an asynchronous operation, ldap_sasl_interactive_bind_s
* is synchronous */
LDAPMessageQueue *LDAPSaslInteractiveBind::sendRequest()
{
DEBUG(LDAP_DEBUG_TRACE, "LDAPSaslInteractiveBind::sendRequest()" <<
m_mech << std::endl);
LDAPControl** tmpSrvCtrls=m_cons->getSrvCtrlsArray();
LDAPControl** tmpClCtrls=m_cons->getClCtrlsArray();
int res = ldap_sasl_interactive_bind_s( m_connection->getSessionHandle(),
"", m_mech.c_str(), tmpSrvCtrls, tmpClCtrls, m_flags,
my_sasl_interact, m_sih );
DEBUG(LDAP_DEBUG_TRACE, "ldap_sasl_interactive_bind_s returned: "
<< res << std::endl);
if(res != LDAP_SUCCESS){
throw LDAPException(res);
} else {
m_res = new LDAPResult(LDAPMsg::BIND_RESPONSE, res, "");
}
return new LDAPMessageQueue(this);
}
LDAPMsg* LDAPSaslInteractiveBind::getNextMessage() const
{
return m_res;
}
LDAPSaslInteractiveBind::~LDAPSaslInteractiveBind()
{
DEBUG(LDAP_DEBUG_DESTROY,"LDAPSaslInteractiveBind::~LDAPSaslInteractiveBind()" << endl);
}
// $OpenLDAP$
/*
* Copyright 2000-2020 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
#ifndef LDAP_BIND_REQUEST_H
#define LDAP_BIND_REQUEST_H
#include <LDAPRequest.h>
#include <LDAPResult.h>
#include <SaslInteractionHandler.h>
class LDAPBindRequest : LDAPRequest {
private:
std::string m_dn;
std::string m_cred;
std::string m_mech;
public:
LDAPBindRequest( const LDAPBindRequest& req);
//just for simple authentication
LDAPBindRequest(const std::string&, const std::string& passwd,
LDAPAsynConnection *connect, const LDAPConstraints *cons,
bool isReferral=false);
virtual ~LDAPBindRequest();
virtual LDAPMessageQueue *sendRequest();
};
class LDAPSaslBindRequest : LDAPRequest
{
public:
LDAPSaslBindRequest( const std::string& mech, const std::string& cred,
LDAPAsynConnection *connect, const LDAPConstraints *cons,
bool isReferral=false);
virtual LDAPMessageQueue *sendRequest();
virtual ~LDAPSaslBindRequest();
private:
std::string m_mech;
std::string m_cred;
};
class LDAPSaslInteractiveBind : LDAPRequest
{
public:
LDAPSaslInteractiveBind( const std::string& mech, int flags,
SaslInteractionHandler *sih, LDAPAsynConnection *connect,
const LDAPConstraints *cons, bool isReferral=false);
virtual LDAPMessageQueue *sendRequest();
virtual LDAPMsg* getNextMessage() const;
virtual ~LDAPSaslInteractiveBind();
private:
std::string m_mech;
int m_flags;
SaslInteractionHandler *m_sih;
LDAPResult *m_res;
};
#endif //LDAP_BIND_REQUEST_H
// $OpenLDAP$
/*
* Copyright 2000-2020 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
#include <ldap.h>
#include "debug.h"
#include "LDAPCompareRequest.h"
#include "LDAPException.h"
#include "LDAPMessageQueue.h"
#include "LDAPResult.h"
using namespace std;
LDAPCompareRequest::LDAPCompareRequest(const LDAPCompareRequest& req){
DEBUG(LDAP_DEBUG_CONSTRUCT,
"LDAPCompareRequest::LDAPCompareRequest(&)" << endl);
m_dn=req.m_dn;
m_attr=req.m_attr;
}
LDAPCompareRequest::LDAPCompareRequest(const string& dn,
const LDAPAttribute& attr, LDAPAsynConnection *connect,
const LDAPConstraints *cons, bool isReferral,
const LDAPRequest* parent) :
LDAPRequest(connect, cons, isReferral,parent){
DEBUG(LDAP_DEBUG_CONSTRUCT, "LDAPCompareRequest::LDAPCompareRequest()"
<< endl);
DEBUG(LDAP_DEBUG_CONSTRUCT | LDAP_DEBUG_PARAMETER, " dn:" << dn << endl
<< " attr:" << attr << endl);
m_requestType=LDAPRequest::COMPARE;
m_dn=dn;
m_attr=attr;
}
LDAPCompareRequest::~LDAPCompareRequest(){
DEBUG(LDAP_DEBUG_DESTROY, "LDAPCompareRequest::~LDAPCompareRequest()"
<< endl);
}
LDAPMessageQueue* LDAPCompareRequest::sendRequest(){
DEBUG(LDAP_DEBUG_TRACE, "LDAPCompareRequest::sendRequest()" << endl);
int msgID=0;
BerValue **val=m_attr.getBerValues();
LDAPControl** tmpSrvCtrls=m_cons->getSrvCtrlsArray();
LDAPControl** tmpClCtrls=m_cons->getClCtrlsArray();
int err=ldap_compare_ext(m_connection->getSessionHandle(),m_dn.c_str(),
m_attr.getName().c_str(), val[0], tmpSrvCtrls,
tmpClCtrls, &msgID);
ber_bvecfree(val);
LDAPControlSet::freeLDAPControlArray(tmpSrvCtrls);
LDAPControlSet::freeLDAPControlArray(tmpClCtrls);
if(err != LDAP_SUCCESS){
throw LDAPException(err);
}else{
m_msgID=msgID;
return new LDAPMessageQueue(this);
}
}
LDAPRequest* LDAPCompareRequest::followReferral(LDAPMsg* ref){
DEBUG(LDAP_DEBUG_TRACE, "LDAPCompareRequest::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){
return 0;
}
if(con != 0){
return new LDAPCompareRequest(m_dn, m_attr, 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_COMPARE_REQUEST_H
#define LDAP_COMPARE_REQUEST_H
#include <LDAPRequest.h>
class LDAPMessageQueue;
class LDAPCompareRequest : public LDAPRequest {
public :
LDAPCompareRequest(const LDAPCompareRequest& req);
LDAPCompareRequest(const std::string& dn, const LDAPAttribute& attr,
LDAPAsynConnection *connect, const LDAPConstraints *cons,
bool isReferral=false, const LDAPRequest* parent=0);
virtual ~LDAPCompareRequest();
virtual LDAPMessageQueue* sendRequest();
virtual LDAPRequest* followReferral(LDAPMsg* urls);
private :
std::string m_dn;
LDAPAttribute m_attr;
};
#endif //LDAP_COMPARE_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 "LDAPException.h"
#include "LDAPUrlList.h"
#include "LDAPConnection.h"
const int LDAPConnection::SEARCH_BASE = LDAPAsynConnection::SEARCH_BASE;
const int LDAPConnection::SEARCH_ONE = LDAPAsynConnection::SEARCH_ONE;
const int LDAPConnection::SEARCH_SUB = LDAPAsynConnection::SEARCH_SUB;
using namespace std;
LDAPConnection::LDAPConnection(const string& hostname, int port,
LDAPConstraints* cons) :
LDAPAsynConnection(hostname, port, cons){
}
LDAPConnection::~LDAPConnection(){
}
void LDAPConnection::start_tls(){
LDAPAsynConnection::start_tls();
}
void LDAPConnection::bind(const string& dn, const string& passwd,
LDAPConstraints* cons){
DEBUG(LDAP_DEBUG_TRACE,"LDAPConnection::bind" << endl);
LDAPMessageQueue* msg=0;
LDAPResult* res=0;
try{
msg = LDAPAsynConnection::bind(dn,passwd,cons);
res = (LDAPResult*)msg->getNext();
}catch(LDAPException e){
delete msg;
delete res;
throw;
}
int resCode=res->getResultCode();
if(resCode != LDAPResult::SUCCESS) {
if(resCode == LDAPResult::REFERRAL){
LDAPUrlList urls = res->getReferralUrls();
delete res;
delete msg;
throw LDAPReferralException(urls);
}else{
string srvMsg = res->getErrMsg();
delete res;
delete msg;
throw LDAPException(resCode, srvMsg);
}
}
delete res;
delete msg; // memcheck
}
void LDAPConnection::saslInteractiveBind( const std::string &mech,
int flags,
SaslInteractionHandler *sih,
const LDAPConstraints *cons)
{
DEBUG(LDAP_DEBUG_TRACE,"LDAPConnection::bind" << endl);
LDAPMessageQueue* msg=0;
LDAPResult* res=0;
try{
msg = LDAPAsynConnection::saslInteractiveBind(mech, flags, sih, cons);
res = (LDAPResult*)msg->getNext();
}catch(LDAPException e){
delete msg;
delete res;
throw;
}
int resCode=res->getResultCode();
if(resCode != LDAPResult::SUCCESS) {
if(resCode == LDAPResult::REFERRAL){
LDAPUrlList urls = res->getReferralUrls();
delete res;
delete msg;
throw LDAPReferralException(urls);
}else{
string srvMsg = res->getErrMsg();
delete res;
delete msg;
throw LDAPException(resCode, srvMsg);
}
}
delete res;
delete msg;
}
void LDAPConnection::unbind(){
LDAPAsynConnection::unbind();
}
bool LDAPConnection::compare(const string& dn, const LDAPAttribute& attr,
LDAPConstraints* cons){
DEBUG(LDAP_DEBUG_TRACE,"LDAPConnection::compare" << endl);
LDAPMessageQueue* msg=0;
LDAPResult* res=0;
try{
msg = LDAPAsynConnection::compare(dn,attr,cons);
res = (LDAPResult*)msg->getNext();
}catch(LDAPException e){
delete msg;
delete res;
throw;
}
int resCode=res->getResultCode();
switch (resCode){
case LDAPResult::COMPARE_TRUE :
delete res;
delete msg;
return true;
break;
case LDAPResult::COMPARE_FALSE :
delete res;
delete msg;
return false;
break;
case LDAPResult::REFERRAL :
{
LDAPUrlList urls = res->getReferralUrls();
delete res;
delete msg;
throw LDAPReferralException(urls);
}
break;
default :
string srvMsg = res->getErrMsg();
delete res;
delete msg;
throw LDAPException(resCode, srvMsg);
}
}
void LDAPConnection::del(const string& dn, const LDAPConstraints* cons){
DEBUG(LDAP_DEBUG_TRACE,"LDAPConnection::del" << endl);
LDAPMessageQueue* msg=0;
LDAPResult* res=0;
try{
msg = LDAPAsynConnection::del(dn,cons);
res = (LDAPResult*)msg->getNext();
}catch(LDAPException e){
delete msg;
delete res;
throw;
}
int resCode=res->getResultCode();
switch (resCode){
case LDAPResult::SUCCESS :
delete res;
delete msg;
break;
case LDAPResult::REFERRAL :
{
LDAPUrlList urls = res->getReferralUrls();
delete res;
delete msg;
throw LDAPReferralException(urls);
}
break;
default :
string srvMsg = res->getErrMsg();
delete res;
delete msg;
throw LDAPException(resCode, srvMsg);
}
}
void LDAPConnection::add(const LDAPEntry* le, const LDAPConstraints* cons){
DEBUG(LDAP_DEBUG_TRACE,"LDAPConnection::add" << endl);
LDAPMessageQueue* msg=0;
LDAPResult* res=0;
try{
msg = LDAPAsynConnection::add(le,cons);
res = (LDAPResult*)msg->getNext();
}catch(LDAPException e){
delete msg;
delete res;
throw;
}
int resCode=res->getResultCode();
switch (resCode){
case LDAPResult::SUCCESS :
delete res;
delete msg;
break;
case LDAPResult::REFERRAL :
{
LDAPUrlList urls = res->getReferralUrls();
delete res;
delete msg;
throw LDAPReferralException(urls);
}
break;
default :
string srvMsg = res->getErrMsg();
delete res;
delete msg;
throw LDAPException(resCode, srvMsg);
}
}
void LDAPConnection::modify(const string& dn, const LDAPModList* mods,
const LDAPConstraints* cons){
DEBUG(LDAP_DEBUG_TRACE,"LDAPConnection::modify" << endl);
LDAPMessageQueue* msg=0;
LDAPResult* res=0;
try{
msg = LDAPAsynConnection::modify(dn,mods,cons);
res = (LDAPResult*)msg->getNext();
}catch(LDAPException e){
delete msg;
delete res;
throw;
}
int resCode=res->getResultCode();
switch (resCode){
case LDAPResult::SUCCESS :
delete res;
delete msg;
break;
case LDAPResult::REFERRAL :
{
LDAPUrlList urls = res->getReferralUrls();
delete res;
delete msg;
throw LDAPReferralException(urls);
}
break;
default :
string srvMsg = res->getErrMsg();
delete res;
delete msg;
throw LDAPException(resCode, srvMsg);
}
}
void LDAPConnection::rename(const string& dn, const string& newRDN,
bool delOldRDN, const string& newParentDN,
const LDAPConstraints* cons){
DEBUG(LDAP_DEBUG_TRACE,"LDAPConnection::rename" << endl);
LDAPMessageQueue* msg=0;
LDAPResult* res=0;
try{
msg = LDAPAsynConnection::rename(dn,newRDN,delOldRDN, newParentDN,
cons);
res = (LDAPResult*)msg->getNext();
}catch(LDAPException e){
delete msg;
delete res;
throw;
}
int resCode=res->getResultCode();
switch (resCode){
case LDAPResult::SUCCESS :
delete res;
delete msg;
break;
case LDAPResult::REFERRAL :
{
LDAPUrlList urls = res->getReferralUrls();
delete res;
delete msg;
throw LDAPReferralException(urls);
}
break;
default :
string srvMsg = res->getErrMsg();
delete res;
delete msg;
throw LDAPException(resCode, srvMsg);
}
}
LDAPSearchResults* LDAPConnection::search(const string& base, int scope,
const string& filter, const StringList& attrs, bool attrsOnly,
const LDAPConstraints* cons){
DEBUG(LDAP_DEBUG_TRACE,"LDAPConnection::search" << endl);
LDAPMessageQueue* msgq=0;
LDAPResult* res=0;
LDAPSearchResults* results= 0;
try{
results = new LDAPSearchResults();
msgq = LDAPAsynConnection::search(base,scope, filter, attrs, attrsOnly,
cons);
res = results->readMessageQueue(msgq);
}catch(LDAPException e){
delete results; // memcheck
delete msgq;
throw;
}
if(res != 0){
int resCode=res->getResultCode();
switch (resCode){
case LDAPResult::SUCCESS :
delete res;
delete msgq;
return results;
break;
case LDAPResult::REFERRAL :
{
LDAPUrlList urls = res->getReferralUrls();
delete results; // memcheck
delete res;
delete msgq;
throw LDAPReferralException(urls);
}
break;
default :
string srvMsg = res->getErrMsg();
delete results; // memcheck
delete res;
delete msgq;
throw LDAPException(resCode, srvMsg);
}
}
return 0;
}
LDAPExtResult* LDAPConnection::extOperation(const string& oid,
const string& value, const LDAPConstraints *cons){
DEBUG(LDAP_DEBUG_TRACE,"LDAPConnection::extOperation" << endl);
LDAPMessageQueue* msg=0;
LDAPExtResult* res=0;
try{
msg = LDAPAsynConnection::extOperation(oid,value,cons);
res = (LDAPExtResult*)msg->getNext();
}catch(LDAPException e){
delete msg;
delete res;
throw;
}
int resCode=res->getResultCode();
switch (resCode){
case LDAPResult::SUCCESS :
delete msg;
return res;
case LDAPResult::REFERRAL :
{
LDAPUrlList urls = res->getReferralUrls();
delete res;
delete msg;
throw LDAPReferralException(urls);
}
break;
default :
string srvMsg = res->getErrMsg();
delete res;
delete msg;
throw LDAPException(resCode, srvMsg);
}
}
const string& LDAPConnection::getHost() const{
return LDAPAsynConnection::getHost();
}
int LDAPConnection::getPort() const{
return LDAPAsynConnection::getPort();
}
void LDAPConnection::setConstraints(LDAPConstraints* cons){
LDAPAsynConnection::setConstraints(cons);
}
const LDAPConstraints* LDAPConnection::getConstraints() const{
return LDAPAsynConnection::getConstraints();
}
TlsOptions LDAPConnection::getTlsOptions() const {
return LDAPAsynConnection::getTlsOptions();
}
// $OpenLDAP$
/*
* Copyright 2000-2020 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
#ifndef LDAP_CONNECTION_H
#define LDAP_CONNECTION_H
#include <LDAPSearchResults.h>
#include <LDAPExtResult.h>
#include <LDAPAsynConnection.h>
/** Main class for synchronous LDAP-Communication
*
* The class represent a LDAP-Connection to perform synchronous
* LDAP-Operations. This provides methodes for the different
* LDAP-Operations. All the methods for the LDAP-operations block until
* all results for the operation are received or until an error occurs
*/
class LDAPConnection : private LDAPAsynConnection {
public :
/**
* Constant for the Search-Operation to indicate a Base-Level
* Search
*/
static const int SEARCH_BASE;
/**
* Constant for the Search-Operation to indicate a One-Level
* Search
*/
static const int SEARCH_ONE;
/**
* Constant for the Search-Operation to indicate a Subtree
* Search
*/
static const int SEARCH_SUB;
/** This Constructor initializes synchronous LDAP-Connection
*
* During execution of this constructor no network communication
* is performed. Just some internal data structure are initialized
* @param hostname Name (or IP-Adress) of the destination host
* @param port Port the LDAP server is running on
* @param cons Default constraints to use with operations over
* this connection
*/
LDAPConnection(const std::string& hostname="localhost", int port=389,
LDAPConstraints* cons=new LDAPConstraints());
/**
* Destructor
*/
~LDAPConnection();
/**
* Initzializes a synchronous connection to a server.
*
* There is actually no
* communication to the server. Just the object is initialized
* (e.g. this method is called within the
* LDAPConnection(char*,int,LDAPConstraints) constructor.)
* @param hostname The Name or IP-Address of the destination
* LDAP-Server
* @param port The Network Port the server is running on
*/
void init(const std::string& hostname, int port);
/**
* Start TLS on this connection. This isn't in the constructor,
* because it could fail (i.e. server doesn't have SSL cert, client
* api wasn't compiled against OpenSSL, etc.).
* @throws LDAPException if the TLS Layer could not be setup
* correctly
*/
void start_tls();
/**
* Performs a simple authentication with the server
*
* @throws LDAPReferralException if a referral is received
* @throws LDAPException for any other error occuring during the
* operation
* @param dn The name of the entry to bind as
* @param passwd The cleartext password for the entry
*/
void bind(const std::string& dn="", const std::string& passwd="",
LDAPConstraints* cons=0);
void saslInteractiveBind(const std::string& mech,
int flags=0,
SaslInteractionHandler *sih=0,
const LDAPConstraints *cons=0);
/**
* Performs the UNBIND-operation on the destination server
*
* @throws LDAPException in any case of an error
*/
void unbind();
/**
* Performs a COMPARE-operation on an entery of the destination
* server.
*
* @throws LDAPReferralException if a referral is received
* @throws LDAPException for any other error occuring during the
* operation
* @param dn Distinguished name of the entry for which the compare
* should be performed
* @param attr An Attribute (one (!) value) to use for the
* compare operation
* @param cons A set of constraints that should be used with this
* request
* @returns The result of the compare operation. true if the
* attr-parameter matched an Attribute of the entry. false if it
* did not match
*/
bool compare(const std::string& dn, const LDAPAttribute& attr,
LDAPConstraints* cons=0);
/**
* Deletes an entry from the directory
*
* This method performs the DELETE operation on the server
* @throws LDAPReferralException if a referral is received
* @throws LDAPException for any other error occuring during the
* operation
* @param dn Distinguished name of the entry that should be deleted
* @param cons A set of constraints that should be used with this
* request
*/
void del(const std::string& dn, const LDAPConstraints* cons=0);
/**
* Use this method to perform the ADD-operation
*
* @throws LDAPReferralException if a referral is received
* @throws LDAPException for any other error occuring during the
* operation
* @param le the entry to add to the directory
* @param cons A set of constraints that should be used with this
* request
*/
void add(const LDAPEntry* le, const LDAPConstraints* cons=0);
/**
* To modify the attributes of an entry, this method can be used
*
* @throws LDAPReferralException if a referral is received
* @throws LDAPException for any other error occuring during the
* operation
* @param dn The DN of the entry which should be modified
* @param mods A set of modifications for that entry.
* @param cons A set of constraints that should be used with this
* request
*/
void modify(const std::string& dn, const LDAPModList* mods,
const LDAPConstraints* cons=0);
/**
* This method performs the ModDN-operation.
*
* It can be used to rename or move an entry by modifing its DN.
*
* @throws LDAPReferralException if a referral is received
* @throws LDAPException for any other error occuring during the
* operation
* @param dn The DN that should be modified
* @param newRDN If the RDN of the entry should be modified the
* new RDN can be put here.
* @param delOldRDN If the old RDN should be removed from the
* entry's attribute this parameter has to be
* "true"
* @param newParentDN If the entry should be moved inside the
* DIT, the DN of the new parent of the entry
* can be given here.
* @param cons A set of constraints that should be used with this
* request
*/
void rename(const std::string& dn, const std::string& newRDN,
bool delOldRDN=false, const std::string& newParentDN="",
const LDAPConstraints* cons=0);
/**
* This method can be used for the sync. SEARCH-operation.
*
* @throws LDAPReferralException if a referral is received
* @throws LDAPException for any other error occuring during the
* operation
* @param base The distinguished name of the starting point for the
* search
* @param scope The scope of the search. Possible values: <BR>
* LDAPAsynConnection::SEARCH_BASE, <BR>
* LDAPAsynConnection::SEARCH_ONE, <BR>
* LDAPAsynConnection::SEARCH_SUB
* @param filter The std::string representation of a search filter to
* use with this operation
* @param attrsOnly true if only the attributes names (no values)
* should be returned
* @param cons A set of constraints that should be used with this
* request
* @returns A pointer to a LDAPSearchResults-object that can be
* used to read the results of the search.
*/
LDAPSearchResults* search(const std::string& base, int scope=0,
const std::string& filter="objectClass=*",
const StringList& attrs=StringList(), bool attrsOnly=false,
const LDAPConstraints* cons=0);
/**
* This method is for extended LDAP-Operations.
*
* @throws LDAPReferralException if a referral is received
* @throws LDAPException for any other error occuring during the
* operation
* @param oid The Object Identifier of the Extended Operation that
* should be performed.
* @param strint If the Extended Operation needs some additional
* data it can be passed to the server by this parameter.
* @param cons A set of constraints that should be used with this
* request
* @returns The result of the Extended Operation as an
* pointer to a LDAPExtResult-object.
*/
LDAPExtResult* extOperation(const std::string& oid, const std::string&
value="", const LDAPConstraints *const = 0);
const std::string& getHost() const;
int getPort() const;
void setConstraints(LDAPConstraints *cons);
const LDAPConstraints* getConstraints() const ;
TlsOptions getTlsOptions() const;
};
#endif //LDAP_CONNECTION_H
// $OpenLDAP$
/*
* Copyright 2000-2020 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
#include "debug.h"
#include "config.h"
#include "ac/time.h"
#include "LDAPConstraints.h"
#include "LDAPControlSet.h"
using namespace std;
LDAPConstraints::LDAPConstraints(){
DEBUG(LDAP_DEBUG_CONSTRUCT,"LDAPConstraints::LDAPConstraints()" << endl);
m_aliasDeref=LDAPConstraints::DEREF_NEVER;
m_maxTime=LDAP_NO_LIMIT;
m_maxSize=LDAP_NO_LIMIT;
m_referralChase=false;
m_HopLimit=7;
m_serverControls=0;
m_clientControls=0;
m_refRebind=0;
}
LDAPConstraints::LDAPConstraints(const LDAPConstraints& c){
DEBUG(LDAP_DEBUG_CONSTRUCT,"LDAPConstraints::LDAPConstraints(&)" << endl);
m_aliasDeref=c.m_aliasDeref;
m_maxTime=c.m_maxTime;
m_maxSize=c.m_maxSize;
m_referralChase=c.m_referralChase;
m_HopLimit=c.m_HopLimit;
m_deref=c.m_deref;
if(c.m_serverControls){
m_serverControls=new LDAPControlSet(*c.m_serverControls);
}else{
m_serverControls=0;
}
if(c.m_clientControls){
m_clientControls=new LDAPControlSet(*c.m_clientControls);
}else{
m_clientControls=0;
}
m_refRebind=c.m_refRebind;
}
LDAPConstraints::~LDAPConstraints(){
DEBUG(LDAP_DEBUG_DESTROY,"LDAPConstraints::~LDAPConstraints()" << endl);
delete m_clientControls;
delete m_serverControls;
}
void LDAPConstraints::setAliasDeref(int deref){
DEBUG(LDAP_DEBUG_TRACE,"LDAPConstraints::setAliasDeref()" << endl);
DEBUG(LDAP_DEBUG_TRACE | LDAP_DEBUG_PARAMETER,
" deref:" << deref << endl);
if( (deref == LDAPConstraints::DEREF_NEVER) ||
(deref == LDAPConstraints::DEREF_SEARCHING) ||
(deref == LDAPConstraints::DEREF_FINDING) ||
(deref == LDAPConstraints::DEREF_ALWAYS)
){
m_aliasDeref=deref;
}
}
void LDAPConstraints::setMaxTime(int t){
DEBUG(LDAP_DEBUG_TRACE,"LDAPConstraints::setMaxTime()" << endl);
DEBUG(LDAP_DEBUG_TRACE | LDAP_DEBUG_PARAMETER," time:" << t << endl);
m_maxTime=t;
}
void LDAPConstraints::setSizeLimit(int s){
DEBUG(LDAP_DEBUG_TRACE,"LDAPConstraints::setSizeLimit()" << endl);
DEBUG(LDAP_DEBUG_TRACE | LDAP_DEBUG_PARAMETER," size:" << s << endl);
m_maxSize=s;
}
void LDAPConstraints::setReferralChase(bool rc){
DEBUG(LDAP_DEBUG_TRACE,"LDAPConstraints::setReferralChase()" << endl);
DEBUG(LDAP_DEBUG_TRACE | LDAP_DEBUG_PARAMETER," rc:" << rc << endl);
m_referralChase=rc;
}
void LDAPConstraints::setHopLimit(int limit){
DEBUG(LDAP_DEBUG_TRACE,"LDAPConstraints::setHopLimit()" << endl);
DEBUG(LDAP_DEBUG_TRACE | LDAP_DEBUG_PARAMETER,
" limit:" << limit << endl);
m_HopLimit=limit;
}
void LDAPConstraints::setReferralRebind(const LDAPRebind* rebind){
DEBUG(LDAP_DEBUG_TRACE,"LDAPConstraints::setReferralRebind()" << endl);
m_refRebind = rebind;
}
void LDAPConstraints::setServerControls(const LDAPControlSet* ctrls){
DEBUG(LDAP_DEBUG_TRACE,"LDAPConstraints::setServerControls()" << endl);
m_serverControls=new LDAPControlSet(*ctrls);
}
void LDAPConstraints::setClientControls(const LDAPControlSet* ctrls){
DEBUG(LDAP_DEBUG_TRACE,"LDAPConstraints::setClientControls()" << endl);
m_clientControls=new LDAPControlSet(*ctrls);
}
int LDAPConstraints::getAliasDeref() const {
DEBUG(LDAP_DEBUG_TRACE,"LDAPConstraints::getAliasDeref()" << endl);
return m_aliasDeref;
}
int LDAPConstraints::getMaxTime() const {
DEBUG(LDAP_DEBUG_TRACE,"LDAPConstraints::getMaxTime()" << endl);
return m_maxTime;
}
int LDAPConstraints::getSizeLimit() const {
DEBUG(LDAP_DEBUG_TRACE,"LDAPConstraints::getSizeLimit()" << endl);
return m_maxSize;
}
const LDAPRebind* LDAPConstraints::getReferralRebind() const{
DEBUG(LDAP_DEBUG_TRACE,"LDAPConstraints::getReferralRebind()" << endl);
return m_refRebind;
}
const LDAPControlSet* LDAPConstraints::getServerControls() const{
DEBUG(LDAP_DEBUG_TRACE,"LDAPConstraints::getServerControls()" << endl);
return m_serverControls;
}
const LDAPControlSet* LDAPConstraints::getClientControls() const{
DEBUG(LDAP_DEBUG_TRACE,"LDAPConstraints::getClientControls()" << endl);
return m_clientControls;
}
LDAPControl** LDAPConstraints::getSrvCtrlsArray() const {
DEBUG(LDAP_DEBUG_TRACE,"LDAPContstraints::getSrvCtrlsArray()" << endl);
if(m_serverControls){
return m_serverControls->toLDAPControlArray();
}else{
return 0;
}
}
LDAPControl** LDAPConstraints::getClCtrlsArray() const {
DEBUG(LDAP_DEBUG_TRACE,"LDAPContstraints::getClCtrlsArray()" << endl);
if(m_clientControls){
return m_clientControls->toLDAPControlArray();
}else{
return 0;
}
}
timeval* LDAPConstraints::getTimeoutStruct() const {
DEBUG(LDAP_DEBUG_TRACE,"LDAPContstraints::getTimeoutStruct()" << endl);
if(m_maxTime == LDAP_NO_LIMIT){
return 0;
}else{
timeval *ret = new timeval;
ret->tv_sec=m_maxTime;
ret->tv_usec=0;
return ret;
}
}
bool LDAPConstraints::getReferralChase() const {
DEBUG(LDAP_DEBUG_TRACE,"LDAPContstraints::getReferralChase()" << endl);
return m_referralChase;
}
int LDAPConstraints::getHopLimit() const{
DEBUG(LDAP_DEBUG_TRACE,"LDAPContstraints::getHopLimit()" << endl);
return m_HopLimit;
}
// $OpenLDAP$
/*
* Copyright 2000-2020 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
#ifndef LDAP_CONSTRAINTS_H
#define LDAP_CONSTRAINTS_H
#include <list>
#include <LDAPControl.h>
#include <LDAPControlSet.h>
#include <LDAPRebind.h>
//TODO!!
// * implement the Alias-Handling Option (OPT_DEREF)
// * the Restart-Option ???
// * default Server(s)
//* Class for representating the various protocol options
/** This class represents some options that can be set for a LDAPConnection
* operation. Namely these are time and size limits. Options for referral
* chasing and a default set of client of server controls to be used with
* every request
*/
class LDAPConstraints{
public :
static const int DEREF_NEVER = 0x00;
static const int DEREF_SEARCHING = 0x01;
static const int DEREF_FINDING = 0x02;
static const int DEREF_ALWAYS = 0x04;
//* Constructs a LDAPConstraints object with default values
LDAPConstraints();
//* Copy constructor
LDAPConstraints(const LDAPConstraints& c);
~LDAPConstraints();
void setAliasDeref(int deref);
void setMaxTime(int t);
void setSizeLimit(int s);
void setReferralChase(bool rc);
void setHopLimit(int hop);
void setReferralRebind(const LDAPRebind* rebind);
void setServerControls(const LDAPControlSet* ctrls);
void setClientControls(const LDAPControlSet* ctrls);
int getAliasDeref() const;
int getMaxTime() const ;
int getSizeLimit() const;
const LDAPRebind* getReferralRebind() const;
const LDAPControlSet* getServerControls() const;
const LDAPControlSet* getClientControls() const;
//*for internal use only
LDAPControl** getSrvCtrlsArray() const;
//*for internal use only
LDAPControl** getClCtrlsArray() const;
//*for internal use only
timeval* getTimeoutStruct() const;
bool getReferralChase() const ;
int getHopLimit() const;
private :
int m_aliasDeref;
//* max. time the server may spend for a search request
int m_maxTime;
//* max number of entries to return from a search request
int m_maxSize;
//* Flag for enabling automatic referral/reference chasing
bool m_referralChase;
//* HopLimit for referral chasing
int m_HopLimit;
//* Alias dereferencing option
int m_deref;
//* Object used to do bind for Referral chasing
const LDAPRebind* m_refRebind;
//* List of Client Controls that should be used for each request
LDAPControlSet* m_clientControls;
//* List of Server Controls that should be used for each request
LDAPControlSet* m_serverControls;
};
#endif //LDAP_CONSTRAINTS_H
// $OpenLDAP$
/*
* Copyright 2000-2020 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
#include "LDAPControl.h"
#include "debug.h"
using namespace std;
LDAPCtrl::LDAPCtrl(const char *oid, bool critical, const char* data,
int length){
DEBUG(LDAP_DEBUG_CONSTRUCT,"LDAPCtrl::LDAPCtrl()" << endl);
DEBUG(LDAP_DEBUG_CONSTRUCT | LDAP_DEBUG_PARAMETER,
" oid:" << oid << endl << " critical:" << critical << endl);
m_oid = oid;
m_isCritical=critical;
if (data != 0 && length !=0){
m_data.assign(data,length);
m_noData=false;
}else{
m_data=string();
m_noData=true;
}
}
LDAPCtrl::LDAPCtrl(const string& oid, bool critical, const string& data){
DEBUG(LDAP_DEBUG_CONSTRUCT,"LDAPCtrl::LDAPCtrl()" << endl);
DEBUG(LDAP_DEBUG_CONSTRUCT | LDAP_DEBUG_PARAMETER,
" oid:" << oid << endl << " critical:" << critical << endl);
m_oid=oid;
m_isCritical=critical;
m_data=data;
m_noData=false;
}
LDAPCtrl::LDAPCtrl(const LDAPControl* ctrl){
DEBUG(LDAP_DEBUG_CONSTRUCT,"LDAPCtrl::LDAPCtrl()" << endl);
m_oid = string(ctrl->ldctl_oid);
m_isCritical = ctrl->ldctl_iscritical ? true : false;
m_data = string(ctrl->ldctl_value.bv_val, ctrl->ldctl_value.bv_len );
m_noData = ctrl->ldctl_value.bv_len ? false : true;
}
LDAPCtrl::~LDAPCtrl(){
DEBUG(LDAP_DEBUG_DESTROY,"LDAPCtrl::~LDAPCtrl" << endl);
}
string LDAPCtrl::getOID() const{
DEBUG(LDAP_DEBUG_TRACE,"LDAPCtrl::getOID()" << endl);
return m_oid;
}
bool LDAPCtrl::isCritical()const {
DEBUG(LDAP_DEBUG_TRACE,"LDAPCtrl::isCritical()" << endl);
return m_isCritical;
}
bool LDAPCtrl::hasData() const{
return !m_noData;
}
string LDAPCtrl::getData() const {
DEBUG(LDAP_DEBUG_TRACE,"LDAPCtrl::getData()" << endl);
return m_data;
}
LDAPControl* LDAPCtrl::getControlStruct() const {
DEBUG(LDAP_DEBUG_TRACE,"LDAPCtrl::getControlStruct()" << endl);
LDAPControl* ret = new LDAPControl;
ret->ldctl_oid= new char[m_oid.size() + 1];
m_oid.copy(ret->ldctl_oid,string::npos);
ret->ldctl_oid[m_oid.size()]=0;
if ( m_noData ) {
ret->ldctl_value.bv_len = 0;
ret->ldctl_value.bv_val = NULL;
} else {
ret->ldctl_value.bv_len=m_data.size();
ret->ldctl_value.bv_val= new char[m_data.size()];
m_data.copy(ret->ldctl_value.bv_val,string::npos);
}
ret->ldctl_iscritical = ( m_isCritical ? 1:0);
return ret;
}
void LDAPCtrl::freeLDAPControlStruct(LDAPControl *ctrl){
DEBUG(LDAP_DEBUG_TRACE,"LDAPCtrl::freeControlStruct()" << endl);
delete[] ctrl->ldctl_oid;
delete[] ctrl->ldctl_value.bv_val;
delete ctrl;
}
// $OpenLDAP$
/*
* Copyright 2000-2020 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
#ifndef LDAP_CONTROL_H
#define LDAP_CONTROL_H
#include <string>
#include <ldap.h>
/**
* This class is used to store Controls. Controls are a mechanism to extend
* and modify LDAP-Operations.
*/
class LDAPCtrl{
public :
/**
* Constructor.
* @param oid: The Object Identifier of the Control
* @param critical: "true" if the Control should be handled
* critical by the server.
* @param data: If there is data for the control, put it here.
* @param length: The length of the data field
*/
LDAPCtrl(const char *oid, bool critical=false, const char *data=0,
int length=0);
/**
* Constructor.
* @param oid: The Object Identifier of the Control
* @param critical: "true" if the Control should be handled
* critical by the server.
* @param data: If there is data for the control, put it here.
*/
LDAPCtrl(const std::string& oid, bool critical,
const std::string& data);
/**
* Creates a copy of the Control that "ctrl is pointing to
*/
LDAPCtrl(const LDAPControl* ctrl);
/**
* Destructor
*/
~LDAPCtrl();
/**
* @return The OID of the control
*/
std::string getOID() const;
/**
* @return true if there is no "Control Value" (there is a
* difference between no and an empty control value)
*/
bool hasData() const;
/**
* @return The Data of the control as a std::string-Object
*/
std::string getData() const;
/**
* @return "true" if the control is critical
*/
bool isCritical() const;
/**
* For internal use only.
*
* Translates the control to a LDAPControl-structure as needed by
* the C-API
*/
LDAPControl* getControlStruct() const;
static void freeLDAPControlStruct(LDAPControl *ctrl);
private :
std::string m_oid;
std::string m_data;
bool m_isCritical;
bool m_noData;
};
#endif //LDAP_CONTROL_H
// $OpenLDAP$
/*
* Copyright 2000-2020 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
#include "debug.h"
#include "LDAPControlSet.h"
using namespace std;
LDAPControlSet::LDAPControlSet(){
}
LDAPControlSet::LDAPControlSet(const LDAPControlSet& cs){
DEBUG(LDAP_DEBUG_CONSTRUCT,"LDAPControlSet::LDAPControlSet(&)" << endl);
data=cs.data;
}
LDAPControlSet::LDAPControlSet(LDAPControl** controls){
DEBUG(LDAP_DEBUG_CONSTRUCT,"LDAPControlSet::LDAPControlSet()" << endl);
if(controls != 0){
LDAPControl** i;
for( i=controls; *i!=0;i++) {
add(LDAPCtrl(*i));
}
}
}
LDAPControlSet::~LDAPControlSet(){
DEBUG(LDAP_DEBUG_DESTROY,"LDAPControlSet::~LDAPControlSet()" << endl);
}
size_t LDAPControlSet::size() const {
DEBUG(LDAP_DEBUG_TRACE,"LDAPControlSet::size()" << endl);
return data.size();
}
bool LDAPControlSet::empty() const {
DEBUG(LDAP_DEBUG_TRACE,"LDAPControlSet::empty()" << endl);
return data.empty();
}
LDAPControlSet::const_iterator LDAPControlSet::begin() const{
DEBUG(LDAP_DEBUG_TRACE,"LDAPControlSet::begin()" << endl);
return data.begin();
}
LDAPControlSet::const_iterator LDAPControlSet::end() const{
DEBUG(LDAP_DEBUG_TRACE,"LDAPControlSet::end()" << endl);
return data.end ();
}
void LDAPControlSet::add(const LDAPCtrl& ctrl){
DEBUG(LDAP_DEBUG_TRACE,"LDAPControlSet::add()" << endl);
data.push_back(ctrl);
}
LDAPControl** LDAPControlSet::toLDAPControlArray() const{
DEBUG(LDAP_DEBUG_TRACE, "LDAPControlSet::toLDAPControlArray()" << endl);
if(data.empty()){
return 0;
}else{
LDAPControl** ret= new LDAPControl*[data.size()+1];
CtrlList::const_iterator i;
int j=0;
for(i=data.begin(); i!=data.end(); i++,j++){
ret[j] = i->getControlStruct();
}
ret[data.size()]=0;
return ret;
}
}
void LDAPControlSet::freeLDAPControlArray(LDAPControl **ctrl){
DEBUG(LDAP_DEBUG_TRACE, "LDAPControlSet::freeLDAPControlArray()" << endl);
if( ctrl ){
for( LDAPControl **i = ctrl; *i != 0; ++i ){
LDAPCtrl::freeLDAPControlStruct(*i);
}
}
delete[] ctrl;
}
// $OpenLDAP$
/*
* Copyright 2000-2020 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
#ifndef LDAP_CONTROL_SET_H
#define LDAP_CONTROL_SET_H
#include <list>
#include <ldap.h>
#include <LDAPControl.h>
typedef std::list<LDAPCtrl> CtrlList;
/**
* This container class is used to store multiple LDAPCtrl-objects.
*/
class LDAPControlSet {
typedef CtrlList::const_iterator const_iterator;
public :
/**
* Constructs an empty std::list
*/
LDAPControlSet();
/**
* Copy-constructor
*/
LDAPControlSet(const LDAPControlSet& cs);
/**
* For internal use only
*
* This constructor creates a new LDAPControlSet for a
* 0-terminiated array of LDAPControl-structures as used by the
* C-API
* @param controls: pointer to a 0-terminated array of pointers to
* LDAPControll-structures
* @note: untested til now. Due to lack of server that return
* Controls
*/
LDAPControlSet(LDAPControl** controls);
/**
* Destructor
*/
~LDAPControlSet();
/**
* @return The number of LDAPCtrl-objects that are currently
* stored in this list.
*/
size_t size() const ;
/**
* @return true if there are zero LDAPCtrl-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 ctrl The Control to add to the list.
*/
void add(const LDAPCtrl& ctrl);
/**
* Translates the list to a 0-terminated array of pointers to
* LDAPControl-structures as needed by the C-API
*/
LDAPControl** toLDAPControlArray()const ;
static void freeLDAPControlArray(LDAPControl **ctrl);
private :
CtrlList data;
} ;
#endif //LDAP_CONTROL_SET_H
// $OpenLDAP$
/*
* Copyright 2000-2020 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
#include <ldap.h>
#include "debug.h"
#include "LDAPDeleteRequest.h"
#include "LDAPException.h"
#include "LDAPMessageQueue.h"
#include "LDAPResult.h"
using namespace std;
LDAPDeleteRequest::LDAPDeleteRequest( const LDAPDeleteRequest& req) :
LDAPRequest(req){
DEBUG(LDAP_DEBUG_CONSTRUCT,
"LDAPDeleteRequest::LDAPDeleteRequest(&)" << endl);
m_dn = req.m_dn;
}
LDAPDeleteRequest::LDAPDeleteRequest(const string& dn,
LDAPAsynConnection *connect, const LDAPConstraints *cons,
bool isReferral, const LDAPRequest* parent)
: LDAPRequest(connect, cons, isReferral, parent) {
DEBUG(LDAP_DEBUG_CONSTRUCT,
"LDAPDeleteRequest::LDAPDeleteRequest()" << endl);
DEBUG(LDAP_DEBUG_CONSTRUCT | LDAP_DEBUG_PARAMETER, " dn:" << dn << endl);
m_requestType=LDAPRequest::DELETE;
m_dn=dn;
}
LDAPDeleteRequest::~LDAPDeleteRequest(){
DEBUG(LDAP_DEBUG_DESTROY,
"LDAPDeleteRequest::~LDAPDeleteRequest()" << endl);
}
LDAPMessageQueue* LDAPDeleteRequest::sendRequest(){
DEBUG(LDAP_DEBUG_TRACE, "LDAPDeleteRequest::sendRequest()" << endl);
int msgID=0;
LDAPControl** tmpSrvCtrls=m_cons->getSrvCtrlsArray();
LDAPControl** tmpClCtrls=m_cons->getClCtrlsArray();
int err=ldap_delete_ext(m_connection->getSessionHandle(),m_dn.c_str(),
tmpSrvCtrls, tmpClCtrls ,&msgID);
LDAPControlSet::freeLDAPControlArray(tmpSrvCtrls);
LDAPControlSet::freeLDAPControlArray(tmpClCtrls);
if(err != LDAP_SUCCESS){
throw LDAPException(err);
}else{
m_msgID=msgID;
return new LDAPMessageQueue(this);
}
}
LDAPRequest* LDAPDeleteRequest::followReferral(LDAPMsg* refs){
DEBUG(LDAP_DEBUG_TRACE, "LDAPDeleteRequest::followReferral()" << endl);
LDAPUrlList::const_iterator usedUrl;
LDAPUrlList urls= ((LDAPResult*)refs)->getReferralUrls();
LDAPAsynConnection* con=0;
try{
con = getConnection()->referralConnect(urls,usedUrl,m_cons);
}catch (LDAPException e){
delete con;
return 0;
}
if(con != 0){
return new LDAPDeleteRequest(m_dn, 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_DELETE_REQUEST_H
#define LDAP_DELETE_REQUEST_H
#include <LDAPRequest.h>
class LDAPMessageQueue;
class LDAPDeleteRequest : public LDAPRequest{
public :
LDAPDeleteRequest(const LDAPDeleteRequest& req);
LDAPDeleteRequest(const std::string& dn, LDAPAsynConnection *connect,
const LDAPConstraints *cons, bool isReferral=false,
const LDAPRequest* parent=0);
virtual ~LDAPDeleteRequest();
virtual LDAPMessageQueue* sendRequest();
virtual LDAPRequest* followReferral(LDAPMsg* refs);
private :
std::string m_dn;
};
#endif //LDAP_DELETE_REQUEST_H