From 6f9ef526d76a1586aa3f194a13c62f018a47b1e3 Mon Sep 17 00:00:00 2001 From: "mkanat%bugzilla.org" <> Date: Mon, 14 Dec 2009 23:12:04 +0000 Subject: Bug 524603: Allow a non-root jobqueue.pl to write to data/mailer.testfile (for the "Test" mail_delivery_method) Patch by Max Kanat-Alexander r=LpSolit, a=LpSolit --- Bugzilla/Install/Filesystem.pm | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/Bugzilla/Install/Filesystem.pm b/Bugzilla/Install/Filesystem.pm index 12c0bc222..63cff1e21 100644 --- a/Bugzilla/Install/Filesystem.pm +++ b/Bugzilla/Install/Filesystem.pm @@ -36,6 +36,7 @@ use Bugzilla::Util; use File::Find; use File::Path; use File::Basename; +use File::Copy qw(move); use IO::File; use POSIX (); @@ -129,7 +130,6 @@ sub FILESYSTEM { 'docs/*/README.docs' => { perms => $owner_readable }, "$datadir/bugzilla-update.xml" => { perms => $ws_writeable }, "$datadir/params" => { perms => $ws_writeable }, - "$datadir/mailer.testfile" => { perms => $ws_writeable }, "$extensionsdir/create.pl" => { perms => $owner_executable }, ); @@ -212,6 +212,12 @@ sub FILESYSTEM { my %create_files = ( "$datadir/extensions/additional" => { perms => $ws_readable, contents => '' }, + # We create this file so that it always has the right owner + # and permissions. Otherwise, the webserver creates it as + # owned by itself, which can cause problems if jobqueue.pl + # or something else is not running as the webserver or root. + "$datadir/mailer.testfile" => { perms => $ws_writeable, + contents => '' }, ); # Each standard stylesheet has an associated custom stylesheet that @@ -347,6 +353,13 @@ sub update_filesystem { } } + # Move the testfile if we can't write to it, so that we can re-create + # it with the correct permissions below. + if (!-w "$datadir/mailer.testfile") { + _rename_file("$datadir/mailer.testfile", + "$datadir/mailer.testfile.old"); + } + _create_files(%files); if ($params->{index_html}) { _create_files(%{$fs->{index_html}}); @@ -442,6 +455,17 @@ sub create_htaccess { } } +sub _rename_file { + my ($from, $to) = @_; + print "Renaming $from to $to...\n"; + if (-e $to) { + warn "$to already exists, not moving\n"; + } + else { + move($from, $to) or warn $!; + } +} + # A helper for the above functions. sub _create_files { my (%files) = @_; -- cgit v1.2.3-24-g4f1b