Some cosmetic changes in FTPd (net branch)

git-svn-id: svn://kolibrios.org@2585 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
hidnplayr 2012-04-07 18:42:58 +00:00
parent 953b8091f9
commit 70caf20c58
2 changed files with 66 additions and 45 deletions

View File

@ -81,10 +81,10 @@ commands: ; all commands must be in uppercase
dd cmdPASS dd cmdPASS
db 'PASV' db 'PASV'
dd cmdPASV dd cmdPASV
db 'PWD', 0
dd cmdPWD
db 'PORT' db 'PORT'
dd cmdPORT dd cmdPORT
db 'PWD', 0
dd cmdPWD
db 'QUIT' db 'QUIT'
dd cmdQUIT dd cmdQUIT
db 'RETR' db 'RETR'
@ -97,8 +97,6 @@ commands: ; all commands must be in uppercase
dd cmdTYPE dd cmdTYPE
db 'USER' db 'USER'
dd cmdUSER dd cmdUSER
db 'XPWD'
dd cmdPWD
db 0 ; end marker db 0 ; end marker
@ -112,24 +110,34 @@ cmdABOR:
align 4 align 4
cmdCDUP: cmdCDUP:
cmp byte [edx + thread_data.work_dir+1], 0 cmp byte [edx + thread_data.work_dir+1], 0 ; are we in "/" ?
je .done je .done
mov ecx, 1024 mov ecx, 1024
xor al, al xor al, al
lea edi, [edx + thread_data.work_dir+1024] lea edi, [edx + thread_data.work_dir]
repne scasb repne scasb
std std
dec edi dec edi
dec edi
dec edi
mov al,'/' mov al,'/'
scasb repne scasb
cld cld
mov byte[edi], 0 mov byte[edi+1], 0
.done: .done:
mcall send, [edx + thread_data.socketnum], str250, str250.length, 0 ; command successful ; Print the new working dir on the console
lea eax, [edx + thread_data.work_dir]
push eax
call [con_write_asciiz]
push str_newline
call [con_write_asciiz]
mcall send, [edx + thread_data.socketnum], str250, str250.length, 0 ; command successful
ret ret
align 4 align 4
cmdCWD: ; Change Working Directory cmdCWD: ; Change Working Directory
@ -174,6 +182,13 @@ cmdCWD: ; Change Working Directory
@@: @@:
mov byte [edi], 0 mov byte [edi], 0
; Print the new working dir on the console
lea eax, [edx + thread_data.work_dir]
push eax
call [con_write_asciiz]
push str_newline
call [con_write_asciiz]
mcall send, [edx + thread_data.socketnum], str250, str250.length, 0 mcall send, [edx + thread_data.socketnum], str250, str250.length, 0
ret ret
@ -198,6 +213,7 @@ cmdDELE:
ret ret
align 4 align 4
cmdLIST: cmdLIST:
@ -344,11 +360,7 @@ cmdLIST:
; close the data socket.. ; close the data socket..
mov edx, [esp+4] ; thread_data pointer mov edx, [esp+4] ; thread_data pointer
mcall close, [edx + thread_data.datasocketnum] mcall close, [edx + thread_data.datasocketnum]
cmp [edx + thread_data.mode], MODE_PASSIVE_OK
jne @f
mov [edx + thread_data.mode], MODE_NOTREADY mov [edx + thread_data.mode], MODE_NOTREADY
@@:
; And send "transfer ok" on the base connection ; And send "transfer ok" on the base connection
mcall send, [edx + thread_data.socketnum], str226, str226.length, 0 mcall send, [edx + thread_data.socketnum], str226, str226.length, 0
@ -448,6 +460,7 @@ cmdPASV:
ret ret
align 4 align 4
cmdPWD: ; Print Working Directory cmdPWD: ; Print Working Directory
@ -471,14 +484,20 @@ cmdPWD: ; Print Working Directory
sub esi, edx sub esi, edx
mov ecx, [edx + thread_data.socketnum] mov ecx, [edx + thread_data.socketnum]
lea edx, [edx + thread_data.buffer] lea edx, [edx + thread_data.buffer]
mcall send, , , , 0 xor edi, edi
mcall send
; push work_dir mov edx, [esp+4]
; push str_pwd ; Print the new working dir on the console
; call [con_printf] lea eax, [edx + thread_data.work_dir]
push eax
call [con_write_asciiz]
push str_newline
call [con_write_asciiz]
ret ret
align 4 align 4
cmdPORT: cmdPORT:
@ -620,11 +639,7 @@ cmdRETR:
je .read_more je .read_more
mcall close, [edx + thread_data.datasocketnum] mcall close, [edx + thread_data.datasocketnum]
mov [edx + thread_data.mode], MODE_NOTREADY
cmp [edx + thread_data.mode], MODE_PASSIVE_OK
jne @f
mov [edx + thread_data.mode], MODE_PASSIVE_WAIT
@@:
mcall send, [edx + thread_data.socketnum], str226, str226.length, 0 ; transfer ok mcall send, [edx + thread_data.socketnum], str226, str226.length, 0 ; transfer ok
@ -684,7 +699,6 @@ cmdTYPE:
mov [edx + thread_data.type], TYPE_EBDIC mov [edx + thread_data.type], TYPE_EBDIC
.subtype: .subtype:
cmp ecx, 8 cmp ecx, 8
jb .non_print jb .non_print
@ -733,21 +747,21 @@ cmdTYPE:
ret ret
align 4 align 4
cmdUSER: cmdUSER:
; TODO: check user and set home directory (and permissions) ; TODO: check user and set home directory (and permissions)
mcall send, [edx + thread_data.socketnum], str331, str331.length, 0
mov edx, [esp+4] ; thread_data pointer
mov [edx + thread_data.state], STATE_LOGIN mov [edx + thread_data.state], STATE_LOGIN
mov word [edx + thread_data.home_dir], "/" ; "/", 0
mov byte [edx + thread_data.work_dir], "/" mov word [edx + thread_data.work_dir], "/" ; "/", 0
mov byte [edx + thread_data.work_dir+1], 0
push str_logged_in push str_logged_in
call [con_write_asciiz] call [con_write_asciiz]
mcall send, [edx + thread_data.socketnum], str331, str331.length, 0 ; Now send me the password!
ret ret

View File

@ -64,7 +64,7 @@ start:
; find path to main settings file ; find path to main settings file
mov edi, path ; Calculate the length of zero-terminated string mov edi, path ; Calculate the length of zero-terminated string
xor al , al xor al, al
mov ecx, 1024 mov ecx, 1024
repne scasb repne scasb
dec edi dec edi
@ -101,9 +101,9 @@ start:
push str2 push str2
call [con_write_asciiz] call [con_write_asciiz]
;; mcall setsockopt, [socketnum], SOL_SOCKET, SO_REUSEADDR, &yes, ; mcall setsockopt, [socketnum], SOL_SOCKET, SO_REUSEADDR, &yes,
;; cmp eax, -1 ; cmp eax, -1
;; je opt_err ; je opt_err
mcall bind, [socketnum], sockaddr1, sockaddr1.length mcall bind, [socketnum], sockaddr1, sockaddr1.length
cmp eax, -1 cmp eax, -1
@ -132,6 +132,7 @@ mainloop:
; NOTE: upon initialisation of the thread, stack will not be available! ; NOTE: upon initialisation of the thread, stack will not be available!
jmp mainloop jmp mainloop
diff16 "threadstart", 0, $
threadstart: threadstart:
mcall 68, 12, sizeof.thread_data ; allocate the thread data struct mcall 68, 12, sizeof.thread_data ; allocate the thread data struct
cmp eax, -1 cmp eax, -1
@ -142,8 +143,12 @@ threadstart:
mcall 40, 1 shl 7 ; we only want network events for this thread mcall 40, 1 shl 7 ; we only want network events for this thread
pushd 0x03
call [con_set_flags]
push str8 push str8
call [con_write_asciiz] ; print on the console that we have created the new thread successfully call [con_write_asciiz] ; print on the console that we have created the new thread successfully
pushd 0x07
call [con_set_flags]
mcall accept, [socketnum], sockaddr1, sockaddr1.length ; time to accept the awaiting connection.. mcall accept, [socketnum], sockaddr1, sockaddr1.length ; time to accept the awaiting connection..
cmp eax, -1 cmp eax, -1
@ -187,8 +192,10 @@ threadloop:
mov edx, [esp+4] ; pointer to thread_data mov edx, [esp+4] ; pointer to thread_data
mov byte [edx + thread_data.buffer + eax], 0 ; append received data with a 0 byte mov byte [edx + thread_data.buffer + eax], 0 ; append received data with a 0 byte
pushd 0x0a ; print received data to console (in green color) pushd 0x02 ; print received data to console (in green color)
call [con_set_flags] call [con_set_flags]
push str_newline
call [con_write_asciiz]
lea eax, [edx + thread_data.buffer] lea eax, [edx + thread_data.buffer]
push eax push eax
call [con_write_asciiz] call [con_write_asciiz]
@ -244,22 +251,22 @@ thread_exit:
title db 'KolibriOS FTP daemon 0.1', 0 title db 'KolibriOS FTP daemon 0.1', 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,10,0 str2b db ' OK!',10,0
str3 db 'Listen error',10,10,0 str3 db 'Listen error',10,0
str4 db 'Bind error',10,10,0 str4 db 'Bind error',10,0
;str5 db 'Setsockopt error.',10,10,0 ;str5 db 'Setsockopt error.',10,10,0
str6 db 'Could not open socket',10,10,0 str6 db 'Could not open socket',10,0
str7 db 'Got data!',10,10,0 str7 db 'Got data!',10,10,0
str8 db 10,'New thread created!',10,10,0 str8 db 10,'New thread created!',10,0
str_bye db 10,'Closing thread!',10,10,0 str_bye db 10,'Closing thread!',10,0
str_logged_in db 'Login ok',10,10,0 str_logged_in db 'Login ok',10,0
str_pass_ok db 'Password ok - Logged in',10,10,0 str_pass_ok db 'Password ok - Logged in',10,0
str_pwd db 'Current directory is "%s"\n',0 str_pwd db 'Current directory is "%s"\n',0
str_err2 db 'ERROR: cannot open directory',10,10,0 str_err2 db 'ERROR: cannot open directory',10,0
str_datasock db 'Passive data socket connected!',10,10,0 str_datasock db 'Passive data socket connected!',10,0
str_notfound db 'ERROR: file not found',10,10,0 str_notfound db 'ERROR: file not found',10,0
str_sockerr db 'ERROR: socket error',10,10,0 str_sockerr db 'ERROR: socket error',10,0
str_newline db 10, 0 str_newline db 10, 0
str_mask db '*', 0 str_mask db '*', 0