code improvements and cleanup for FTPd

git-svn-id: svn://kolibrios.org@2892 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
hidnplayr 2012-07-26 23:24:24 +00:00
parent 83c26b2500
commit ad2eb55fab
2 changed files with 76 additions and 92 deletions

View File

@ -279,6 +279,54 @@ nextpasvport:
ret ret
align 4
open_datasock:
cmp [ebp + thread_data.mode], MODE_PASSIVE_OK
je .start
; If we are in active mode, it's time to open a data socket..
cmp [ebp + thread_data.mode], MODE_ACTIVE
jne .not_active
mov ecx, [ebp + thread_data.datasocketnum]
lea edx, [ebp + thread_data.datasock]
mov esi, sizeof.thread_data.datasock
mcall connect
cmp eax, -1
jne .start
.socketerror:
add esp, 4
jmp socketerror
; If we are still in passive_wait, it's time we accept an incomming call..
.not_active:
cmp [ebp + thread_data.mode], MODE_PASSIVE_WAIT
jne .socketerror
.try_now:
mov ecx, [ebp + thread_data.passivesocknum]
lea edx, [ebp + thread_data.datasock]
mov esi, sizeof.thread_data.datasock
mcall accept
cmp eax, -1
jne .pasv_ok
mov [ebp + thread_data.mode], MODE_PASSIVE_FAILED ; assume that we will fail
mcall 23, 200
mcall accept
cmp eax, -1
je .socketerror
.pasv_ok:
mov [ebp + thread_data.datasocketnum], eax
mov [ebp + thread_data.mode], MODE_PASSIVE_OK
mcall close ; [ebp + thread_data.passivesocknum]
mov [ebp + thread_data.passivesocknum], -1
invoke con_write_asciiz, str_datasock
.start:
ret
;------------------------------------------------ ;------------------------------------------------
; "ABOR" ; "ABOR"
; ;
@ -425,44 +473,8 @@ cmdLIST:
test [ebp + thread_data.permissions], PERMISSION_EXEC test [ebp + thread_data.permissions], PERMISSION_EXEC
jz permission_denied jz permission_denied
cmp [ebp + thread_data.mode], MODE_PASSIVE_OK call open_datasock
je .start
; If we are in active mode, it's time to open a data socket..
cmp [ebp + thread_data.mode], MODE_ACTIVE
jne .not_active
mov ecx, [ebp + thread_data.datasocketnum]
lea edx, [ebp + thread_data.datasock]
mov esi, sizeof.thread_data.datasock
mcall connect
cmp eax, -1
je socketerror
jmp .start
; If we are still in passive_wait, it's time we accept an incomming call..
.not_active:
cmp [ebp + thread_data.mode], MODE_PASSIVE_WAIT
jne socketerror
.try_now:
mov ecx, [ebp + thread_data.passivesocknum]
lea edx, [ebp + thread_data.datasock]
mov esi, sizeof.thread_data.datasock
mcall accept
cmp eax, -1
jne .pasv_ok
mov [ebp + thread_data.mode], MODE_PASSIVE_FAILED ; assume that we will fail
mcall 23, 200
mcall accept
cmp eax, -1
je socketerror
.pasv_ok:
mov [ebp + thread_data.datasocketnum], eax
mov [ebp + thread_data.mode], MODE_PASSIVE_OK
mcall close ; [ebp + thread_data.passivesocknum]
mov [ebp + thread_data.passivesocknum], -1
invoke con_write_asciiz, str_datasock
.start:
; Create fpath from home_dir and work_dir ; Create fpath from home_dir and work_dir
call create_path call create_path
@ -687,10 +699,10 @@ cmdPASS:
align 4 align 4
cmdPASV: cmdPASV:
cmp [ebp + thread_data.passivesocknum], -1 ; cmp [ebp + thread_data.passivesocknum], -1
je @f ; je @f
mcall close, [ebp + thread_data.passivesocknum] ; if there is still a socket open, close it ; mcall close, [ebp + thread_data.passivesocknum] ; if there is still a socket open, close it
@@: ; @@:
; Open a new TCP socket ; Open a new TCP socket
mcall socket, AF_INET4, SOCK_STREAM, 0 mcall socket, AF_INET4, SOCK_STREAM, 0
@ -886,49 +898,11 @@ cmdRETR:
sub ecx, 5 sub ecx, 5
jb .cannot_open jb .cannot_open
cmp [ebp + thread_data.mode], MODE_PASSIVE_OK call open_datasock
je .start
; If we are in active mode, it's time to open a data socket..
cmp [ebp + thread_data.mode], MODE_ACTIVE
jne .not_active
mov ecx, [ebp + thread_data.datasocketnum]
lea edx, [ebp + thread_data.datasock]
mov esi, sizeof.thread_data.datasock
mcall connect
cmp eax, -1
je socketerror
jmp .start
; If we are still in passive_wait, it's time we accept an incomming call..
.not_active:
cmp [ebp + thread_data.mode], MODE_PASSIVE_WAIT
jne socketerror
mov [ebp + thread_data.mode], MODE_PASSIVE_FAILED ; assume that we will fail
.try_now:
mov ecx, [ebp + thread_data.passivesocknum]
lea edx, [ebp + thread_data.datasock]
mov esi, sizeof.thread_data.datasock
mcall accept
cmp eax, -1
jne .pasv_ok
mcall 23, 200
mcall accept
cmp eax, -1
je socketerror
.pasv_ok:
mov [ebp + thread_data.datasocketnum], eax
mov [ebp + thread_data.mode], MODE_PASSIVE_OK
mcall close ; [ebp + thread_data.passivesocknum]
mov [ebp + thread_data.passivesocknum], -1
invoke con_write_asciiz, str_datasock
.start:
call create_path call create_path
dec edi dec edi
add esi, 5 lea esi, [ebp + thread_data.buffer + 5]
lea esi, [ebp + thread_data.buffer] ; FIXME
mov ecx, 1024 mov ecx, 1024
.loop: .loop:
lodsb lodsb
@ -961,6 +935,8 @@ cmdRETR:
cmp eax, -1 cmp eax, -1
je .cannot_open ; FIXME: this is not the correct error je .cannot_open ; FIXME: this is not the correct error
invoke con_write_asciiz, str2
push eax ebx push eax ebx
mov esi, eax mov esi, eax
mov ecx, [ebp + thread_data.datasocketnum] mov ecx, [ebp + thread_data.datasocketnum]
@ -979,6 +955,8 @@ cmdRETR:
invoke file.close, ebx invoke file.close, ebx
invoke con_write_asciiz, str2b
mov [ebp + thread_data.mode], MODE_NOTREADY mov [ebp + thread_data.mode], MODE_NOTREADY
mcall close, [ebp + thread_data.datasocketnum] mcall close, [ebp + thread_data.datasocketnum]

View File

@ -1,20 +1,26 @@
; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Kolibrios FTP Daemon ;; ;;
; ;; Copyright (C) KolibriOS team 2010-2012. All rights reserved. ;;
; hidnplayr@gmail.com ;; Distributed under terms of the GNU General Public License ;;
; ;; ;;
; GPLv2 ;; ftpd.asm - FTP Daemon for KolibriOS ;;
; ;; ;;
;; Written by hidnplayr@kolibrios.org ;;
;; ;;
;; GNU GENERAL PUBLIC LICENSE ;;
;; Version 2, June 1991 ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
DEBUG = 0 ; if set to one, program will run in a single thread DEBUG = 0 ; if set to one, program will run in a single thread
BUFFERSIZE = 8192 BUFFERSIZE = 8192
; using multiple's of 4 ; using multiple's of 4
STATE_CONNECTED = 4*0 STATE_CONNECTED = 0*4
STATE_LOGIN = 4*1 STATE_LOGIN = 1*4
STATE_LOGIN_FAIL = 4*2 ; When an invalid username was given STATE_LOGIN_FAIL = 2*4 ; When an invalid username was given
STATE_ACTIVE = 4*3 STATE_ACTIVE = 3*4
TYPE_UNDEF = 0 TYPE_UNDEF = 0