Back to index

openldap  2.4.31
readSchema.cpp
Go to the documentation of this file.
00001 // $OpenLDAP$
00002 /*
00003  * Copyright 2008-2012 The OpenLDAP Foundation, All Rights Reserved.
00004  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
00005  */
00006 
00007 #include <iostream>
00008 #include <sstream>
00009 #include "LDAPConnection.h"
00010 #include "LDAPConstraints.h"
00011 #include "LDAPSearchReference.h"
00012 #include "LDAPSearchResults.h"
00013 #include "LDAPAttribute.h"
00014 #include "LDAPAttributeList.h"
00015 #include "LDAPEntry.h"
00016 #include "LDAPException.h"
00017 #include "LDAPModification.h"
00018 #include "LDAPSchema.h"
00019 
00020 #include "debug.h"
00021 
00022 int main(){
00023     LDAPConnection *lc=new LDAPConnection("192.168.3.128",389);
00024     std::cout << "----------------------doing bind...." <<  std::endl;
00025     try{
00026         lc->bind("uid=admin,dc=home,dc=local" , "secret");
00027         std::cout << lc->getHost() << std::endl;
00028         StringList tmp;
00029         tmp.add("subschemasubentry");
00030         LDAPSearchResults* entries = lc->search("", 
00031                         LDAPConnection::SEARCH_BASE,
00032                         "(objectClass=*)",
00033                         tmp );
00034         LDAPEntry* rootDse = entries->getNext();
00035         std::string schemabase="cn=subschema";
00036 
00037         if(rootDse){
00038             const LDAPAttribute* schemaAttr = rootDse->getAttributes()->getAttributeByName("subschemaSubentry");
00039             schemabase = *(schemaAttr->getValues().begin());   
00040         }
00041         StringList attrs;
00042         attrs.add("objectClasses");
00043         attrs.add("attributeTypes");
00044         entries = lc->search(schemabase, LDAPConnection::SEARCH_BASE, "(objectClass=*)",
00045                         attrs);
00046         if (entries != 0){
00047             LDAPEntry* entry = entries->getNext();
00048             if(entry != 0){
00049                 const LDAPAttribute* oc = entry->getAttributes()->getAttributeByName("objectClasses");
00050                 LDAPSchema schema;
00051                 schema.setObjectClasses((oc->getValues()));
00052                 LDAPObjClass test = schema.getObjectClassByName("inetOrgPerson");
00053                 std::cout << test.getDesc() << std::endl;
00054 //                StringList mustAttr = test.getMay();
00055 //                for( StringList::const_iterator i = mustAttr.begin(); i != mustAttr.end(); i++ ){
00056 //                    std::cout << *i << std::endl;
00057 //                }
00058                 StringList sup = test.getSup();
00059                 for( StringList::const_iterator i = sup.begin(); i != sup.end(); i++ ){
00060                     std::cout << *i << std::endl;
00061                 }
00062             }
00063         }
00064         
00065         lc->unbind();
00066         delete lc;
00067    }catch (LDAPException e){
00068         std::cout << "---------------- caught Exception ---------"<< std::endl;
00069         std::cout << e << std::endl;
00070     }
00071 
00072 }
00073