ldapsdk  0.0.1
Public Member Functions | Static Public Attributes | List of all members
LDAPConnection Class Reference

Main class for synchronous LDAP-Communication. More...

#include <LDAPConnection.h>

Inheritance diagram for LDAPConnection:
LDAPAsynConnection

Public Member Functions

 LDAPConnection (const std::string &hostname="localhost", int port=389, LDAPConstraints *cons=new LDAPConstraints())
 This Constructor initializes synchronous LDAP-Connection. More...
 
 ~LDAPConnection ()
 Destructor. More...
 
void init (const std::string &hostname, int port)
 Initzializes a synchronous connection to a server. More...
 
void start_tls ()
 Start TLS on this connection. More...
 
void bind (const std::string &dn="", const std::string &passwd="", LDAPConstraints *cons=0)
 Performs a simple authentication with the server. More...
 
void saslInteractiveBind (const std::string &mech, int flags=0, SaslInteractionHandler *sih=0, const LDAPConstraints *cons=0)
 
void unbind ()
 Performs the UNBIND-operation on the destination server. More...
 
bool compare (const std::string &dn, const LDAPAttribute &attr, LDAPConstraints *cons=0)
 Performs a COMPARE-operation on an entery of the destination server. More...
 
void del (const std::string &dn, const LDAPConstraints *cons=0)
 Deletes an entry from the directory. More...
 
void add (const LDAPEntry *le, const LDAPConstraints *cons=0)
 Use this method to perform the ADD-operation. More...
 
void modify (const std::string &dn, const LDAPModList *mods, const LDAPConstraints *cons=0)
 To modify the attributes of an entry, this method can be used. More...
 
void rename (const std::string &dn, const std::string &newRDN, bool delOldRDN=false, const std::string &newParentDN="", const LDAPConstraints *cons=0)
 This method performs the ModDN-operation. More...
 
LDAPSearchResultssearch (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 can be used for the sync. More...
 
LDAPExtResultextOperation (const std::string &oid, const std::string &value="", const LDAPConstraints *const =0)
 This method is for extended LDAP-Operations. More...
 
const std::string & getHost () const
 
int getPort () const
 
void setConstraints (LDAPConstraints *cons)
 
const LDAPConstraintsgetConstraints () const
 
TlsOptions getTlsOptions () const
 

Static Public Attributes

static const int SEARCH_BASE = LDAPAsynConnection::SEARCH_BASE
 Constant for the Search-Operation to indicate a Base-Level Search. More...
 
static const int SEARCH_ONE = LDAPAsynConnection::SEARCH_ONE
 Constant for the Search-Operation to indicate a One-Level Search. More...
 
static const int SEARCH_SUB = LDAPAsynConnection::SEARCH_SUB
 Constant for the Search-Operation to indicate a Subtree Search. More...
 

Detailed Description

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

Constructor & Destructor Documentation

◆ LDAPConnection()

LDAPConnection::LDAPConnection ( const std::string &  hostname = "localhost",
int  port = 389,
LDAPConstraints cons = new LDAPConstraints() 
)

This Constructor initializes synchronous LDAP-Connection.

During execution of this constructor no network communication is performed. Just some internal data structure are initialized

Parameters
hostnameName (or IP-Adress) of the destination host
portPort the LDAP server is running on
consDefault constraints to use with operations over this connection

◆ ~LDAPConnection()

LDAPConnection::~LDAPConnection ( )

Destructor.

Member Function Documentation

◆ add()

void LDAPConnection::add ( const LDAPEntry le,
const LDAPConstraints cons = 0 
)

Use this method to perform the ADD-operation.

Exceptions
LDAPReferralExceptionif a referral is received
LDAPExceptionfor any other error occuring during the operation
Parameters
lethe entry to add to the directory
consA set of constraints that should be used with this request

References LDAPAsynConnection::add(), DEBUG, LDAPResult::getErrMsg(), LDAPMessageQueue::getNext(), LDAPResult::getReferralUrls(), LDAPResult::getResultCode(), LDAP_DEBUG_TRACE, LDAPResult::REFERRAL, and LDAPResult::SUCCESS.

◆ bind()

void LDAPConnection::bind ( const std::string &  dn = "",
const std::string &  passwd = "",
LDAPConstraints cons = 0 
)

Performs a simple authentication with the server.

Exceptions
LDAPReferralExceptionif a referral is received
LDAPExceptionfor any other error occuring during the operation
Parameters
dnThe name of the entry to bind as
passwdThe cleartext password for the entry

References LDAPAsynConnection::bind(), DEBUG, LDAPResult::getErrMsg(), LDAPMessageQueue::getNext(), LDAPResult::getReferralUrls(), LDAPResult::getResultCode(), LDAP_DEBUG_TRACE, LDAPResult::REFERRAL, and LDAPResult::SUCCESS.

◆ compare()

bool LDAPConnection::compare ( const std::string &  dn,
const LDAPAttribute attr,
LDAPConstraints cons = 0 
)

Performs a COMPARE-operation on an entery of the destination server.

Exceptions
LDAPReferralExceptionif a referral is received
LDAPExceptionfor any other error occuring during the operation
Parameters
dnDistinguished name of the entry for which the compare should be performed
attrAn Attribute (one (!) value) to use for the compare operation
consA 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

References LDAPAsynConnection::compare(), LDAPResult::COMPARE_FALSE, LDAPResult::COMPARE_TRUE, DEBUG, LDAPResult::getErrMsg(), LDAPMessageQueue::getNext(), LDAPResult::getReferralUrls(), LDAPResult::getResultCode(), LDAP_DEBUG_TRACE, and LDAPResult::REFERRAL.

◆ del()

void LDAPConnection::del ( const std::string &  dn,
const LDAPConstraints cons = 0 
)

Deletes an entry from the directory.

This method performs the DELETE operation on the server

Exceptions
LDAPReferralExceptionif a referral is received
LDAPExceptionfor any other error occuring during the operation
Parameters
dnDistinguished name of the entry that should be deleted
consA set of constraints that should be used with this request

References DEBUG, LDAPAsynConnection::del(), LDAPResult::getErrMsg(), LDAPMessageQueue::getNext(), LDAPResult::getReferralUrls(), LDAPResult::getResultCode(), LDAP_DEBUG_TRACE, LDAPResult::REFERRAL, and LDAPResult::SUCCESS.

◆ extOperation()

LDAPExtResult * LDAPConnection::extOperation ( const std::string &  oid,
const std::string &  value = "",
const LDAPConstraints const = 0 
)

This method is for extended LDAP-Operations.

Exceptions
LDAPReferralExceptionif a referral is received
LDAPExceptionfor any other error occuring during the operation
Parameters
oidThe Object Identifier of the Extended Operation that should be performed.
strintIf the Extended Operation needs some additional data it can be passed to the server by this parameter.
consA set of constraints that should be used with this request
Returns
The result of the Extended Operation as an pointer to a LDAPExtResult-object.

References DEBUG, LDAPAsynConnection::extOperation(), LDAPResult::getErrMsg(), LDAPMessageQueue::getNext(), LDAPResult::getReferralUrls(), LDAPResult::getResultCode(), LDAP_DEBUG_TRACE, LDAPResult::REFERRAL, and LDAPResult::SUCCESS.

◆ getConstraints()

const LDAPConstraints * LDAPConnection::getConstraints ( ) const

◆ getHost()

const string & LDAPConnection::getHost ( ) const

◆ getPort()

int LDAPConnection::getPort ( ) const

◆ getTlsOptions()

TlsOptions LDAPConnection::getTlsOptions ( ) const

◆ init()

void LDAPConnection::init ( const std::string &  hostname,
int  port 
)

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.)

Parameters
hostnameThe Name or IP-Address of the destination LDAP-Server
portThe Network Port the server is running on

◆ modify()

void LDAPConnection::modify ( const std::string &  dn,
const LDAPModList mods,
const LDAPConstraints cons = 0 
)

To modify the attributes of an entry, this method can be used.

Exceptions
LDAPReferralExceptionif a referral is received
LDAPExceptionfor any other error occuring during the operation
Parameters
dnThe DN of the entry which should be modified
modsA set of modifications for that entry.
consA set of constraints that should be used with this request

References DEBUG, LDAPResult::getErrMsg(), LDAPMessageQueue::getNext(), LDAPResult::getReferralUrls(), LDAPResult::getResultCode(), LDAP_DEBUG_TRACE, LDAPAsynConnection::modify(), LDAPResult::REFERRAL, and LDAPResult::SUCCESS.

◆ rename()

void LDAPConnection::rename ( const std::string &  dn,
const std::string &  newRDN,
bool  delOldRDN = false,
const std::string &  newParentDN = "",
const LDAPConstraints cons = 0 
)

This method performs the ModDN-operation.

It can be used to rename or move an entry by modifing its DN.

Exceptions
LDAPReferralExceptionif a referral is received
LDAPExceptionfor any other error occuring during the operation
Parameters
dnThe DN that should be modified
newRDNIf the RDN of the entry should be modified the new RDN can be put here.
delOldRDNIf the old RDN should be removed from the entry's attribute this parameter has to be "true"
newParentDNIf the entry should be moved inside the DIT, the DN of the new parent of the entry can be given here.
consA set of constraints that should be used with this request

References DEBUG, LDAPResult::getErrMsg(), LDAPMessageQueue::getNext(), LDAPResult::getReferralUrls(), LDAPResult::getResultCode(), LDAP_DEBUG_TRACE, LDAPResult::REFERRAL, LDAPAsynConnection::rename(), and LDAPResult::SUCCESS.

◆ saslInteractiveBind()

void LDAPConnection::saslInteractiveBind ( const std::string &  mech,
int  flags = 0,
SaslInteractionHandler sih = 0,
const LDAPConstraints cons = 0 
)

◆ search()

LDAPSearchResults * LDAPConnection::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 can be used for the sync.

SEARCH-operation.

Exceptions
LDAPReferralExceptionif a referral is received
LDAPExceptionfor any other error occuring during the operation
Parameters
baseThe distinguished name of the starting point for the search
scopeThe scope of the search. Possible values:
LDAPAsynConnection::SEARCH_BASE,
LDAPAsynConnection::SEARCH_ONE,
LDAPAsynConnection::SEARCH_SUB
filterThe std::string representation of a search filter to use with this operation
attrsOnlytrue if only the attributes names (no values) should be returned
consA 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.

References DEBUG, LDAPResult::getErrMsg(), LDAPResult::getReferralUrls(), LDAPResult::getResultCode(), LDAP_DEBUG_TRACE, LDAPSearchResults::readMessageQueue(), LDAPResult::REFERRAL, LDAPAsynConnection::search(), and LDAPResult::SUCCESS.

◆ setConstraints()

void LDAPConnection::setConstraints ( LDAPConstraints cons)

◆ start_tls()

void LDAPConnection::start_tls ( )

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.).

Exceptions
LDAPExceptionif the TLS Layer could not be setup correctly

References LDAPAsynConnection::start_tls().

◆ unbind()

void LDAPConnection::unbind ( )

Performs the UNBIND-operation on the destination server.

Exceptions
LDAPExceptionin any case of an error

References LDAPAsynConnection::unbind().

Member Data Documentation

◆ SEARCH_BASE

const int LDAPConnection::SEARCH_BASE = LDAPAsynConnection::SEARCH_BASE
static

Constant for the Search-Operation to indicate a Base-Level Search.

◆ SEARCH_ONE

const int LDAPConnection::SEARCH_ONE = LDAPAsynConnection::SEARCH_ONE
static

Constant for the Search-Operation to indicate a One-Level Search.

◆ SEARCH_SUB

const int LDAPConnection::SEARCH_SUB = LDAPAsynConnection::SEARCH_SUB
static

Constant for the Search-Operation to indicate a Subtree Search.


The documentation for this class was generated from the following files: