]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 524603: Allow a non-root jobqueue.pl to write to data/mailer.testfile (for the...
authormkanat%bugzilla.org <>
Mon, 14 Dec 2009 23:13:26 +0000 (23:13 +0000)
committermkanat%bugzilla.org <>
Mon, 14 Dec 2009 23:13:26 +0000 (23:13 +0000)
Patch by Max Kanat-Alexander <mkanat@bugzilla.org> r=LpSolit, a=LpSolit

Bugzilla/Install/Filesystem.pm

index 17129b2abb40914281c5ff7e205db97701624b76..7ea36b24824aa6388a7289d926aa968152756f41 100644 (file)
@@ -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) = @_;