[yast-commit] r48603 - in /trunk/ldap-server/src: LdapServer.pm agent/SlapdConfigAgent.cc agent/SlapdConfigAgent.h lib/backConfigTest.cpp lib/backConfigTest.h tree_structure.ycp
Author: rhafer Date: Fri Jun 27 15:57:30 2008 New Revision: 48603 URL: http://svn.opensuse.org/viewcvs/yast?rev=48603&view=rev Log: - reading Database is now done with .ldapserver.database.{index} - initial write support for databases Modified: trunk/ldap-server/src/LdapServer.pm 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 trunk/ldap-server/src/tree_structure.ycp Modified: trunk/ldap-server/src/LdapServer.pm URL: http://svn.opensuse.org/viewcvs/yast/trunk/ldap-server/src/LdapServer.pm?rev=48603&r1=48602&r2=48603&view=diff ============================================================================== --- trunk/ldap-server/src/LdapServer.pm (original) +++ trunk/ldap-server/src/LdapServer.pm Fri Jun 27 15:57:30 2008 @@ -123,95 +123,100 @@ my $self = shift; y2milestone("LdapServer::Write"); my $ret = 1; - my $progressItems = [ _("Writing Startup Configuration"), - _("Cleaning up config directory"), - _("Creating Configuration"), - _("Starting OpenLDAP Server")]; - Progress->New("Writing OpenLDAP Server Configuration", "", 4, $progressItems, $progressItems, ""); - - Progress->NextStage(); - - my $rc = SCR->Write('.sysconfig.openldap.OPENLDAP_CONFIG_BACKEND', 'ldap'); - if ( ! $rc ) - { - y2error("Error while switch to config backend"); - $self->SetError( _("Switch from slapd.conf to config backend failed.") ); - Progress->Finish(); - return 0; - } - $rc = SCR->Write('.sysconfig.openldap.OPENLDAP_START_LDAPI', 'yes'); - if ( ! $rc ) + if ( ! $usesBackConfig ) { - y2error("Error while enabling LDAPI listener"); - $self->SetError( _("Enabling thi LDAPI Protocol listener failed.") ); - Progress->Finish(); - return 0; - } - $rc = SCR->Read('.sysconfig.openldap.OPENLDAP_START_LDAPI'); - y2milestone(Data::Dumper->Dump([$rc])); + my $progressItems = [ _("Writing Startup Configuration"), + _("Cleaning up config directory"), + _("Creating Configuration"), + _("Starting OpenLDAP Server")]; + Progress->New("Writing OpenLDAP Server Configuration", "", 4, $progressItems, $progressItems, ""); - # FIXME: - # Explicit cache flush, see bnc#350581 for details - SCR->Write(".sysconfig.openldap", undef); - Progress->NextStage(); + Progress->NextStage(); - $rc = SCR->Execute('.target.bash', 'rm -rf /etc/openldap/slapd.d/cn=config*' ); - if ( $rc ) - { - y2error("Error while cleaning up to config directory"); - $self->SetError( _("Config Directory cleanup failed.") ); - Progress->Finish(); - return 0; - } + my $rc = SCR->Write('.sysconfig.openldap.OPENLDAP_CONFIG_BACKEND', 'ldap'); + if ( ! $rc ) + { + y2error("Error while switch to config backend"); + $self->SetError( _("Switch from slapd.conf to config backend failed.") ); + Progress->Finish(); + return 0; + } + $rc = SCR->Write('.sysconfig.openldap.OPENLDAP_START_LDAPI', 'yes'); + if ( ! $rc ) + { + y2error("Error while enabling LDAPI listener"); + $self->SetError( _("Enabling thi LDAPI Protocol listener failed.") ); + Progress->Finish(); + return 0; + } + $rc = SCR->Read('.sysconfig.openldap.OPENLDAP_START_LDAPI'); + y2milestone(Data::Dumper->Dump([$rc])); - Progress->NextStage(); - $rc = SCR->Execute('.target.bash_output', 'mktemp /tmp/slapd-conf-ldif.XXXXXX' ); - if ( $rc->{'exit'} == 0 ) - { - my $tmpfile = $rc->{'stdout'}; - chomp $tmpfile; - y2milestone("using tempfile: ".$tmpfile ); - my $ldif = SCR->Read('.ldapserver.configAsLdif' ); - y2milestone($ldif); - $rc = SCR->Write('.target.string', $tmpfile, $ldif ); + # FIXME: + # Explicit cache flush, see bnc#350581 for details + SCR->Write(".sysconfig.openldap", undef); + Progress->NextStage(); + + $rc = SCR->Execute('.target.bash', 'rm -rf /etc/openldap/slapd.d/cn=config*' ); if ( $rc ) { - $rc = SCR->Execute('.target.bash_output', - "/usr/sbin/slapadd -F /etc/openldap/slapd.d -b cn=config -l $tmpfile" ); - if ( $rc->{'exit'} ) + y2error("Error while cleaning up to config directory"); + $self->SetError( _("Config Directory cleanup failed.") ); + Progress->Finish(); + return 0; + } + + Progress->NextStage(); + $rc = SCR->Execute('.target.bash_output', 'mktemp /tmp/slapd-conf-ldif.XXXXXX' ); + if ( $rc->{'exit'} == 0 ) + { + my $tmpfile = $rc->{'stdout'}; + chomp $tmpfile; + y2milestone("using tempfile: ".$tmpfile ); + my $ldif = SCR->Read('.ldapserver.configAsLdif' ); + y2milestone($ldif); + $rc = SCR->Write('.target.string', $tmpfile, $ldif ); + if ( $rc ) + { + $rc = SCR->Execute('.target.bash_output', + "/usr/sbin/slapadd -F /etc/openldap/slapd.d -b cn=config -l $tmpfile" ); + if ( $rc->{'exit'} ) + { + y2error("Error during slapadd:" .$rc->{'stderr'}); + $ret = 0; + } + } + else { - y2error("Error during slapadd:" .$rc->{'stderr'}); + y2error("Error while write configuration to LDIF file"); $ret = 0; } + # cleanup + SCR->Execute('.target.bash', "rm -f $tmpfile" ); } - else + Progress->NextStage(); + + $rc = Service->Enable("ldap"); + if ( ! $rc ) { - y2error("Error while write configuration to LDIF file"); - $ret = 0; + y2error("Error while enabing the LDAP Service: ". Service->Error() ); + $self->SetError( _("Enabling the LDAP Service failed.") ); + Progress->Finish(); + return 0; + } + $rc = Service->Restart("ldap"); + if (! $rc ) + { + y2error("Error while starting the LDAP service"); + $self->SetError( _("Starting the LDAP service failed.") ); + Progress->Finish(); + return 0; } - # cleanup - SCR->Execute('.target.bash', "rm -f $tmpfile" ); - } - Progress->NextStage(); - $rc = Service->Enable("ldap"); - if ( ! $rc ) - { - y2error("Error while enabing the LDAP Service: ". Service->Error() ); - $self->SetError( _("Enabling the LDAP Service failed.") ); - Progress->Finish(); - return 0; - } - $rc = Service->Restart("ldap"); - if (! $rc ) - { - y2error("Error while starting the LDAP service"); - $self->SetError( _("Starting the LDAP service failed.") ); Progress->Finish(); - return 0; + } else { + SCR->Execute('.ldapserver.commitChanges' ); } - - Progress->Finish(); sleep(1); return $ret; } @@ -503,12 +508,24 @@ } BEGIN { $TYPEINFO {GetDatabase} = ["function", [ "map" , "string", "string"], "integer" ]; } -sub GetDatabase{ +sub GetDatabase +{ my ($self, $index) = @_; y2milestone("GetDatabase ".$index); - my $rc = SCR->Read(".ldapserver.database", YaST::YCP::Integer($index) ); + my $rc = SCR->Read(".ldapserver.database.{".$index."}" ); y2milestone( "Database: ".Data::Dumper->Dump([$rc]) ); return $rc; } + +BEGIN { $TYPEINFO {UpdateDatabase} = ["function", "boolean", "integer", [ "map" , "string", "string"] ]; } +sub UpdateDatabase +{ + my ($self, $index, $changes) = @_; + my $rc = SCR->Write(".ldapserver.database.{".$index."}", $changes); + y2milestone( "Database: ".Data::Dumper->Dump([$rc]) ); + return $rc; + +} + 1; # EOF Modified: trunk/ldap-server/src/agent/SlapdConfigAgent.cc URL: http://svn.opensuse.org/viewcvs/yast/trunk/ldap-server/src/agent/SlapdConfigAgent.cc?rev=48603&r1=48602&r2=48603&view=diff ============================================================================== --- trunk/ldap-server/src/agent/SlapdConfigAgent.cc (original) +++ trunk/ldap-server/src/agent/SlapdConfigAgent.cc Fri Jun 27 15:57:30 2008 @@ -96,6 +96,9 @@ } else if ( path->component_str(0) == "global" ) { y2milestone("Global Write"); return WriteGlobal(path->at(1), arg, arg2); + } else if ( path->component_str(0) == "database" ) { + y2milestone("Database Write"); + return WriteDatabase(path->at(1), arg, arg2); } else { return YCPNull(); } @@ -190,6 +193,14 @@ } } } + else if ( path->component_str(0) == "commitChanges" ) + { + OlcDatabaseList::const_iterator i; + for ( i = databases.begin(); i != databases.end() ; i++ ) + { + olc.updateEntry(**i); + } + } return YCPBoolean(true); } @@ -278,12 +289,28 @@ { y2milestone("Path %s Length %ld ", path->toString().c_str(), path->length()); - int index = arg->asInteger()->value(); - y2milestone("Database to read: %d", index); + std::string dbIndexStr = path->component_str(0); + int dbIndex = -2; + if ( dbIndexStr[0] == '{' ) + { + std::string::size_type pos = dbIndexStr.find('}'); + std::istringstream indexstr(dbIndexStr.substr(1, pos-1)); + indexstr >> dbIndex; + } else { + y2error("Database Index expected, got: %s", dbIndexStr.c_str() ); + return YCPNull(); + } + if ( dbIndex < -1 ) + { + y2error("Invalid database index: %d", dbIndex ); + return YCPNull(); + } + + y2milestone("Database to read: %d", dbIndex); OlcDatabaseList::const_iterator i; for ( i = databases.begin(); i != databases.end() ; i++ ) { - if ( (*i)->getIndex() == index ) + if ( (*i)->getIndex() == dbIndex ) { YCPMap resMap; resMap.add( YCPString("suffix"), @@ -324,6 +351,46 @@ return YCPBoolean(false); } +YCPBoolean SlapdConfigAgent::WriteDatabase( const YCPPath &path, + const YCPValue &arg, + const YCPValue &arg2) +{ + y2milestone("Path %s Length %ld ", path->toString().c_str(), + path->length()); + std::string dbIndexStr = path->component_str(0); + YCPMap changesMap= arg->asMap(); + int dbIndex = -2; + if ( dbIndexStr[0] == '{' ) + { + std::string::size_type pos = dbIndexStr.find('}'); + std::istringstream indexstr(dbIndexStr.substr(1, pos-1)); + indexstr >> dbIndex; + } else { + y2error("Database Index expected, got: %s", dbIndexStr.c_str() ); + return YCPNull(); + } + if ( dbIndex < -1 ) + { + y2error("Invalid database index: %d", dbIndex ); + return YCPNull(); + } + + y2milestone("Database to write: %d", dbIndex); + OlcDatabaseList::const_iterator i; + for ( i = databases.begin(); i != databases.end() ; i++ ) + { + if ( (*i)->getIndex() == dbIndex ) + { + YCPValue val = changesMap.value( YCPString("rootdn") ); + if ( val->isString() ) + { + (*i)->setStringValue( "olcRootDn", val->asString()->value_cstr() ); + } + } + } + return YCPBoolean(false); +} + YCPString SlapdConfigAgent::ConfigToLdif() const { y2milestone("ConfigToLdif"); Modified: trunk/ldap-server/src/agent/SlapdConfigAgent.h URL: http://svn.opensuse.org/viewcvs/yast/trunk/ldap-server/src/agent/SlapdConfigAgent.h?rev=48603&r1=48602&r2=48603&view=diff ============================================================================== --- trunk/ldap-server/src/agent/SlapdConfigAgent.h (original) +++ trunk/ldap-server/src/agent/SlapdConfigAgent.h Fri Jun 27 15:57:30 2008 @@ -49,6 +49,9 @@ YCPBoolean WriteGlobal( const YCPPath &path, const YCPValue &arg = YCPNull(), const YCPValue &opt = YCPNull()); + YCPBoolean WriteDatabase( const YCPPath &path, + const YCPValue &arg = YCPNull(), + const YCPValue &opt = YCPNull()); YCPString ConfigToLdif() const; private: Modified: trunk/ldap-server/src/lib/backConfigTest.cpp URL: http://svn.opensuse.org/viewcvs/yast/trunk/ldap-server/src/lib/backConfigTest.cpp?rev=48603&r1=48602&r2=48603&view=diff ============================================================================== --- trunk/ldap-server/src/lib/backConfigTest.cpp (original) +++ trunk/ldap-server/src/lib/backConfigTest.cpp Fri Jun 27 15:57:30 2008 @@ -501,7 +501,7 @@ return ldifStream.str(); } -LDAPModList OlcConfigEntry::entryDifftoMod() { +LDAPModList OlcConfigEntry::entryDifftoMod() const { LDAPAttributeList::const_iterator i = m_dbEntry.getAttributes()->begin(); LDAPModList modifications; for(; i != m_dbEntry.getAttributes()->end(); i++ ) @@ -613,6 +613,17 @@ } } +void OlcConfig::updateEntry( const OlcConfigEntry &oce ) +{ + try { + LDAPModList ml = oce.entryDifftoMod(); + m_lc->modify( oce.getDn(), &ml ); + } catch (LDAPException e) { + std::cout << e << std::endl; + throw; + } +} + OlcDatabaseList OlcConfig::getDatabases() { OlcDatabaseList res; Modified: trunk/ldap-server/src/lib/backConfigTest.h URL: http://svn.opensuse.org/viewcvs/yast/trunk/ldap-server/src/lib/backConfigTest.h?rev=48603&r1=48602&r2=48603&view=diff ============================================================================== --- trunk/ldap-server/src/lib/backConfigTest.h (original) +++ trunk/ldap-server/src/lib/backConfigTest.h Fri Jun 27 15:57:30 2008 @@ -21,10 +21,10 @@ inline OlcConfigEntry() : m_dbEntry(), m_dbEntryChanged() {} inline OlcConfigEntry(const LDAPEntry& le) : m_dbEntry(le), m_dbEntryChanged(le) {} - inline std::string getDn() { + inline std::string getDn() const { return m_dbEntry.getDN(); } - LDAPModList entryDifftoMod(); + LDAPModList entryDifftoMod() const; StringList getStringValues(const std::string &type) const; void setStringValues(const std::string &type, const StringList &values); @@ -127,6 +127,7 @@ OlcConfig(LDAPConnection *lc=0 ); OlcGlobalConfig getGlobals(); void setGlobals( OlcGlobalConfig &olcg); + void updateEntry( const OlcConfigEntry &oce ); OlcDatabaseList getDatabases(); private: LDAPConnection *m_lc; Modified: trunk/ldap-server/src/tree_structure.ycp URL: http://svn.opensuse.org/viewcvs/yast/trunk/ldap-server/src/tree_structure.ycp?rev=48603&r1=48602&r2=48603&view=diff ============================================================================== --- trunk/ldap-server/src/tree_structure.ycp (original) +++ trunk/ldap-server/src/tree_structure.ycp Fri Jun 27 15:57:30 2008 @@ -747,7 +747,16 @@ map<string,string> db = $[]; db["rootdn"] = (string)UI::QueryWidget( `te_rootdn, `Value ); + if( db["rootdn"]:"" != "" && (boolean)UI::QueryWidget( `cb_append_basedn, `Value ) ) + { + string suffix = (string)widget_map[current_tree_item,"name"]:""; + db["rootdn"] = db["rootdn"]:"" + "," + suffix; + } + y2milestone( "updated Database: %1", db ); + + boolean res = LdapServer::UpdateDatabase( index, db); + // boolean is_new_db = (boolean)widget_map[current_tree_item,"new_db"]:nil; // y2debug( "widget_map entry for item '%1': '%2'", suffix, widget_map[current_tree_item]:nil ); // if( is_new_db == nil ) -- 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