+sub _handle_superuser_privileges {
+ my ($self, $form) = @_;
+
+ if ($form->{database_superuser_username}) {
+ $::auth->set_session_value("database_superuser_username" => $form->{database_superuser_username}, "database_superuser_password" => $form->{database_superuser_password});
+ }
+
+ my %dbconnect_form = %{ $form };
+ my ($su_user, $su_password) = map { $::auth->get_session_value("database_superuser_$_") } qw(username password);
+
+ if ($su_user) {
+ $dbconnect_form{dbuser} = $su_user;
+ $dbconnect_form{dbpasswd} = $su_password;
+ }
+
+ dbconnect_vars(\%dbconnect_form, $form->{dbname});
+
+ my %result = (
+ username => $dbconnect_form{dbuser},
+ password => $dbconnect_form{dbpasswd},
+ );
+
+ $::auth->set_session_value("database_superuser_username" => $dbconnect_form{dbuser}, "database_superuser_password" => $dbconnect_form{dbpasswd});
+
+ my $dbh = SL::DBConnect->connect($dbconnect_form{dbconnect}, $dbconnect_form{dbuser}, $dbconnect_form{dbpasswd}, SL::DBConnect->get_options);
+ return (%result, error => $::locale->text('The credentials (username & password) for connecting database are wrong.')) if !$dbh;
+
+ my $is_superuser = SL::DBUtils::role_is_superuser($dbh, $dbconnect_form{dbuser});
+
+ $dbh->disconnect;
+
+ return (%result, have_privileges => 1) if $is_superuser;
+ return (%result) if !$su_user; # no error message if credentials weren't set by the user
+ return (%result, error => $::locale->text('The database user \'#1\' does not have superuser privileges.', $dbconnect_form{dbuser}));
+}
+