[yast-commit] r48615 - 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:58:22 2008 New Revision: 48615 URL: http://svn.opensuse.org/viewcvs/yast?rev=48615&view=rev Log: Support for adding new Schema entries. Remove has yet to come 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=48615&r1=48614&r2=48615&view=diff ============================================================================== --- trunk/ldap-server/src/LdapServer.pm (original) +++ trunk/ldap-server/src/LdapServer.pm Fri Jun 27 15:58:22 2008 @@ -566,6 +566,16 @@ return $rc; } +BEGIN { $TYPEINFO {AddLdifToSchemaList} = ["function", "boolean", "string" ]; } +sub AddLdifToSchemaList +{ + my ($self, $file) = @_; + + my $rc = SCR->Write(".ldapserver.schema.addFromLdif", $file); + + return 1; +} + BEGIN { $TYPEINFO {UpdateDatabase} = ["function", "boolean", "integer", [ "map" , "string", "string"] ]; } sub UpdateDatabase { Modified: trunk/ldap-server/src/agent/SlapdConfigAgent.cc URL: http://svn.opensuse.org/viewcvs/yast/trunk/ldap-server/src/agent/SlapdConfigAgent.cc?rev=48615&r1=48614&r2=48615&view=diff ============================================================================== --- trunk/ldap-server/src/agent/SlapdConfigAgent.cc (original) +++ trunk/ldap-server/src/agent/SlapdConfigAgent.cc Fri Jun 27 15:58:22 2008 @@ -6,6 +6,7 @@ #include <LDAPEntry.h> #include <SaslInteraction.h> #include <sstream> +#include <fstream> #define DEFAULT_PORT 389 #define ANSWER 42 @@ -104,6 +105,9 @@ } else if ( path->component_str(0) == "database" ) { y2milestone("Database Write"); return WriteDatabase(path->at(1), arg, arg2); + } else if ( path->component_str(0) == "schema" ) { + y2milestone("Schema Write"); + return WriteSchema(path->at(1), arg, arg2); } else { return YCPNull(); } @@ -208,6 +212,11 @@ { olc.updateEntry(**i); } + OlcSchemaList::const_iterator j; + for ( j = schema.begin(); j != schema.end() ; j++ ) + { + olc.updateEntry(**j); + } } return YCPBoolean(true); } @@ -372,20 +381,19 @@ { y2milestone("Path %s Length %ld ", path->toString().c_str(), path->length()); - - OlcSchemaList schemaList = olc.getSchemaNames(); -// if ( databases.size() == 0 ) -// { -// databases = olc.getDatabases(); -// } + if ( schema.size() == 0 ) + { + schema = olc.getSchemaNames(); + } OlcSchemaList::const_iterator i; - YCPList schema; - for (i = schemaList.begin(); i != schemaList.end(); i++ ) + YCPList resultList; + for (i = schema.begin(); i != schema.end(); i++ ) { - schema.add( YCPString( (*i)->getName() ) ); + resultList.add( YCPString( (*i)->getName() ) ); } - return schema; + return resultList; } + YCPBoolean SlapdConfigAgent::WriteGlobal( const YCPPath &path, const YCPValue &arg, const YCPValue &arg2) @@ -524,6 +532,31 @@ return YCPBoolean(false); } +YCPBoolean SlapdConfigAgent::WriteSchema( const YCPPath &path, + const YCPValue &arg, + const YCPValue &arg2) +{ + y2milestone("Path %s Length %ld ", path->toString().c_str(), + path->length()); + + y2milestone("WriteSchema"); + std::string subpath = path->component_str(0); + if ( subpath == "addFromLdif" ) + { + std::string filename = arg->asString()->value_cstr(); + y2milestone("adding Ldif File: %s", filename.c_str()); + std::ifstream ldifFile(filename.c_str()); + LdifReader ldif(ldifFile); + if ( ldif.readNextRecord() ) + { + LDAPEntry entry, oldEntry; + entry = ldif.getEntryRecord(); + schema.push_back( boost::shared_ptr<OlcSchemaConfig>(new OlcSchemaConfig(oldEntry, entry)) ); + } + } + 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=48615&r1=48614&r2=48615&view=diff ============================================================================== --- trunk/ldap-server/src/agent/SlapdConfigAgent.h (original) +++ trunk/ldap-server/src/agent/SlapdConfigAgent.h Fri Jun 27 15:58:22 2008 @@ -57,11 +57,15 @@ YCPBoolean WriteDatabase( const YCPPath &path, const YCPValue &arg = YCPNull(), const YCPValue &opt = YCPNull()); + YCPBoolean WriteSchema( const YCPPath &path, + const YCPValue &arg = YCPNull(), + const YCPValue &opt = YCPNull()); YCPString ConfigToLdif() const; private: OlcConfig olc; OlcDatabaseList databases; + OlcSchemaList schema; 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=48615&r1=48614&r2=48615&view=diff ============================================================================== --- trunk/ldap-server/src/lib/backConfigTest.cpp (original) +++ trunk/ldap-server/src/lib/backConfigTest.cpp Fri Jun 27 15:58:22 2008 @@ -269,6 +269,21 @@ entryIndex = 0; } } +OlcSchemaConfig::OlcSchemaConfig(const LDAPEntry &e1, const LDAPEntry &e2) : OlcConfigEntry(e1, e2) +{ + std::cout << "OlcSchemaConfig::OlcSchemaConfig(const LDAPEntry &e) : OlcConfigEntry(e)" << std::endl; + std::string name(this->getStringValue("cn")); + if ( name[0] == '{' ) + { + std::string::size_type pos = name.find('}'); + std::istringstream indexstr(name.substr(1, pos-1)); + indexstr >> entryIndex; + m_name = name.substr( pos+1, std::string::npos ); + } else { + m_name = name; + entryIndex = 0; + } +} const std::string& OlcSchemaConfig::getName() const { @@ -566,9 +581,16 @@ return ldifStream.str(); } +bool OlcConfigEntry::isNewEntry() const +{ + return ( this->getDn().empty() ); +} + LDAPModList OlcConfigEntry::entryDifftoMod() const { LDAPAttributeList::const_iterator i = m_dbEntry.getAttributes()->begin(); LDAPModList modifications; + std::cout << "Old Entry DN: " << m_dbEntry.getDN() << std::endl; + std::cout << "New Entry DN: " << m_dbEntryChanged.getDN() << std::endl; for(; i != m_dbEntry.getAttributes()->end(); i++ ) { std::cout << i->getName() << std::endl; @@ -698,11 +720,16 @@ void OlcConfig::updateEntry( const OlcConfigEntry &oce ) { try { - LDAPModList ml = oce.entryDifftoMod(); - if ( ! ml.empty() ) { - m_lc->modify( oce.getDn(), &ml ); + if ( oce.isNewEntry () ) + { + m_lc->add(&oce.getChangedEntry()); } else { - std::cout << oce.getDn() << ": no changes" << std::endl; + LDAPModList ml = oce.entryDifftoMod(); + if ( ! ml.empty() ) { + m_lc->modify( oce.getDn(), &ml ); + } else { + std::cout << oce.getDn() << ": no changes" << std::endl; + } } } catch (LDAPException e) { std::cout << e << std::endl; Modified: trunk/ldap-server/src/lib/backConfigTest.h URL: http://svn.opensuse.org/viewcvs/yast/trunk/ldap-server/src/lib/backConfigTest.h?rev=48615&r1=48614&r2=48615&view=diff ============================================================================== --- trunk/ldap-server/src/lib/backConfigTest.h (original) +++ trunk/ldap-server/src/lib/backConfigTest.h Fri Jun 27 15:58:22 2008 @@ -21,9 +21,15 @@ inline OlcConfigEntry() : m_dbEntry(), m_dbEntryChanged() {} inline OlcConfigEntry(const LDAPEntry& le) : m_dbEntry(le), m_dbEntryChanged(le) {} + inline OlcConfigEntry(const LDAPEntry& le, const LDAPEntry& le1) : m_dbEntry(le), m_dbEntryChanged(le1) {} inline std::string getDn() const { return m_dbEntry.getDN(); } + inline const LDAPEntry& getChangedEntry() const { + return m_dbEntryChanged; + } + bool isNewEntry() const; + LDAPModList entryDifftoMod() const; StringList getStringValues(const std::string &type) const; @@ -126,6 +132,7 @@ public: OlcSchemaConfig(); OlcSchemaConfig(const LDAPEntry &e); + OlcSchemaConfig(const LDAPEntry &e1, const LDAPEntry &e2); const std::string& getName() const; private: Modified: trunk/ldap-server/src/tree_structure.ycp URL: http://svn.opensuse.org/viewcvs/yast/trunk/ldap-server/src/tree_structure.ycp?rev=48615&r1=48614&r2=48615&view=diff ============================================================================== --- trunk/ldap-server/src/tree_structure.ycp (original) +++ trunk/ldap-server/src/tree_structure.ycp Fri Jun 27 15:58:22 2008 @@ -141,7 +141,7 @@ { //add a new file to the list /* file dialog heading */ - string new_item = UI::AskForExistingFile( "/etc/openldap/schema/", "*.schema *", _("Select New Schema File") ); + string new_item = UI::AskForExistingFile( "/etc/openldap/schema/", "*.ldif *", _("Select New Schema File") ); if( new_item == nil ) return true; @@ -152,7 +152,7 @@ return false; } -// LdapServer::AddItemToSchemaList(new_item); + LdapServer::AddLdifToSchemaList(new_item); list<string> inclist = LdapServer::GetSchemaList(); update_schemalist( inclist, new_item ); -- 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