1#!/usr/local/bin/perl 2# Update the password for root, both in MySQL and Webmin 3 4require './mysql-lib.pl'; 5&ReadParse(); 6&error_setup($text{'root_err'}); 7$access{'perms'} == 1 || &error($text{'perms_ecannot'}); 8 9# Validate inputs 10$in{'newpass1'} || &error($text{'root_epass1'}); 11$in{'newpass1'} eq $in{'newpass2'} || &error($text{'root_epass2'}); 12$in{'newpass1'} =~ /\\/ && &error($text{'user_eslash'}); 13 14# Update MySQL 15$user = $mysql_login || "root"; 16$d = &execute_sql_safe($master_db, 17 "select host from user where user = ?", $user); 18@hosts = map { $_->[0] } @{$d->{'data'}}; 19foreach my $host (@hosts) { 20 $sql = get_change_pass_sql($in{'newpass1'}, $user, $host); 21 eval { 22 local $main::error_must_die = 1; 23 &execute_sql_logged($master_db, $sql); 24 }; 25 if ($@) { 26 # Try again with the new password 27 local $config{'pass'} = $in{'newpass1'}; 28 &execute_sql_logged($master_db, $sql); 29 } 30 } 31 32# Update webmin 33$config{'pass'} = $in{'newpass1'}; 34&lock_file($module_config_file); 35&save_module_config(); 36&unlock_file($module_config_file); 37 38&webmin_log("root"); 39&redirect(""); 40