Author: rhafer
Date: Fri Jul 4 15:17:21 2008
New Revision: 48892
URL: http://svn.opensuse.org/viewcvs/yast?rev=48892&view=rev
Log:
revived Database add support
Modified:
trunk/ldap-server/src/LdapServer.pm
trunk/ldap-server/src/Makefile.am
trunk/ldap-server/src/agent/SlapdConfigAgent.cc
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=48892&r1=48891&r2=48892&view=diff
==============================================================================
--- trunk/ldap-server/src/LdapServer.pm (original)
+++ trunk/ldap-server/src/LdapServer.pm Fri Jul 4 15:17:21 2008
@@ -82,7 +82,6 @@
}
);
-my @databases = ();
my @schema = ();
my @globalAcl = (
@@ -161,8 +160,6 @@
y2milestone("LDAP server is running. How should I connect?");
SCR->Execute('.ldapserver.init' );
my $rc = SCR->Read('.ldapserver.databases');
- y2milestone("Databases: ". Data::Dumper->Dump([$rc]));
- @databases = @{$rc};
}
else
{
@@ -835,7 +832,6 @@
}
SCR->Execute('.ldapserver.initDatabases', [ $frontenddb, $cfgdatabase, $database ] );
- $rc = SCR->Read('.ldapserver.databases');
if ( $dbDefaults{'defaultIndex'} == 1 )
{
foreach my $idx ( @defaultIndexes )
@@ -843,8 +839,6 @@
$self->ChangeDatabaseIndex(1, $idx );
}
}
- y2milestone("Databases: ". Data::Dumper->Dump([$rc]));
- @databases = @{$rc};
push @added_databases, { suffix => $dbDefaults{'basedn'},
rootdn => $dbDefaults{'rootdn'},
rootpw => $dbDefaults{'rootpw_clear'} };
@@ -858,7 +852,8 @@
y2milestone("GetDatabaseList");
my $self = shift;
my $ret = ();
- foreach my $db ( @databases )
+ my $rc = SCR->Read('.ldapserver.databases');
+ foreach my $db ( @{$rc} )
{
my $tmp = { 'type' => $db->{'type'},
'suffix' => $db->{'suffix'},
@@ -994,6 +989,45 @@
return $rc;
}
+
+BEGIN { $TYPEINFO {AddDatabase} = ["function", "boolean", "integer", [ "map" , "string", "string"], "boolean" ]; }
+sub AddDatabase
+{
+ my ($self, $index, $db, $createDir) = @_;
+ y2milestone("AddDatabase: ".Data::Dumper->Dump([$db]) );
+ if ( $createDir )
+ {
+ my $ret = SCR->Execute(".target.bash", "mkdir -m 0700 -p ".$db->{directory});
+ if( ( $ret ) && ( ! defined SCR->Read(".target.dir", $db->{directory}) ) ) {
+ $self->SetError(_("Could not create directory."), "");
+ return 0;
+ }
+ my $owner = SCR->Read('.sysconfig.openldap.OPENLDAP_USER');
+ my $group = SCR->Read('.sysconfig.openldap.OPENLDAP_GROUP');
+ $ret = SCR->Execute(".target.bash", "chown ".$owner.":".$group." ".$db->{directory});
+ if ( $ret ) {
+ $self->SetError(_("Could adjust ownership of database directory."), "");
+ return 0;
+ }
+ }
+ my $rc;
+ if ( $index > 0 )
+ {
+ $rc = SCR->Write(".ldapserver.database.new.{".$index."}", $db);
+ }
+ else
+ {
+ $rc = SCR->Write(".ldapserver.database.new.", $db);
+ }
+ if(! $rc ) {
+ my $err = SCR->Error(".ldapserver");
+ y2error("Adding Database failed: ".$err->{'summary'}." ".$err->{'description'});
+ $self->SetError( $err->{'summary'}, $err->{'description'} );
+ return 0;
+ }
+ return 1;
+}
+
BEGIN { $TYPEINFO {UpdateDatabase} = ["function", "boolean", "integer", [ "map" , "string", "string"] ]; }
sub UpdateDatabase
{
Modified: trunk/ldap-server/src/Makefile.am
URL: http://svn.opensuse.org/viewcvs/yast/trunk/ldap-server/src/Makefile.am?rev=48892&r1=48891&r2=48892&view=diff
==============================================================================
--- trunk/ldap-server/src/Makefile.am (original)
+++ trunk/ldap-server/src/Makefile.am Fri Jul 4 15:17:21 2008
@@ -21,7 +21,8 @@
ldap-server.desktop
module_DATA = \
- LdapServer.pm
+ LdapServer.pm \
+ LdapDatabase.ycp
EXTRA_DIST = $(client_DATA) $(ynclude_DATA) $(module_DATA) $(desktop_DATA)
Modified: trunk/ldap-server/src/agent/SlapdConfigAgent.cc
URL: http://svn.opensuse.org/viewcvs/yast/trunk/ldap-server/src/agent/SlapdConfigAgent.cc?rev=48892&r1=48891&r2=48892&view=diff
==============================================================================
--- trunk/ldap-server/src/agent/SlapdConfigAgent.cc (original)
+++ trunk/ldap-server/src/agent/SlapdConfigAgent.cc Fri Jul 4 15:17:21 2008
@@ -115,9 +115,7 @@
y2milestone("Path %s Length %ld ", path->toString().c_str(),
path->length());
- if ( path->length() < 2 ) {
- return YCPNull();
- } else if ( path->component_str(0) == "global" ) {
+ if ( path->component_str(0) == "global" ) {
y2milestone("Global Write");
return WriteGlobal(path->at(1), arg, arg2);
} else if ( path->component_str(0) == "database" ) {
@@ -127,6 +125,11 @@
y2milestone("Schema Write");
return WriteSchema(path->at(1), arg, arg2);
} else {
+ lastError->add(YCPString("summary"), YCPString("Write Failed") );
+ std::string msg = "Unsupported SCR path: `.ldapserver.";
+ msg += path->toString().c_str();
+ msg += "`";
+ lastError->add(YCPString("description"), YCPString(msg) );
return YCPNull();
}
}
@@ -757,152 +760,258 @@
{
y2milestone("Path %s Length %ld ", path->toString().c_str(),
path->length());
- std::string dbIndexStr = path->component_str(0);
- YCPMap changesMap= arg->asMap();
+ int component = 0;
+ bool databaseAdd = false;
+ std::string dbIndexStr = path->component_str(component);
+
+ if ( dbIndexStr == "new" )
+ {
+ component++;
+ databaseAdd = true;
+ if ( path->length() > component )
+ {
+ dbIndexStr = path->component_str(component);
+ }
+ else
+ {
+ dbIndexStr = "";
+ }
+ }
+ YCPMap dbMap= 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 {
+ }
+ else if (! databaseAdd ) // Add without index is support (append database to the end)
+ {
y2error("Database Index expected, got: %s", dbIndexStr.c_str() );
return YCPBoolean(false);
}
- if ( dbIndex < -1 )
+
+ if ( (dbIndex < -1) && (!databaseAdd) )
{
y2error("Invalid database index: %d", dbIndex );
return YCPBoolean(false);
}
- y2milestone("Database to write: %d", dbIndex);
- OlcDatabaseList::const_iterator i;
bool ret = false;
- for ( i = databases.begin(); i != databases.end() ; i++ )
+ if ( databaseAdd )
{
- if ( (*i)->getEntryIndex() == dbIndex )
+ y2milestone("creating new Database");
+ if ( dbIndex == -2 )
{
- if ( path->length() == 1 )
+ dbIndex = databases.size()-1; //Database indexes start counting from -1
+ }
+ else if ( (dbIndex <=0) || (dbIndex > (int)databases.size()-2) )
+ {
+ lastError->add(YCPString("summary"), YCPString("Adding Database Failed") );
+ std::string msg = "Invalid Index for new Database";
+ lastError->add(YCPString("description"), YCPString(msg) );
+ return ret;
+ }
+ y2milestone("Database will get Index: %d", dbIndex);
+ std::string dbtype(dbMap->value(YCPString("type"))->asString()->value_cstr());
+ boost::shared_ptr<OlcDatabase> db;
+ if ( dbtype == "bdb" )
+ {
+ db = boost::shared_ptr<OlcDatabase>(new OlcBdbDatabase() );
+ }
+ else
+ {
+ db = boost::shared_ptr<OlcDatabase>( new OlcDatabase(dbtype.c_str()) );
+ }
+ db->setIndex(dbIndex);
+ YCPMapIterator j = dbMap.begin();
+ for ( ; j != dbMap.end(); j++ )
+ {
+ y2milestone("Key: %s, Valuetype: %s",
+ j.key()->asString()->value_cstr(),
+ j.value()->valuetype_str() );
+ if ( std::string("suffix") == j.key()->asString()->value_cstr() )
+ {
+ db->setSuffix( j.value()->asString()->value_cstr() );
+ continue;
+ }
+ else if (std::string("rootdn") == j.key()->asString()->value_cstr() )
+ {
+ db->setRootDn( j.value()->asString()->value_cstr() );
+ continue;
+ }
+ else if (std::string("rootpw") == j.key()->asString()->value_cstr() )
+ {
+ db->setRootPw( j.value()->asString()->value_cstr() );
+ continue;
+ }
+ else if (std::string("access") == j.key()->asString()->value_cstr() )
{
- YCPValue val = changesMap.value( YCPString("rootdn") );
- if ( ! val.isNull() && val->isString() )
+ YCPList aclList = j.value()->asList();
+ for ( int k=0 ; k < aclList.size(); k++ )
{
- (*i)->setStringValue( "olcRootDn", val->asString()->value_cstr() );
+ db->addStringValue( "olcAccess", aclList.value(k)->asString()->value_cstr() );
}
- val = changesMap.value( YCPString("rootpw") );
- if ( ! val.isNull() && val->isString() )
+ continue;
+ }
+ if ( dbtype == "bdb" )
+ {
+ boost::shared_ptr<OlcBdbDatabase> bdb =
+ boost::dynamic_pointer_cast<OlcBdbDatabase>(db);
+ if (std::string("directory") == j.key()->asString()->value_cstr() )
{
- (*i)->setStringValue( "olcRootPw", val->asString()->value_cstr() );
+ bdb->setDirectory( j.value()->asString()->value_cstr() );
}
- ret = true;
- } else {
- std::string dbComponent = path->component_str(1);
- y2milestone("Component '%s'", dbComponent.c_str());
- if ( dbComponent == "index" )
+ else if (std::string("entrycache") == j.key()->asString()->value_cstr() )
{
- boost::shared_ptr<OlcBdbDatabase> bdb =
- boost::dynamic_pointer_cast<OlcBdbDatabase>(*i);
- if ( bdb == 0 )
- {
- y2milestone("Database doesn't provide indexing\n");
- ret = false;
- }
- else
- {
- std::vector<IndexType> idx;
- std::string attr( arg->asMap()->value(YCPString("name"))->asString()->value_cstr() );
- y2milestone("Edit Index for Attribute: '%s'", attr.c_str() );
- if ( arg->asMap()->value(YCPString("pres"))->asBoolean()->value() == true )
- {
- idx.push_back(Present);
- }
- if ( arg->asMap()->value(YCPString("eq"))->asBoolean()->value() == true )
- {
- idx.push_back(Eq);
- }
- if ( arg->asMap()->value(YCPString("sub"))->asBoolean()->value() == true )
- {
- idx.push_back(Sub);
- }
- if ( ( idx.empty()) || ( ! bdb->getDatabaseIndex(attr).empty() ) ) {
- bdb->deleteIndex( attr );
- }
- if ( ! idx.empty() ) {
- bdb->addIndex(attr, idx);
- }
- ret = true;
- }
+ bdb->setEntryCache( j.value()->asInteger()->value() );
}
- else if (dbComponent == "ppolicy" )
+ else if (std::string("idlcache") == j.key()->asString()->value_cstr() )
{
- OlcOverlayList overlays = (*i)->getOverlays();
- OlcOverlayList::const_iterator j = overlays.begin();
- for (; j != overlays.end(); j++ )
+ bdb->setIdlCache( j.value()->asInteger()->value() );
+ }
+ else if (std::string("checkpoint") == j.key()->asString()->value_cstr() )
+ {
+ YCPList cpList = j.value()->asList();
+ bdb->setCheckPoint( cpList->value(0)->asInteger()->value(),
+ cpList->value(1)->asInteger()->value() );
+ }
+ }
+ }
+ databases.push_back(db);
+ ret = true;
+ }
+ else
+ {
+ y2milestone("Database to write: %d", dbIndex);
+ OlcDatabaseList::const_iterator i;
+ for ( i = databases.begin(); i != databases.end() ; i++ )
+ {
+ if ( (*i)->getEntryIndex() == dbIndex )
+ {
+ if ( path->length() == 1 )
+ {
+ YCPValue val = dbMap.value( YCPString("rootdn") );
+ if ( ! val.isNull() && val->isString() )
{
- if ( (*j)->getType() == "ppolicy" )
- {
- break;
- }
+ (*i)->setStringValue( "olcRootDn", val->asString()->value_cstr() );
}
- YCPMap argMap = arg->asMap();
- if ( j == overlays.end() && argMap.size() == 0 )
+ val = dbMap.value( YCPString("rootpw") );
+ if ( ! val.isNull() && val->isString() )
{
- y2milestone("Empty overlay nothing to do");
+ (*i)->setStringValue( "olcRootPw", val->asString()->value_cstr() );
}
- else
+ ret = true;
+ } else {
+ std::string dbComponent = path->component_str(1);
+ y2milestone("Component '%s'", dbComponent.c_str());
+ if ( dbComponent == "index" )
{
- boost::shared_ptr<OlcOverlay> ppolicyOlc;
- if ( j == overlays.end() )
+ boost::shared_ptr<OlcBdbDatabase> bdb =
+ boost::dynamic_pointer_cast<OlcBdbDatabase>(*i);
+ if ( bdb == 0 )
{
- y2milestone("New Overlay added");
- boost::shared_ptr<OlcOverlay> tmp(new OlcOverlay("ppolicy", (*i)->getDn()));
- ppolicyOlc = tmp;
- (*i)->addOverlay(ppolicyOlc);
+ y2milestone("Database doesn't provide indexing\n");
+ ret = false;
}
else
{
- y2milestone("Update existing Overlay");
- ppolicyOlc = *j;
- }
- if ( argMap.size() == 0 ){
- y2milestone("Delete ppolicy overlay");
- ppolicyOlc->clearChangedEntry();
- } else {
- ppolicyOlc->setStringValue("olcPpolicyDefault",
- argMap->value(YCPString("defaultPolicy"))->asString()->value_cstr() );
- if ( argMap->value(YCPString("useLockout"))->asBoolean()->value() == true )
+ std::vector<IndexType> idx;
+ std::string attr( arg->asMap()->value(YCPString("name"))->asString()->value_cstr() );
+ y2milestone("Edit Index for Attribute: '%s'", attr.c_str() );
+ if ( arg->asMap()->value(YCPString("pres"))->asBoolean()->value() == true )
{
- ppolicyOlc->setStringValue("olcPpolicyUseLockout", "TRUE");
+ idx.push_back(Present);
}
- else
+ if ( arg->asMap()->value(YCPString("eq"))->asBoolean()->value() == true )
{
- ppolicyOlc->setStringValue("olcPpolicyUseLockout", "FALSE");
+ idx.push_back(Eq);
}
- if ( argMap->value(YCPString("hashClearText"))->asBoolean()->value() == true )
+ if ( arg->asMap()->value(YCPString("sub"))->asBoolean()->value() == true )
{
- ppolicyOlc->setStringValue("olcPpolicyHashCleartext", "TRUE");
+ idx.push_back(Sub);
+ }
+ if ( ( idx.empty()) || ( ! bdb->getDatabaseIndex(attr).empty() ) ) {
+ bdb->deleteIndex( attr );
+ }
+ if ( ! idx.empty() ) {
+ bdb->addIndex(attr, idx);
+ }
+ ret = true;
+ }
+ }
+ else if (dbComponent == "ppolicy" )
+ {
+ OlcOverlayList overlays = (*i)->getOverlays();
+ OlcOverlayList::const_iterator j = overlays.begin();
+ for (; j != overlays.end(); j++ )
+ {
+ if ( (*j)->getType() == "ppolicy" )
+ {
+ break;
+ }
+ }
+ YCPMap argMap = arg->asMap();
+ if ( j == overlays.end() && argMap.size() == 0 )
+ {
+ y2milestone("Empty overlay nothing to do");
+ }
+ else
+ {
+ boost::shared_ptr<OlcOverlay> ppolicyOlc;
+ if ( j == overlays.end() )
+ {
+ y2milestone("New Overlay added");
+ boost::shared_ptr<OlcOverlay> tmp(new OlcOverlay("ppolicy", (*i)->getDn()));
+ ppolicyOlc = tmp;
+ (*i)->addOverlay(ppolicyOlc);
}
else
{
- ppolicyOlc->setStringValue("olcPpolicyHashCleartext", "FALSE");
+ y2milestone("Update existing Overlay");
+ ppolicyOlc = *j;
+ }
+ if ( argMap.size() == 0 ){
+ y2milestone("Delete ppolicy overlay");
+ ppolicyOlc->clearChangedEntry();
+ } else {
+ ppolicyOlc->setStringValue("olcPpolicyDefault",
+ argMap->value(YCPString("defaultPolicy"))->asString()->value_cstr() );
+ if ( argMap->value(YCPString("useLockout"))->asBoolean()->value() == true )
+ {
+ ppolicyOlc->setStringValue("olcPpolicyUseLockout", "TRUE");
+ }
+ else
+ {
+ ppolicyOlc->setStringValue("olcPpolicyUseLockout", "FALSE");
+ }
+ if ( argMap->value(YCPString("hashClearText"))->asBoolean()->value() == true )
+ {
+ ppolicyOlc->setStringValue("olcPpolicyHashCleartext", "TRUE");
+ }
+ else
+ {
+ ppolicyOlc->setStringValue("olcPpolicyHashCleartext", "FALSE");
+ }
}
}
+ ret = true;
+ }
+ else
+ {
+ lastError->add(YCPString("summary"), YCPString("Write Failed") );
+ std::string msg = "Unsupported SCR path: `.ldapserver.database.";
+ msg += path->toString().c_str();
+ msg += "`";
+ lastError->add(YCPString("description"), YCPString(msg) );
+ ret = false;
}
- ret = true;
- }
- else
- {
- lastError->add(YCPString("summary"), YCPString("Write Failed") );
- std::string msg = "Unsupported SCR path: `.ldapserver.database.";
- msg += path->toString().c_str();
- msg += "`";
- lastError->add(YCPString("description"), YCPString(msg) );
- ret = false;
}
+ break;
}
- break;
}
}
+
return YCPBoolean(ret);
}
Modified: trunk/ldap-server/src/tree_structure.ycp
URL: http://svn.opensuse.org/viewcvs/yast/trunk/ldap-server/src/tree_structure.ycp?rev=48892&r1=48891&r2=48892&view=diff
==============================================================================
--- trunk/ldap-server/src/tree_structure.ycp (original)
+++ trunk/ldap-server/src/tree_structure.ycp Fri Jul 4 15:17:21 2008
@@ -10,6 +10,7 @@
textdomain "ldap-server";
import "LdapServer";
+import "LdapDatabase";
import "Report";
import "Label";
import "HTML";
@@ -543,157 +544,25 @@
define boolean cb_input_databases()
``{
y2milestone( "calling databases input handler" );
-// if( handler_cmd == `pb_add )
-// {
-// any ret = nil;
-// boolean user_changed_dbdir = false;
-// list<string> dblist = LdapServer::ReadDbList();
-// integer numDbs = size(dblist);
-//
-// UI::OpenDialog( (term)widget_map["databases","dialogs","adddb"]:`Label( _("Dialog not found") ) );
-//
-// UI::ChangeWidget( `te_rootdn, `Value, "cn=Administrator" );
-// UI::ChangeWidget( `te_directory, `Value, "/var/lib/ldap/" );
-// UI::ChangeWidget( `cb_ppolicy_hashcleartext, `Enabled , false );
-// UI::ChangeWidget( `cb_ppolicy_uselockout, `Enabled , false );
-// UI::ChangeWidget( `te_ppolicy_defaultpolicy, `Enabled , false );
-// UI::ChangeWidget( `cb_pp_append_basedn ,`Enabled, false );
-// while( true )
-// {
-// ret = UI::UserInput();
-// y2milestone( "cb_input_databases: dialog returns '%1'", ret );
-// if( ret == `cancel ) break;
-// else if( ret == `pb_directory ) {
-// /*directory selection dialog heading*/
-// string name = UI::AskForExistingDirectory( "/var/lib/ldap", _("Select Database Directory") );
-// if( name != nil ) UI::ChangeWidget( `te_directory, `Value, name );
-// continue;
-// }
-// else if ( ret == `te_directory ) {
-// user_changed_dbdir = true;
-// }
-// else if ( ret == `te_basedn ) {
-// if ( ( user_changed_dbdir != true ) && (numDbs > 0) ) {
-// string suffix = String::CutBlanks( (string)UI::QueryWidget( `te_basedn, `Value ) );
-// suffix = String::Replace(suffix, ",", "_");
-// suffix = String::CutRegexMatch(suffix, "[^0-9a-zA-Z_=-]", true);
-// string dbdir = "/var/lib/ldap/" + suffix;
-// UI::ChangeWidget( `te_directory, `Value, dbdir );
-// }
-// }
-// else if ( ret == `cb_ppolicy_overlay ) {
-// if ( UI::QueryWidget( `cb_ppolicy_overlay, `Value ) == true ) {
-// UI::ChangeWidget( `cb_ppolicy_hashcleartext, `Enabled , true );
-// UI::ChangeWidget( `cb_ppolicy_uselockout, `Enabled , true );
-// UI::ChangeWidget( `te_ppolicy_defaultpolicy, `Enabled , true );
-// UI::ChangeWidget( `cb_pp_append_basedn ,`Enabled, true );
-// } else {
-// UI::ChangeWidget( `cb_ppolicy_hashcleartext, `Enabled , false );
-// UI::ChangeWidget( `cb_ppolicy_uselockout, `Enabled , false );
-// UI::ChangeWidget( `te_ppolicy_defaultpolicy, `Enabled , false );
-// UI::ChangeWidget( `cb_pp_append_basedn ,`Enabled, false );
-// }
-// }
-// else if( ret == `ok ) {
-// //TODO: add database
-// string suffix = String::CutBlanks( (string)UI::QueryWidget( `te_basedn, `Value ) );
-// string rootdn = String::CutBlanks( (string)UI::QueryWidget( `te_rootdn, `Value ) );
-// string rootpw = (string)UI::QueryWidget( `te_rootpw, `Value );
-// string directory = String::CutBlanks( (string)UI::QueryWidget( `te_directory, `Value ) );
-// boolean createdir = false;
-// string cryptmethod = (string)UI::QueryWidget( `cb_cryptmethod, `Value );
-//
-// //check values
-// if( suffix == "" )
-// {
-// /*error popup*/
-// Popup::Error( _("Base DN must be set.") );
-// continue;
-// }
-//
-// list<string> dblist = (list<string>)merge( LdapServer::ReadDbList(), LdapServer::ReadDbListNEW() );
-// if( contains( dblist, suffix ) )
-// {
-// /* Error Popup */
-// Popup::Error( _("A database with that Base DN already exists.") );
-// continue;
-// }
-// if( rootpw != "" && rootdn == "" )
-// {
-// /* Error Popup */
-// Popup::Error( _("Root DN must be set if a password is given.") );
-// continue;
-// }
-// if( rootpw != "" && rootpw != (string)UI::QueryWidget( `te_valid_rootpw, `Value ) )
-// {
-// /* Error Popup */
-// Popup::Error( _("Password validation failed.") );
-// continue;
-// }
-// if( directory == "" )
-// {
-// /* Error Popup */
-// Popup::Error( _("A directory must be specified.") );
-// continue;
-// }
-// if ( SCR::Read(.target.dir, directory) == nil ) {
-// boolean res = Popup::AnyQuestion(Label::ErrorMsg(),
-// _("The directory does not exist. Create it?"),
-// Label::YesButton(), Label::NoButton(), `focus);
-// if ( res == false ) {
-// continue;
-// } else {
-// y2debug( "Create dir == true" );
-// createdir = true;
-// }
-// }
-//
-// //create new database
-// map