%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
$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();
$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();
}
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 ".
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);
$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);
=cut
sub error
{
+$main::no_miniserv_userdb = 1;
my $msg = join("", @_);
$msg =~ s/<[^>]*>//g;
if (!$main::error_must_die) {
=cut
sub popup_error
{
+$main::no_miniserv_userdb = 1;
&load_theme_library();
if ($main::error_must_die) {
die @_;
# 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") {
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));
$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);
=cut
sub get_userdb_string
{
+return undef if ($main::no_miniserv_userdb);
my %miniserv;
&get_miniserv_config(\%miniserv);
return $miniserv{'userdb'};
$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") {
$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") {
my ($str, $h) = @_;
if ($str =~ /^(mysql|postgresql):/) {
# DBI disconnnect
+ $h->commit();
$h->disconnect();
}
elsif ($str =~ /^ldap:/) {