Skip to content

Commit

Permalink
Item9211: Add some limits on the number of reported file errors. If
Browse files Browse the repository at this point in the history
excessive errors, identify that the RCS expert permissions might be set
incorrectly.  Also documented the checkTreePerms function and ran perl
Tidy

git-svn-id: http://svn.foswiki.org/trunk@8020 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
GeorgeClark authored and GeorgeClark committed Jul 4, 2010
1 parent d4763d6 commit c47c2be
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 7 deletions.
55 changes: 52 additions & 3 deletions core/lib/Foswiki/Configure/Checker.pm
Expand Up @@ -11,7 +11,7 @@ our @ISA = ('Foswiki::Configure::UI');
use File::Spec ();
use CGI ();

=begin
=begin TML
---+++ ObjectMethod check($value, $root) -> 'html'
* $value - **UNDOCUMENTED**
* $root - **UNDOCUMENTED**
Expand Down Expand Up @@ -89,11 +89,56 @@ sub guessMajorDir {
return $msg;
}

=begin TML
---+++ ObjectMethod checkTreePerms($path, $perms, $filter) -> 'html'
Called by a Checker to perform
a recursive check of the specified path. The recursive check
is limited to the configured "PathCheckLimit". This prevents excessive
delay on installations with large data or pub directories. The
count of files checked is available in the class method $this->{fileCount}
$perms is a string of permissions to check:
Basic checks:
* r - File or directory is readable
* w - File or directory is writable
* x - File is executable.
All failures of the basic checks are reported back to the caller.
Enhanced checks:
* d - Directory permission matches the permissions in {RCS}{dirPermission}
* f - File permission matches the permission in {RCS}{filePermission} (FUTURE)
If > 10 enhanced errors are encountered, reporting is stopped to avoid excessive
errors to the administrator. The count of enhanced errors is reported back
to the caller by the object variable: $this->{fileErrors}
In addition to the basic and enhanced checks specified in the $perms string,
Directories are always checked to determine if they have the 'x' permission.
$filter is a regular expression. Files matching the supplied regex if present
will not be checked. This is used to skip rcs,v or .txt files because they
have different permission requirements.
Note that the enhanced checks are important especially on hosted sites. In some
environments, the Foswiki perl scripts run under a different user/group than
the web server. Basic checks will pass, but the server may still be unable
to access the file. The enhanced checks will detect this condition.
Callers of this checker should reset $this->{fileCount} and $this->{fileErrors}
to zero before calling this routine.
=cut

sub checkTreePerms {
my ( $this, $path, $perms, $filter ) = @_;

return '' if ( defined($filter) && $path =~ $filter && !-d $path );

$this->{fileErrors} = 0 unless ( defined $this->{fileErrors} );

#let's ignore Subversion directories
return '' if ( $path =~ /^_svn$/ );
return '' if ( $path =~ /^\.svn$/ );
Expand All @@ -114,7 +159,9 @@ sub checkTreePerms {
my $operm = sprintf( '%04o', $Foswiki::cfg{RCS}{dirPermission} );
$permErrs .=
"$path - directory permission mismatch $omode should be $operm"
. CGI::br();
. CGI::br()
unless ( $this->{fileErrors} > 10 );
$this->{fileErrors}++;
}
}

Expand Down Expand Up @@ -233,7 +280,9 @@ sub checkGnuProgram {
#$diffOut =~ /(\d+(\.\d+)+)/;
#$mess = "($prog is version $1).";
}
} elsif ($Foswiki::cfg{OS} eq 'WINDOWS') {
}
elsif ( $Foswiki::cfg{OS} eq 'WINDOWS' ) {

#real windows - using GnuWin32 tools
}

Expand Down
17 changes: 15 additions & 2 deletions core/lib/Foswiki/Configure/Checkers/DataDir.pm
Expand Up @@ -10,7 +10,9 @@ our @ISA = ('Foswiki::Configure::Checker');
sub check {
my $this = shift;

$this->{filecount} = 0;
$this->{filecount} = 0;
$this->{fileErrors} = 0;

my $e = $this->guessMajorDir( 'DataDir', 'data' );

# Don't check directories against {RCS} permissions on Windows
Expand All @@ -34,7 +36,18 @@ sub check {
$e2 .= $this->checkTreePerms( $Foswiki::cfg{DataDir}, "r", qr/\.txt$/ );
$e .= $this->WARN($e2) if $e2;

$this->{filecount} = 0;
if ( $this->{fileErrors} > 10 ) {
$e .= $this->ERROR(<<ERRMSG)
File/Directory permission mismatch reporting stopped at 10 warnings.
$this->{fileErrors} directories or files have mismatched permissions.
Verify that the Store expert settings of {RCS}{filePermission} and {RCS}{dirPermission}
are set correctly for your environment and correct file system permissions if necessary.
ERRMSG
}

$this->{filecount} = 0;
$this->{fileErrors} = 0;

return $e;
}

Expand Down
16 changes: 14 additions & 2 deletions core/lib/Foswiki/Configure/Checkers/PubDir.pm
Expand Up @@ -10,7 +10,8 @@ our @ISA = ('Foswiki::Configure::Checker');
sub check {
my $this = shift;

$this->{filecount} = 0;
$this->{filecount} = 0;
$this->{fileErrors} = 0;
my $e = $this->guessMajorDir( 'PubDir', 'pub' );
$e .= $this->warnAboutWindowsBackSlashes( $Foswiki::cfg{PubDir} );

Expand All @@ -25,14 +26,25 @@ sub check {
$this->checkTreePerms( $Foswiki::cfg{PubDir}, 'rw' . $dirchk, qr/,v$/ );
$e .= $this->WARN($e2) if $e2;

if ( $this->{fileErrors} > 10 ) {
$e .= $this->ERROR(<<ERRMSG)
File/Directory permission mismatch reporting stopped at 10 warnings.
$this->{fileErrors} directories or files have mismatched permissions.
Verify that the Store expert settings of {RCS}{filePermission} and {RCS}{dirPermission}
are set correctly for your environment and correct file system permissions if necessary.
ERRMSG
}

$e .=
( $this->{filecount} >= $Foswiki::cfg{PathCheckLimit} )
? $this->NOTE(
"File checking limit $Foswiki::cfg{PathCheckLimit} reached, checking stopped - see expert options"
)
: $this->NOTE("File count - $this->{filecount} ");

$this->{filecount} = 0;
$this->{filecount} = 0;
$this->{fileErrors} = 0;

return $e;
}

Expand Down

0 comments on commit c47c2be

Please sign in to comment.