From ad2eb55faba4bbbfb7cefa85c0fe9250617a1ae2 Mon Sep 17 00:00:00 2001 From: hidnplayr Date: Thu, 26 Jul 2012 23:24:24 +0000 Subject: [PATCH] code improvements and cleanup for FTPd git-svn-id: svn://kolibrios.org@2892 a494cfbc-eb01-0410-851d-a64ba20cac60 --- .../net/applications/ftpd/commands.inc | 140 ++++++++---------- .../branches/net/applications/ftpd/ftpd.asm | 28 ++-- 2 files changed, 76 insertions(+), 92 deletions(-) diff --git a/kernel/branches/net/applications/ftpd/commands.inc b/kernel/branches/net/applications/ftpd/commands.inc index 27afbec21f..3f4bb03938 100644 --- a/kernel/branches/net/applications/ftpd/commands.inc +++ b/kernel/branches/net/applications/ftpd/commands.inc @@ -279,6 +279,54 @@ nextpasvport: 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" ; @@ -425,44 +473,8 @@ cmdLIST: test [ebp + thread_data.permissions], PERMISSION_EXEC jz permission_denied - cmp [ebp + thread_data.mode], MODE_PASSIVE_OK - je .start + call open_datasock -; 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 call create_path @@ -687,10 +699,10 @@ cmdPASS: align 4 cmdPASV: - cmp [ebp + thread_data.passivesocknum], -1 - je @f - mcall close, [ebp + thread_data.passivesocknum] ; if there is still a socket open, close it - @@: +; cmp [ebp + thread_data.passivesocknum], -1 +; je @f +; mcall close, [ebp + thread_data.passivesocknum] ; if there is still a socket open, close it +; @@: ; Open a new TCP socket mcall socket, AF_INET4, SOCK_STREAM, 0 @@ -886,49 +898,11 @@ cmdRETR: sub ecx, 5 jb .cannot_open - cmp [ebp + thread_data.mode], MODE_PASSIVE_OK - je .start + call open_datasock -; 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 dec edi - add esi, 5 - - lea esi, [ebp + thread_data.buffer] ; FIXME + lea esi, [ebp + thread_data.buffer + 5] mov ecx, 1024 .loop: lodsb @@ -961,6 +935,8 @@ cmdRETR: cmp eax, -1 je .cannot_open ; FIXME: this is not the correct error + invoke con_write_asciiz, str2 + push eax ebx mov esi, eax mov ecx, [ebp + thread_data.datasocketnum] @@ -979,6 +955,8 @@ cmdRETR: invoke file.close, ebx + invoke con_write_asciiz, str2b + mov [ebp + thread_data.mode], MODE_NOTREADY mcall close, [ebp + thread_data.datasocketnum] diff --git a/kernel/branches/net/applications/ftpd/ftpd.asm b/kernel/branches/net/applications/ftpd/ftpd.asm index 0611d4aa1a..c36fd0a98a 100644 --- a/kernel/branches/net/applications/ftpd/ftpd.asm +++ b/kernel/branches/net/applications/ftpd/ftpd.asm @@ -1,20 +1,26 @@ -; -; Kolibrios FTP Daemon -; -; hidnplayr@gmail.com -; -; GPLv2 -; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; ;; +;; Copyright (C) KolibriOS team 2010-2012. All rights reserved. ;; +;; Distributed under terms of the GNU General Public License ;; +;; ;; +;; 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 BUFFERSIZE = 8192 ; using multiple's of 4 -STATE_CONNECTED = 4*0 -STATE_LOGIN = 4*1 -STATE_LOGIN_FAIL = 4*2 ; When an invalid username was given -STATE_ACTIVE = 4*3 +STATE_CONNECTED = 0*4 +STATE_LOGIN = 1*4 +STATE_LOGIN_FAIL = 2*4 ; When an invalid username was given +STATE_ACTIVE = 3*4 TYPE_UNDEF = 0