1
// $OpenLDAP: pkg/ldap/contrib/ldapc++/examples/main.cpp,v 1.1.8.3 2008/04/14 23:18:59 quanah Exp $
3
* Copyright 2000, OpenLDAP Foundation, All Rights Reserved.
4
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
9
#include "LDAPConnection.h"
10
#include "LDAPConstraints.h"
11
#include "LDAPSearchReference.h"
12
#include "LDAPSearchResults.h"
13
#include "LDAPAttribute.h"
14
#include "LDAPAttributeList.h"
15
#include "LDAPEntry.h"
16
#include "LDAPException.h"
17
#include "LDAPModification.h"
22
LDAPConstraints* cons=new LDAPConstraints;
23
LDAPControlSet* ctrls=new LDAPControlSet;
24
ctrls->add(LDAPCtrl(LDAP_CONTROL_MANAGEDSAIT));
25
cons->setServerControls(ctrls);
26
LDAPConnection *lc=new LDAPConnection("localhost",9009);
27
lc->setConstraints(cons);
28
std::cout << "----------------------doing bind...." << std::endl;
30
lc->bind("cn=Manager,o=Organisation,c=DE" , "secret",cons);
31
std::cout << lc->getHost() << std::endl;
32
bool result = lc->compare("cn=Manager,o=Organisation,c=DE",
33
LDAPAttribute("cn","Manaer"));
34
std::cout << "Compare: " << result << std::endl;
36
LDAPAttributeList* attrs=new LDAPAttributeList();
41
attrs->addAttribute(LDAPAttribute("objectClass",values));
42
attrs->addAttribute(LDAPAttribute("cn","Peter"));
43
attrs->addAttribute(LDAPAttribute("sn","Peter,hallo"));
44
LDAPEntry* entry=new LDAPEntry(
45
"cn=Peter , o=Organisation, c=DE", attrs);
48
// lc->del("ou=Groups,o=Organisation,c=DE");
50
LDAPSearchResults* entries = lc->search("o=Organisation,c=DE",
51
LDAPConnection::SEARCH_ONE);
53
LDAPEntry* entry = entries->getNext();
55
std::cout << *(entry) << std::endl;
59
entry = entries->getNext();
61
std::cout << *(entry) << std::endl;
64
}catch(LDAPReferralException e){
65
std::cout << "Caught Referral" << std::endl;
72
}catch (LDAPException &e){
73
std::cout << "-------------- caught Exception ---------"<< std::endl;
74
std::cout << e << std::endl;
78
std::cout << "--------------------starting search" << std::endl;
79
LDAPAttributeList* attrs=new LDAPAttributeList();
82
values.add("organizationalUnit");
83
attrs->addAttribute(LDAPAttribute("objectClass",values));
84
attrs->addAttribute(LDAPAttribute("ou","Groups"));
85
LDAPEntry* entry=new LDAPEntry(
86
"ou=Groups, o=Organisation, c=DE", attrs);
88
LDAPAttribute newattr("description");
89
LDAPModification::mod_op op = LDAPModification::OP_DELETE;
90
LDAPModList *mod=new LDAPModList();
91
mod->addModification(LDAPModification(newattr,op));
92
LDAPMessageQueue* q=0;
94
q=lc->search("o=Organisation,c=de",LDAPAsynConnection::SEARCH_SUB,
95
"objectClass=*",StringList());
97
// q=lc->modify("cn=Manager,o=Organisation,c=DE",
99
LDAPMsg *res=q->getNext();
102
switch(res->getMessageType()){
103
LDAPSearchResult *res2;
104
const LDAPEntry *entry;
105
case LDAP_RES_SEARCH_ENTRY :
106
res2= (LDAPSearchResult*)res;
107
entry= res2->getEntry();
108
std::cout << "Entry: " << *entry << std::endl;
112
case LDAP_RES_SEARCH_REFERENCE :
113
std::cout << "Reference: " << std::endl;
118
std::cout << ( *(LDAPResult*) res) << std::endl;
120
std::cout << "-----------------search done" << std::endl;
126
}catch (LDAPException e){
127
std::cout << "----------------error during search" << std::endl;
129
std::cout << e << std::endl;