2007-09-21 19:27:23 +08:00
|
|
|
#include<iostream>
|
|
|
|
#include<sstream>
|
2005-04-20 21:03:09 +08:00
|
|
|
#include "LDAPConnection.h"
|
|
|
|
#include "LDAPConstraints.h"
|
|
|
|
#include "LDAPSearchReference.h"
|
|
|
|
#include "LDAPSearchResults.h"
|
|
|
|
#include "LDAPAttribute.h"
|
|
|
|
#include "LDAPAttributeList.h"
|
|
|
|
#include "LDAPEntry.h"
|
|
|
|
#include "LDAPException.h"
|
|
|
|
#include "LDAPModification.h"
|
|
|
|
#include "LDAPReferralException.h"
|
|
|
|
#include "LDAPSchema.h"
|
|
|
|
|
|
|
|
#include"debug.h"
|
|
|
|
|
|
|
|
int main(){
|
|
|
|
LDAPConnection *lc=new LDAPConnection("192.168.3.128",389);
|
2007-09-21 19:27:23 +08:00
|
|
|
std::cout << "----------------------doing bind...." << std::endl;
|
2005-04-20 21:03:09 +08:00
|
|
|
try{
|
|
|
|
lc->bind("uid=admin,dc=home,dc=local" , "secret");
|
2007-09-21 19:27:23 +08:00
|
|
|
std::cout << lc->getHost() << std::endl;
|
2005-04-20 21:03:09 +08:00
|
|
|
StringList tmp;
|
|
|
|
tmp.add("subschemasubentry");
|
|
|
|
LDAPSearchResults* entries = lc->search("",
|
|
|
|
LDAPConnection::SEARCH_BASE,
|
|
|
|
"(objectClass=*)",
|
|
|
|
tmp );
|
|
|
|
LDAPEntry* rootDse = entries->getNext();
|
|
|
|
std::string schemabase="cn=subschema";
|
|
|
|
|
|
|
|
if(rootDse){
|
|
|
|
const LDAPAttribute* schemaAttr = rootDse->getAttributes()->getAttributeByName("subschemaSubentry");
|
|
|
|
schemabase = *(schemaAttr->getValues().begin());
|
|
|
|
}
|
|
|
|
StringList attrs;
|
|
|
|
attrs.add("objectClasses");
|
|
|
|
attrs.add("attributeTypes");
|
|
|
|
entries = lc->search(schemabase, LDAPConnection::SEARCH_BASE, "(objectClass=*)",
|
|
|
|
attrs);
|
|
|
|
if (entries != 0){
|
|
|
|
LDAPEntry* entry = entries->getNext();
|
|
|
|
if(entry != 0){
|
|
|
|
const LDAPAttribute* oc = entry->getAttributes()->getAttributeByName("objectClasses");
|
|
|
|
LDAPSchema schema;
|
|
|
|
schema.setObjectClasses((oc->getValues()));
|
|
|
|
LDAPObjClass test = schema.getObjectClassByName("inetOrgPerson");
|
2007-09-21 19:27:23 +08:00
|
|
|
std::cout << test.getDesc() << std::endl;
|
2005-04-20 21:03:09 +08:00
|
|
|
// StringList mustAttr = test.getMay();
|
|
|
|
// for( StringList::const_iterator i = mustAttr.begin(); i != mustAttr.end(); i++ ){
|
2007-09-21 19:27:23 +08:00
|
|
|
// std::cout << *i << std::endl;
|
2005-04-20 21:03:09 +08:00
|
|
|
// }
|
|
|
|
StringList sup = test.getSup();
|
|
|
|
for( StringList::const_iterator i = sup.begin(); i != sup.end(); i++ ){
|
2007-09-21 19:27:23 +08:00
|
|
|
std::cout << *i << std::endl;
|
2005-04-20 21:03:09 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
lc->unbind();
|
|
|
|
delete lc;
|
|
|
|
}catch (LDAPException e){
|
2007-09-21 19:27:23 +08:00
|
|
|
std::cout << "---------------- caught Exception ---------"<< std::endl;
|
|
|
|
std::cout << e << std::endl;
|
2005-04-20 21:03:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|