summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rwxr-xr-xlib/rddb.pm16
1 files changed, 13 insertions, 3 deletions
diff --git a/lib/rddb.pm b/lib/rddb.pm
index 1ef296c..a7506a2 100755
--- a/lib/rddb.pm
+++ b/lib/rddb.pm
@@ -24,12 +24,18 @@ sub opendb
return ($dbh, 'OK', 'success');
}
+sub closedb
+{
+ my $dbh = shift;
+ $dbh->disconnect();
+}
+
sub get_token
{
my $username = shift;
my ($dbh, $state, $errorstring) = opendb();
- unless($dbh) {
+ unless(defined $dbh) {
return ('', $state, $errorstring);
}
@@ -40,9 +46,13 @@ sub get_token
or return ('', 'ERROR', "Database Error: " . $sth->errstr);
my ($token) = $sth->fetchrow_array;
- return ($token, 'OK', 'success') if(defined $token);
+ $sth->finish();
+ closedb($dbh);
- return ('', 'ERROR', "user '" . $username . "' not known by rivendell")
+ unless(defined $token) {
+ return ('', 'ERROR', "user '" . $username . "' not known by rivendell")
+ }
+ return ($token, 'OK', 'success');
}
return 1;