FTPd: allow commands with only LF instead of CR LF, print commands to console, other small improvements.

git-svn-id: svn://kolibrios.org@3819 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
hidnplayr 2013-07-12 20:42:36 +00:00
parent 4828326119
commit 685f1172f0
2 changed files with 32 additions and 19 deletions

View File

@ -740,12 +740,11 @@ cmdPASV:
; 227 Entering Passive Mode (a1,a2,a3,a4,p1,p2) ; 227 Entering Passive Mode (a1,a2,a3,a4,p1,p2)
; where a1.a2.a3.a4 is the IP address and p1*256+p2 is the port number. ; where a1.a2.a3.a4 is the IP address and p1*256+p2 is the port number.
; '227 (' ; '227 Entering passive mode ('
lea edi, [ebp + thread_data.buffer] lea edi, [ebp + thread_data.buffer]
mov eax, '227 ' mov ecx, str_227.length
stosd mov esi, str_227
mov al, '(' rep movsb
stosb
; ip ; ip
movzx eax, byte [serverip] movzx eax, byte [serverip]
call dword_to_ascii call dword_to_ascii
@ -771,7 +770,7 @@ cmdPASV:
movzx eax, byte [ebp + thread_data.datasock.sin_port+1] movzx eax, byte [ebp + thread_data.datasock.sin_port+1]
call dword_to_ascii call dword_to_ascii
; ')', 13, 10, 0 ; ')', 13, 10, 0
mov eax, ')' + 0x000a0d00 mov eax, ')' + (0x000a0d shl 8)
stosd stosd
lea esi, [edi - thread_data.buffer] lea esi, [edi - thread_data.buffer]
@ -783,6 +782,12 @@ cmdPASV:
ret ret
iglobal
str_227 db "227 Entering passive mode ("
.length = $ - str_227
endg
;------------------------------------------------ ;------------------------------------------------
; "PWD" ; "PWD"
; ;

View File

@ -76,10 +76,11 @@ macro sendFTP str {
local string, length local string, length
xor edi, edi xor edi, edi
mcall send, [ebp + thread_data.socketnum], string, length mcall send, [ebp + thread_data.socketnum], string, length
invoke con_write_asciiz, string
iglobal iglobal
string db str, 13, 10 string db str, 13, 10, 0
length = $ - string length = $ - string - 1
\} \}
} }
@ -87,7 +88,7 @@ include 'commands.inc'
start: start:
mcall 68, 11 ; init heap mcall 68, 11 ; init heap
mcall 40, 1 shl 7 ; we only want network events mcall 40, EVM_STACK ; we only want network events
; load libraries ; load libraries
stdcall dll.Load, @IMPORT stdcall dll.Load, @IMPORT
@ -138,7 +139,7 @@ start:
add esp, 8 add esp, 8
; open listening socket ; open listening socket
mcall socket, AF_INET4, SOCK_STREAM, 0 mcall socket, AF_INET4, SOCK_STREAM, SO_NONBLOCK ; we dont want to block on accept
cmp eax, -1 cmp eax, -1
je sock_err je sock_err
mov [socketnum], eax mov [socketnum], eax
@ -208,7 +209,7 @@ threadstart:
lea esp, [eax + thread_data.stack] ; init stack lea esp, [eax + thread_data.stack] ; init stack
mov ebp, eax mov ebp, eax
mcall 40, 1 shl 7 ; we only want network events for this thread mcall 40, EVM_STACK ; we only want network events for this thread
lea ebx, [ebp + thread_data.buffer] ; get information about the current process lea ebx, [ebp + thread_data.buffer] ; get information about the current process
or ecx, -1 or ecx, -1
@ -241,15 +242,17 @@ end if
diff16 "threadloop", 0, $ diff16 "threadloop", 0, $
threadloop: threadloop:
; Check if our socket is still connected ;; Check if our socket is still connected
mcall send, [ebp + thread_data.socketnum], 0, 0 ; Try to send zero bytes, if socket is closed, this will return -1 ; mcall send, [ebp + thread_data.socketnum], 0, 0 ; Try to send zero bytes, if socket is closed, this will return -1
cmp eax, -1 ; cmp eax, -1
je thread_exit ; je thread_exit
cmp [alive], 0 ; Did main thread take a run for it? cmp [alive], 0 ; Did main thread take a run for it?
je thread_exit je thread_exit
mcall 10 ; Wait for network event mcall 23, 100 ; Wait for network event
test eax, eax
jz threadloop
cmp [ebp + thread_data.mode], MODE_PASSIVE_WAIT cmp [ebp + thread_data.mode], MODE_PASSIVE_WAIT
jne .not_passive jne .not_passive
@ -282,12 +285,17 @@ threadloop:
; Check if we received a newline character, if not, wait for more data ; Check if we received a newline character, if not, wait for more data
mov ecx, eax mov ecx, eax
mov al, 13 mov al, 10
repne scasb repne scasb
jne threadloop jne threadloop
cmp word[edi-1], 0x0a0d
jne .got_command
dec edi
; We got a command! ; We got a command!
mov byte [edi + 1], 0 ; append string with zero byte .got_command:
mov byte [edi], 0 ; append string with zero byte
lea esi, [ebp + thread_data.buffer] lea esi, [ebp + thread_data.buffer]
mov ecx, [ebp + thread_data.buffer_ptr] mov ecx, [ebp + thread_data.buffer_ptr]
sub ecx, esi sub ecx, esi
@ -332,7 +340,7 @@ thread_exit:
; initialized data ; initialized data
title db 'KolibriOS FTP daemon 0.1', 0 title db 'FTP daemon', 0
str1 db 'Starting FTP daemon on port %u.', 0 str1 db 'Starting FTP daemon on port %u.', 0
str2 db '.', 0 str2 db '.', 0
str2b db ' OK!',10,0 str2b db ' OK!',10,0