[yast-commit] r48601 - in /trunk/ldap-server/src: agent/SlapdConfigAgent.cc agent/SlapdConfigAgent.h lib/backConfigTest.cpp lib/backConfigTest.h
Author: rhafer Date: Fri Jun 27 15:57:20 2008 New Revision: 48601 URL: http://svn.opensuse.org/viewcvs/yast?rev=48601&view=rev Log: - Use SASL External Authentication for LDAP Connection - Reworked .ldapserver.databases Code Modified: trunk/ldap-server/src/agent/SlapdConfigAgent.cc trunk/ldap-server/src/agent/SlapdConfigAgent.h trunk/ldap-server/src/lib/backConfigTest.cpp trunk/ldap-server/src/lib/backConfigTest.h Modified: trunk/ldap-server/src/agent/SlapdConfigAgent.cc URL: http://svn.opensuse.org/viewcvs/yast/trunk/ldap-server/src/agent/SlapdConfigAgent.cc?rev=48601&r1=48600&r2=48601&view=diff ============================================================================== --- trunk/ldap-server/src/agent/SlapdConfigAgent.cc (original) +++ trunk/ldap-server/src/agent/SlapdConfigAgent.cc Fri Jun 27 15:57:20 2008 @@ -4,12 +4,41 @@ #include <LdifReader.h> #include <LdifWriter.h> #include <LDAPEntry.h> +#include <SaslInteraction.h> #include <sstream> #define DEFAULT_PORT 389 #define ANSWER 42 #define MAX_LENGTH_ID 5 +class SaslExternalHandler : SaslInteractionHandler +{ + public: + virtual void handleInteractions(const std::list<SaslInteraction*> &cb ); + virtual ~SaslExternalHandler(); + private: + std::list<SaslInteraction*> cleanupList; + +}; + +void SaslExternalHandler::handleInteractions( const std::list<SaslInteraction *> &cb ) +{ + std::list<SaslInteraction*>::const_iterator i; + + for (i = cb.begin(); i != cb.end(); i++ ) { + cleanupList.push_back(*i); + } +} + +SaslExternalHandler::~SaslExternalHandler() +{ + std::list<SaslInteraction*>::const_iterator i; + for (i = cleanupList.begin(); i != cleanupList.end(); i++ ) { + delete(*i); + } +} + + SlapdConfigAgent::SlapdConfigAgent() { y2milestone("SlapdConfigAgent::SlapdConfigAgent"); @@ -72,6 +101,14 @@ const YCPValue &arg2) { y2milestone("Execute Path %s", path->toString().c_str() ); + if ( path->component_str(0) == "init" ) + { + + LDAPConnection *lc = new LDAPConnection("ldapi:///"); + SaslExternalHandler sih; + lc->saslInteractiveBind("external", 2 /* LDAP_SASL_QUIET */, (SaslInteractionHandler*)&sih); + olc = OlcConfig(lc); + } if ( path->component_str(0) == "initFromLdif" ) { std::istringstream ldifstream(arg->asString()->value_cstr()); @@ -213,25 +250,18 @@ { y2milestone("Path %s Length %ld ", path->toString().c_str(), path->length()); - std::list<boost::shared_ptr<OlcDatabase> >::const_iterator i; + if ( databases.size() == 0 ) + { + databases = olc.getDatabases(); + } + OlcDatabaseList::const_iterator i; YCPList dbList; for (i = databases.begin(); i != databases.end(); i++ ) { YCPMap ymap; - std::map<std::string, std::list<std::string> > dbMap = (*i)->toMap(); - std::map<std::string, std::list<std::string> >::const_iterator j; - for ( j = dbMap.begin(); j != dbMap.end(); j++ ) - { - YCPList l; - YCPString type(j->first); - std::list<std::string> vals = j->second; - std::list<std::string>::const_iterator k; - for (k = vals.begin(); k != vals.end(); k++ ) - { - l.add(YCPString(*k)); - } - ymap.add(type, l); - } + ymap.add( YCPString("suffix"), YCPString((*i)->getSuffix()) ); + ymap.add( YCPString("type"), YCPString((*i)->getType()) ); + ymap.add( YCPString("index"), YCPInteger((*i)->getIndex()) ); dbList.add(ymap); } return dbList; @@ -266,7 +296,7 @@ YCPString SlapdConfigAgent::ConfigToLdif() const { y2milestone("ConfigToLdif"); - std::list<boost::shared_ptr<OlcDatabase> >::const_iterator i = databases.begin(); + OlcDatabaseList::const_iterator i = databases.begin(); std::ostringstream ldif; ldif << globals->toLdif() << std::endl; ldif << schemaBase->toLdif() << std::endl; @@ -281,3 +311,4 @@ } return YCPString(ldif.str()); } + Modified: trunk/ldap-server/src/agent/SlapdConfigAgent.h URL: http://svn.opensuse.org/viewcvs/yast/trunk/ldap-server/src/agent/SlapdConfigAgent.h?rev=48601&r1=48600&r2=48601&view=diff ============================================================================== --- trunk/ldap-server/src/agent/SlapdConfigAgent.h (original) +++ trunk/ldap-server/src/agent/SlapdConfigAgent.h Fri Jun 27 15:57:20 2008 @@ -50,7 +50,7 @@ private: OlcConfig olc; - std::list<boost::shared_ptr<OlcDatabase> > databases; + OlcDatabaseList databases; boost::shared_ptr<OlcGlobalConfig> globals; boost::shared_ptr<OlcSchemaConfig> schemaBase; }; Modified: trunk/ldap-server/src/lib/backConfigTest.cpp URL: http://svn.opensuse.org/viewcvs/yast/trunk/ldap-server/src/lib/backConfigTest.cpp?rev=48601&r1=48600&r2=48601&view=diff ============================================================================== --- trunk/ldap-server/src/lib/backConfigTest.cpp (original) +++ trunk/ldap-server/src/lib/backConfigTest.cpp Fri Jun 27 15:57:20 2008 @@ -24,7 +24,20 @@ return false; } -OlcDatabase::OlcDatabase( const LDAPEntry& le=LDAPEntry()) : OlcConfigEntry(le) { } +OlcDatabase::OlcDatabase( const LDAPEntry& le=LDAPEntry()) : OlcConfigEntry(le) +{ + std::string type(this->getStringValue("olcdatabase")); + if ( type[0] == '{' ) + { + std::string::size_type pos = type.find('}'); + std::istringstream indexstr(type.substr(1, pos-1)); + indexstr >> entryIndex; + m_type = type.substr( pos+1, std::string::npos ); + } else { + m_type = type; + entryIndex = 0; + } +} OlcDatabase::OlcDatabase( const std::string& type ) : m_type(type) { @@ -337,6 +350,11 @@ this->updateEntryDn(); } +int OlcConfigEntry::getIndex() const +{ + return this->entryIndex; +} + void OlcConfigEntry::updateEntryDn() { } @@ -386,6 +404,16 @@ this->setStringValue("olcRootPW", rootpw); } +const std::string OlcDatabase::getSuffix() const +{ + return this->getStringValue("olcSuffix"); +} + +const std::string OlcDatabase::getType() const +{ + return this->m_type; +} + std::map<std::string, std::list<std::string> > OlcBdbDatabase::toMap() const { std::map<std::string, std::list<std::string> > resMap = @@ -585,8 +613,24 @@ } } -OlcBdbDatabase getDatabase(std::string &basedn) +OlcDatabaseList OlcConfig::getDatabases() { + OlcDatabaseList res; + try { + LDAPSearchResults *sr = m_lc->search( "cn=config", + LDAPConnection::SEARCH_ONE, "objectclass=olcDatabaseConfig" ); + LDAPEntry *dbEntry; + while ( dbEntry = sr->getNext() ) + { + std::cout << "Got Database Entry: " << dbEntry->getDN() << std::endl; + boost::shared_ptr<OlcDatabase> olce(OlcDatabase::createFromLdapEntry(*dbEntry)); + res.push_back(olce); + } + } catch (LDAPException e ) { + std::cout << e << std::endl; + throw; + } + return res; } OlcTlsSettings::OlcTlsSettings( const OlcGlobalConfig &ogc ) Modified: trunk/ldap-server/src/lib/backConfigTest.h URL: http://svn.opensuse.org/viewcvs/yast/trunk/ldap-server/src/lib/backConfigTest.h?rev=48601&r1=48600&r2=48601&view=diff ============================================================================== --- trunk/ldap-server/src/lib/backConfigTest.h (original) +++ trunk/ldap-server/src/lib/backConfigTest.h Fri Jun 27 15:57:20 2008 @@ -8,6 +8,7 @@ #include <map> #include <vector> #include <LDAPEntry.h> +#include <boost/shared_ptr.hpp> class OlcConfigEntry { @@ -35,6 +36,8 @@ void setIndex( int index ); void getEntryDn(); + int getIndex() const; + virtual std::map<std::string, std::list<std::string> > toMap() const; virtual std::string toLdif() const; @@ -53,12 +56,16 @@ OlcDatabase( const LDAPEntry &le ); OlcDatabase( const std::string& type ); + static bool isBdbDatabase( const LDAPEntry& le ); void setSuffix( const std::string &suffix); void setRootDn( const std::string &rootdn); void setRootPw( const std::string &rootpw); + const std::string getSuffix() const; + const std::string getType() const; + virtual std::map<std::string, std::list<std::string> > toMap() const; protected: @@ -114,12 +121,13 @@ OlcSchemaConfig(); }; +typedef std::list<boost::shared_ptr<OlcDatabase> > OlcDatabaseList; class OlcConfig { public: OlcConfig(LDAPConnection *lc=0 ); OlcGlobalConfig getGlobals(); void setGlobals( OlcGlobalConfig &olcg); - OlcBdbDatabase getDatabase(std::string &basedn); + OlcDatabaseList getDatabases(); private: LDAPConnection *m_lc; }; -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org
participants (1)
-
rhafer@svn.opensuse.org