From e6158a19a81ce10f0540cffb6ed8d58460a60c95 Mon Sep 17 00:00:00 2001 From: hidnplayr Date: Mon, 15 Jul 2013 10:49:21 +0000 Subject: [PATCH] FTPd: bugfix: do not send 0 byte in PASV and PWD replies. git-svn-id: svn://kolibrios.org@3824 a494cfbc-eb01-0410-851d-a64ba20cac60 --- programs/network/ftpd/commands.inc | 30 +++++++++++++++++++++--------- programs/network/ftpd/ftpd.asm | 2 ++ 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/programs/network/ftpd/commands.inc b/programs/network/ftpd/commands.inc index f0c4d0ab17..a0090e94fe 100644 --- a/programs/network/ftpd/commands.inc +++ b/programs/network/ftpd/commands.inc @@ -90,7 +90,7 @@ commands: ; all commands must be in uppercase ; dd 'MDTM', login_first, login_first, login_first, cmd_MDTM ; dd 'MKD', login_first, login_first, login_first, cmd_MKD ; dd 'MODE', login_first, login_first, login_first, cmd_MODE - dd 'NLST', login_first, login_first, login_first, cmdNLST +; dd 'NLST', login_first, login_first, login_first, cmdNLST dd 'NOOP', login_first, login_first, login_first, cmdNOOP dd 'PASS', cmdPASS.0, cmdPASS , cmdPASS.2, cmdPASS.3 dd 'PASV', login_first, login_first, login_first, cmdPASV @@ -283,9 +283,9 @@ align 4 open_datasock: cmp [ebp + thread_data.mode], MODE_PASSIVE_OK - je .start + je .already_open -; If we are in active mode, it's time to open a data socket.. +; If we are in active mode, it's time to open the data socket.. cmp [ebp + thread_data.mode], MODE_ACTIVE jne .not_active mov ecx, [ebp + thread_data.datasocketnum] @@ -293,7 +293,13 @@ open_datasock: mov esi, sizeof.thread_data.datasock mcall connect cmp eax, -1 - jne .start + je .socketerror + invoke con_write_asciiz, str_datasock2 + ret + + .already_open: + invoke con_write_asciiz, str_alopen + ret .socketerror: add esp, 4 @@ -323,7 +329,6 @@ open_datasock: mov [ebp + thread_data.passivesocknum], -1 invoke con_write_asciiz, str_datasock - .start: ret @@ -600,7 +605,7 @@ cmdLIST: mov [ebp + thread_data.mode], MODE_NOTREADY mcall close, [ebp + thread_data.datasocketnum] - sendFTP "226 Transfer OK" + sendFTP "226 List OK" ret .nosuchdir: @@ -773,13 +778,15 @@ cmdPASV: mov eax, ')' + (0x000a0d shl 8) stosd - lea esi, [edi - thread_data.buffer] + lea esi, [edi - thread_data.buffer - 1] ; calculate length, do not cound the trailing 0 byte sub esi, ebp mov ecx, [ebp + thread_data.socketnum] lea edx, [ebp + thread_data.buffer] xor edi, edi mcall send + invoke con_write_asciiz, edx + ret @@ -813,7 +820,7 @@ cmdPWD: .ok: mov dword [edi], '"' + 0x000a0d00 ; '"',13,10,0 - lea esi, [edi - thread_data.buffer + 4] + lea esi, [edi - thread_data.buffer + 3] sub esi, ebp mov ecx, [ebp + thread_data.socketnum] lea edx, [ebp + thread_data.buffer] @@ -991,13 +998,18 @@ cmdSTOR: test [ebp + thread_data.permissions], PERMISSION_WRITE jz permission_denied + sendFTP " Ready to receive" + + +;;;; TODO -;;;; test [ebp + thread_data.permissions], ABORT jnz abort_transfer ;;;; + sendFTP "226 Transfer OK" + ret ;------------------------------------------------ diff --git a/programs/network/ftpd/ftpd.asm b/programs/network/ftpd/ftpd.asm index c149cae2b9..2f223bd095 100644 --- a/programs/network/ftpd/ftpd.asm +++ b/programs/network/ftpd/ftpd.asm @@ -358,6 +358,8 @@ str_pass_err db 'Password/Username incorrect',10,0 str_pwd db 'Current directory is "%s"\n',0 str_err2 db 'ERROR: cannot open the directory.',10,0 str_datasock db 'Passive data socket connected.',10,0 +str_datasock2 db 'Active data socket connected.',10,0 +str_alopen db 'Data connection already open.',10,0 str_notfound db 'ERROR: file not found.',10,0 str_sockerr db 'ERROR: socket error.',10,0