From: mkanat%bugzilla.org <> Date: Mon, 14 Dec 2009 23:13:26 +0000 (+0000) Subject: Bug 524603: Allow a non-root jobqueue.pl to write to data/mailer.testfile (for the... X-Git-Tag: bugzilla-3.4.5~20 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ff776acd37cec9d5a01862975cbe5d286806d335;p=thirdparty%2Fbugzilla.git 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 --- diff --git a/Bugzilla/Install/Filesystem.pm b/Bugzilla/Install/Filesystem.pm index 17129b2abb..7ea36b2482 100644 --- a/Bugzilla/Install/Filesystem.pm +++ b/Bugzilla/Install/Filesystem.pm @@ -35,6 +35,7 @@ use Bugzilla::Util; use File::Find; use File::Path; use File::Basename; +use File::Copy qw(move); use IO::File; use POSIX (); @@ -126,7 +127,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 }, ); # Directories that we want to set the perms on, but not @@ -207,7 +207,14 @@ sub FILESYSTEM { # The name of each file, pointing at its default permissions and # default contents. - my %create_files = (); + my %create_files = ( + # 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 # we create. Also, we create placeholders for standard stylesheets @@ -342,6 +349,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}}); @@ -432,6 +446,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) = @_;