1 | #! {- $config{HASHBANGPERL} -}
|
---|
2 |
|
---|
3 | use strict;
|
---|
4 | use warnings;
|
---|
5 |
|
---|
6 | use File::Basename;
|
---|
7 | use File::Spec::Functions;
|
---|
8 |
|
---|
9 | BEGIN {
|
---|
10 | # This method corresponds exactly to 'use OpenSSL::Util',
|
---|
11 | # but allows us to use a platform specific file spec.
|
---|
12 | require {-
|
---|
13 | use Cwd qw(abs_path);
|
---|
14 |
|
---|
15 | "'" . abs_path(catfile($config{sourcedir},
|
---|
16 | 'util', 'perl', 'OpenSSL', 'Util.pm')) . "'";
|
---|
17 | -};
|
---|
18 | OpenSSL::Util->import();
|
---|
19 | }
|
---|
20 |
|
---|
21 | my $there = canonpath(catdir(dirname($0), updir()));
|
---|
22 | my $std_engines = catdir($there, 'engines');
|
---|
23 | my $std_providers = catdir($there, 'providers');
|
---|
24 | my $std_openssl_conf = catdir($there, 'apps/openssl.cnf');
|
---|
25 | my $unix_shlib_wrap = catfile($there, 'util/shlib_wrap.sh');
|
---|
26 | my $std_openssl_conf_include;
|
---|
27 |
|
---|
28 | if ($ARGV[0] eq '-fips') {
|
---|
29 | $std_openssl_conf = {-
|
---|
30 | use Cwd qw(abs_path);
|
---|
31 |
|
---|
32 | "'" . abs_path(catfile($config{sourcedir}, 'test/fips-and-base.cnf')) . "'";
|
---|
33 | -};
|
---|
34 | shift;
|
---|
35 |
|
---|
36 | $std_openssl_conf_include = catdir($there, 'providers');
|
---|
37 | }
|
---|
38 |
|
---|
39 | local $ENV{OPENSSL_CONF_INCLUDE} = $std_openssl_conf_include
|
---|
40 | if defined $std_openssl_conf_include
|
---|
41 | &&($ENV{OPENSSL_CONF_INCLUDE} // '') eq ''
|
---|
42 | && -d $std_openssl_conf_include;
|
---|
43 | local $ENV{OPENSSL_ENGINES} = $std_engines
|
---|
44 | if ($ENV{OPENSSL_ENGINES} // '') eq '' && -d $std_engines;
|
---|
45 | local $ENV{OPENSSL_MODULES} = $std_providers
|
---|
46 | if ($ENV{OPENSSL_MODULES} // '') eq '' && -d $std_providers;
|
---|
47 | local $ENV{OPENSSL_CONF} = $std_openssl_conf
|
---|
48 | if ($ENV{OPENSSL_CONF} // '') eq '' && -f $std_openssl_conf;
|
---|
49 | {-
|
---|
50 | # For VMS, we define logical names to get the libraries properly
|
---|
51 | # defined.
|
---|
52 | use File::Spec::Functions qw(rel2abs);
|
---|
53 |
|
---|
54 | if ($^O eq "VMS") {
|
---|
55 | my $bldtop = rel2abs($config{builddir});
|
---|
56 | my %names =
|
---|
57 | map { platform->sharedname($_) => $bldtop.platform->sharedlib($_) }
|
---|
58 | grep { !$unified_info{attributes}->{libraries}->{$_}->{noinst} }
|
---|
59 | @{$unified_info{libraries}};
|
---|
60 |
|
---|
61 | foreach (sort keys %names) {
|
---|
62 | $OUT .= "local \$ENV\{'$_'\} = '$names{$_}';\n";
|
---|
63 | }
|
---|
64 | }
|
---|
65 | -}
|
---|
66 | my $use_system = 0;
|
---|
67 | my @cmd;
|
---|
68 |
|
---|
69 | if ($^O eq 'VMS') {
|
---|
70 | # VMS needs the command to be appropriately quotified
|
---|
71 | @cmd = fixup_cmd(@ARGV);
|
---|
72 | } elsif (-x $unix_shlib_wrap) {
|
---|
73 | @cmd = ( $unix_shlib_wrap, @ARGV );
|
---|
74 | } else {
|
---|
75 | # Hope for the best
|
---|
76 | @cmd = ( @ARGV );
|
---|
77 | }
|
---|
78 |
|
---|
79 | # The exec() statement on MSWin32 doesn't seem to give back the exit code
|
---|
80 | # from the call, so we resort to using system() instead.
|
---|
81 | my $waitcode = system @cmd;
|
---|
82 |
|
---|
83 | # According to documentation, -1 means that system() couldn't run the command,
|
---|
84 | # otherwise, the value is similar to the Unix wait() status value
|
---|
85 | # (exitcode << 8 | signalcode)
|
---|
86 | die "wrap.pl: Failed to execute '", join(' ', @cmd), "': $!\n"
|
---|
87 | if $waitcode == -1;
|
---|
88 |
|
---|
89 | # When the subprocess aborted on a signal, we simply raise the same signal.
|
---|
90 | kill(($? & 255) => $$) if ($? & 255) != 0;
|
---|
91 |
|
---|
92 | # If that didn't stop this script, mimic what Unix shells do, by
|
---|
93 | # converting the signal code to an exit code by setting the high bit.
|
---|
94 | # This only happens on Unix flavored operating systems, the others don't
|
---|
95 | # have this sort of signaling to date, and simply leave the low byte zero.
|
---|
96 | exit(($? & 255) | 128) if ($? & 255) != 0;
|
---|
97 |
|
---|
98 | # When not a signal, just shift down the subprocess exit code and use that.
|
---|
99 | my $exitcode = $? >> 8;
|
---|
100 |
|
---|
101 | # For VMS, perl recommendations is to emulate what the C library exit() does
|
---|
102 | # for all non-zero exit codes, except we set the error severity rather than
|
---|
103 | # success.
|
---|
104 | # Ref: https://perldoc.perl.org/perlport#exit
|
---|
105 | # https://perldoc.perl.org/perlvms#$?
|
---|
106 | if ($^O eq 'VMS' && $exitcode != 0) {
|
---|
107 | $exitcode =
|
---|
108 | 0x35a000 # C facility code
|
---|
109 | + ($exitcode * 8) # shift up to make space for the 3 severity bits
|
---|
110 | + 2 # Severity: E(rror)
|
---|
111 | + 0x10000000; # bit 28 set => the shell stays silent
|
---|
112 | }
|
---|
113 | exit($exitcode);
|
---|