summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOliver Tappe2007-07-31 23:38:03 +0200
committerOliver Tappe2007-07-31 23:38:03 +0200
commit880ba4090cd8af757f17604af3284afab6fd198c (patch)
tree4d37ef92b0cefc2ab1149d875b78fe0cf05dcd9e
parent* Fixed another bug reported by Bastian: (diff)
downloadcore-880ba4090cd8af757f17604af3284afab6fd198c.tar.gz
core-880ba4090cd8af757f17604af3284afab6fd198c.tar.xz
core-880ba4090cd8af757f17604af3284afab6fd198c.zip
* dropped support for CSV databases, as they are simply not good enough
* added support for db-user and db-passwd: + the mysql backend will now ask for the password upon connect + you can specify the db-user and db-passwd via slxsettings (so you never have to enter it manually afterwards) * slxsettings now checks db-type against an explicit pattern to avoid problems caused by typos git-svn-id: http://svn.openslx.org/svn/openslx/trunk@1295 95ad53e4-c205-0410-b2fa-d234c58c8868
-rw-r--r--Makefile2
-rwxr-xr-xbin/slxsettings33
-rw-r--r--config-db/OpenSLX/ConfigDB.pm3
-rw-r--r--config-db/OpenSLX/MetaDB/CSV.pm182
-rw-r--r--config-db/OpenSLX/MetaDB/mysql.pm18
-rw-r--r--lib/OpenSLX/Basics.pm4
-rw-r--r--packaging/rpm/openslx.spec4
7 files changed, 51 insertions, 195 deletions
diff --git a/Makefile b/Makefile
index dbdf8358..c6040d3f 100644
--- a/Makefile
+++ b/Makefile
@@ -110,7 +110,7 @@ install:
echo "Reading local settings..."; \
. ${SLX_CONFIG_PATH}/settings; \
fi; \
- for m in $${SLX_DB_TYPE} SQLite CSV mysql; do \
+ for m in $${SLX_DB_TYPE} SQLite mysql; do \
if ! perl -Ilib -Iconfig-db -e "use OpenSLX::MetaDB::$$m" 2>>${SLX_INSTALL_LOG} ; then \
echo -e " 'DBD::$$m' not found (or too old), so $$m-databases will not be \
supported."; \
diff --git a/bin/slxsettings b/bin/slxsettings
index e6daf0cf..907f6f60 100755
--- a/bin/slxsettings
+++ b/bin/slxsettings
@@ -58,8 +58,17 @@ if ($versionReq) {
exit 1;
}
+if ($> != 0) {
+ die _tr("Sorry, this script can only be executed by the superuser!\n");
+}
+
openslxInit() or pod2usage(2);
+# some settings must match a certain pattern:
+my %configPattern = (
+ 'db-type' => '(SQLite|mysql)',
+);
+
# the remaining cmdline arguments are set or reset actions, each followed
# by a single argument:
while (scalar @ARGV) {
@@ -89,6 +98,11 @@ while (scalar @ARGV) {
# fetch current content of local settings file...
my $fileName = "$openslxConfig{'config-path'}/settings";
+if (!-e $fileName) {
+ # create empty default settings file with tight mode (root-only access)
+ # [I know this isn't *secure* as such, but it's still better than nothing]
+ slxsystem("touch $fileName && chmod 0600 $fileName");
+}
my $configObj = Config::General->new(
-ConfigFile => $fileName,
-SplitDelimiter => '\s*=\s*',
@@ -109,6 +123,12 @@ foreach my $key (keys %givenSettings) {
if ($key =~ m{^(base-path|config-path)$}) {
die _tr("option '%s' is fixed!", $key);
}
+ if (exists $configPattern{$key} && $value !~ m{$configPattern{$key}}) {
+ die _tr(
+ "option '%s' must match pattern '%s'!", $key, $configPattern{$key}
+ );
+ }
+
vlog(0, _tr("setting %s to '%s'", $key, $value)) unless $quiet;
my $externalKey = externalKeyFor($key);
if (!exists $settings{$externalKey} || $settings{$externalKey} ne $value) {
@@ -162,8 +182,13 @@ if (!keys %changed) {
my @extSettings = grep { !exists $cmdlineConfig{$_} } keys %openslxConfig;
foreach my $key (sort @extSettings) {
next if $key =~ m[^(base-path|config-path)$];
- my $val = $openslxConfig{$key} || '';
- print qq[\t$key='$val'\n];
+ my $val = $openslxConfig{$key};
+ if (defined $val) {
+ print qq[\t$key='$val'\n];
+ }
+ else {
+ print qq[\t$key=<unset>\n];
+ }
}
}
@@ -280,9 +305,9 @@ Default is $SLX_DB_SPEC (usually empty as it will be built automatically).
=item B<< db-type=<string> >>
-Sets the type of database to connect to (CSV, SQLite, mysql, ...).
+Sets the type of database to connect to (SQLite, mysql, ...).
-Default $SLX_DB_TYPE (usually C<CSV>).
+Default $SLX_DB_TYPE (usually C<SQLite>).
=item B<< locale=<string> >>
diff --git a/config-db/OpenSLX/ConfigDB.pm b/config-db/OpenSLX/ConfigDB.pm
index 402678e5..061b560f 100644
--- a/config-db/OpenSLX/ConfigDB.pm
+++ b/config-db/OpenSLX/ConfigDB.pm
@@ -155,7 +155,6 @@ sub connect ## no critic (ProhibitBuiltinHomonyms)
# map db-type to name of module, such that the user doesn't have
# to type the correct case:
my %dbTypeMap = (
- 'csv' => 'CSV',
'mysql' => 'mysql',
'sqlite' => 'SQLite',
);
@@ -180,7 +179,7 @@ sub connect ## no critic (ProhibitBuiltinHomonyms)
if (!$metaDB->connect($dbParams)) {
warn _tr("Unable to connect to DB-module <%s>\n%s", $dbModuleName, $@);
warn _tr("These DB-modules seem to work ok:");
- foreach my $dbMod ('CSV', 'mysql', 'SQLite') {
+ foreach my $dbMod ('mysql', 'SQLite') {
my $fullDbModName = "DBD/$dbMod.pm";
if (eval { require $fullDbModName }) {
vlog(0, "\t$dbMod\n");
diff --git a/config-db/OpenSLX/MetaDB/CSV.pm b/config-db/OpenSLX/MetaDB/CSV.pm
deleted file mode 100644
index fbd2c7ec..00000000
--- a/config-db/OpenSLX/MetaDB/CSV.pm
+++ /dev/null
@@ -1,182 +0,0 @@
-# Copyright (c) 2006, 2007 - OpenSLX GmbH
-#
-# This program is free software distributed under the GPL version 2.
-# See http://openslx.org/COPYING
-#
-# If you have any feedback please consult http://openslx.org/feedback and
-# send your suggestions, praise, or complaints to feedback@openslx.org
-#
-# General information about OpenSLX can be found at http://openslx.org/
-# -----------------------------------------------------------------------------
-# CSV.pm
-# - provides CSV-specific overrides of the OpenSLX MetaDB API.
-# -----------------------------------------------------------------------------
-package OpenSLX::MetaDB::CSV;
-
-use strict;
-use warnings;
-
-use base qw(OpenSLX::MetaDB::DBI);
-
-################################################################################
-### This class provides a MetaDB backend for CSV files (CSV = comma separated
-### files).
-### - each table will be stored into a CSV file.
-### - by default all files will be created inside a 'openslxdata-csv' directory.
-################################################################################
-use Fcntl qw(:DEFAULT :flock);
-use DBD::CSV 0.22;
-use OpenSLX::Basics;
-
-################################################################################
-### implementation
-################################################################################
-sub new
-{
- my $class = shift;
- my $self = {};
- return bless $self, $class;
-}
-
-sub connect ## no critic (ProhibitBuiltinHomonyms)
-{
- my $self = shift;
-
- my $dbSpec = $openslxConfig{'db-spec'};
- if (!defined $dbSpec) {
- # build $dbSpec from individual parameters:
- my $dbBasepath = "$openslxConfig{'private-path'}/db";
- my $dbDatadir = "$openslxConfig{'db-name'}-csv";
- my $dbPath = "$dbBasepath/$dbDatadir";
- system("mkdir -p $dbPath") unless -e $dbPath;
- $dbSpec = "f_dir=$dbPath;csv_eol=\n;";
- }
- vlog(1, "trying to connect to CSV-database <$dbSpec>");
- $self->{'dbh'} =
- DBI->connect("dbi:CSV:$dbSpec", undef, undef, {PrintError => 0})
- or die _tr("Cannot connect to database '%s' (%s)", $dbSpec, $DBI::errstr);
- return;
-}
-
-sub quote
-{ # DBD::CSV has a buggy quoting mechanism which can't cope with backslashes
- # so we reimplement the quoting ourselves...
- my $self = shift;
- my $val = shift;
-
- $val =~ s[(['])][\\$1]go;
- return "'$val'";
-}
-
-sub start_transaction
-{ # simulate a global transaction by flocking a file:
- my $self = shift;
-
- my $dbh = $self->{'dbh'};
- my $lockFile = "$dbh->{'f_dir'}/transaction-lock";
- sysopen(TRANSFILE, $lockFile, O_RDWR | O_CREAT)
- or croak _tr(q[Can't open transaction-file '%s' (%s)], $lockFile, $!);
- $self->{"transaction-lock"} = *TRANSFILE;
- flock(TRANSFILE, LOCK_EX)
- or croak _tr(q[Can't lock transaction-file '%s' (%s)], $lockFile, $!);
- return;
-}
-
-sub commit_transaction
-{ # free transaction-lock
- my $self = shift;
-
- if (!defined $self->{"transaction-lock"}) {
- croak _tr(q[no open transaction-lock found!]);
- }
- close($self->{"transaction-lock"});
- $self->{"transaction-lock"} = undef;
- return 1;
-}
-
-sub rollback_transaction
-{ # free transaction-lock
- my $self = shift;
-
- if (!defined $self->{"transaction-lock"}) {
- croak _tr(q[no open transaction-lock found!]);
- }
- close($self->{"transaction-lock"});
- $self->{"transaction-lock"} = undef;
- return 1;
-}
-
-sub generateNextIdForTable
-{ # CSV doesn't provide any mechanism to generate IDs, we provide one
- my $self = shift;
- my $table = shift;
-
- return 1 unless defined $table;
-
- # fetch the next ID from a table-specific file:
- my $dbh = $self->{'dbh'};
- my $idFile = "$dbh->{'f_dir'}/id-$table";
- sysopen(IDFILE, $idFile, O_RDWR | O_CREAT)
- or croak _tr(q[Can't open ID-file '%s' (%s)], $idFile, $!);
- flock(IDFILE, LOCK_EX)
- or croak _tr(q[Can't lock ID-file '%s' (%s)], $idFile, $!);
- my $nextID = <IDFILE>;
- if (!$nextID) {
- # no ID information available, we protect against users having
- # deleted the ID-file by fetching the highest ID from the DB:
- #
- # N.B.: older versions of DBD::CSV (notably the one that comes with
- # SUSE-9.3) do not understand the max() function, so we determine
- # the maximum ID manually:
- my @IDs =
- sort { $b <=> $a } $self->_doSelect("SELECT id FROM $table", 'id');
- my $maxID = $IDs[0];
- $nextID = 1 + $maxID;
- }
- seek(IDFILE, 0, 0)
- or croak _tr(q[Can't to seek ID-file '%s' (%s)], $idFile, $!);
- truncate(IDFILE, 0)
- or croak _tr(q[Can't truncate ID-file '%s' (%s)], $idFile, $!);
- print IDFILE $nextID + 1
- or croak _tr(q[Can't update ID-file '%s' (%s)], $idFile, $!);
- close(IDFILE);
-
- return $nextID;
-}
-
-sub schemaDeclareTable
-{ # explicitly set file name for each table such that it makes
- # use of '.csv'-extension
- my $self = shift;
- my $table = shift;
-
- my $dbh = $self->{'dbh'};
- $dbh->{'csv_tables'}->{"$table"} = {'file' => "${table}.csv"};
- return;
-}
-
-sub schemaRenameTable
-{ # renames corresponding id-file after renaming the table
- my $self = shift;
- my $oldTable = shift;
- my $newTable = shift;
-
- $self->schemaDeclareTable($newTable);
- $self->SUPER::schemaRenameTable($oldTable, $newTable, @_);
- my $dbh = $self->{'dbh'};
- rename "$dbh->{'f_dir'}/id-$oldTable", "$dbh->{'f_dir'}/id-$newTable";
- return;
-}
-
-sub schemaDropTable
-{ # removes corresponding id-file after dropping the table
- my $self = shift;
- my $table = shift;
-
- $self->SUPER::schemaDropTable($table, @_);
- my $dbh = $self->{'dbh'};
- unlink "$dbh->{'f_dir'}/id-$table";
- return;
-}
-
-1;
diff --git a/config-db/OpenSLX/MetaDB/mysql.pm b/config-db/OpenSLX/MetaDB/mysql.pm
index 8206ec2a..865b035d 100644
--- a/config-db/OpenSLX/MetaDB/mysql.pm
+++ b/config-db/OpenSLX/MetaDB/mysql.pm
@@ -44,10 +44,22 @@ sub connect ## no critic (ProhibitBuiltinHomonyms)
# build $dbSpec from individual parameters:
$dbSpec = "database=$openslxConfig{'db-name'}";
}
- my $user = (getpwuid($>))[0];
- vlog(1, "trying to connect user <$user> to mysql-database <$dbSpec>");
+ my $dbUser
+ = $openslxConfig{'db-user'}
+ ? $openslxConfig{'db-user'}
+ : (getpwuid($>))[0];
+ my $dbPasswd = $openslxConfig{'db-passwd'};
+ if (!defined $dbPasswd) {
+ use Term::ReadLine;
+ my $term = Term::ReadLine->new('slx');
+ my $attribs = $term->Attribs;
+ $attribs->{redisplay_function} = $attribs->{shadow_redisplay};
+ $dbPasswd = $term->readline("db-password> ");
+ }
+
+ vlog(1, "trying to connect user '$dbUser' to mysql-database '$dbSpec'");
$self->{'dbh'} = DBI->connect(
- "dbi:mysql:$dbSpec", $user, 'secret', {PrintError => 0}
+ "dbi:mysql:$dbSpec", $dbUser, $dbPasswd, {PrintError => 0}
) or die _tr("Cannot connect to database '%s' (%s)", $dbSpec, $DBI::errstr);
return 1;
}
diff --git a/lib/OpenSLX/Basics.pm b/lib/OpenSLX/Basics.pm
index 93f671bf..53103cef 100644
--- a/lib/OpenSLX/Basics.pm
+++ b/lib/OpenSLX/Basics.pm
@@ -83,9 +83,11 @@ my $translations;
# extended settings follow, which are only supported by slxsettings,
# but not by any other script:
#
- 'ossetup-max-try-count' => '5',
+ 'db-user' => undef,
+ 'db-passwd' => undef,
'default-shell' => 'bash',
'default-timezone' => 'Europe/Berlin',
+ 'ossetup-max-try-count' => '5',
);
chomp($openslxConfig{'locale-charmap'});
diff --git a/packaging/rpm/openslx.spec b/packaging/rpm/openslx.spec
index 2cf4180e..893bb877 100644
--- a/packaging/rpm/openslx.spec
+++ b/packaging/rpm/openslx.spec
@@ -9,12 +9,12 @@ License: GNU General Public License (GPL)
Group: Productivity/Networking/System
Url: http://openslx.org/
Autoreqprov: on
-Requires: perl-DBD-CSV perl-DBD-SQLite perl-DBD-mysql
+Requires: perl-DBD-SQLite perl-DBD-mysql
#PreReq:
Source: %{name}-%{version}.tar.bz2
Summary: Open StateLess Extensions
BuildRoot: %{_tmppath}/%{name}-%{version}-build
-BuildRequires: perl-DBD-CSV perl-DBD-SQLite perl-DBD-mysql
+BuildRequires: perl-DBD-SQLite perl-DBD-mysql
%description
OpenSLX aims on the Linux desktop as a middleware solution to provide easy