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