aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorYang Tse <yangsita@gmail.com>2009-04-13 03:47:16 +0000
committerYang Tse <yangsita@gmail.com>2009-04-13 03:47:16 +0000
commitaa330b8240c819da037c83e2df2088cb420c8191 (patch)
treed9da0ff9a1e278f11ee6c3ca50f044ef9ead4a66 /tests
parente43606eb4d3b2b914ff3c4a53e68ff9ad68503b8 (diff)
improve stunnel version detection
Diffstat (limited to 'tests')
-rw-r--r--tests/httpsserver.pl53
1 files changed, 37 insertions, 16 deletions
diff --git a/tests/httpsserver.pl b/tests/httpsserver.pl
index 95ba10317..fa9fde5db 100644
--- a/tests/httpsserver.pl
+++ b/tests/httpsserver.pl
@@ -28,7 +28,7 @@ my $srcdir=$path;
my $proto='https';
-do {
+while(@ARGV) {
if($ARGV[0] eq "-v") {
$verbose=1;
}
@@ -54,15 +54,44 @@ do {
elsif($ARGV[0] =~ /^(\d+)$/) {
$port = $1;
}
-} while(shift @ARGV);
+ shift @ARGV;
+};
my $conffile="$path/stunnel.conf"; # stunnel configuration data
my $certfile="$srcdir/stunnel.pem"; # stunnel server certificate
my $pidfile="$path/.$proto.pid"; # stunnel process pid file
-open(CONF, ">$conffile") || exit 1;
-print CONF "
- CApath=$path
+# find out version info for the given stunnel binary
+my $ver_major;
+my $ver_minor;
+foreach my $veropt (('-version', '-V')) {
+ foreach my $verstr (qx($stunnel $veropt 2>&1)) {
+ if($verstr =~ /^stunnel (\d+)\.(\d+) on /) {
+ $ver_major = $1;
+ $ver_minor = $2;
+ last;
+ }
+ }
+ last if($ver_major);
+}
+
+my $cmd;
+if(!$ver_major) {
+ print STDERR "no stunnel or unknown version\n";
+}
+elsif($ver_major < 4) {
+ # stunnel version less than 4.00
+ $cmd = "$stunnel -p $certfile -P $pidfile -d $port -r $target_port ";
+ $cmd .= "2>/dev/null";
+}
+else {
+ # stunnel version 4.00 or later
+ $cmd = "$stunnel $conffile ";
+ $cmd .= "2>/dev/null";
+ # stunnel configuration file
+ open(STUNCONF, ">$conffile") || exit 1;
+ print STUNCONF "
+ CApath = $path
cert = $certfile
pid = $pidfile
debug = 0
@@ -72,17 +101,9 @@ print CONF "
[curltest]
accept = $port
connect = $target_port
-";
-close CONF;
-#system("chmod go-rwx $conffile $certfile"); # secure permissions
-
- # works only with stunnel versions < 4.00
-my $cmd="$stunnel -p $certfile -P $pidfile -d $port -r $target_port 2>/dev/null";
-
-# use some heuristics to determine stunnel version
-my $version_ge_4=system("$stunnel -V 2>&1|grep '^stunnel.* on '>/dev/null 2>&1");
- # works only with stunnel versions >= 4.00
-if ($version_ge_4) { $cmd="$stunnel $conffile"; }
+ ";
+ close STUNCONF;
+}
if($verbose) {
print uc($proto)." server: $cmd\n";