[yast-commit] r64412 - in /branches/SuSE-Code-11-SP2-Branch/ldap-server/src/agent: SlapdConfigAgent.cc SlapdConfigAgent.h
Author: rhafer Date: Thu Jun 16 13:38:19 2011 New Revision: 64412 URL: http://svn.opensuse.org/viewcvs/yast?rev=64412&view=rev Log: helper methods for converting YCPMap to OlcSyncRepl and for allocating an unassinged RID. Will be used to refactor the WriteDatabase() a bit Modified: branches/SuSE-Code-11-SP2-Branch/ldap-server/src/agent/SlapdConfigAgent.cc branches/SuSE-Code-11-SP2-Branch/ldap-server/src/agent/SlapdConfigAgent.h Modified: branches/SuSE-Code-11-SP2-Branch/ldap-server/src/agent/SlapdConfigAgent.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/ldap-server/src/agent/SlapdConfigAgent.cc?rev=64412&r1=64411&r2=64412&view=diff ============================================================================== --- branches/SuSE-Code-11-SP2-Branch/ldap-server/src/agent/SlapdConfigAgent.cc (original) +++ branches/SuSE-Code-11-SP2-Branch/ldap-server/src/agent/SlapdConfigAgent.cc Thu Jun 16 13:38:19 2011 @@ -2357,3 +2357,118 @@ } } } + +class CompareRid +{ + private: + int theRid; + + public: + CompareRid( int val ) : theRid(val) {} + + bool operator() ( const boost::shared_ptr<OlcSyncRepl> sr ) const + { + return theRid == sr->getRid(); + } +}; + +int SlapdConfigAgent::getNextRid() const +{ + OlcDatabaseList::const_iterator i; + int rid; + for ( rid = 1; rid < 999; rid++ ) + { + bool isFree = true; + + for ( i = databases.begin(); i != databases.end() ; i++ ) + { + OlcSyncReplList::const_iterator found; + OlcSyncReplList srl = (*i)->getSyncRepl(); + found = find_if( srl.begin(), srl.end(), CompareRid(rid) ); + if ( found != srl.end() ) + { + isFree = false; + break; + } + } + if ( isFree ) + { + return rid; + } + } + return 0; +} + +bool SlapdConfigAgent::ycpMap2SyncRepl( const YCPMap &srMap, boost::shared_ptr<OlcSyncRepl> sr ) +{ + bool ret = true; + YCPMap providerMap = srMap->value(YCPString("provider"))->asMap(); + std::string protocol( providerMap->value(YCPString("protocol"))->asString()->value_cstr() ); + std::string target( providerMap->value(YCPString("target"))->asString()->value_cstr() ); + int port = providerMap->value(YCPString("port"))->asInteger()->value(); + std::string type( srMap->value(YCPString("type"))->asString()->value_cstr() ); + std::string basedn( srMap->value(YCPString("basedn"))->asString()->value_cstr() ); + std::string binddn( srMap->value(YCPString("binddn"))->asString()->value_cstr() ); + std::string cred( srMap->value(YCPString("credentials"))->asString()->value_cstr() ); + bool starttls = false; + if (! srMap->value(YCPString("starttls")).isNull() ) + { + starttls = srMap->value(YCPString("starttls"))->asBoolean()->value(); + } + + LDAPUrl prvuri; + prvuri.setScheme(protocol); + prvuri.setHost(target); + if ( ( protocol == "ldap" && port != 389 ) || ( protocol == "ldaps" && port != 636 ) ) + { + prvuri.setPort(port); + } + + sr->setType( type ); + sr->setProvider( prvuri ); + sr->setSearchBase( basedn ); + sr->setBindDn( binddn ); + sr->setCredentials( cred ); + // default retry (every 120 seconds) + sr->setRetryString( "120 +" ); + sr->setTlsReqCert("demand"); + + if ( starttls ) + { + sr->setStartTls( OlcSyncRepl::StartTlsCritical ); + } + else + { + sr->setStartTls( OlcSyncRepl::StartTlsNo ); + } + + if ( type == "refreshOnly" ) + { + if ( srMap->value(YCPString("interval")).isNull() ) + { + lastError->add(YCPString("summary"), YCPString("Writing SyncRepl config failed") ); + lastError->add(YCPString("description"), YCPString("\"RefreshOnly needs Interval\"") ); + ret = false; + } + else + { + YCPMap ivMap = srMap->value(YCPString("interval"))->asMap(); + int days = ivMap->value(YCPString("days"))->asInteger()->value(); + int hours = ivMap->value(YCPString("hours"))->asInteger()->value(); + int mins = ivMap->value(YCPString("mins"))->asInteger()->value(); + int secs = ivMap->value(YCPString("secs"))->asInteger()->value(); + + if ( days == 0 && hours == 0 && mins == 0 && secs == 0 ) + { + lastError->add(YCPString("summary"), YCPString("Writing SyncRepl config failed") ); + lastError->add(YCPString("description"), YCPString("\"Syncrepl Interval is 00:00:00\"") ); + ret = false; + } + else + { + sr->setInterval( days, hours, mins, secs ); + } + } + } + return ret; +} Modified: branches/SuSE-Code-11-SP2-Branch/ldap-server/src/agent/SlapdConfigAgent.h URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/ldap-server/src/agent/SlapdConfigAgent.h?rev=64412&r1=64411&r2=64412&view=diff ============================================================================== --- branches/SuSE-Code-11-SP2-Branch/ldap-server/src/agent/SlapdConfigAgent.h (original) +++ branches/SuSE-Code-11-SP2-Branch/ldap-server/src/agent/SlapdConfigAgent.h Thu Jun 16 13:38:19 2011 @@ -77,6 +77,8 @@ void syncCheck( LDAPConnection &c, const std::string &basedn ); void assignServerId( const std::string &uri ); + int getNextRid() const; + bool ycpMap2SyncRepl( const YCPMap &srMap, boost::shared_ptr<OlcSyncRepl> sr ); private: YCPMap lastError; -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org
participants (1)
-
rhafer@svn2.opensuse.org