Skip to content

Commit

Permalink
Item14205: Merge branch 'Item14205' into Release02x01
Browse files Browse the repository at this point in the history
Resolves several issue around autoconfigure of email
 - CA Certificates were not being picked up for validation
 - Wizards were not useable from CLI
 - Wizards could not capture STDERR under fcgi
 - STARTTLS connections were always failing on latest IO::Socket::SSL
 - Checkers for CA files were failing with invalid characteres in
   filename.
 - The CA Certificates wizard was not looking for file system locations

It integrates a new STDERR / STDOUT capture module written for the
OO Foswiki branch. It is simple, but does a better job of releasing the
capture at end.
  • Loading branch information
gac410 committed Nov 14, 2016
2 parents 9a11a49 + 27821cd commit 8ff14e4
Show file tree
Hide file tree
Showing 12 changed files with 431 additions and 121 deletions.
11 changes: 9 additions & 2 deletions FastCGIEngineContrib/lib/Foswiki/Engine/FastCGI.pm
Expand Up @@ -65,7 +65,13 @@ sub run {
or die "Failed to create FastCGI socket: $!";
}
$args ||= {};
my $r = FCGI::Request( \*STDIN, \*STDOUT, \*STDERR, \%ENV, $sock,

# Prepare output handles for FastCGI.
$this->{$_} = IO::Handle->new foreach qw(fhIN fhOUT fhERR);
# This is a little trick to make all `print STDERR' clauses send their
# output to the log file. May not work for spawned processes.
STDERR->fdopen($this->{fhERR}->fileno, "w");
my $r = FCGI::Request( $this->{fhIN}, $this->{fhOUT}, $this->{fhERR}, \%ENV, $sock,
&FCGI::FAIL_ACCEPT_ON_INTR );
my $manager;

Expand Down Expand Up @@ -187,7 +193,8 @@ sub preparePath {
}

sub write {
syswrite STDOUT, $_[1];
my $this = shift;
syswrite $this->{fhOUT}, $_[0];
}

sub closeSocket {
Expand Down
7 changes: 2 additions & 5 deletions core/lib/Foswiki.spec
Expand Up @@ -1906,17 +1906,15 @@ $Foswiki::cfg{SMTP}{SENDERHOST} = '';
# This verifies the identity of the server to which mail is sent.
$Foswiki::cfg{Email}{SSLVerifyServer} = $FALSE;

# **PATH EXPERT LABEL="Certificate Authorities Filename" \
# **PATH LABEL="Certificate Authorities Filename" \
# FEEDBACK="icon='ui-icon-shuffle';label='Guess certificate locations'; wizard='SSLCertificates'; method='guess_locations'"\
# DISPLAY_IF="{EnableEmail} && /^Net::SMTP/.test({Email}{MailMethod}) && {Email}{SSLVerifyServer}"**
# Specify the file used to verify the server certificate trust chain.
# This is the list of root Certificate authorities that you trust to issue
# certificates. You do not need to include intermediate CAs in this file.
# If you do not specify this or {Email}{SSLCaPath}, system defaults will
# be used.
$Foswiki::cfg{Email}{SSLCaFile} = '';

# **PATH LABEL="Certificate Authorities Directory" EXPERT \
# **PATH LABEL="Certificate Authorities Directory" \
# FEEDBACK="icon='ui-icon-shuffle';label='Guess certificate locations'; wizard='SSLCertificates'; method='guess_locations'"\
# FEEDBACK='label="Validate Contents"; wizard="SSLCertificates"; method="validate";\
# title="Examines every file in the directory and verifies \
Expand All @@ -1925,7 +1923,6 @@ $Foswiki::cfg{Email}{SSLCaFile} = '';
# Specify the directory used to verify the server certificate trust chain.
# This is the list of root Certificate authorities that you trust to issue
# certificates. You do not need to include intermediate CAs in this directory.
# If you do not specify this or {Email}{SSLCaFile}, system defaults will be used.
# Refer to the openssl documentation for the format of this directory.
# Note that it can also contain Certificate Revocation Lists.
$Foswiki::cfg{Email}{SSLCaPath} = '';
Expand Down
136 changes: 136 additions & 0 deletions core/lib/Foswiki/Aux/MuteOut.pm
@@ -0,0 +1,136 @@
# See bottom of file for license and copyright information

package Foswiki::Aux::MuteOut;
use strict;
use warnings;

=begin TML
---+!! Package Foswiki::Aux::MuteOut
Very simplistic redirection of STDERR/STDOUT.
---++ SYNOPSIS
Simply avoid any output:
<verbatim>
use Foswiki::Aux::MuteOut;
sub proc {
my ($dir) = @_;
my $rc = system "ls -la $dir";
print STDERR "RC=", $rc;
}
my $mute = Foswiki::Aux::MuteOut->new;
# Nothing will be displayed by proc()
$mute->exec(\&proc, "/etc");
</verbatim>
Capture output into files:
<verbatim>
my $capture = Foswiki::Aux::MuteOut->new(
outFile => 'stdout.txt',
errFile => 'stderr.txt',
);
# The output will end up in corresponding files.
$capture->exec(\&proc, "/etc");
</verbatim>
---++ DESCRIPTION
Redirections are restored when the object destroyed.
=cut

sub new {
my $class = shift;
my %params = @_;

$class = ref($class) || $class;

my ( $oldOut, $oldErr, $rc );

my $outFile = $params{outFile} // File::Spec->devnull;
my $errFile = $params{errFile} // File::Spec->devnull;

unless ( open $oldOut, ">&", STDOUT ) {
Foswiki::Aux::Dependencies::_msg( "Cannot dup STDOUT: " . $! );
return undef;
}
unless ( open $oldErr, ">&", STDERR ) {
Foswiki::Aux::Dependencies::_msg( "Cannot dup STDERR: " . $! );
return undef;
}
unless ( open STDOUT, ">", $outFile ) {
Foswiki::Aux::Dependencies::_msg( "Failed to redirect STDOUT: " . $! );
}
unless ( open STDERR, ">", $errFile ) {
Foswiki::Aux::Dependencies::_msg( "Failed to redirect STDERR: " . $! );
}

my $obj = bless {
oldOut => $oldOut,
oldErr => $oldErr,
outFile => $outFile,
errFile => $errFile,
}, $class;

return $obj;
}

sub exec {
my $this = shift;
my ($sub) = shift;

my @rc;
my $wantarray = wantarray;
if ($wantarray) {
@rc = $sub->(@_);
}
elsif ( defined $wantarray ) {
$rc[0] = $sub->(@_);
}
else {
$sub->(@_);
}

return $wantarray ? @rc : $rc[0];
}

sub DESTROY {
my $this = shift;

unless ( open STDOUT, ">&", $this->{oldOut} ) {
Foswiki::Aux::Dependencies::_msg( "Failed to restore STDOUT: " . $! );
}
unless ( open STDERR, ">&", $this->{oldErr} ) {
Foswiki::Aux::Dependencies::_msg( "Failed to restore STDERR: " . $! );
}
}

1;
__END__
Foswiki - The Free and Open Source Wiki, http://foswiki.org/
Copyright (C) 2016 Foswiki Contributors. Foswiki Contributors
are listed in the AUTHORS file in the root of this distribution.
NOTE: Please extend that file, not this notice.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version. For
more details read LICENSE in the root of this distribution.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
As per the GPL, removal of this notice is prohibited.
6 changes: 1 addition & 5 deletions core/lib/Foswiki/Configure/Checkers/Email/SSLCaFile.pm
Expand Up @@ -17,10 +17,6 @@ sub check_current_value {

my $file = $this->checkExpandedValue($reporter);
if ($file) {
unless ( $file =~ m,^([\w_./]+)$, ) {
return $this->ERROR("Invalid characters in $file");
}
$file = $1;

if ( -r $file ) {
$reporter->NOTE( "File was last modified "
Expand Down Expand Up @@ -97,7 +93,7 @@ __END__
Foswiki - The Free and Open Source Wiki, http://foswiki.org/
Copyright (C) 2008-2010 Foswiki Contributors. Foswiki Contributors
Copyright (C) 2008-2016 Foswiki Contributors. Foswiki Contributors
are listed in the AUTHORS file in the root of this distribution.
NOTE: Please extend that file, not this notice.
Expand Down
2 changes: 1 addition & 1 deletion core/lib/Foswiki/Configure/Checkers/Email/SSLCaPath.pm
Expand Up @@ -52,7 +52,7 @@ sub check_current_value {
__END__
Foswiki - The Free and Open Source Wiki, http://foswiki.org/
Copyright (C) 2008-2010 Foswiki Contributors. Foswiki Contributors
Copyright (C) 2008-2016 Foswiki Contributors. Foswiki Contributors
are listed in the AUTHORS file in the root of this distribution.
NOTE: Please extend that file, not this notice.
Expand Down
3 changes: 0 additions & 3 deletions core/lib/Foswiki/Configure/Checkers/Email/SSLCrlFile.pm
Expand Up @@ -58,9 +58,6 @@ sub check_current_value {
my $file = $value;

if ($file) {
return $reporter->ERROR("Invalid characters in $file")
unless $file =~ m,^([\w_./]+)$,;
$file = $1;

if ( -r $file ) {
$reporter->NOTE( "File was last modified "
Expand Down

0 comments on commit 8ff14e4

Please sign in to comment.