From 43e088d22aaef330b1f9ea06171af2cbe247d51d Mon Sep 17 00:00:00 2001 From: "bbaetz%student.usyd.edu.au" Date: Sun, 7 Apr 2002 03:56:46 +0000 Subject: [PATCH] Bug 134575 - some scripts trying to make world writable directories r=justdave, gerv --- webtools/bugzilla/defparams.pl | 4 +--- webtools/bugzilla/globals.pl | 16 +++++++++++++--- webtools/bugzilla/importxml.pl | 6 +----- webtools/bugzilla/move.pl | 6 +----- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/webtools/bugzilla/defparams.pl b/webtools/bugzilla/defparams.pl index eddf50942457..d88938f3c818 100644 --- a/webtools/bugzilla/defparams.pl +++ b/webtools/bugzilla/defparams.pl @@ -64,8 +64,6 @@ sub WriteParams { delete $::param{$item}; } } - mkdir("data", 0777); - chmod 0777, "data"; my $tmpname = "data/params.$$"; open(FID, ">$tmpname") || die "Can't create $tmpname"; my $v = $::param{'version'}; @@ -76,7 +74,7 @@ sub WriteParams { print FID "1;\n"; close FID; rename $tmpname, "data/params" || die "Can't rename $tmpname to data/params"; - chmod 0666, "data/params"; + ChmodDataFile('data/params', 0666); } diff --git a/webtools/bugzilla/globals.pl b/webtools/bugzilla/globals.pl index cb3612671c5e..249945ad97a9 100644 --- a/webtools/bugzilla/globals.pl +++ b/webtools/bugzilla/globals.pl @@ -117,6 +117,18 @@ $::superusergroupset = "9223372036854775807"; #} #$::SIG{__DIE__} = \&die_with_dignity; +# Some files in the data directory must be world readable iff we don't have +# a webserver group. Call this function to do this. +sub ChmodDataFile($$) { + my ($file, $mask) = @_; + my $perm = 0770; + if ((stat('data'))[2] & 0002) { + $perm = 0777; + } + $perm = $perm & $mask; + chmod $perm,$file; +} + sub ConnectToDatabase { my ($useshadow) = (@_); if (!defined $::db) { @@ -565,8 +577,6 @@ sub GenerateVersionTable { my @list = sort { uc($a) cmp uc($b)} keys(%::versions); @::legal_product = @list; - mkdir("data", 0777); - chmod 0777, "data"; my $tmpname = "data/versioncache.$$"; open(FID, ">$tmpname") || die "Can't create $tmpname"; @@ -636,7 +646,7 @@ sub GenerateVersionTable { print FID "1;\n"; close FID; rename $tmpname, "data/versioncache" || die "Can't rename $tmpname to versioncache"; - chmod 0666, "data/versioncache"; + ChmodDataFile('data/versioncache', 0666); } diff --git a/webtools/bugzilla/importxml.pl b/webtools/bugzilla/importxml.pl index f2ed77d5c273..964d29a6f043 100755 --- a/webtools/bugzilla/importxml.pl +++ b/webtools/bugzilla/importxml.pl @@ -135,11 +135,7 @@ sub Log { sub Lock { if ($::lockcount <= 0) { $::lockcount = 0; - if (!open(LOCKFID, ">>data/maillock")) { - mkdir "data", 0777; - chmod 0777, "data"; - open(LOCKFID, ">>data/maillock") || die "Can't open lockfile."; - } + open(LOCKFID, ">>data/maillock") || die "Can't open data/maillock: $!"; my $val = flock(LOCKFID,2); if (!$val) { # '2' is magic 'exclusive lock' const. print "Content-type: text/html\n\n"; diff --git a/webtools/bugzilla/move.pl b/webtools/bugzilla/move.pl index f38644358341..b20ee528ba72 100755 --- a/webtools/bugzilla/move.pl +++ b/webtools/bugzilla/move.pl @@ -50,11 +50,7 @@ sub Log { sub Lock { if ($::lockcount <= 0) { $::lockcount = 0; - if (!open(LOCKFID, ">>data/maillock")) { - mkdir "data", 0777; - chmod 0777, "data"; - open(LOCKFID, ">>data/maillock") || die "Can't open lockfile."; - } + open(LOCKFID, ">>data/maillock") || die "Can't open data/maillock: $!"; my $val = flock(LOCKFID,2); if (!$val) { # '2' is magic 'exclusive lock' const. print "Content-type: text/html\n\n";