Skip to content
ftpserver.pl 28.9 KiB
Newer Older
        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's avatar
Daniel Stenberg committed

        if($i !~ /^DATA/) {
            logmsg "sockfilt said $i";
            if($i =~ /^DISC/) {
                # disconnect
                last;
            }
            next;
        }

        # SIZE of data
Daniel Stenberg's avatar
Daniel Stenberg committed
        
        ftpmsg $_;
        
        # Remove trailing CRLF.
        s/[\n\r]+$//;
Daniel Stenberg's avatar
Daniel Stenberg committed
        my $full=$_;
        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;
        }
        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 $text;
        $text = $customreply{$FTPCMD};
        my $fake = $text;
        if($text eq "") {
            $text = $displaytext{$FTPCMD};
        }
        else {
            if($customcount{$FTPCMD} && (!--$customcount{$FTPCMD})) {
                # used enough number of times, now blank the customreply
                $customreply{$FTPCMD}="";
            }
Daniel Stenberg's avatar
Daniel Stenberg committed
        if($text) {
Daniel Stenberg's avatar
Daniel Stenberg committed
        }
            $check=1; # no response yet
        if($fake eq "") {
            # only perform this if we're not faking a reply
            my $func = $commandfunc{$FTPCMD};
            if($func) {
Daniel Stenberg's avatar
Daniel Stenberg committed
        }
            logmsg "$FTPCMD wasn't handled!\n";
            sendcontrol "500 $FTPCMD is not dealt with!\r\n";
        }
Daniel Stenberg's avatar
Daniel Stenberg committed
            
    } # while(1)
    if($serverlogslocked) {
        $serverlogslocked = 0;
        clear_advisor_read_lock($SERVERLOGS_LOCK);
    }
Yang Tse's avatar
 
Yang Tse committed
unlink($pidfile);

if($serverlogslocked) {
    $serverlogslocked = 0;
    clear_advisor_read_lock($SERVERLOGS_LOCK);
}