Newer
Older
Daniel Stenberg
committed
if($input !~ /^CNCT/) {
# we wait for a connected client
logmsg "sockfilt said: $input";
Daniel Stenberg
committed
next;
}
logmsg "====> Client connect\n";
Daniel Stenberg
committed
set_advisor_read_lock($SERVERLOGS_LOCK);
Yang Tse
committed
$serverlogslocked = 1;
Daniel Stenberg
committed
Daniel Stenberg
committed
$slavepid=0;
&customize(); # read test control instructions
Daniel Stenberg
committed
sendcontrol @welcome;
for(@welcome) {
print STDERR "OUT: $_";
}
Daniel Stenberg
committed
Daniel Stenberg
committed
my $i;
# Now we expect to read DATA\n[hex size]\n[prot], where the [prot]
# part only is FTP lingo.
# COMMAND
sysread_or_die(\*SFREAD, \$i, 5);
Daniel Stenberg
committed
if($i !~ /^DATA/) {
logmsg "sockfilt said $i";
if($i =~ /^DISC/) {
# disconnect
last;
}
next;
}
# SIZE of data
sysread_or_die(\*SFREAD, \$i, 5);
Daniel Stenberg
committed
my $size = hex($i);
# data
sysread SFREAD, $_, $size;
ftpmsg $_;
# Remove trailing CRLF.
s/[\n\r]+$//;
Daniel Stenberg
committed
my $cmdid;
my $FTPCMD;
my $FTPARG;
if($proto eq "imap") {
# IMAP is different with its identifier first on the command line
unless (m/^([^ ]+) ([^ ]+) (.*)/i) {
sendcontrol "500 '$_': command not understood.\r\n";
last;
}
$cmdid=$1;
$FTPCMD=$2;
$FTPARG=$3;
}
else {
unless (m/^([A-Z]{3,4})\s?(.*)/i) {
sendcontrol "500 '$_': command not understood.\r\n";
last;
}
$FTPCMD=$1;
$FTPARG=$2;
}
Daniel Stenberg
committed
Daniel Stenberg
committed
logmsg "< \"$full\"\n";
Daniel Stenberg
committed
if($verbose) {
print STDERR "IN: $full\n";
}
my $delay = $delayreply{$FTPCMD};
if($delay) {
# just go sleep this many seconds!
logmsg("Sleep for $delay seconds\n");
sleep($delay);
}
my $text;
$text = $customreply{$FTPCMD};
my $fake = $text;
if($text eq "") {
$text = $displaytext{$FTPCMD};
}
if($customcount{$FTPCMD} && (!--$customcount{$FTPCMD})) {
# used enough number of times, now blank the customreply
$customreply{$FTPCMD}="";
}
Daniel Stenberg
committed
my $check;
sendcontrol "$cmdid$text\r\n";
Daniel Stenberg
committed
else {
$check=1; # no response yet
Daniel Stenberg
committed
}
Daniel Stenberg
committed
if($fake eq "") {
# only perform this if we're not faking a reply
my $func = $commandfunc{$FTPCMD};
if($func) {
Daniel Stenberg
committed
&$func($FTPARG, $FTPCMD);
Daniel Stenberg
committed
$check=0; # taken care of
Daniel Stenberg
committed
if($check) {
logmsg "$FTPCMD wasn't handled!\n";
Daniel Stenberg
committed
sendcontrol "500 $FTPCMD is not dealt with!\r\n";
}
Daniel Stenberg
committed
logmsg "====> Client disconnected\n";
Yang Tse
committed
if($serverlogslocked) {
$serverlogslocked = 0;
clear_advisor_read_lock($SERVERLOGS_LOCK);
}
Daniel Stenberg
committed
}
Daniel Stenberg
committed
print SFWRITE "QUIT\n";
waitpid $sfpid, 0;
Yang Tse
committed
if($serverlogslocked) {
$serverlogslocked = 0;
clear_advisor_read_lock($SERVERLOGS_LOCK);
}