---- Changes since 1.470 ----
Added code to detect a password in /root/.my.cnf which overrides the MYSQL_PWD variable, and thus causes login failures.
MySQL stored procedures are now included in backups, where supported.
+---- Changes since 1.480 ----
+Restores and imports from local files are now run as the Unix user configured for backups, rather than root.
close(SQL);
print "<pre>";
-($ex, $out) = &execute_sql_file($in{'db'}, $file);
+($ex, $out) = &execute_sql_file($in{'db'}, $file,
+ undef, undef, $access{'buser'});
print &html_escape($out);
$got++ if ($out =~ /\S/);
print "<i>$text{'exec_noout'}</i>\n" if (!$got);
print &text('import_fileout', "<tt>$in{'file'}</tt>"),"<p>\n";
}
-# Execute the import command ..
+# Build the import command
if ($in{'table'}) {
$nfile = &transname("$in{'table'}.txt");
- system("cp $file $nfile");
+ ©_source_dest($file, $nfile);
unlink($file) if ($need_unlink);
$file = $nfile;
$need_unlink = 1;
elsif ($in{'format'} == 1) {
$format = "--fields-terminated-by ,";
}
+
+# Execute the import command ..
print "<pre>";
&additional_log('exec', undef, "$config{'mysqlimport'} $authstr $delete $ignore $format $in{'db'} $file");
-&open_execute_command(SQL, "$config{'mysqlimport'} $authstr $delete $ignore $format ".quotemeta($in{'db'})." $file 2>&1", 1, 0);
+$cmd = "$config{'mysqlimport'} $authstr $delete $ignore $format ".quotemeta($in{'db'})." ".quotemeta($file);
+if ($access{'buser'} && $access{'buser'} ne 'root' && $< == 0) {
+ $cmd = &command_as_user($access{'buser'}, 0, $cmd);
+ }
+&open_execute_command(SQL, $cmd, 2, 0);
while(<SQL>) {
print &html_escape($_);
$got++ if (/\S/);
acl_bnone=Disallow backups
acl_indexes=Can view and manage indexes?
acl_views=Can view and manage views?
+acl_files=Can execute SQL from local files?
log_start=Started MySQL server
log_stop=Stopped MySQL server
return @sql;
}
-# execute_sql_file(database, file, [user, pass])
+# execute_sql_file(database, file, [user, pass], [unix-user])
# Executes some file of SQL commands, and returns the exit status and output
sub execute_sql_file
{
local $authstr = &make_authstr($user, $pass);
local $cmd = "$config{'mysql'} $authstr -t ".quotemeta($db)." <".quotemeta($file);
-r $file || return (1, "$file does not exist");
+if ($_[4] && $_[4] ne 'root' && $< == 0) {
+ # Restoring as a Unix user
+ $cmd = &command_as_user($_[4], 0, $cmd);
+ }
local $out = &backquote_logged("$cmd 2>&1");
local @rv = ($?, $? ? $out || "$cmd failed" : $out);
&make_authstr(); # Put back old password environment variable