# killsockfilters kills sockfilter processes for a given server.
#
sub killsockfilters {
- my ($proto, $ipvnum, $idnum, $verbose, $which) = @_;
+ my ($piddir, $proto, $ipvnum, $idnum, $verbose, $which) = @_;
my $server;
my $pidfile;
my $pid;
$server = servername_id($proto, $ipvnum, $idnum) if($verbose);
if(!$which || ($which eq 'main')) {
- $pidfile = mainsockf_pidfilename($proto, $ipvnum, $idnum);
+ $pidfile = mainsockf_pidfilename($piddir, $proto, $ipvnum, $idnum);
$pid = processexists($pidfile);
if($pid > 0) {
printf("* kill pid for %s-%s => %d\n", $server,
return if($proto ne 'ftp');
if(!$which || ($which eq 'data')) {
- $pidfile = datasockf_pidfilename($proto, $ipvnum, $idnum);
+ $pidfile = datasockf_pidfilename($piddir, $proto, $ipvnum, $idnum);
$pid = processexists($pidfile);
if($pid > 0) {
printf("* kill pid for %s-data => %d\n", $server,
# killallsockfilters kills sockfilter processes for all servers.
#
sub killallsockfilters {
- my $verbose = $_[0];
+ my ($piddir, $verbose) = @_;
for my $proto (('ftp', 'imap', 'pop3', 'smtp')) {
for my $ipvnum (('4', '6')) {
for my $idnum (('1', '2')) {
- killsockfilters($proto, $ipvnum, $idnum, $verbose);
+ killsockfilters($piddir, $proto, $ipvnum, $idnum, $verbose);
}
}
}
# All socket/network/TCP related stuff is done by the 'sockfilt' program.
#
+use strict;
+use warnings;
+
BEGIN {
push(@INC, $ENV{'srcdir'}) if(defined $ENV{'srcdir'});
push(@INC, ".");
}
}
-use strict;
-use warnings;
use IPC::Open2;
use Digest::MD5;
+use File::Basename;
require "getpart.pm";
require "ftp.pm";
my $testno = 0; # test case number (read from ftpserver.cmd)
my $path = '.';
my $logdir = $path .'/log';
+my $piddir;
#**********************************************************************
# global vars used for server address and primary listener port
#**********************************************************************
# global vars used for file names
#
+my $PORTFILE="ftpserver.port"; # server port file name
+my $portfile; # server port file path
my $pidfile; # server pid file name
-my $portfile=".ftpserver.port"; # server port file name
my $logfile; # server log file name
my $mainsockf_pidfile; # pid file for primary connection sockfilt process
my $mainsockf_logfile; # log file for primary connection sockfilt process
sub exit_signal_handler {
my $signame = shift;
# For now, simply mimic old behavior.
- killsockfilters($proto, $ipvnum, $idnum, $verbose);
+ killsockfilters($piddir, $proto, $ipvnum, $idnum, $verbose);
unlink($pidfile);
unlink($portfile);
if($serverlogslocked) {
logmsg "Error: $srvrname server, sysread error: $!\n";
logmsg "Exited from sysread_or_die() at $fcaller " .
"line $lcaller. $srvrname server, sysread error: $!\n";
- killsockfilters($proto, $ipvnum, $idnum, $verbose);
+ killsockfilters($piddir, $proto, $ipvnum, $idnum, $verbose);
unlink($pidfile);
unlink($portfile);
if($serverlogslocked) {
logmsg "Error: $srvrname server, read zero\n";
logmsg "Exited from sysread_or_die() at $fcaller " .
"line $lcaller. $srvrname server, read zero\n";
- killsockfilters($proto, $ipvnum, $idnum, $verbose);
+ killsockfilters($piddir, $proto, $ipvnum, $idnum, $verbose);
unlink($pidfile);
unlink($portfile);
if($serverlogslocked) {
if($pong !~ /^PONG/) {
logmsg "Failed sockfilt command: $mainsockfcmd\n";
- killsockfilters($proto, $ipvnum, $idnum, $verbose);
+ killsockfilters($piddir, $proto, $ipvnum, $idnum, $verbose);
unlink($pidfile);
unlink($portfile);
if($serverlogslocked) {
# kill previous data connection sockfilt when alive
if($datasockf_runs eq 'yes') {
- killsockfilters($proto, $ipvnum, $idnum, $verbose, 'data');
+ killsockfilters($piddir, $proto, $ipvnum, $idnum, $verbose, 'data');
logmsg "DATA sockfilt for $datasockf_mode data channel killed\n";
}
datasockf_state('STOPPED');
logmsg "DATA sockfilt unexpected response: $pong\n";
logmsg "DATA sockfilt for passive data channel failed\n";
logmsg "DATA sockfilt killed now\n";
- killsockfilters($proto, $ipvnum, $idnum, $verbose, 'data');
+ killsockfilters($piddir, $proto, $ipvnum, $idnum, $verbose, 'data');
logmsg "DATA sockfilt not running\n";
datasockf_state('STOPPED');
sendcontrol "500 no free ports!\r\n";
logmsg "DATA sockfilt unknown listener port\n";
logmsg "DATA sockfilt for passive data channel failed\n";
logmsg "DATA sockfilt killed now\n";
- killsockfilters($proto, $ipvnum, $idnum, $verbose, 'data');
+ killsockfilters($piddir, $proto, $ipvnum, $idnum, $verbose, 'data');
logmsg "DATA sockfilt not running\n";
datasockf_state('STOPPED');
sendcontrol "500 no free ports!\r\n";
"on port $pasvport\n";
logmsg "accept failed or connection not even attempted\n";
logmsg "DATA sockfilt killed now\n";
- killsockfilters($proto, $ipvnum, $idnum, $verbose, 'data');
+ killsockfilters($piddir, $proto, $ipvnum, $idnum, $verbose, 'data');
logmsg "DATA sockfilt not running\n";
datasockf_state('STOPPED');
return;
# kill previous data connection sockfilt when alive
if($datasockf_runs eq 'yes') {
- killsockfilters($proto, $ipvnum, $idnum, $verbose, 'data');
+ killsockfilters($piddir, $proto, $ipvnum, $idnum, $verbose, 'data');
logmsg "DATA sockfilt for $datasockf_mode data channel killed\n";
}
datasockf_state('STOPPED');
logmsg "DATA sockfilt unexpected response: $pong\n";
logmsg "DATA sockfilt for active data channel failed\n";
logmsg "DATA sockfilt killed now\n";
- killsockfilters($proto, $ipvnum, $idnum, $verbose, 'data');
+ killsockfilters($piddir, $proto, $ipvnum, $idnum, $verbose, 'data');
logmsg "DATA sockfilt not running\n";
datasockf_state('STOPPED');
# client shall timeout awaiting connection from server
# Initialize command line option dependent variables
#
+if($pidfile) {
+ # Use our pidfile directory to store the other pidfiles
+ $piddir = dirname($pidfile);
+}
+else {
+ # Use the current directory to store all the pidfiles
+ $piddir = $path;
+ $pidfile = server_pidfilename($piddir, $proto, $ipvnum, $idnum);
+}
+if(!$portfile) {
+ $portfile = $piddir . "/" . $PORTFILE;
+}
if(!$srcdir) {
$srcdir = $ENV{'srcdir'} || '.';
}
-if(!$pidfile) {
- $pidfile = "$path/". server_pidfilename($proto, $ipvnum, $idnum);
-}
if(!$logfile) {
$logfile = server_logfilename($logdir, $proto, $ipvnum, $idnum);
}
-$mainsockf_pidfile = "$path/".
- mainsockf_pidfilename($proto, $ipvnum, $idnum);
+$mainsockf_pidfile = mainsockf_pidfilename($piddir, $proto, $ipvnum, $idnum);
$mainsockf_logfile =
mainsockf_logfilename($logdir, $proto, $ipvnum, $idnum);
$serverlogs_lockfile = "$logdir/$SERVERLOGS_LOCK";
if($proto eq 'ftp') {
- $datasockf_pidfile = "$path/".
- datasockf_pidfilename($proto, $ipvnum, $idnum);
+ $datasockf_pidfile = datasockf_pidfilename($piddir, $proto, $ipvnum, $idnum);
$datasockf_logfile =
datasockf_logfilename($logdir, $proto, $ipvnum, $idnum);
}
# kill previous data connection sockfilt when alive
if($datasockf_runs eq 'yes') {
- killsockfilters($proto, $ipvnum, $idnum, $verbose, 'data');
+ killsockfilters($piddir, $proto, $ipvnum, $idnum, $verbose, 'data');
logmsg "DATA sockfilt for $datasockf_mode data channel killed now\n";
}
datasockf_state('STOPPED');
}
}
-killsockfilters($proto, $ipvnum, $idnum, $verbose);
+killsockfilters($piddir, $proto, $ipvnum, $idnum, $verbose);
unlink($pidfile);
if($serverlogslocked) {
$serverlogslocked = 0;
#
#***************************************************************************
+use strict;
+use warnings;
+
BEGIN {
push(@INC, $ENV{'srcdir'}) if(defined $ENV{'srcdir'});
push(@INC, ".");
}
-use strict;
-use warnings;
+use File::Basename;
use serverhelp qw(
server_pidfilename
my $flags = "";
my $path = '.';
my $logdir = $path .'/log';
+my $piddir;
while(@ARGV) {
if($ARGV[0] eq '--pidfile') {
shift @ARGV;
}
-if(!$srcdir) {
- $srcdir = $ENV{'srcdir'} || '.';
+#***************************************************************************
+# Initialize command line option dependent variables
+#
+
+if($pidfile) {
+ # Use our pidfile directory to store the other pidfiles
+ $piddir = dirname($pidfile);
}
-if(!$pidfile) {
- $pidfile = "$path/". server_pidfilename($proto, $ipvnum, $idnum);
+else {
+ # Use the current directory to store all the pidfiles
+ $piddir = $path;
+ $pidfile = server_pidfilename($piddir, $proto, $ipvnum, $idnum);
}
if(!$portfile) {
- $portfile = "$path/". server_portfilename($proto, $ipvnum, $idnum);
+ $portfile = server_portfilename($piddir, $proto, $ipvnum, $idnum);
+}
+if(!$srcdir) {
+ $srcdir = $ENV{'srcdir'} || '.';
}
if(!$logfile) {
$logfile = server_logfilename($logdir, $proto, $ipvnum, $idnum);
#
#***************************************************************************
+use strict;
+use warnings;
+
BEGIN {
push(@INC, $ENV{'srcdir'}) if(defined $ENV{'srcdir'});
push(@INC, ".");
}
-use strict;
-use warnings;
-
use serverhelp qw(
server_pidfilename
server_logfilename
shift @ARGV;
}
+#***************************************************************************
+# Initialize command line option dependent variables
+#
+
+if(!$pidfile) {
+ $pidfile = server_pidfilename($path, $proto, $ipvnum, $idnum);
+}
if(!$srcdir) {
$srcdir = $ENV{'srcdir'} || '.';
}
-if(!$pidfile) {
- $pidfile = "$path/". server_pidfilename($proto, $ipvnum, $idnum);
-}
if(!$logfile) {
$logfile = server_logfilename($logdir, $proto, $ipvnum, $idnum);
}
my $ACURL=$VCURL; # what curl binary to use to talk to APIs (relevant for CI)
# ACURL is handy to set to the system one for reliability
my $DBGCURL=$CURL; #"../src/.libs/curl"; # alternative for debugging
-my $LOGDIR="log";
my $TESTDIR="$srcdir/data";
my $LIBDIR="./libtest";
my $UNITDIR="./unit";
+my $LOGDIR="log";
# TODO: $LOGDIR could eventually change later on, so must regenerate all the
# paths depending on it after $LOGDIR itself changes.
+my $PIDDIR = "$LOGDIR/server";
# TODO: change this to use server_inputfilename()
my $SERVERIN="$LOGDIR/server.input"; # what curl sent the server
my $SERVER2IN="$LOGDIR/server2.input"; # what curl sent the second server
my $PROXYIN="$LOGDIR/proxy.input"; # what curl sent the proxy
my $SOCKSIN="$LOGDIR/socksd-request.log"; # what curl sent to the SOCKS proxy
-my $CURLLOG="commands.log"; # all command lines run
+my $CURLLOG="$LOGDIR/commands.log"; # all command lines run
my $FTPDCMD="$LOGDIR/ftpserver.cmd"; # copy server instructions here
my $SERVERLOGS_LOCK="$LOGDIR/serverlogs.lock"; # server logs advisor read lock
my $CURLCONFIG="../curl-config"; # curl-config from current build
for my $ipvnum ((4, 6)) {
for my $idnum ((1, 2, 3)) {
my $serv = servername_id("$proto$ssl", $ipvnum, $idnum);
- my $pidf = server_pidfilename("$proto$ssl", $ipvnum, $idnum);
+ my $pidf = server_pidfilename($PIDDIR, "$proto$ssl", $ipvnum, $idnum);
$serverpidfile{$serv} = $pidf;
- my $portf = server_portfilename("$proto$ssl", $ipvnum, $idnum);
+ my $portf = server_portfilename($PIDDIR, "$proto$ssl", $ipvnum, $idnum);
$serverportfile{$serv} = $portf;
}
}
for my $ipvnum ((4, 6)) {
for my $idnum ((1, 2)) {
my $serv = servername_id($proto, $ipvnum, $idnum);
- my $pidf = server_pidfilename($proto, $ipvnum, $idnum);
+ my $pidf = server_pidfilename($PIDDIR, $proto, $ipvnum, $idnum);
$serverpidfile{$serv} = $pidf;
- my $portf = server_portfilename($proto, $ipvnum, $idnum);
+ my $portf = server_portfilename($PIDDIR, $proto, $ipvnum, $idnum);
$serverportfile{$serv} = $portf;
}
}
for my $proto (('http', 'imap', 'pop3', 'smtp', 'http/2', 'http/3')) {
for my $ssl (('', 's')) {
my $serv = servername_id("$proto$ssl", "unix", 1);
- my $pidf = server_pidfilename("$proto$ssl", "unix", 1);
+ my $pidf = server_pidfilename($PIDDIR, "$proto$ssl", "unix", 1);
$serverpidfile{$serv} = $pidf;
- my $portf = server_portfilename("$proto$ssl", "unix", 1);
+ my $portf = server_portfilename($PIDDIR, "$proto$ssl", "unix", 1);
$serverportfile{$serv} = $portf;
}
}
my $proto = $1;
my $idnum = ($2 && ($2 > 1)) ? $2 : 1;
my $ipvnum = ($3 && ($3 =~ /6$/)) ? 6 : 4;
- killsockfilters($proto, $ipvnum, $idnum, $verbose);
+ killsockfilters($PIDDIR, $proto, $ipvnum, $idnum, $verbose);
}
#
# All servers relative to the given one must be stopped also
#
sub verifyssh {
my ($proto, $ipvnum, $idnum, $ip, $port) = @_;
- my $pidfile = server_pidfilename($proto, $ipvnum, $idnum);
+ my $pidfile = server_pidfilename($PIDDIR, $proto, $ipvnum, $idnum);
my $pid = processexists($pidfile);
if($pid < 0) {
logmsg "RUN: SSH server has died after starting up\n";
sub verifyhttptls {
my ($proto, $ipvnum, $idnum, $ip, $port) = @_;
my $server = servername_id($proto, $ipvnum, $idnum);
- my $pidfile = server_pidfilename($proto, $ipvnum, $idnum);
+ my $pidfile = server_pidfilename($PIDDIR, $proto, $ipvnum, $idnum);
my $verifyout = "$LOGDIR/".
servername_canon($proto, $ipvnum, $idnum) .'_verify.out';
#
sub verifysocks {
my ($proto, $ipvnum, $idnum, $ip, $port) = @_;
- my $pidfile = server_pidfilename($proto, $ipvnum, $idnum);
+ my $pidfile = server_pidfilename($PIDDIR, $proto, $ipvnum, $idnum);
my $pid = processexists($pidfile);
if($pid < 0) {
logmsg "RUN: SOCKS server has died after starting up\n";
#
sub cleardir {
my $dir = $_[0];
- my $done = 1;
+ my $done = 1; # success
my $file;
# Get all files
opendir(my $dh, $dir) ||
return 0; # can't open dir
while($file = readdir($dh)) {
- if(($file !~ /^(\.|\.\.)\z/)) {
+ # Don't clear the $PIDDIR since those need to live beyond one test
+ if(($file !~ /^(\.|\.\.)\z/) && "$dir/$file" ne $PIDDIR) {
if(-d "$dir/$file") {
if(!cleardir("$dir/$file")) {
$done = 0;
logmsg "$CMDLINE\n";
}
- open(my $cmdlog, ">", "$LOGDIR/$CURLLOG") || die "Failure writing log file";
+ open(my $cmdlog, ">", $CURLLOG) || die "Failure writing log file";
print $cmdlog "$CMDLINE\n";
close($cmdlog) || die "Failure writing log file";
#
# kill sockfilter processes for all pingpong servers
#
- killallsockfilters($verb);
+ killallsockfilters($PIDDIR, $verb);
#
# kill all server pids from %run hash clearing them
#
cleardir($LOGDIR);
mkdir($LOGDIR, 0777);
+mkdir($PIDDIR, 0777);
#######################################################################
# initialize some variables
# harness. Actually just a layer that runs stunnel properly using the
# non-secure test harness servers.
+use strict;
+use warnings;
+
BEGIN {
push(@INC, $ENV{'srcdir'}) if(defined $ENV{'srcdir'});
push(@INC, ".");
}
-use strict;
-use warnings;
use Cwd;
use Cwd 'abs_path';
# Initialize command line option dependent variables
#
if(!$pidfile) {
- $pidfile = "$path/". server_pidfilename($proto, $ipvnum, $idnum);
+ $pidfile = server_pidfilename($path, $proto, $ipvnum, $idnum);
}
if(!$logfile) {
$logfile = server_logfilename($logdir, $proto, $ipvnum, $idnum);
# Return file name for server pid file.
#
sub server_pidfilename {
- my ($proto, $ipver, $idnum) = @_;
+ my ($piddir, $proto, $ipver, $idnum) = @_;
my $trailer = '_server.pid';
- return '.'. servername_canon($proto, $ipver, $idnum) ."$trailer";
+ return "${piddir}/". servername_canon($proto, $ipver, $idnum) ."$trailer";
}
#***************************************************************************
# Return file name for server port file.
#
sub server_portfilename {
- my ($proto, $ipver, $idnum) = @_;
+ my ($piddir, $proto, $ipver, $idnum) = @_;
my $trailer = '_server.port';
- return '.'. servername_canon($proto, $ipver, $idnum) ."$trailer";
+ return "${piddir}/". servername_canon($proto, $ipver, $idnum) ."$trailer";
}
# Return file name for main or primary sockfilter pid file.
#
sub mainsockf_pidfilename {
- my ($proto, $ipver, $idnum) = @_;
+ my ($piddir, $proto, $ipver, $idnum) = @_;
die "unsupported protocol: '$proto'" unless($proto &&
(lc($proto) =~ /^(ftp|imap|pop3|smtp)s?$/));
my $trailer = (lc($proto) =~ /^ftps?$/) ? '_sockctrl.pid':'_sockfilt.pid';
- return '.'. servername_canon($proto, $ipver, $idnum) ."$trailer";
+ return "${piddir}/". servername_canon($proto, $ipver, $idnum) ."$trailer";
}
# Return file name for data or secondary sockfilter pid file.
#
sub datasockf_pidfilename {
- my ($proto, $ipver, $idnum) = @_;
+ my ($piddir, $proto, $ipver, $idnum) = @_;
die "unsupported protocol: '$proto'" unless($proto &&
(lc($proto) =~ /^ftps?$/));
my $trailer = '_sockdata.pid';
- return '.'. servername_canon($proto, $ipver, $idnum) ."$trailer";
+ return "${piddir}/". servername_canon($proto, $ipver, $idnum) ."$trailer";
}
shift @ARGV;
}
+#***************************************************************************
+# Initialize command line option dependent variables
+#
+
#***************************************************************************
# Default ssh daemon pid file name
#
if(!$pidfile) {
- $pidfile = "$path/". server_pidfilename($proto, $ipvnum, $idnum);
+ $pidfile = server_pidfilename($path, $proto, $ipvnum, $idnum);
}
-
#***************************************************************************
# ssh and sftp server log file names
#
$srcdir = $ENV{'srcdir'} || '.';
}
if(!$pidfile) {
- $pidfile = "$path/". server_pidfilename($proto, $ipvnum, $idnum);
+ $pidfile = server_pidfilename($path, $proto, $ipvnum, $idnum);
}
if(!$logfile) {
$logfile = server_logfilename($logdir, $proto, $ipvnum, $idnum);