2008-05-17 06:18:56 +00:00
|
|
|
#!/usr/local/bin/perl
|
|
|
|
# Update the password for root, both in MySQL and Webmin
|
|
|
|
|
|
|
|
require './mysql-lib.pl';
|
|
|
|
&ReadParse();
|
|
|
|
&error_setup($text{'root_err'});
|
|
|
|
$access{'perms'} == 1 || &error($text{'perms_ecannot'});
|
|
|
|
|
|
|
|
# Validate inputs
|
|
|
|
$in{'newpass1'} || &error($text{'root_epass1'});
|
|
|
|
$in{'newpass1'} eq $in{'newpass2'} || &error($text{'root_epass2'});
|
2016-12-04 10:25:48 -08:00
|
|
|
$in{'newpass1'} =~ /\\/ && &error($text{'user_eslash'});
|
2008-05-17 06:18:56 +00:00
|
|
|
|
|
|
|
# Update MySQL
|
2008-05-20 18:05:34 +00:00
|
|
|
$user = $mysql_login || "root";
|
2015-12-28 17:04:35 -08:00
|
|
|
$d = &execute_sql_safe($master_db,
|
|
|
|
"select host from user where user = ?", $user);
|
|
|
|
@hosts = map { $_->[0] } @{$d->{'data'}};
|
|
|
|
foreach my $host (@hosts) {
|
2020-09-23 16:55:52 +03:00
|
|
|
$sql = get_change_pass_sql($in{'newpass1'}, $user, $host);
|
2015-12-28 17:04:35 -08:00
|
|
|
eval {
|
|
|
|
local $main::error_must_die = 1;
|
|
|
|
&execute_sql_logged($master_db, $sql);
|
|
|
|
};
|
|
|
|
if ($@) {
|
2016-06-04 16:46:28 -07:00
|
|
|
# Try again with the new password
|
2015-12-28 17:04:35 -08:00
|
|
|
local $config{'pass'} = $in{'newpass1'};
|
|
|
|
&execute_sql_logged($master_db, $sql);
|
|
|
|
}
|
|
|
|
}
|
2008-05-17 06:18:56 +00:00
|
|
|
|
|
|
|
# Update webmin
|
|
|
|
$config{'pass'} = $in{'newpass1'};
|
|
|
|
&lock_file($module_config_file);
|
|
|
|
&save_module_config();
|
|
|
|
&unlock_file($module_config_file);
|
|
|
|
|
|
|
|
&webmin_log("root");
|
|
|
|
&redirect("");
|