srctop_dir srctop_file
data_file data_dir
result_file result_dir
- pipe with cmdstr quotify
+ pipe with cmdstr
openssl_versions
ok_nofips is_nofips isnt_nofips));
use File::Path 2.00 qw/rmtree mkpath/;
use File::Basename;
use Cwd qw/getcwd abs_path/;
+use OpenSSL::Util;
my $level = 0;
my @cmdargs = ( @$cmd );
my @prog = __wrap_cmd(shift @cmdargs, $opts{exe_shell} // ());
- return __decorate_cmd($num, [ @prog, quotify(@cmdargs) ],
+ return __decorate_cmd($num, [ @prog, fixup_cmd_elements(@cmdargs) ],
%opts);
}
}
=over 4
-=item B<quotify LIST>
-
-LIST is a list of strings that are going to be used as arguments for a
-command, and makes sure to inject quotes and escapes as necessary depending
-on the content of each string.
-
-This can also be used to put quotes around the executable of a command.
-I<This must never ever be done on VMS.>
-
-=back
-
-=cut
-
-sub quotify {
- # Unix setup (default if nothing else is mentioned)
- my $arg_formatter =
- sub { $_ = shift;
- ($_ eq '' || /\s|[\{\}\\\$\[\]\*\?\|\&:;<>]/) ? "'$_'" : $_ };
-
- if ( $^O eq "VMS") { # VMS setup
- $arg_formatter = sub {
- $_ = shift;
- if ($_ eq '' || /\s|["[:upper:]]/) {
- s/"/""/g;
- '"'.$_.'"';
- } else {
- $_;
- }
- };
- } elsif ( $^O eq "MSWin32") { # MSWin setup
- $arg_formatter = sub {
- $_ = shift;
- if ($_ eq '' || /\s|["\|\&\*\;<>]/) {
- s/(["\\])/\\$1/g;
- '"'.$_.'"';
- } else {
- $_;
- }
- };
- }
-
- return map { $arg_formatter->($_) } @_;
-}
-
=over 4
=item B<openssl_versions>
# Otherwise, use the standard wrapper
my $std_wrapper = __bldtop_file("util", "wrap.pl");
- if ($^O eq "VMS") {
- # On VMS, running random executables without having a command
- # symbol means running them with the MCR command. This is an
- # old PDP-11 command that stuck around. So we get a command
- # running perl running the script.
- @prefix = ( "MCR", $^X, $std_wrapper );
- } elsif ($^O eq "MSWin32") {
- # In the Windows case, we run perl explicitly. We might not
- # need it, but that depends on if the user has associated the
- # '.pl' extension with a perl interpreter, so better be safe.
+ if ($^O eq "VMS" || $^O eq "MSWin32") {
+ # On VMS and Windows, we run the perl executable explicitly,
+ # with necessary fixups. We might not need that for Windows,
+ # but that depends on if the user has associated the '.pl'
+ # extension with a perl interpreter, so better be safe.
@prefix = ( __fixup_prg($^X), $std_wrapper );
} else {
# Otherwise, we assume Unix semantics, and trust that the #!
sub __fixup_prg {
my $prog = shift;
- my $prefix = "";
-
- if ($^O eq "VMS" ) {
- $prefix = ($prog =~ /^(?:[\$a-z0-9_]+:)?[<\[]/i ? "mcr " : "mcr []");
- }
-
- if (defined($prog)) {
- # Make sure to quotify the program file on platforms that may
- # have spaces or similar in their path name.
- # To our knowledge, VMS is the exception where quotifying should
- # never happen.
- ($prog) = quotify($prog) unless $^O eq "VMS";
- return $prefix.$prog;
- }
-
- print STDERR "$prog not found\n";
- return undef;
+ return join(' ', fixup_cmd($prog));
}
# __decorate_cmd NUM, CMDARRAYREF
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
$VERSION = "0.1";
@ISA = qw(Exporter);
-@EXPORT = qw(cmp_versions quotify1 quotify_l dump_data);
+@EXPORT = qw(cmp_versions quotify1 quotify_l fixup_cmd_elements fixup_cmd
+ dump_data);
@EXPORT_OK = qw();
=head1 NAME
} @_;
}
+=over 4
+
+=item fixup_cmd_elements LIST
+
+Fixes up the command line elements given by LIST in a platform specific
+manner.
+
+The result of this function is a copy of LIST with strings where quotes and
+escapes have been injected as necessary depending on the content of each
+LIST string.
+
+This can also be used to put quotes around the executable of a command.
+I<This must never ever be done on VMS.>
+
+=back
+
+=cut
+
+sub fixup_cmd_elements {
+ # A formatter for the command arguments, defaulting to the Unix setup
+ my $arg_formatter =
+ sub { $_ = shift;
+ ($_ eq '' || /\s|[\{\}\\\$\[\]\*\?\|\&:;<>]/) ? "'$_'" : $_ };
+
+ if ( $^O eq "VMS") { # VMS setup
+ $arg_formatter = sub {
+ $_ = shift;
+ if ($_ eq '' || /\s|["[:upper:]]/) {
+ s/"/""/g;
+ '"'.$_.'"';
+ } else {
+ $_;
+ }
+ };
+ } elsif ( $^O eq "MSWin32") { # MSWin setup
+ $arg_formatter = sub {
+ $_ = shift;
+ if ($_ eq '' || /\s|["\|\&\*\;<>]/) {
+ s/(["\\])/\\$1/g;
+ '"'.$_.'"';
+ } else {
+ $_;
+ }
+ };
+ }
+
+ return ( map { $arg_formatter->($_) } @_ );
+}
+
+=over 4
+
+=item fixup_cmd LIST
+
+This is a sibling of fixup_cmd_elements() that expects the LIST to be a
+complete command line. It does the same thing as fixup_cmd_elements(),
+expect that it treats the first LIST element specially on VMS.
+
+=back
+
+=cut
+
+sub fixup_cmd {
+ return fixup_cmd_elements(@_) unless $^O eq 'VMS';
+
+ # The rest is VMS specific
+ my $prog = shift;
+
+ # On VMS, running random executables without having a command symbol
+ # means running them with the MCR command. This is an old PDP-11
+ # command that stuck around.
+ # This assumes that we're passed the name of an executable. This is a
+ # safe assumption for OpenSSL command lines
+ my $prefix = 'MCR';
+
+ if ($prog =~ /^MCR$/i) {
+ # If the first element is "MCR" (independent of case) already, then
+ # we assume that the program it runs is already written the way it
+ # should, and just grab it.
+ $prog = shift;
+ } else {
+ # If the command itself doesn't have a directory spec, make sure
+ # that there is one. Otherwise, MCR assumes that the program
+ # resides in SYS$SYSTEM:
+ $prog = '[]' . $prog unless $prog =~ /^(?:[\$a-z0-9_]+:)?[<\[]/i;
+ }
+
+ return ( $prefix, $prog, fixup_cmd_elements(@_) );
+}
+
=item dump_data REF, OPTS
Dump the data from REF into a string that can be evaluated into the same