mirror of
https://github.com/webmin/webmin.git
synced 2026-09-15 01:50:39 +01:00
Fixed up postgresql support
This commit is contained in:
@@ -18,9 +18,7 @@ do 'md5-lib.pl';
|
||||
%access = &get_module_acl();
|
||||
$access{'switch'} = 0 if (&is_readonly_mode());
|
||||
|
||||
# XXX test with postgresql
|
||||
# XXX LDAP support
|
||||
# XXX infinite loop on failure
|
||||
|
||||
=head2 list_users
|
||||
|
||||
@@ -271,7 +269,7 @@ if ($miniserv{'userdb'} && !$miniserv{'userdb_addto'}) {
|
||||
$cmd && $cmd->execute($user{'name'}, $user{'pass'}) ||
|
||||
&error("Failed to add user : ".$dbh->errstr);
|
||||
$cmd->finish();
|
||||
my $cmd = $dbh->prepare("select last_insert_id()");
|
||||
my $cmd = $dbh->prepare("select max(id) from webmin_user");
|
||||
$cmd->execute();
|
||||
my ($id) = $cmd->fetchrow();
|
||||
$cmd->finish();
|
||||
@@ -733,7 +731,7 @@ if ($miniserv{'userdb'} && !$miniserv{'userdb_addto'}) {
|
||||
$cmd && $cmd->execute($group{'name'}, $group{'desc'}) ||
|
||||
&error("Failed to add group : ".$dbh->errstr);
|
||||
$cmd->finish();
|
||||
my $cmd = $dbh->prepare("select last_insert_id()");
|
||||
my $cmd = $dbh->prepare("select max(id) from webmin_group");
|
||||
$cmd->execute();
|
||||
my ($id) = $cmd->fetchrow();
|
||||
$cmd->finish();
|
||||
@@ -1751,11 +1749,11 @@ if ($str =~ /^mysql:/) {
|
||||
}
|
||||
elsif ($str =~ /^postgresql:/) {
|
||||
return ( "create table webmin_user ".
|
||||
"(id int8 not null primary key, ".
|
||||
"(id serial not null primary key, ".
|
||||
"name varchar(255), ".
|
||||
"pass varchar(255))",
|
||||
"create table webmin_group ".
|
||||
"(id int8 not null primary key, ".
|
||||
"(id serial not null primary key, ".
|
||||
"name varchar(255), ".
|
||||
"description varchar(255))",
|
||||
"create table webmin_user_attr ".
|
||||
|
||||
@@ -20,9 +20,16 @@ foreach $sql (&userdb_table_sql($in{'userdb'})) {
|
||||
print &text('make_failed', &html_escape($dbh->errstr)),"<p>\n";
|
||||
}
|
||||
else {
|
||||
$cmd->finish();
|
||||
print $text{'make_done'},"<p>\n";
|
||||
}
|
||||
}
|
||||
&disconnect_userdb($in{'userdb'}, $dbh);
|
||||
|
||||
# XXX create table fails for postgresql!!
|
||||
#$dbh = &connect_userdb($in{'userdb'});
|
||||
#$cmd = $dbh->prepare("select * from webmin_user");
|
||||
#$cmd && $cmd->execute() || &error("select failed : ".$dbh->errstr);
|
||||
|
||||
# Check again if OK
|
||||
$err = &validate_userdb($in{'userdb'}, 0);
|
||||
|
||||
@@ -2061,6 +2061,11 @@ if (&get_type($full) eq "internal/cgi" && $validated != 4) {
|
||||
$baseauthuser : undef;
|
||||
$ENV{"REMOTE_PASS"} = $authpass if (defined($authpass) &&
|
||||
$config{'pass_password'});
|
||||
$uinfo = &get_user_details($baseauthuser);
|
||||
if ($uinfo && $uinfo->{'proto'}) {
|
||||
$ENV{"REMOTE_USER_PROTO"} = $uinfo->{'proto'};
|
||||
$ENV{"REMOTE_USER_ID"} = $uinfo->{'id'};
|
||||
}
|
||||
print DEBUG "REMOTE_USER = ",$ENV{"REMOTE_USER"},"\n";
|
||||
print DEBUG "BASE_REMOTE_USER = ",$ENV{"BASE_REMOTE_USER"},"\n";
|
||||
$ENV{"SSL_USER"} = $peername if ($validated == 2);
|
||||
|
||||
@@ -1314,6 +1314,7 @@ by the message setup using that function.
|
||||
=cut
|
||||
sub error
|
||||
{
|
||||
$main::no_miniserv_userdb = 1;
|
||||
my $msg = join("", @_);
|
||||
$msg =~ s/<[^>]*>//g;
|
||||
if (!$main::error_must_die) {
|
||||
@@ -1392,6 +1393,7 @@ headers suitable for a popup window.
|
||||
=cut
|
||||
sub popup_error
|
||||
{
|
||||
$main::no_miniserv_userdb = 1;
|
||||
&load_theme_library();
|
||||
if ($main::error_must_die) {
|
||||
die @_;
|
||||
@@ -3316,8 +3318,9 @@ elsif ($u ne '') {
|
||||
# Use normal Webmin ACL, if a user is set
|
||||
my $userdb = &get_userdb_string();
|
||||
my $foundindb = 0;
|
||||
if ($userdb) {
|
||||
# Look for this user in the user/group DB
|
||||
if ($userdb && ($u ne $base_remote_user || $remote_user_proto)) {
|
||||
# Look for this user in the user/group DB, if one is defined
|
||||
# and if the user might be in the DB
|
||||
my ($dbh, $proto) = &connect_userdb($userdb);
|
||||
ref($dbh) || &error(&text('euserdbacl', $dbh));
|
||||
if ($proto eq "mysql" || $proto eq "postgresql") {
|
||||
@@ -3465,7 +3468,7 @@ if (!$_[3] && &foreign_check("acl")) {
|
||||
|
||||
my $userdb = &get_userdb_string();
|
||||
my $foundindb = 0;
|
||||
if ($userdb) {
|
||||
if ($userdb && ($u ne $base_remote_user || $remote_user_proto)) {
|
||||
# Look for this user in the user/group DB
|
||||
my ($dbh, $proto) = &connect_userdb($userdb);
|
||||
ref($dbh) || &error(&text('euserdbacl', $dbh));
|
||||
@@ -3849,6 +3852,9 @@ my $u = $ENV{'BASE_REMOTE_USER'} || $ENV{'REMOTE_USER'};
|
||||
$base_remote_user = $u;
|
||||
$remote_user = $ENV{'REMOTE_USER'};
|
||||
|
||||
# Work out if user is definitely in the DB
|
||||
$remote_user_proto = $ENV{"REMOTE_USER_PROTO"};
|
||||
|
||||
if ($module_name) {
|
||||
# Find and load the configuration file for this module
|
||||
my (@ruinfo, $rgroup);
|
||||
@@ -8946,6 +8952,7 @@ Returns the URL-style string for connecting to the users and groups database
|
||||
=cut
|
||||
sub get_userdb_string
|
||||
{
|
||||
return undef if ($main::no_miniserv_userdb);
|
||||
my %miniserv;
|
||||
&get_miniserv_config(\%miniserv);
|
||||
return $miniserv{'userdb'};
|
||||
@@ -8971,6 +8978,7 @@ if ($proto eq "mysql") {
|
||||
$cstr .= ";port=$port" if ($port);
|
||||
my $dbh = $drh->connect($cstr, $user, $pass, { });
|
||||
$dbh || return &text('sql_emysqlconnect', $drh->errstr);
|
||||
$dbh->{'AutoCommit'} = 1;
|
||||
return wantarray ? ($dbh, $proto) : $dbh;
|
||||
}
|
||||
elsif ($proto eq "postgresql") {
|
||||
@@ -8982,6 +8990,7 @@ elsif ($proto eq "postgresql") {
|
||||
$cstr .= ";port=$port" if ($port);
|
||||
my $dbh = $drh->connect($cstr, $user, $pass);
|
||||
$dbh || return &text('sql_epostgresqlconnect', $drh->errstr);
|
||||
$dbh->{'AutoCommit'} = 1;
|
||||
return wantarray ? ($dbh, $proto) : $dbh;
|
||||
}
|
||||
elsif ($proto eq "ldap") {
|
||||
@@ -9003,6 +9012,7 @@ sub disconnect_userdb
|
||||
my ($str, $h) = @_;
|
||||
if ($str =~ /^(mysql|postgresql):/) {
|
||||
# DBI disconnnect
|
||||
$h->commit();
|
||||
$h->disconnect();
|
||||
}
|
||||
elsif ($str =~ /^ldap:/) {
|
||||
|
||||
Reference in New Issue
Block a user