mirror of
https://github.com/webmin/webmin.git
synced 2026-03-20 08:40:24 +00:00
Add support for account locking in MariaDB
This commit is contained in:
@@ -64,9 +64,14 @@ my $unixsocket = $plugin && $u->[$plugin] eq 'unix_socket';
|
||||
my $nopass = ((!defined($epassfield1) || !$u->[$epassfield1]) &&
|
||||
(!defined($epassfield2) || !$u->[$epassfield2]));
|
||||
my $hashpass = $u->[$epassfield1] || $u->[$epassfield2];
|
||||
my $lock_supported = exists($fieldmap{'account_locked'}) &&
|
||||
defined($u->[$fieldmap{'account_locked'}]);
|
||||
my $lock_supported = &get_account_lock_support();
|
||||
# Old way for checking account locking
|
||||
my $locked = $u->[$fieldmap{'account_locked'}] eq 'Y';
|
||||
# New account locking check
|
||||
if (!exists($fieldmap{'account_locked'}) ||
|
||||
!defined($u->[$fieldmap{'account_locked'}])) {
|
||||
$locked = &get_account_lock_status($u->[1], $u->[0]);
|
||||
}
|
||||
print &ui_table_row($text{'user_pass'},
|
||||
&ui_radio("mysqlpass_mode", $in{'new'} ? 0 :
|
||||
$lock_supported && $locked ? 4 :
|
||||
|
||||
@@ -1730,6 +1730,27 @@ my $conf = &get_mysql_config();
|
||||
return &unique(map { $_->{'file'} } @$conf);
|
||||
}
|
||||
|
||||
# get_account_lock_status(user, host)
|
||||
# Returns the account lock status of a user
|
||||
sub get_account_lock_status
|
||||
{
|
||||
my ($user, $host) = @_;
|
||||
my $sql = "show create user '".$user."'\@'".$host."'";
|
||||
my $rv = &execute_sql($master_db, $sql);
|
||||
return undef if (!ref($rv) || !@{$rv->{'data'}});
|
||||
return $rv->{'data'}->[0][0] =~ /account\s+lock/i ? 1 : 0;
|
||||
}
|
||||
|
||||
# get_account_lock_support()
|
||||
# Returns 1 if the MySQL/MariaDB server supports account locking
|
||||
sub get_account_lock_support
|
||||
{
|
||||
my ($ver, $variant) = &get_remote_mysql_variant();
|
||||
return
|
||||
$variant eq "mariadb" && &compare_version_numbers($ver, "10.4.2") >= 0 ||
|
||||
$variant eq "mysql" && &compare_version_numbers($ver, "8.0") >= 0;
|
||||
}
|
||||
|
||||
# get_plugin_sql(version, variant, plainpass, plugin)
|
||||
# Get the right query for setting user password with plugin
|
||||
sub get_plugin_sql
|
||||
@@ -1737,8 +1758,7 @@ sub get_plugin_sql
|
||||
my ($ver, $variant, $plainpass, $plugin) = @_;
|
||||
my $pass = &escapestr($plainpass);
|
||||
# Has account locking support?
|
||||
my $suplock = $variant eq "mysql" && &compare_version_numbers($ver, "8.0") >= 0 ||
|
||||
$variant eq "mariadb" && &compare_version_numbers($ver, "10.4.2") >= 0;
|
||||
my $suplock = &get_account_lock_support();
|
||||
my $lockcurr;
|
||||
if ($suplock) {
|
||||
$lockcurr = !defined($plainpass);
|
||||
|
||||
Reference in New Issue
Block a user