Author: rhafer Date: Fri Jun 10 10:28:45 2011 New Revision: 64307 URL: http://svn.opensuse.org/viewcvs/yast?rev=64307&view=rev Log: Reworked slave cn=config initialization The config database of a syncrepl slave is now initialized with a complete LDIF dump from the master database. This simpler and less error prone as it avoids manually touching the the entry CSN Attributes. Modified: branches/SuSE-Code-11-SP2-Branch/ldap-server/src/LdapServer.pm 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/LdapServer.pm URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/ldap-server/src/LdapServer.pm?rev=64307&r1=64306&r2=64307&view=diff ============================================================================== --- branches/SuSE-Code-11-SP2-Branch/ldap-server/src/LdapServer.pm (original) +++ branches/SuSE-Code-11-SP2-Branch/ldap-server/src/LdapServer.pm Fri Jun 10 10:28:45 2011 @@ -197,6 +197,7 @@ my $syncreplaccount = {}; my $syncreplbaseconfig = {}; +my $masterldif = ""; ## # Read all ldap-server settings @@ -735,12 +736,15 @@ my $tmpfile = $rc->{'stdout'}; chomp $tmpfile; y2milestone("using tempfile: ".$tmpfile ); - my $overrideCsn = {}; + my $ldif = ""; if ( $setupSyncreplSlave ) { - $overrideCsn = { resetCsn => 0 }; + $ldif = $masterldif; + } + else + { + $ldif = SCR->Read('.ldapserver.configAsLdif'); } - my $ldif = SCR->Read('.ldapserver.configAsLdif', $overrideCsn ); y2debug($ldif); if ( ! $ldif ) { @@ -1710,15 +1714,9 @@ my $frontenddb = { 'type' => 'frontend' }; $self->InitGlobals(); - - if ( $self->ReadSetupSlave() ) - { - SCR->Execute('.ldapserver.initDatabases', [ $frontenddb, $cfgdatabase ] ); - SCR->Write(".ldapserver.database.{0}.syncrepl", $syncreplbaseconfig ); - my $ldif = SCR->Read('.ldapserver.configAsLdif' ); - y2debug($ldif); - } - else #master or standalone + + if (! $self->ReadSetupSlave() ) # Slave setup was already initialized by dumping Master + # Database to $masterldif, nothing to do here. { SCR->Execute('.ldapserver.initSchema' ); my $rc = SCR->Write(".ldapserver.schema.addFromLdif", "/etc/openldap/schema/core.ldif" ); @@ -3087,7 +3085,9 @@ } } } + y2milestone("Updating remote configuration"); SCR->Execute(".ldapserver.commitChanges" ); + $masterldif = SCR->Execute(".ldapserver.dumpConfDb" ); SCR->Execute(".ldapserver.reset" ); $globals_initialized = 0; 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=64307&r1=64306&r2=64307&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 Fri Jun 10 10:28:45 2011 @@ -113,14 +113,7 @@ } else if ( path->component_str(0) == "configAsLdif" ) { - if ( arg.isNull() || !arg->asMap()->size()) - { - return ConfigToLdif(); - } - else - { - return ConfigToLdif(true); - } + return ConfigToLdif(); } } catch ( std::runtime_error e ) { y2error("Error during Read: %s", e.what() ); @@ -409,6 +402,37 @@ return YCPBoolean(false); } } + else if ( path->component_str(0) == "dumpConfDb" ) + { + try { + StringList attrs; + attrs.add("*"); + attrs.add("+"); + LDAPSearchResults *sr = m_lc->search( "cn=config", LDAPConnection::SEARCH_SUB, + "objectclass=*", attrs ); + std::ostringstream ldifStream; + LdifWriter ldif(ldifStream); + while ( LDAPEntry *e = sr->getNext() ) + { + ldif.writeRecord( *e ); + } + return YCPString( ldifStream.str() ); + } catch ( LDAPException e ) { + std::string errstring = "Error while reading remote Database"; + std::string details = e.getResultMsg() + ": " + e.getServerMsg(); + + lastError->add(YCPString("summary"), + YCPString(errstring) ); + lastError->add(YCPString("description"), YCPString( details ) ); + return YCPBoolean(false); + } catch ( std::runtime_error e ) { + lastError->add(YCPString("summary"), + YCPString("Error while trying to read remote Database") ); + lastError->add(YCPString("description"), + YCPString(std::string( e.what() ) ) ); + return YCPBoolean(false); + } + } else if ( path->component_str(0) == "waitForBackgroundTasks" ) { olc.waitForBackgroundTasks(); @@ -2092,7 +2116,7 @@ return YCPBoolean(false); } -YCPString SlapdConfigAgent::ConfigToLdif( bool resetCsn ) const +YCPString SlapdConfigAgent::ConfigToLdif() const { y2milestone("ConfigToLdif"); std::ostringstream ldif; @@ -2100,34 +2124,19 @@ { throw std::runtime_error("Configuration not initialized. Can't create LDIF dump." ); } - if ( resetCsn ) - { - globals->setStringValue("entryCSN", "19700101000000.000000Z#000000#000#000000"); - // schemaBase entryCSN won't be resetted as it cause trouble during replication - // of hardcoded schema values - } ldif << globals->toLdif() << std::endl; if ( schemaBase ) { - if ( resetCsn ) - schemaBase->setStringValue("entryCSN", "19700101000000.000000Z#000000#000#000000"); - ldif << schemaBase->toLdif() << std::endl; OlcSchemaList::const_iterator j; for ( j = schema.begin(); j != schema.end() ; j++ ) { - if ( resetCsn ) - (*j)->setStringValue("entryCSN", "19700101000000.000000Z#000000#000#000000"); - ldif << (*j)->toLdif() << std::endl; } } OlcDatabaseList::const_iterator i = databases.begin(); for ( ; i != databases.end(); i++ ) { - if ( resetCsn ) - (*i)->setStringValue("entryCSN", "19700101000000.000000Z#000000#000#000000"); - ldif << (*i)->toLdif() << std::endl; OlcOverlayList overlays = (*i)->getOverlays(); OlcOverlayList::iterator k; 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=64307&r1=64306&r2=64307&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 Fri Jun 10 10:28:45 2011 @@ -67,7 +67,7 @@ YCPBoolean WriteSchema( const YCPPath &path, const YCPValue &arg = YCPNull(), const YCPValue &opt = YCPNull()); - YCPString ConfigToLdif( bool resetCsn = false ) const; + YCPString ConfigToLdif() const; bool remoteBindCheck( const YCPValue &arg ); bool remoteSyncCheck( const YCPValue &arg ); void startTlsCheck( LDAPConnection &c); -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org