| 1 |
// $OpenLDAP$ |
| 2 |
/* |
| 3 |
* Copyright 2008-2024 The OpenLDAP Foundation, All Rights Reserved. |
| 4 |
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file |
| 5 |
*/ |
| 6 |
|
| 7 |
#include <iostream> |
| 8 |
#include <sstream> |
| 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" |
| 18 |
#include "LDAPSchema.h" |
| 19 |
|
| 20 |
#include "debug.h" |
| 21 |
|
| 22 |
int main(){ |
| 23 |
LDAPConnection *lc=new LDAPConnection("192.168.3.128",389); |
| 24 |
std::cout << "----------------------doing bind...." << std::endl; |
| 25 |
try{ |
| 26 |
lc->bind("uid=admin,dc=home,dc=local" , "secret"); |
| 27 |
std::cout << lc->getHost() << std::endl; |
| 28 |
StringList tmp; |
| 29 |
tmp.add("subschemasubentry"); |
| 30 |
LDAPSearchResults* entries = lc->search("", |
| 31 |
LDAPConnection::SEARCH_BASE, |
| 32 |
"(objectClass=*)", |
| 33 |
tmp ); |
| 34 |
LDAPEntry* rootDse = entries->getNext(); |
| 35 |
std::string schemabase="cn=subschema"; |
| 36 |
|
| 37 |
if(rootDse){ |
| 38 |
const LDAPAttribute* schemaAttr = rootDse->getAttributes()->getAttributeByName("subschemaSubentry"); |
| 39 |
schemabase = *(schemaAttr->getValues().begin()); |
| 40 |
} |
| 41 |
StringList attrs; |
| 42 |
attrs.add("objectClasses"); |
| 43 |
attrs.add("attributeTypes"); |
| 44 |
entries = lc->search(schemabase, LDAPConnection::SEARCH_BASE, "(objectClass=*)", |
| 45 |
attrs); |
| 46 |
if (entries != 0){ |
| 47 |
LDAPEntry* entry = entries->getNext(); |
| 48 |
if(entry != 0){ |
| 49 |
const LDAPAttribute* oc = entry->getAttributes()->getAttributeByName("objectClasses"); |
| 50 |
LDAPSchema schema; |
| 51 |
schema.setObjectClasses((oc->getValues())); |
| 52 |
LDAPObjClass test = schema.getObjectClassByName("inetOrgPerson"); |
| 53 |
std::cout << test.getDesc() << std::endl; |
| 54 |
// StringList mustAttr = test.getMay(); |
| 55 |
// for( StringList::const_iterator i = mustAttr.begin(); i != mustAttr.end(); i++ ){ |
| 56 |
// std::cout << *i << std::endl; |
| 57 |
// } |
| 58 |
StringList sup = test.getSup(); |
| 59 |
for( StringList::const_iterator i = sup.begin(); i != sup.end(); i++ ){ |
| 60 |
std::cout << *i << std::endl; |
| 61 |
} |
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
lc->unbind(); |
| 66 |
delete lc; |
| 67 |
}catch (LDAPException e){ |
| 68 |
std::cout << "---------------- caught Exception ---------"<< std::endl; |
| 69 |
std::cout << e << std::endl; |
| 70 |
} |
| 71 |
|
| 72 |
} |
| 73 |
|