Subversion Repositories Kolibri OS

Rev

Rev 2585 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2585 Rev 2598
Line 6... Line 6...
6
; GPLv2
6
; GPLv2
7
;
7
;
Line 8... Line 8...
8
 
8
 
Line 9... Line 9...
9
BUFFERSIZE              = 8192
9
BUFFERSIZE              = 8192
10
 
10
 
11
STATE_DISCONNECTED      = 0
11
; using multiple's of 4
-
 
12
STATE_CONNECTED         = 4*0
12
STATE_CONNECTED         = 1
13
STATE_LOGIN             = 4*1
Line 13... Line 14...
13
STATE_LOGIN             = 2
14
STATE_LOGIN_FAIL        = 4*2           ; When an invalid username was given
Line 14... Line 15...
14
STATE_ACTIVE            = 3
15
STATE_ACTIVE            = 4*3
15
 
16
 
Line 23... Line 24...
23
TYPE_ASA                = 00000011b
24
TYPE_ASA                = 00000011b
Line 24... Line 25...
24
 
25
 
25
TYPE_IMAGE              = 01000000b     ; binary data
26
TYPE_IMAGE              = 01000000b     ; binary data
26
TYPE_LOCAL              = 10000000b     ; bits per byte must be specified
27
TYPE_LOCAL              = 10000000b     ; bits per byte must be specified
27
                                        ; lower 4 bits will hold this value
-
 
28
 
28
                                        ; lower 4 bits will hold this value
29
MODE_NOTREADY           = 0
29
MODE_NOTREADY           = 0
30
MODE_ACTIVE             = 1
30
MODE_ACTIVE             = 1
31
MODE_PASSIVE_WAIT       = 2
31
MODE_PASSIVE_WAIT       = 2
-
 
32
MODE_PASSIVE_OK         = 3
-
 
33
MODE_PASSIVE_FAILED     = 4
-
 
34
 
-
 
35
PERMISSION_EXEC         = 1b            ; LIST
-
 
36
PERMISSION_READ         = 10b
-
 
37
PERMISSION_WRITE        = 100b
-
 
38
PERMISSION_DELETE       = 1000b
-
 
39
PERMISSION_CD           = 10000b        ; Change Directory
-
 
40
 
Line 32... Line 41...
32
MODE_PASSIVE_OK         = 3
41
ABORT                   = 1 shl 31
Line 33... Line 42...
33
 
42
 
34
format binary as ""
43
format binary as ""
Line 60... Line 69...
60
        test    eax, eax
69
        test    eax, eax
61
        jnz     exit
70
        jnz     exit
Line 62... Line 71...
62
 
71
 
Line 63... Line 72...
63
        mcall   68, 11                  ; init heap
72
        mcall   68, 11                  ; init heap
64
 
73
 
65
; find path to main settings file
74
; find path to main settings file (ftpd.ini)
66
        mov     edi, path               ; Calculate the length of zero-terminated string
75
        mov     edi, path               ; Calculate the length of zero-terminated string
67
        xor     al, al
76
        xor     al, al
68
        mov     ecx, 1024
77
        mov     ecx, 1024
69
        repne   scasb
78
        repne   scasb
70
        dec     edi
79
        dec     edi
71
        mov     esi, filename           ; append it with '.ini'
80
        mov     esi, str_ini            ; append it with '.ini', 0
Line -... Line 81...
-
 
81
        movsd
-
 
82
        movsb
-
 
83
 
-
 
84
; now create the second path (users.ini)
-
 
85
        std
-
 
86
        mov     al, '/'
-
 
87
        repne   scasb
-
 
88
        lea     ecx, [edi - path + 2]
-
 
89
        cld
-
 
90
        mov     esi, path
-
 
91
        mov     edi, path2
-
 
92
        rep     movsb
-
 
93
        mov     esi, str_users
-
 
94
        movsd
72
        movsd
95
        movsd
73
        movsb
96
        movsw
74
 
97
 
Line 75... Line 98...
75
; initialize console
98
; initialize console
Line 83... Line 106...
83
        push    -1
106
        push    -1
84
        call    [con_init]
107
        call    [con_init]
Line 85... Line 108...
85
 
108
 
Line -... Line 109...
-
 
109
        mcall   40, 1 shl 7             ; we only want network events
-
 
110
 
-
 
111
        invoke  ini.get_str, path, str_ftpd, str_ip, ini_buf, 16, 0
-
 
112
        mov     esi, ini_buf
-
 
113
        call    ip_to_dword
86
        mcall   40, 1 shl 7             ; we only want network events
114
        mov     [serverip], ebx
87
 
115
 
Line 88... Line 116...
88
        invoke  ini.get_int, path, str_ftpd, str_port, 21
116
        invoke  ini.get_int, path, str_ftpd, str_port, 21
89
        mov     [sockaddr1.port], ax
117
        mov     [sockaddr1.port], ax
Line 138... Line 166...
138
        cmp     eax, -1
166
        cmp     eax, -1
139
        je      exit
167
        je      exit
Line 140... Line 168...
140
 
168
 
141
        lea     esp, [eax + thread_data.stack]  ; init stack
169
        lea     esp, [eax + thread_data.stack]  ; init stack
-
 
170
        push    eax                             ; save pointer to thread_data on stack
Line 142... Line 171...
142
        push    eax                             ; save pointer to thread_data on stack
171
        mov     ebp, esp
Line 143... Line 172...
143
 
172
 
144
        mcall   40, 1 shl 7                     ; we only want network events for this thread
173
        mcall   40, 1 shl 7                     ; we only want network events for this thread
Line 151... Line 180...
151
        call    [con_set_flags]
180
        call    [con_set_flags]
Line 152... Line 181...
152
 
181
 
153
        mcall   accept, [socketnum], sockaddr1, sockaddr1.length                ; time to accept the awaiting connection..
182
        mcall   accept, [socketnum], sockaddr1, sockaddr1.length                ; time to accept the awaiting connection..
154
        cmp     eax, -1
183
        cmp     eax, -1
155
        je      thread_exit
184
        je      thread_exit
156
        mov     edx, [esp]                                                      ; pointer to thread_data
185
        mov     edx, [ebp]                                                      ; pointer to thread_data
Line 157... Line 186...
157
        mov     [edx + thread_data.socketnum], eax
186
        mov     [edx + thread_data.socketnum], eax
-
 
187
 
-
 
188
        mov     [edx + thread_data.state], STATE_CONNECTED
-
 
189
        mov     [edx + thread_data.permissions], 0
-
 
190
        mov     [edx + thread_data.mode], MODE_NOTREADY
-
 
191
        lea     eax, [edx + thread_data.buffer]
-
 
192
        mov     [edx + thread_data.buffer_ptr], eax
Line 158... Line 193...
158
 
193
 
159
        mcall   send, [edx + thread_data.socketnum], str220, str220.length, 0   ; send welcome string to the FTP client
194
        sendFTP "220 Welcome to KolibriOS FTP daemon"
Line 160... Line 195...
160
 
195
 
Line 161... Line 196...
161
threadloop:
196
threadloop:
162
        mcall   10
197
        mcall   10
163
 
198
 
164
        mov     edx, [esp]                                                      ; pointer to thread_data
199
        mov     edx, [ebp]                                                      ; pointer to thread_data
165
 
200
 
166
        cmp     [edx + thread_data.mode], MODE_PASSIVE_WAIT
201
        cmp     [edx + thread_data.mode], MODE_PASSIVE_WAIT
167
        jne     @f
202
        jne     .not_passive
168
        mov     ecx, [edx + thread_data.passivesocknum]
203
        mov     ecx, [edx + thread_data.passivesocknum]
169
        lea     edx, [edx + thread_data.datasock]
204
        lea     edx, [edx + thread_data.datasock]
170
        mov     esi, sizeof.thread_data.datasock
205
        mov     esi, sizeof.thread_data.datasock
171
        mcall   accept
206
        mcall   accept
Line 172... Line 207...
172
        mov     edx, [esp]                                                      ; pointer to thread_data
207
        mov     edx, [ebp]                                                      ; pointer to thread_data
173
        cmp     eax, -1
208
        cmp     eax, -1
174
        je      @f
209
        je      .not_passive
Line 175... Line 210...
175
        mov     [edx + thread_data.datasocketnum], eax
210
        mov     [edx + thread_data.datasocketnum], eax
176
        mov     [edx + thread_data.mode], MODE_PASSIVE_OK
211
        mov     [edx + thread_data.mode], MODE_PASSIVE_FAILED
177
 
212
 
178
        push    str_datasock
213
        push    str_datasock
179
        call    [con_write_asciiz]                                              ; print on the console that the datasock is now ready
214
        call    [con_write_asciiz]                                              ; print on the console that the datasock is now ready
180
       @@:
215
  .not_passive:
181
 
216
 
182
        mov     ecx, [edx + thread_data.socketnum]
217
        mov     ecx, [edx + thread_data.socketnum]
183
        lea     edx, [edx + thread_data.buffer]
-
 
Line 184... Line 218...
184
        mov     esi, sizeof.thread_data.buffer
218
        mov     edx, [edx + thread_data.buffer_ptr]
185
        mcall   recv
219
        mov     esi, sizeof.thread_data.buffer    ;;; FIXME
-
 
220
        mcall   recv
-
 
221
        inc     eax                                                             ; error? (-1)
-
 
222
        jz      threadloop
-
 
223
        dec     eax                                                             ; 0 bytes read?
-
 
224
        jz      threadloop
-
 
225
 
-
 
226
        mov     edx, [ebp]                                                      ; pointer to thread_data
Line -... Line 227...
-
 
227
        mov     edi, [edx + thread_data.buffer_ptr]
-
 
228
        add     [edx + thread_data.buffer_ptr], eax
-
 
229
 
-
 
230
; Check if we received a newline character, if not, wait for more data
-
 
231
        mov     ecx, eax
-
 
232
        mov     al, 13
-
 
233
        repne   scasb
-
 
234
        jne     threadloop
186
        cmp     eax, -1                                                         ; error?
235
 
187
        je      threadloop
236
; We got a command!
188
        or      eax, eax                                                        ; 0 bytes read?
237
        lea     eax, [edx + thread_data.buffer]
189
        jz      threadloop
238
        mov     ecx, [edx + thread_data.buffer_ptr]
190
        push    eax                                                             ; save number of bytes read on stack
-
 
191
 
239
        sub     ecx, eax
192
        mov     edx, [esp+4]                                                    ; pointer to thread_data
240
        push    ecx                                                             ; push full data size on stack
193
        mov     byte [edx + thread_data.buffer + eax], 0                        ; append received data with a 0 byte
241
        mov     [edx + thread_data.buffer_ptr], eax                             ; reset buffer ptr
194
 
242
 
Line -... Line 243...
-
 
243
        push    eax;;;;
195
        pushd   0x02                                                            ; print received data to console (in green color)
244
        pushd   0x02                                                            ; print received data to console (in green color)
196
        call    [con_set_flags]
245
        call    [con_set_flags]
197
        push    str_newline
246
        push    str_newline
Line 198... Line 247...
198
        call    [con_write_asciiz]
247
        call    [con_write_asciiz]
Line 266... Line 315...
266
str_err2        db 'ERROR: cannot open directory',10,0
315
str_err2        db 'ERROR: cannot open directory',10,0
267
str_datasock    db 'Passive data socket connected!',10,0
316
str_datasock    db 'Passive data socket connected!',10,0
268
str_notfound    db 'ERROR: file not found',10,0
317
str_notfound    db 'ERROR: file not found',10,0
269
str_sockerr     db 'ERROR: socket error',10,0
318
str_sockerr     db 'ERROR: socket error',10,0
Line -... Line 319...
-
 
319
 
-
 
320
str_login_invalid db 'Login invalid',10,0
270
 
321
 
271
str_newline     db 10, 0
322
str_newline     db 10, 0
Line 272... Line 323...
272
str_mask        db '*', 0
323
str_mask        db '*', 0
273
 
324
 
Line 282... Line 333...
282
                dd 'Sep '
333
                dd 'Sep '
283
                dd 'Oct '
334
                dd 'Oct '
284
                dd 'Nov '
335
                dd 'Nov '
285
                dd 'Dec '
336
                dd 'Dec '
Line -... Line 337...
-
 
337
 
286
 
338
str_users       db 'users'
287
filename        db '.ini', 0
339
str_ini         db '.ini', 0
288
str_port        db 'port', 0
340
str_port        db 'port', 0
289
str_ftpd        db 'ftpd', 0
341
str_ftpd        db 'ftpd', 0
-
 
342
str_conn        db 'conn', 0
-
 
343
str_ip          db 'ip', 0
-
 
344
str_pass        db 'pass', 0
-
 
345
str_home        db 'home', 0
-
 
346
str_mode        db 'mode', 0
Line 290... Line 347...
290
str_conn        db 'conn', 0
347
 
291
 
348
 
292
sockaddr1:
349
sockaddr1:
293
                dw AF_INET4
350
                dw AF_INET4
Line 336... Line 393...
336
 
393
 
Line 337... Line 394...
337
; uninitialised data
394
; uninitialised data
338
 
395
 
-
 
396
        socketnum       dd ?
339
        socketnum       dd ?
397
        path            rb 1024
-
 
398
        path2           rb 1024
-
 
399
        params          rb 1024
-
 
400
        serverip        dd ?
Line 340... Line 401...
340
        path            rb 1024
401