mirror of
https://github.com/webmin/webmin.git
synced 2026-10-27 21:50:40 +00:00
If MySQL backups are being done as a non-root user, also run pre and post backup commands as that user
This commit is contained in:
@@ -151,7 +151,8 @@ if (!$in{'save'}) {
|
||||
@dbs = $in{'all'} ? @alldbs : ( $in{'db'} );
|
||||
if ($cmode == 1) {
|
||||
# Run and check before-backup command (for all DBs)
|
||||
$bok = &execute_before(undef, STDOUT, 1, $in{'file'}, undef);
|
||||
$bok = &execute_before(undef, STDOUT, 1, $in{'file'}, undef,
|
||||
$access{'buser'});
|
||||
if (!$bok) {
|
||||
print "$main::whatfailed : ",
|
||||
$text{'backup_ebefore'},"<p>\n";
|
||||
@@ -195,7 +196,8 @@ if (!$in{'save'}) {
|
||||
if ($cron && $cmode == 0) {
|
||||
# Run and check before-backup command (for one DB)
|
||||
$bok = &execute_before($db, STDOUT, 1, $file,
|
||||
$in{'all'} ? undef : $db);
|
||||
$in{'all'} ? undef : $db,
|
||||
$access{'buser'});
|
||||
if (!$bok) {
|
||||
print $text{'backup_ebefore'},"<p>\n";
|
||||
next;
|
||||
@@ -216,7 +218,8 @@ if (!$in{'save'}) {
|
||||
print &text('backup_done', "<tt>$db</tt>",
|
||||
"<tt>$file</tt>", int($st[7])),"<p>\n";
|
||||
}
|
||||
&execute_after($db, STDOUT, 1, $file, $in{'all'} ? undef : $db)
|
||||
&execute_after($db, STDOUT, 1, $file, $in{'all'} ? undef : $db,
|
||||
$access{'buser'})
|
||||
if ($cron && $cmode == 0);
|
||||
|
||||
if ($in{'dest'}) {
|
||||
@@ -229,7 +232,8 @@ if (!$in{'save'}) {
|
||||
&unlink_file($file);
|
||||
}
|
||||
}
|
||||
&execute_after(undef, STDOUT, 1, $in{'file'}, undef) if ($cmode == 1);
|
||||
&execute_after(undef, STDOUT, 1, $in{'file'}, undef,
|
||||
$access{'buser'}) if ($cmode == 1);
|
||||
donebackup:
|
||||
}
|
||||
|
||||
|
||||
@@ -1014,16 +1014,18 @@ if ($config{'webmin_subs'}) {
|
||||
return $rv;
|
||||
}
|
||||
|
||||
# execute_before(db, handle, escape, path, db-for-config)
|
||||
# execute_before(db, handle, escape, path, db-for-config, [&as-user])
|
||||
# Executes the before-backup command for some DB, and sends output to the
|
||||
# given file handle. Returns 1 if the command succeeds, or 0 on failure
|
||||
sub execute_before
|
||||
{
|
||||
my ($db, $h, $escape, $path, $db) = @_;
|
||||
my ($db, $h, $escape, $path, $db, $asuser) = @_;
|
||||
my $cmd = $config{'backup_before_'.$db};
|
||||
if ($cmd) {
|
||||
$ENV{'BACKUP_FILE'} = $path;
|
||||
my $out;
|
||||
$cmd = &command_as_user($asuser, 0, $cmd)
|
||||
if ($asuser && $asuser ne "root");
|
||||
my $rv = &execute_command($cmd, undef, \$out, \$out);
|
||||
if ($h && $out) {
|
||||
print $h $escape ? "<pre>".&html_escape($out)."</pre>" : $out;
|
||||
@@ -1033,16 +1035,18 @@ if ($cmd) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
# execute_after(db, handle, escape, path, db-for-config)
|
||||
# execute_after(db, handle, escape, path, db-for-config, [&as-user])
|
||||
# Executes the after-backup command for some DB, and sends output to the
|
||||
# given file handle. Returns 1 if the command succeeds, or 0 on failure
|
||||
sub execute_after
|
||||
{
|
||||
my ($db, $h, $escape, $path, $db) = @_;
|
||||
my ($db, $h, $escape, $path, $db, $asuser) = @_;
|
||||
my $cmd = $config{'backup_after_'.$_[4]};
|
||||
if ($cmd) {
|
||||
$ENV{'BACKUP_FILE'} = $path;
|
||||
my $out;
|
||||
$cmd = &command_as_user($asuser, 0, $cmd)
|
||||
if ($asuser && $asuser ne "root");
|
||||
my $rv = &execute_command($cmd, undef, \$out, \$out);
|
||||
if ($h && $out) {
|
||||
print $h $escape ? "<pre>".&html_escape($out)."</pre>" : $out;
|
||||
|
||||
Reference in New Issue
Block a user