Newer
Older
}
Daniel Stenberg
committed
elsif($_ =~ /RETRWEIRDO/) {
logmsg "FTPD: instructed to use RETRWEIRDO\n";
Daniel Stenberg
committed
$retrweirdo=1;
}
elsif($_ =~ /RETRNOSIZE/) {
logmsg "FTPD: instructed to use RETRNOSIZE\n";
$retrnosize=1;
}
elsif($_ =~ /PASVBADIP/) {
logmsg "FTPD: instructed to use PASVBADIP\n";
$pasvbadip=1;
}
elsif($_ =~ /NOSAVE/) {
# don't actually store the file we upload - to be used when
# uploading insanely huge amounts
$nosave = 1;
logmsg "FTPD: NOSAVE prevents saving of uploaded data\n";
}
}
close(CUSTOM);
}
my @welcome;
if(($proto eq "ftp") || ($proto eq "smtp")) {
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
@welcome=(
'220- _ _ ____ _ '."\r\n",
'220- ___| | | | _ \| | '."\r\n",
'220- / __| | | | |_) | | '."\r\n",
'220- | (__| |_| | _ <| |___ '."\r\n",
'220 \___|\___/|_| \_\_____|'."\r\n");
}
elsif($proto eq "pop3") {
@welcome=(
' _ _ ____ _ '."\r\n",
' ___| | | | _ \| | '."\r\n",
' / __| | | | |_) | | '."\r\n",
' | (__| |_| | _ <| |___ '."\r\n",
' \___|\___/|_| \_\_____|'."\r\n",
'+OK cURL POP3 server ready to serve'."\r\n");
}
elsif($proto eq "imap") {
@welcome=(
' _ _ ____ _ '."\r\n",
' ___| | | | _ \| | '."\r\n",
' / __| | | | |_) | | '."\r\n",
' | (__| |_| | _ <| |___ '."\r\n",
' \___|\___/|_| \_\_____|'."\r\n",
'* OK cURL IMAP server ready to serve'."\r\n");
}
Daniel Stenberg
committed
while(1) {
#
# We read 'sockfilt' commands.
#
my $input;
logmsg "Awaiting input\n";
sysread_or_die(\*SFREAD, \$input, 5);
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 $FTPCMD;
my $FTPARG;
if($proto eq "imap") {
# IMAP is different with its identifier first on the command line
unless (m/^([^ ]+) ([^ ]+) (.*)/ ||
m/^([^ ]+) ([^ ]+)/) {
sendcontrol "$1 '$_': command not understood.\r\n";
last;
}
$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");
my $twentieths = $delay * 20;
while($twentieths--) {
select(undef, undef, undef, 0.05) unless($got_exit_signal);
}
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);
}