2000-09-02 02:46:32 +08:00
|
|
|
/*
|
|
|
|
* Copyright 2000, OpenLDAP Foundation, All Rights Reserved.
|
|
|
|
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include<iostream.h>
|
|
|
|
#include<strstream>
|
2000-10-04 02:25:34 +08:00
|
|
|
#include "LDAPConnection.h"
|
2000-09-02 02:46:32 +08:00
|
|
|
#include "LDAPConstraints.h"
|
2000-10-04 02:25:34 +08:00
|
|
|
#include "LDAPSearchReference.h"
|
|
|
|
#include "LDAPSearchResults.h"
|
|
|
|
#include "LDAPAttribute.h"
|
|
|
|
#include "LDAPAttributeList.h"
|
|
|
|
#include "LDAPEntry.h"
|
|
|
|
#include "LDAPException.h"
|
|
|
|
#include "LDAPModification.h"
|
|
|
|
#include "LDAPReferralException.h"
|
|
|
|
|
2000-09-02 02:46:32 +08:00
|
|
|
#include"debug.h"
|
|
|
|
|
|
|
|
int main(){
|
2000-10-04 02:25:34 +08:00
|
|
|
LDAPConstraints* cons=new LDAPConstraints;
|
|
|
|
LDAPControlSet* ctrls=new LDAPControlSet;
|
|
|
|
ctrls->add(LDAPCtrl(LDAP_CONTROL_MANAGEDSAIT));
|
|
|
|
cons->setServerControls(ctrls);
|
|
|
|
LDAPConnection *lc=new LDAPConnection("localhost",9009);
|
|
|
|
lc->setConstraints(cons);
|
2000-09-02 02:46:32 +08:00
|
|
|
cout << "----------------------doing bind...." << endl;
|
|
|
|
try{
|
2000-10-04 02:25:34 +08:00
|
|
|
lc->bind("cn=Manager,o=Organisation,c=DE" , "secret",cons);
|
|
|
|
cout << lc->getHost() << endl;
|
|
|
|
bool result = lc->compare("cn=Manager,o=Organisation,c=DE",
|
|
|
|
LDAPAttribute("cn","Manaer"));
|
|
|
|
cout << "Compare: " << result << endl;
|
|
|
|
|
|
|
|
LDAPAttributeList* attrs=new LDAPAttributeList();
|
|
|
|
StringList values;
|
2000-10-12 01:18:27 +08:00
|
|
|
StringList s2;
|
2000-10-04 02:25:34 +08:00
|
|
|
values.add("top");
|
|
|
|
values.add("Person");
|
|
|
|
attrs->addAttribute(LDAPAttribute("objectClass",values));
|
|
|
|
attrs->addAttribute(LDAPAttribute("cn","Peter"));
|
|
|
|
attrs->addAttribute(LDAPAttribute("sn","Peter,hallo"));
|
|
|
|
LDAPEntry* entry=new LDAPEntry(
|
|
|
|
"cn=Peter , o=Organisation, c=DE", attrs);
|
|
|
|
// lc->add(entry);
|
|
|
|
|
|
|
|
// lc->del("ou=Groups,o=Organisation,c=DE");
|
|
|
|
|
|
|
|
LDAPSearchResults* entries = lc->search("o=Organisation,c=DE",
|
|
|
|
LDAPConnection::SEARCH_ONE);
|
|
|
|
if (entries != 0){
|
|
|
|
LDAPEntry* entry = entries->getNext();
|
|
|
|
if(entry != 0){
|
|
|
|
cout << *(entry) << endl;
|
|
|
|
}
|
|
|
|
while(entry){
|
|
|
|
try{
|
|
|
|
entry = entries->getNext();
|
|
|
|
if(entry != 0){
|
|
|
|
cout << *(entry) << endl;
|
|
|
|
}
|
|
|
|
delete entry;
|
|
|
|
}catch(LDAPReferralException e){
|
|
|
|
cout << "Caught Referral" << endl;
|
|
|
|
}
|
|
|
|
}
|
2000-09-02 02:46:32 +08:00
|
|
|
}
|
2000-10-04 02:25:34 +08:00
|
|
|
|
|
|
|
lc->unbind();
|
|
|
|
delete lc;
|
|
|
|
}catch (LDAPException e){
|
|
|
|
cout << "------------------------- caught Exception ---------"<< endl;
|
2000-09-02 02:46:32 +08:00
|
|
|
cout << e << endl;
|
|
|
|
}
|
2000-10-04 02:25:34 +08:00
|
|
|
|
|
|
|
/*
|
2000-09-02 02:46:32 +08:00
|
|
|
cout << "--------------------starting search" << endl;
|
2000-10-04 02:25:34 +08:00
|
|
|
LDAPAttributeList* attrs=new LDAPAttributeList();
|
|
|
|
StringList values;
|
|
|
|
values.add("top");
|
|
|
|
values.add("organizationalUnit");
|
|
|
|
attrs->addAttribute(LDAPAttribute("objectClass",values));
|
|
|
|
attrs->addAttribute(LDAPAttribute("ou","Groups"));
|
|
|
|
LDAPEntry* entry=new LDAPEntry(
|
|
|
|
"ou=Groups, o=Organisation, c=DE", attrs);
|
|
|
|
|
|
|
|
LDAPAttribute newattr("description");
|
|
|
|
LDAPModification::mod_op op = LDAPModification::OP_DELETE;
|
|
|
|
LDAPModList *mod=new LDAPModList();
|
|
|
|
mod->addModification(LDAPModification(newattr,op));
|
|
|
|
LDAPMessageQueue* q=0;
|
2000-09-02 02:46:32 +08:00
|
|
|
try{
|
2000-10-04 02:25:34 +08:00
|
|
|
q=lc->search("o=Organisation,c=de",LDAPAsynConnection::SEARCH_SUB,
|
|
|
|
"objectClass=*",StringList());
|
|
|
|
// q=lc->add(entry);
|
|
|
|
// q=lc->modify("cn=Manager,o=Organisation,c=DE",
|
|
|
|
// mod);
|
|
|
|
LDAPMsg *res=q->getNext();
|
2000-09-02 02:46:32 +08:00
|
|
|
bool cont=true;
|
2000-10-04 02:25:34 +08:00
|
|
|
while( cont ) {
|
2000-09-02 02:46:32 +08:00
|
|
|
switch(res->getMessageType()){
|
|
|
|
LDAPSearchResult *res2;
|
2000-10-04 02:25:34 +08:00
|
|
|
const LDAPEntry *entry;
|
2000-09-02 02:46:32 +08:00
|
|
|
case LDAP_RES_SEARCH_ENTRY :
|
|
|
|
res2= (LDAPSearchResult*)res;
|
|
|
|
entry= res2->getEntry();
|
|
|
|
cout << "Entry: " << *entry << endl;
|
|
|
|
delete res;
|
|
|
|
res=q->getNext();
|
|
|
|
break;
|
|
|
|
case LDAP_RES_SEARCH_REFERENCE :
|
2000-10-04 02:25:34 +08:00
|
|
|
cout << "Reference: " << endl;
|
2000-09-02 02:46:32 +08:00
|
|
|
delete res;
|
|
|
|
res=q->getNext();
|
|
|
|
break;
|
|
|
|
default :
|
2000-10-04 02:25:34 +08:00
|
|
|
cout << ( *(LDAPResult*) res) << endl;
|
2000-09-02 02:46:32 +08:00
|
|
|
delete res;
|
|
|
|
cout << "-----------------search done" << endl;
|
|
|
|
cont=false;
|
|
|
|
break;
|
|
|
|
}
|
2000-10-04 02:25:34 +08:00
|
|
|
}
|
2000-09-02 02:46:32 +08:00
|
|
|
delete q;
|
2000-10-04 02:25:34 +08:00
|
|
|
}catch (LDAPException e){
|
2000-09-02 02:46:32 +08:00
|
|
|
cout << "----------------error during search" << endl;
|
2000-10-04 02:25:34 +08:00
|
|
|
delete q;
|
|
|
|
cout << e << endl;
|
|
|
|
}
|
|
|
|
lc->unbind();
|
|
|
|
*/
|
2000-09-02 02:46:32 +08:00
|
|
|
}
|
|
|
|
|