From 6279082493b8a150dab0af22385b0b3c4d2b6138 Mon Sep 17 00:00:00 2001 From: Dain Nilsson Date: Fri, 21 Dec 2012 11:17:55 +0100 Subject: [PATCH] Added support for reading db config from /etc/ykksm/ --- ykksm-checksum | 17 ++++++++++++----- ykksm-config.php | 19 +++++++++++++++---- ykksm-export | 17 ++++++++++++----- ykksm-import | 17 ++++++++++++----- 4 files changed, 51 insertions(+), 19 deletions(-) diff --git a/ykksm-checksum b/ykksm-checksum index c124bcd..e5c714a 100755 --- a/ykksm-checksum +++ b/ykksm-checksum @@ -55,10 +55,17 @@ sub usage { exit 1; } +#Support dbconfig-common generated database settings, if available +our ($dbuser, $dbpass, $basepath, $dbname, $dbserver, $dbport, $dbtype); +if( -e '/etc/ykksm/config-db.cfg' ) { + require '/etc/ykksm/config-db.cfg'; +} else { + $dbtype = 'mysql'; + $dbname = 'ykksm'; +} + my $verbose = 0; -my $db = "dbi:mysql:ykksm"; -my $dbuser; -my $dbpasswd; +my $db = "dbi:$dbtype:$dbname"; while ($ARGV[0] =~ m/^-(.*)/) { my $cmd = shift @ARGV; if (($cmd eq "-v") || ($cmd eq "--verbose")) { @@ -70,7 +77,7 @@ while ($ARGV[0] =~ m/^-(.*)/) { } elsif ($cmd eq "--db-user") { $dbuser = shift; } elsif ($cmd eq "--db-passwd") { - $dbpasswd = shift; + $dbpass = shift; } } @@ -78,7 +85,7 @@ if ($#ARGV>=0) { usage(); } -my $dbh = DBI->connect($db, $dbuser, $dbpasswd, {'RaiseError' => 1}); +my $dbh = DBI->connect($db, $dbuser, $dbpass, {'RaiseError' => 1}); my $sth = $dbh->prepare ('SELECT serialnr, publicname, internalname, aeskey '. 'FROM yubikeys '. 'ORDER BY serialnr, publicname') diff --git a/ykksm-config.php b/ykksm-config.php index 3aba8b5..50ccb8d 100644 --- a/ykksm-config.php +++ b/ykksm-config.php @@ -1,7 +1,18 @@ diff --git a/ykksm-export b/ykksm-export index 6ad519c..4fb886d 100755 --- a/ykksm-export +++ b/ykksm-export @@ -53,10 +53,17 @@ sub usage { exit 1; } +#Support dbconfig-common generated database settings, if available +our ($dbuser, $dbpass, $basepath, $dbname, $dbserver, $dbport, $dbtype); +if( -e '/etc/ykksm/config-db.cfg' ) { + require '/etc/ykksm/config-db.cfg'; +} else { + $dbtype = 'mysql'; + $dbname = 'ykksm'; +} + my $verbose = 0; -my $db = "dbi:mysql:ykksm"; -my $dbuser; -my $dbpasswd; +my $db = "dbi:$dbtype:$dbname"; while ($ARGV[0] =~ m/^-(.*)/) { my $cmd = shift @ARGV; if (($cmd eq "-v") || ($cmd eq "--verbose")) { @@ -68,7 +75,7 @@ while ($ARGV[0] =~ m/^-(.*)/) { } elsif ($cmd eq "--db-user") { $dbuser = shift; } elsif ($cmd eq "--db-passwd") { - $dbpasswd = shift; + $dbpass = shift; } } @@ -76,7 +83,7 @@ if ($#ARGV>=0) { usage(); } -my $dbh = DBI->connect($db, $dbuser, $dbpasswd, {'RaiseError' => 1}); +my $dbh = DBI->connect($db, $dbuser, $dbpass, {'RaiseError' => 1}); my $sth = $dbh->prepare ('SELECT serialnr, publicname, internalname, aeskey, lockcode, created FROM yubikeys') or die "Couldn't prepare statement: " . $dbh->errstr; diff --git a/ykksm-import b/ykksm-import index ae57e0d..f27d4a4 100755 --- a/ykksm-import +++ b/ykksm-import @@ -57,11 +57,18 @@ sub usage { exit 1; } +#Support dbconfig-common generated database settings, if available +our ($dbuser, $dbpass, $basepath, $dbname, $dbserver, $dbport, $dbtype); +if( -e '/etc/ykksm/config-db.cfg' ) { + require '/etc/ykksm/config-db.cfg'; +} else { + $dbtype = 'mysql'; + $dbname = 'ykksm'; +} + my $verbose = 0; my $creator; -my $db = "dbi:mysql:ykksm"; -my $dbuser; -my $dbpasswd; +my $db = "dbi:$dbtype:$dbname"; while ($ARGV[0] =~ m/^-(.*)/) { my $cmd = shift @ARGV; if (($cmd eq "-v") || ($cmd eq "--verbose")) { @@ -75,7 +82,7 @@ while ($ARGV[0] =~ m/^-(.*)/) { } elsif ($cmd eq "--db-user") { $dbuser = shift; } elsif ($cmd eq "--db-passwd") { - $dbpasswd = shift; + $dbpass = shift; } } @@ -114,7 +121,7 @@ print "signed by: " . $signed_by . "\n"; die "Input not signed?" if !$signed_by; -my $dbh = DBI->connect($db, $dbuser, $dbpasswd, {'RaiseError' => 1}); +my $dbh = DBI->connect($db, $dbuser, $dbpass, {'RaiseError' => 1}); my $inserth = $dbh->prepare_cached(qq{ INSERT INTO yubikeys (creator, created, serialnr, publicname, internalname, aeskey, lockcode)