2004-05-14 05:38:26 +08:00
|
|
|
#! /usr/bin/perl
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
my @directory_vars = ( "dir", "certs", "crl_dir", "new_certs_dir" );
|
|
|
|
my @file_vars = ( "database", "certificate", "serial", "crlnumber",
|
|
|
|
"crl", "private_key", "RANDFILE" );
|
|
|
|
while(<STDIN>) {
|
Perl's chop / chomp considered bad, use a regexp instead
Once upon a time, there was chop, which somply chopped off the last
character of $_ or a given variable, and it was used to take off the
EOL character (\n) of strings.
... but then, you had to check for the presence of such character.
So came chomp, the better chop which checks for \n before chopping it
off. And this worked well, as long as Perl made internally sure that
all EOLs were converted to \n.
These days, though, there seems to be a mixture of perls, so lines
from files in the "wrong" environment might have \r\n as EOL, or just
\r (Mac OS, unless I'm misinformed).
So it's time we went for the more generic variant and use s|\R$||, the
better chomp which recognises all kinds of known EOLs and chops them
off.
A few chops were left alone, as they are use as surgical tools to
remove one last slash or one last comma.
NOTE: \R came with perl 5.10.0. It means that from now on, our
scripts will fail with any older version.
Reviewed-by: Rich Salz <rsalz@openssl.org>
2016-02-12 04:47:30 +08:00
|
|
|
s|\R$||;
|
2004-05-14 05:38:26 +08:00
|
|
|
foreach my $d (@directory_vars) {
|
|
|
|
if (/^(\s*\#?\s*${d}\s*=\s*)\.\/([^\s\#]*)([\s\#].*)$/) {
|
|
|
|
$_ = "$1sys\\\$disk:\[.$2$3";
|
|
|
|
} elsif (/^(\s*\#?\s*${d}\s*=\s*)(\w[^\s\#]*)([\s\#].*)$/) {
|
|
|
|
$_ = "$1sys\\\$disk:\[.$2$3";
|
|
|
|
}
|
|
|
|
s/^(\s*\#?\s*${d}\s*=\s*\$\w+)\/([^\s\#]*)([\s\#].*)$/$1.$2\]$3/;
|
|
|
|
while(/^(\s*\#?\s*${d}\s*=\s*(\$\w+\.|sys\\\$disk:\[\.)[\w\.]+)\/([^\]]*)\](.*)$/) {
|
|
|
|
$_ = "$1.$3]$4";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
foreach my $f (@file_vars) {
|
|
|
|
s/^(\s*\#?\s*${f}\s*=\s*)\.\/(.*)$/$1sys\\\$disk:\[\/$2/;
|
|
|
|
while(/^(\s*\#?\s*${f}\s*=\s*(\$\w+|sys\\\$disk:\[)[^\/]*)\/(\w+\/[^\s\#]*)([\s\#].*)$/) {
|
|
|
|
$_ = "$1.$3$4";
|
|
|
|
}
|
|
|
|
if (/^(\s*\#?\s*${f}\s*=\s*(\$\w+|sys\\\$disk:\[)[^\/]*)\/(\w+)([\s\#].*)$/) {
|
|
|
|
$_ = "$1]$3.$4";
|
|
|
|
} elsif (/^(\s*\#?\s*${f}\s*=\s*(\$\w+|sys\\\$disk:\[)[^\/]*)\/([^\s\#]*)([\s\#].*)$/) {
|
|
|
|
$_ = "$1]$3$4";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
print $_,"\n";
|
|
|
|
}
|