Rev 2602 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2602 | Rev 2609 | ||
---|---|---|---|
Line 24... | Line 24... | ||
24 | macro sendFTP str { |
24 | macro sendFTP str { |
25 | local .string, .length, .label |
25 | local .string, .length, .label |
26 | xor edi, edi |
26 | xor edi, edi |
27 | mcall send, [edx + thread_data.socketnum], .string, .length |
27 | mcall send, [ebp + thread_data.socketnum], .string, .length |
28 | jmp @f |
28 | jmp @f |
29 | .string db str, 13, 10 |
29 | .string db str, 13, 10 |
30 | .length = $ - .string |
30 | .length = $ - .string |
31 | @@: |
31 | @@: |
Line 40... | Line 40... | ||
40 | ; |
40 | ; |
41 | ; input: esi = ptr to ascii commands |
41 | ; input: esi = ptr to ascii commands |
42 | ; ecx = number of bytes input |
42 | ; ecx = number of bytes input |
43 | ; edx = pointer to thread_data structure |
43 | ; ebp = pointer to thread_data structure |
44 | ; |
44 | ; |
45 | ; output: none |
45 | ; output: none |
46 | ; |
46 | ; |
47 | ;------------------------------------------------ |
47 | ;------------------------------------------------ |
48 | align 4 |
48 | align 4 |
49 | parse_cmd: ; esi must point to command |
49 | parse_cmd: ; esi must point to command |
50 | 50 | ||
Line 68... | Line 68... | ||
68 | cmp eax, [edi] |
68 | cmp eax, [edi] |
69 | je .got_it |
69 | je .got_it |
70 | 70 | ||
71 | add edi, 4+4*4 |
71 | add edi, 5*4 |
Line 72... | Line 72... | ||
72 | cmp byte [edi], 0 |
72 | cmp byte [edi], 0 |
73 | jne .scanloop |
73 | jne .scanloop |
74 | 74 | ||
Line 75... | Line 75... | ||
75 | .error: |
75 | .error: |
76 | cmp [edx + thread_data.state], STATE_ACTIVE |
76 | cmp [ebp + thread_data.state], STATE_ACTIVE |
77 | jb login_first |
77 | jb login_first |
78 | sendFTP "500 Unsupported command" |
78 | sendFTP "500 Unsupported command" |
79 | ret |
79 | ret |
Line 80... | Line 80... | ||
80 | 80 | ||
81 | .got_it: |
81 | .got_it: |
82 | mov eax, [edx + thread_data.state] |
82 | mov eax, [ebp + thread_data.state] |
Line 83... | Line 83... | ||
83 | jmp dword [edi + 4 + eax] |
83 | jmp dword [edi + 4 + eax] |
84 | 84 | ||
Line 85... | Line -... | ||
85 | - | ||
86 | align 4 |
85 | |
87 | commands: ; all commands must be in uppercase |
- | |
88 | 86 | align 4 |
|
89 | dd 'ABOR' |
- | |
90 | dd login_first, login_first, login_first, cmdABOR |
87 | commands: ; all commands must be in uppercase |
91 | ; dd 'ACCT |
- | |
92 | ; dd login_first, login_first, login_first, cmd_ACCT |
88 | |
93 | ; dd 'APPE' |
- | |
94 | ; dd login_first, login_first, login_first, cmd_APPE |
89 | dd 'ABOR', login_first, login_first, login_first, cmdABOR |
95 | dd 'CDUP' |
- | |
96 | dd login_first, login_first, login_first, cmdCDUP |
90 | ; dd 'ACCT', login_first, login_first, login_first, cmd_ACCT |
97 | dd 'CWD' |
- | |
98 | dd login_first, login_first, login_first, cmdCWD |
91 | ; dd 'APPE', login_first, login_first, login_first, cmd_APPE |
99 | dd 'DELE' |
- | |
100 | dd login_first, login_first, login_first, cmdDELE |
92 | dd 'CDUP', login_first, login_first, login_first, cmdCDUP |
101 | ; dd 'HELP' |
- | |
102 | ; dd login_first, login_first, login_first, cmd_HELP |
93 | dd 'CWD', login_first, login_first, login_first, cmdCWD |
103 | dd 'LIST' |
- | |
104 | dd login_first, login_first, login_first, cmdLIST |
94 | dd 'DELE', login_first, login_first, login_first, cmdDELE |
105 | ; dd 'MDTM' |
- | |
106 | ; dd login_first, login_first, login_first, cmd_MDTM |
95 | ; dd 'HELP', login_first, login_first, login_first, cmd_HELP |
107 | ; dd 'MKD' |
- | |
108 | ; dd login_first, login_first, login_first, cmd_MKD |
96 | dd 'LIST', login_first, login_first, login_first, cmdLIST |
109 | ; dd 'MODE' |
- | |
110 | ; dd login_first, login_first, login_first, cmd_MODE |
97 | ; dd 'MDTM', login_first, login_first, login_first, cmd_MDTM |
111 | dd 'NLST' |
- | |
112 | dd login_first, login_first, login_first, cmdNLST |
98 | ; dd 'MKD', login_first, login_first, login_first, cmd_MKD |
113 | dd 'NOOP' |
- | |
114 | dd login_first, login_first, login_first, cmdNOOP |
99 | ; dd 'MODE', login_first, login_first, login_first, cmd_MODE |
115 | dd 'PASS' |
- | |
116 | dd cmdPASS.0, cmdPASS , cmdPASS.2, cmdPASS.3 |
100 | dd 'NLST', login_first, login_first, login_first, cmdNLST |
117 | dd 'PASV' |
- | |
118 | dd login_first, login_first, login_first, cmdPASV |
101 | dd 'NOOP', login_first, login_first, login_first, cmdNOOP |
119 | dd 'PORT' |
- | |
120 | dd login_first, login_first, login_first, cmdPORT |
102 | dd 'PASS', cmdPASS.0, cmdPASS , cmdPASS.2, cmdPASS.3 |
121 | dd 'PWD' |
- | |
122 | dd login_first, login_first, login_first, cmdPWD |
103 | dd 'PASV', login_first, login_first, login_first, cmdPASV |
123 | dd 'QUIT' |
- | |
124 | dd cmdQUIT, cmdQUIT, cmdQUIT, cmdQUIT |
104 | dd 'PORT', login_first, login_first, login_first, cmdPORT |
125 | ; dd 'REIN' |
- | |
126 | ; dd login_first, login_first, login_first, cmd_REIN |
105 | dd 'PWD', login_first, login_first, login_first, cmdPWD |
127 | ; dd 'REST' |
- | |
128 | ; dd login_first, login_first, login_first, cmd_REST |
106 | dd 'QUIT', cmdQUIT, cmdQUIT, cmdQUIT, cmdQUIT |
129 | dd 'RETR' |
- | |
130 | dd login_first, login_first, login_first, cmdRETR |
107 | ; dd 'REIN', login_first, login_first, login_first, cmd_REIN |
131 | ; dd 'RMD' |
- | |
132 | ; dd login_first, login_first, login_first, cmd_RMD |
108 | ; dd 'REST', login_first, login_first, login_first, cmd_REST |
133 | ; dd 'RNFR' |
- | |
134 | ; dd login_first, login_first, login_first, cmd_RNFR |
109 | dd 'RETR', login_first, login_first, login_first, cmdRETR |
135 | ; dd 'RNTO' |
- | |
136 | ; dd login_first, login_first, login_first, cmd_RNTO |
110 | ; dd 'RMD', login_first, login_first, login_first, cmd_RMD |
137 | ; dd 'SITE' |
- | |
138 | ; dd login_first, login_first, login_first, cmd_SITE |
111 | ; dd 'RNFR', login_first, login_first, login_first, cmd_RNFR |
139 | ; dd 'SIZE' |
- | |
140 | ; dd login_first, login_first, login_first, cmd_SIZE |
112 | ; dd 'RNTO', login_first, login_first, login_first, cmd_RNTO |
141 | ; dd 'STAT' |
- | |
142 | ; dd login_first, login_first, login_first, cmd_STAT |
113 | ; dd 'SITE', login_first, login_first, login_first, cmd_SITE |
143 | dd 'STOR' |
- | |
144 | dd login_first, login_first, login_first, cmdSTOR |
114 | ; dd 'SIZE', login_first, login_first, login_first, cmd_SIZE |
145 | ; dd 'STOU' |
- | |
146 | ; dd login_first, login_first, login_first, cmd_STOU |
115 | ; dd 'STAT', login_first, login_first, login_first, cmd_STAT |
147 | ; dd 'STRU' |
- | |
148 | ; dd login_first, login_first, login_first, cmd_STRU |
116 | dd 'STOR', login_first, login_first, login_first, cmdSTOR |
149 | dd 'SYST' |
- | |
150 | dd login_first, login_first, login_first, cmdSYST |
117 | ; dd 'STOU', login_first, login_first, login_first, cmd_STOU |
151 | dd 'TYPE' |
118 | ; dd 'STRU', login_first, login_first, login_first, cmd_STRU |
Line 152... | Line 119... | ||
152 | dd login_first, login_first, login_first, cmdTYPE |
119 | dd 'SYST', login_first, login_first, login_first, cmdSYST |
153 | dd 'USER' |
120 | dd 'TYPE', login_first, login_first, login_first, cmdTYPE |
154 | dd cmdUSER, cmdUSER, cmdUSER, cmdUSER.2 |
121 | dd 'USER', cmdUSER, cmdUSER, cmdUSER, cmdUSER.2 |
Line 175... | Line 142... | ||
175 | 142 | ||
176 | align 4 |
143 | align 4 |
Line 177... | Line 144... | ||
177 | abort_transfer: |
144 | abort_transfer: |
178 | and [edx + thread_data.permissions], not ABORT |
145 | and [ebp + thread_data.permissions], not ABORT |
179 | mov [edx + thread_data.mode], MODE_NOTREADY |
146 | mov [ebp + thread_data.mode], MODE_NOTREADY |
180 | invoke file.close, ebx |
147 | invoke file.close, ebx |
181 | mcall close, [edx + thread_data.datasocketnum] |
148 | mcall close, [ebp + thread_data.datasocketnum] |
182 | 149 | ||
Line 183... | Line -... | ||
183 | mov edx, [ebp] |
- | |
184 | sendFTP "530 Transfer aborted" |
150 | sendFTP "530 Transfer aborted" |
185 | ret |
151 | ret |
Line 186... | Line 152... | ||
186 | 152 | ||
187 | align 4 |
153 | align 4 |
Line 268... | Line 234... | ||
268 | align 4 |
234 | align 4 |
Line 269... | Line 235... | ||
269 | create_path: ; combine home_dir and work_dir strings into fpath |
235 | create_path: ; combine home_dir and work_dir strings into fpath |
270 | 236 | ||
Line 271... | Line -... | ||
271 | mov edx, [ebp] |
- | |
272 | lea edi, [edx + thread_data.fpath] |
237 | lea edi, [ebp + thread_data.fpath] |
273 | lea esi, [edx + thread_data.home_dir] |
238 | lea esi, [ebp + thread_data.home_dir] |
274 | mov ecx, 1024 |
239 | mov ecx, 1024 |
275 | .loop1: |
240 | .loop1: |
276 | lodsb |
241 | lodsb |
277 | cmp al, 0x20 |
242 | cmp al, 0x20 |
278 | jb .next |
243 | jb .next |
Line 285... | Line 250... | ||
285 | dec edi |
250 | dec edi |
286 | @@: |
251 | @@: |
287 | 252 | ||
288 | lea esi, [edx + thread_data.work_dir] |
253 | lea esi, [ebp + thread_data.work_dir] |
Line 289... | Line 254... | ||
289 | mov ecx, 1024 |
254 | mov ecx, 1024 |
290 | .loop2: |
255 | .loop2: |
291 | lodsb |
256 | lodsb |
292 | cmp al, 0x20 |
257 | cmp al, 0x20 |
293 | jb .done |
258 | jb .done |
294 | stosb |
259 | stosb |
Line 308... | Line 273... | ||
308 | align 4 |
273 | align 4 |
309 | cmdABOR: |
274 | cmdABOR: |
310 | 275 | ||
311 | or [edx + thread_data.permissions], ABORT |
276 | or [ebp + thread_data.permissions], ABORT |
Line 312... | Line 277... | ||
312 | sendFTP "250 Command succesul" |
277 | sendFTP "250 Command succesul" |
313 | ret |
278 | ret |
314 | 279 | ||
Line 315... | Line 280... | ||
315 | ;------------------------------------------------ |
280 | ;------------------------------------------------ |
316 | ; "CDUP" |
281 | ; "CDUP" |
Line 321... | Line 286... | ||
321 | align 4 |
286 | align 4 |
322 | cmdCDUP: |
287 | cmdCDUP: |
323 | 288 | ||
324 | test [edx + thread_data.permissions], PERMISSION_CD |
289 | test [ebp + thread_data.permissions], PERMISSION_CD |
Line 325... | Line 290... | ||
325 | jz permission_denied |
290 | jz permission_denied |
326 | 291 | ||
Line 327... | Line 292... | ||
327 | cmp byte [edx + thread_data.work_dir+1], 0 ; are we in "/" ? |
292 | cmp byte [ebp + thread_data.work_dir+1], 0 ; are we in "/" ? |
328 | je .done |
293 | je .done |
Line 329... | Line 294... | ||
329 | 294 | ||
330 | mov ecx, 1024 |
295 | mov ecx, 1024 |
331 | xor al, al |
296 | xor al, al |
332 | lea edi, [edx + thread_data.work_dir] |
297 | lea edi, [ebp + thread_data.work_dir] |
333 | repne scasb |
- | |
334 | std |
- | |
335 | dec edi |
- | |
336 | dec edi |
298 | repne scasb |
337 | dec edi |
299 | sub edi, 3 |
- | 300 | mov al,'/' |
|
- | 301 | std |
|
- | 302 | neg ecx |
|
338 | mov al,'/' |
303 | add ecx, 1024 |
339 | repne scasb |
304 | repne scasb |
340 | cld |
305 | cld |
Line 341... | Line 306... | ||
341 | mov byte[edi+1], 0 |
306 | mov byte[edi+1], 0 |
342 | 307 | ||
343 | .done: |
308 | .done: |
344 | ; Print the new working dir on the console |
309 | ; Print the new working dir on the console |
345 | lea eax, [edx + thread_data.work_dir] |
310 | lea eax, [ebp + thread_data.work_dir] |
346 | push eax |
311 | push eax |
347 | call [con_write_asciiz] |
312 | call [con_write_asciiz] |
Line 360... | Line 325... | ||
360 | align 4 |
325 | align 4 |
361 | cmdCWD: |
326 | cmdCWD: |
362 | 327 | ||
363 | test [edx + thread_data.permissions], PERMISSION_CD |
328 | test [ebp + thread_data.permissions], PERMISSION_CD |
Line 364... | Line 329... | ||
364 | jz permission_denied |
329 | jz permission_denied |
365 | 330 | ||
Line 366... | Line 331... | ||
366 | sub ecx, 4 |
331 | sub ecx, 4 |
367 | jb .err |
332 | jb .err |
368 | add esi, 4 |
333 | add esi, 4 |
Line -... | Line 334... | ||
- | 334 | ||
- | 335 | mov ecx, 1024 |
|
- | 336 | lea edi, [ebp + thread_data.work_dir] |
|
- | 337 | cmp byte [esi], '/' |
|
- | 338 | je .loop |
|
369 | 339 | ||
370 | .scan: |
340 | .scan: |
371 | lea edi, [edx + thread_data.work_dir + 1] |
341 | lea edi, [ebp + thread_data.work_dir + 1] |
372 | push ecx |
342 | push ecx |
373 | mov ecx, 1024 |
343 | mov ecx, 1024 |
374 | .find_zero: |
344 | .find_zero: |
375 | cmp byte [edi], 0 |
345 | cmp byte [edi], 0 |
Line 405... | Line 375... | ||
405 | mov byte [edi], 0 |
375 | mov byte [edi], 0 |
406 | 376 | ||
407 | ; Print the new working dir on the console |
377 | ; Print the new working dir on the console |
Line 408... | Line 378... | ||
408 | lea eax, [edx + thread_data.work_dir] |
378 | lea eax, [ebp + thread_data.work_dir] |
409 | push eax |
379 | push eax |
410 | call [con_write_asciiz] |
380 | call [con_write_asciiz] |
411 | push str_newline |
381 | push str_newline |
412 | call [con_write_asciiz] |
382 | call [con_write_asciiz] |
413 | 383 | ||
Line 437... | Line 407... | ||
437 | align 4 |
407 | align 4 |
438 | cmdDELE: |
408 | cmdDELE: |
439 | 409 | ||
440 | test [edx + thread_data.permissions], PERMISSION_DELETE |
410 | test [ebp + thread_data.permissions], PERMISSION_DELETE |
Line 441... | Line 411... | ||
441 | jz permission_denied |
411 | jz permission_denied |
442 | 412 | ||
Line 443... | Line 413... | ||
443 | ret |
413 | ret |
Line 444... | Line 414... | ||
444 | 414 | ||
Line 451... | Line 421... | ||
451 | align 4 |
421 | align 4 |
452 | cmdLIST: |
422 | cmdLIST: |
453 | 423 | ||
454 | test [edx + thread_data.permissions], PERMISSION_EXEC |
424 | test [ebp + thread_data.permissions], PERMISSION_EXEC |
Line 455... | Line 425... | ||
455 | jz permission_denied |
425 | jz permission_denied |
456 | 426 | ||
Line 457... | Line 427... | ||
457 | ; If we are in active mode, it's time to open a data socket.. |
427 | ; If we are in active mode, it's time to open a data socket.. |
458 | cmp [edx + thread_data.mode], MODE_ACTIVE |
428 | cmp [ebp + thread_data.mode], MODE_ACTIVE |
459 | jne @f |
429 | jne @f |
460 | mov ecx, [edx + thread_data.datasocketnum] |
430 | mov ecx, [ebp + thread_data.datasocketnum] |
461 | lea edx, [edx + thread_data.datasock] |
431 | lea edx, [ebp + thread_data.datasock] |
462 | mov esi, sizeof.thread_data.datasock |
432 | mov esi, sizeof.thread_data.datasock |
463 | mcall connect |
433 | mcall connect |
464 | cmp eax, -1 |
434 | cmp eax, -1 |
465 | je socketerror |
435 | je socketerror |
466 | @@: |
436 | @@: |
467 | mov edx, [ebp] |
- | |
Line 468... | Line 437... | ||
468 | 437 | ||
469 | ; Create fpath from home_dir and work_dir |
438 | ; Create fpath from home_dir and work_dir |
Line 470... | Line 439... | ||
470 | call create_path |
439 | call create_path |
471 | 440 | ||
472 | lea ebx, [edx + thread_data.fpath] |
441 | lea ebx, [ebp + thread_data.fpath] |
Line 473... | Line -... | ||
473 | invoke con_write_asciiz, ebx |
- | |
474 | invoke con_write_asciiz, str_newline |
- | |
475 | - | ||
476 | 442 | invoke con_write_asciiz, ebx |
|
477 | mov edx, [ebp] ;;; |
443 | invoke con_write_asciiz, str_newline |
478 | lea ebx, [edx + thread_data.fpath] ;;;; |
444 | |
479 | ; Start the search |
445 | ; Start the search |
Line 480... | Line -... | ||
480 | invoke file.find.first, ebx, str_mask, FA_ANY |
- | |
481 | test eax, eax |
446 | invoke file.find.first, ebx, str_mask, FA_READONLY+FA_FOLDER+FA_NORMAL+FA_ARCHIVED |
482 | jz .nosuchdir |
447 | test eax, eax |
483 | 448 | jz .nosuchdir |
|
484 | mov edx, [ebp] ;;; |
449 | |
485 | lea edi, [edx + thread_data.buffer] |
450 | lea edi, [ebp + thread_data.buffer] |
Line 564... | Line 529... | ||
564 | mov ax, 0x0a0d |
529 | mov ax, 0x0a0d |
565 | stosw |
530 | stosw |
566 | 531 | ||
567 | test [edx + thread_data.permissions], ABORT ; Did we receive ABOR command from client? |
532 | test [ebp + thread_data.permissions], ABORT ; Did we receive ABOR command from client? |
Line 568... | Line 533... | ||
568 | ;;; jnz .abort ; TODO |
533 | ;;; jnz .abort ; TODO |
569 | 534 | ||
Line 570... | Line 535... | ||
570 | ; check next file |
535 | ; check next file |
571 | ;;; invoke file.find.next, ebx |
536 | invoke file.find.next, ebx |
572 | ;;; jmp .parse_file |
537 | jmp .parse_file |
573 | mov eax, ebx ;;;;; |
538 | ;;; mov eax, ebx ;;;;; |
Line 574... | Line 539... | ||
574 | 539 | ||
575 | ; close file desc |
540 | ; close file desc |
576 | .done: |
541 | .done: |
Line 577... | Line 542... | ||
577 | invoke file.find.close, eax ; file discriptor is still in eax at this point! |
542 | invoke file.find.close, ebx ; ebx is the |
578 | 543 | ||
579 | ; append the string with a 0 |
544 | ; append the string with a 0 |
Line 580... | Line 545... | ||
580 | xor al, al |
545 | xor al, al |
581 | stosb |
546 | stosb |
582 | - | ||
583 | ; Warn the client we're about to send the data |
547 | |
584 | push edi |
548 | ; Warn the client we're about to send the data |
Line 585... | Line 549... | ||
585 | mov edx, [ebp] ;;;;;;; |
549 | push edi |
586 | sendFTP "150 Here it comes.." |
- | |
587 | pop esi |
550 | sendFTP "150 Here it comes.." |
588 | 551 | pop esi |
|
589 | ; and send it to the client |
552 | |
590 | mov edx, [ebp] |
553 | ; and send it to the client |
591 | mov ecx, [edx + thread_data.datasocketnum] |
554 | mov ecx, [ebp + thread_data.datasocketnum] |
Line 592... | Line 555... | ||
592 | lea edx, [edx + thread_data.buffer] |
555 | lea edx, [ebp + thread_data.buffer] |
593 | sub esi, edx |
- | |
594 | xor edi, edi |
556 | sub esi, edx |
595 | mcall send |
557 | xor edi, edi |
Line 596... | Line 558... | ||
596 | 558 | mcall send |
|
597 | ; close the data socket.. |
559 | |
Line 598... | Line 560... | ||
598 | mov edx, [ebp] ; thread_data pointer |
560 | ; close the data socket.. |
Line 615... | Line 577... | ||
615 | align 4 |
577 | align 4 |
616 | cmdNLST: |
578 | cmdNLST: |
617 | 579 | ||
618 | test [edx + thread_data.permissions], PERMISSION_EXEC |
580 | test [ebp + thread_data.permissions], PERMISSION_EXEC |
Line 619... | Line 581... | ||
619 | jz permission_denied |
581 | jz permission_denied |
620 | 582 | ||
Line 621... | Line 583... | ||
621 | ; TODO: same as list but simpler output format |
583 | ; TODO: same as list but simpler output format |
Line 622... | Line 584... | ||
622 | 584 | ||
Line 645... | Line 607... | ||
645 | lea esi, [esi + 5] |
607 | lea esi, [esi + 5] |
646 | 608 | ||
647 | ; read the password from users.ini |
609 | ; read the password from users.ini |
Line 648... | Line 610... | ||
648 | lea edi, [edx + thread_data.buffer + 512] ; temp pass |
610 | lea edi, [ebp + thread_data.buffer + 512] ; temp pass |
649 | lea ebx, [edx + thread_data.fpath] ; temp username |
611 | lea ebx, [ebp + thread_data.fpath] ; temp username |
650 | invoke ini.get_str, path2, ebx, str_pass, edi, 512, str_infinity |
612 | invoke ini.get_str, path2, ebx, str_pass, edi, 512, str_infinity |
651 | test eax, eax |
613 | test eax, eax |
652 | jnz .incorrect |
614 | jnz .incorrect |
653 | cmp dword [edi], -1 |
615 | cmp dword [edi], -1 |
654 | je .incorrect |
616 | je .incorrect |
655 | cmp byte[edi], 0 |
617 | cmp byte[edi], 0 |
Line 664... | Line 626... | ||
664 | 626 | ||
665 | .pass_ok: |
627 | .pass_ok: |
Line 666... | Line 628... | ||
666 | invoke ini.get_int, path2, ebx, str_mode, 0 |
628 | invoke ini.get_int, path2, ebx, str_mode, 0 |
667 | mov edx, [ebp] ; because libini destroys edx! |
629 | mov [ebp + thread_data.permissions], eax |
668 | mov [edx + thread_data.permissions], eax |
- | |
669 | 630 | ||
Line 670... | Line 631... | ||
670 | invoke con_write_asciiz, str_pass_ok |
631 | invoke con_write_asciiz, str_pass_ok |
671 | mov [edx + thread_data.state], STATE_ACTIVE |
632 | mov [ebp + thread_data.state], STATE_ACTIVE |
672 | sendFTP "230 You are now logged in" |
633 | sendFTP "230 You are now logged in" |
673 | ret |
634 | ret |
Line 674... | Line 635... | ||
674 | 635 | ||
675 | .2: |
636 | .2: |
676 | .incorrect: |
637 | .incorrect: |
677 | mov [edx + thread_data.state], STATE_CONNECTED |
638 | mov [ebp + thread_data.state], STATE_CONNECTED |
678 | sendFTP "530 Login incorrect" |
639 | sendFTP "530 Login incorrect" |
Line 679... | Line 640... | ||
679 | ret |
640 | ret |
680 | 641 | ||
Line 701... | Line 662... | ||
701 | mcall socket, AF_INET4, SOCK_STREAM, 0 |
662 | mcall socket, AF_INET4, SOCK_STREAM, 0 |
702 | cmp eax, -1 |
663 | cmp eax, -1 |
703 | je socketerror |
664 | je socketerror |
704 | mov edx, [ebp] ; thread_data pointer |
665 | mov [ebp + thread_data.passivesocknum], eax |
705 | mov [edx + thread_data.passivesocknum], eax |
- | |
706 | 666 | ||
Line 707... | Line 667... | ||
707 | ; Bind it to a known local port |
667 | ; Bind it to a known local port |
708 | mov [edx + thread_data.datasock.sin_family], AF_INET4 |
668 | mov [ebp + thread_data.datasock.sin_family], AF_INET4 |
- | 669 | pushw [pasvport] |
|
709 | mov [edx + thread_data.datasock.sin_port], 2000 |
670 | popw [ebp + thread_data.datasock.sin_port] |
- | 671 | inc [pasvport] |
|
710 | mov [edx + thread_data.datasock.sin_addr], 0 |
672 | mov [ebp + thread_data.datasock.sin_addr], 0 |
Line 711... | Line 673... | ||
711 | 673 | ||
712 | mov ecx, eax ; passivesocketnum |
674 | mov ecx, eax ; passivesocketnum |
713 | lea edx, [edx + thread_data.datasock] |
675 | lea edx, [ebp + thread_data.datasock] |
714 | mov esi, sizeof.thread_data.datasock |
676 | mov esi, sizeof.thread_data.datasock |
715 | mcall bind |
677 | mcall bind |
716 | cmp eax, -1 |
678 | cmp eax, -1 |
Line 722... | Line 684... | ||
722 | ; je listen_err ; TODO |
684 | ; je listen_err ; TODO |
723 | 685 | ||
724 | ; Tell our thread we are ready to accept incoming calls |
686 | ; Tell our thread we are ready to accept incoming calls |
Line 725... | Line 687... | ||
725 | mov edx, [ebp] ; thread_data pointer |
687 | mov [ebp + thread_data.mode], MODE_PASSIVE_WAIT |
726 | mov [edx + thread_data.mode], MODE_PASSIVE_WAIT |
- | |
727 | 688 | ||
Line 728... | Line 689... | ||
728 | ; Now tell the client where to connect to in this format: |
689 | ; Now tell the client where to connect to in this format: |
729 | ; 227 Entering Passive Mode (a1,a2,a3,a4,p1,p2) |
690 | ; 227 Entering Passive Mode (a1,a2,a3,a4,p1,p2) |
730 | ; where a1.a2.a3.a4 is the IP address and p1*256+p2 is the port number. |
691 | ; where a1.a2.a3.a4 is the IP address and p1*256+p2 is the port number. |
Line 731... | Line 692... | ||
731 | 692 | ||
732 | ; '227 (' |
693 | ; '227 (' |
733 | lea edi, [edx + thread_data.buffer] |
694 | lea edi, [ebp + thread_data.buffer] |
734 | mov eax, '227 ' ; FIXME (now hardcoded to 127.0.0.1:2000) |
695 | mov eax, '227 ' ; FIXME (now hardcoded to 127.0.0.1:2000) |
735 | stosd |
696 | stosd |
736 | mov al, '(' |
697 | mov al, '(' |
737 | stosb |
698 | stosb |
Line 753... | Line 714... | ||
753 | mov al, ',' |
714 | mov al, ',' |
754 | stosb |
715 | stosb |
755 | ; port |
716 | ; port |
756 | mov eax, 7 |
717 | movzx eax, byte [ebp + thread_data.datasock.sin_port + 1] |
757 | call dword_to_ascii |
718 | call dword_to_ascii |
758 | mov al, ',' |
719 | mov al, ',' |
759 | stosb |
720 | stosb |
760 | mov eax, 208 |
721 | movzx eax, byte [ebp + thread_data.datasock.sin_port] |
761 | call dword_to_ascii |
722 | call dword_to_ascii |
762 | ; ')', 13, 10, 0 |
723 | ; ')', 13, 10, 0 |
763 | mov eax, ')' + 0x000a0d00 |
724 | mov eax, ')' + 0x000a0d00 |
764 | stosd |
725 | stosd |
765 | 726 | ||
766 | lea esi, [edi - thread_data.buffer] |
727 | lea esi, [edi - thread_data.buffer] |
Line 767... | Line 728... | ||
767 | sub esi, edx |
728 | sub esi, ebp |
768 | mov ecx, [edx + thread_data.socketnum] |
729 | mov ecx, [ebp + thread_data.socketnum] |
769 | lea edx, [edx + thread_data.buffer] |
730 | lea edx, [ebp + thread_data.buffer] |
770 | xor edi, edi |
731 | xor edi, edi |
771 | mcall send |
732 | mcall send |
772 | 733 | ||
Line 773... | Line 734... | ||
773 | ret |
734 | ret |
Line 781... | Line 742... | ||
781 | align 4 |
742 | align 4 |
782 | cmdPWD: |
743 | cmdPWD: |
783 | 744 | ||
784 | mov dword [edx + thread_data.buffer], '257 ' |
745 | mov dword [ebp + thread_data.buffer], '257 ' |
Line 785... | Line 746... | ||
785 | mov byte [edx + thread_data.buffer+4], '"' |
746 | mov byte [ebp + thread_data.buffer+4], '"' |
786 | 747 | ||
Line 787... | Line 748... | ||
787 | lea edi, [edx + thread_data.buffer+5] |
748 | lea edi, [ebp + thread_data.buffer+5] |
788 | lea esi, [edx + thread_data.work_dir] |
749 | lea esi, [ebp + thread_data.work_dir] |
789 | mov ecx, 1024 |
750 | mov ecx, 1024 |
790 | .loop: |
751 | .loop: |
791 | lodsb |
752 | lodsb |
792 | or al, al |
753 | or al, al |
793 | jz .ok |
754 | jz .ok |
Line 798... | Line 759... | ||
798 | .ok: |
759 | .ok: |
Line 799... | Line 760... | ||
799 | mov dword [edi], '"' + 0x000a0d00 ; '"',13,10,0 |
760 | mov dword [edi], '"' + 0x000a0d00 ; '"',13,10,0 |
800 | lea esi, [edi - thread_data.buffer + 4] |
761 | lea esi, [edi - thread_data.buffer + 4] |
801 | sub esi, edx |
762 | sub esi, ebp |
802 | mov ecx, [edx + thread_data.socketnum] |
763 | mov ecx, [ebp + thread_data.socketnum] |
803 | lea edx, [edx + thread_data.buffer] |
764 | lea edx, [ebp + thread_data.buffer] |
804 | xor edi, edi |
765 | xor edi, edi |
805 | mcall send |
766 | mcall send |
806 | 767 | ||
Line 807... | Line -... | ||
807 | mov edx, [ebp] |
- | |
808 | ; Print the new working dir on the console |
768 | ; Print the new working dir on the console |
809 | lea eax, [edx + thread_data.work_dir] |
769 | lea eax, [ebp + thread_data.work_dir] |
810 | invoke con_write_asciiz, eax |
770 | invoke con_write_asciiz, eax |
811 | invoke con_write_asciiz, str_newline |
771 | invoke con_write_asciiz, str_newline |
Line 812... | Line 772... | ||
812 | 772 | ||
Line 829... | Line 789... | ||
829 | mov cl, ',' |
789 | mov cl, ',' |
830 | call ip_to_dword |
790 | call ip_to_dword |
831 | ; And put it in datasock |
791 | ; And put it in datasock |
832 | ;;; mov edx, [ebp] |
792 | mov [ebp + thread_data.datasock.sin_addr], ebx |
833 | mov [edx + thread_data.datasock.sin_addr], ebx |
793 | |
834 | - | ||
835 | ; Now the same with portnumber |
794 | ; Now the same with portnumber |
Line 836... | Line 795... | ||
836 | inc esi |
795 | inc esi |
837 | call ascii_to_byte |
796 | call ascii_to_byte |
838 | mov bh, al |
797 | mov bh, al |
839 | inc esi |
798 | inc esi |
840 | call ascii_to_byte |
799 | call ascii_to_byte |
841 | mov bl, al |
800 | mov bl, al |
842 | 801 | ||
Line 843... | Line 802... | ||
843 | ; Save it in datasock too |
802 | ; Save it in datasock too |
844 | mov [edx + thread_data.datasock.sin_port], bx |
803 | mov [ebp + thread_data.datasock.sin_port], bx |
Line 845... | Line 804... | ||
845 | 804 | ||
846 | ; We will open the socket, but do not connect yet! |
805 | ; We will open the socket, but do not connect yet! |
847 | mov [edx + thread_data.datasock.sin_family], AF_INET4 |
806 | mov [ebp + thread_data.datasock.sin_family], AF_INET4 |
848 | mcall socket, AF_INET4, SOCK_STREAM, 0 |
807 | mcall socket, AF_INET4, SOCK_STREAM, 0 |
849 | cmp eax, -1 |
808 | cmp eax, -1 |
Line 850... | Line -... | ||
850 | je socketerror |
- | |
851 | 809 | je socketerror |
|
852 | mov edx, [ebp] ; thread_data pointer |
810 | |
Line 853... | Line 811... | ||
853 | mov [edx + thread_data.datasocketnum], eax |
811 | mov [ebp + thread_data.datasocketnum], eax |
854 | mov [edx + thread_data.mode], MODE_ACTIVE |
812 | mov [ebp + thread_data.mode], MODE_ACTIVE |
Line 855... | Line 813... | ||
855 | 813 | ||
Line 866... | Line 824... | ||
866 | cmdQUIT: |
824 | cmdQUIT: |
867 | 825 | ||
868 | sendFTP "221 Bye!" |
826 | sendFTP "221 Bye!" |
Line 869... | Line 827... | ||
869 | mov edx, [ebp] |
827 | mcall close, [ebp + thread_data.datasocketnum] |
870 | mcall close, [edx + thread_data.datasocketnum] |
- | |
871 | mcall close, [edx + thread_data.socketnum] |
828 | mcall close, [ebp + thread_data.socketnum] |
872 | 829 | ||
Line 873... | Line 830... | ||
873 | add esp, 4 ; get rid of call return address |
830 | add esp, 4 ; get rid of call return address |
874 | jmp thread_exit ; now close this thread |
831 | jmp thread_exit ; now close this thread |
Line 883... | Line 840... | ||
883 | align 4 |
840 | align 4 |
884 | cmdRETR: |
841 | cmdRETR: |
885 | 842 | ||
886 | test [edx + thread_data.permissions], PERMISSION_READ |
843 | test [ebp + thread_data.permissions], PERMISSION_READ |
Line 887... | Line 844... | ||
887 | jz permission_denied |
844 | jz permission_denied |
888 | 845 | ||
Line 889... | Line 846... | ||
889 | cmp ecx, 1024 + 5 |
846 | cmp ecx, 1024 + 5 |
890 | jae .cannot_open |
847 | jae .cannot_open |
Line 891... | Line 848... | ||
891 | 848 | ||
892 | sub ecx, 5 |
849 | sub ecx, 5 |
Line 893... | Line 850... | ||
893 | jb .cannot_open |
850 | jb .cannot_open |
894 | 851 | ||
895 | cmp [edx + thread_data.mode], MODE_ACTIVE |
852 | cmp [ebp + thread_data.mode], MODE_ACTIVE |
896 | jne @f |
853 | jne @f |
897 | push ecx esi |
854 | push ecx esi |
898 | mov ecx, [edx + thread_data.datasocketnum] |
855 | mov ecx, [ebp + thread_data.datasocketnum] |
899 | lea edx, [edx + thread_data.datasock] |
856 | lea edx, [ebp + thread_data.datasock] |
900 | mov esi, sizeof.thread_data.datasock |
857 | mov esi, sizeof.thread_data.datasock |
901 | mcall connect |
858 | mcall connect |
902 | pop esi ecx |
859 | pop esi ecx |
Line 920... | Line 877... | ||
920 | xor al, al |
877 | xor al, al |
921 | stosb |
878 | stosb |
922 | 879 | ||
923 | lea ebx, [edx + thread_data.fpath] |
880 | lea ebx, [ebp + thread_data.fpath] |
Line 924... | Line 881... | ||
924 | invoke con_write_asciiz, ebx |
881 | invoke con_write_asciiz, ebx |
925 | invoke con_write_asciiz, str_newline |
882 | invoke con_write_asciiz, str_newline |
926 | 883 | ||
Line 927... | Line 884... | ||
927 | invoke file.open, ebx, O_READ |
884 | invoke file.open, ebx, O_READ |
928 | test eax, eax |
885 | test eax, eax |
929 | jz .cannot_open |
886 | jz .cannot_open |
Line 930... | Line 887... | ||
930 | 887 | ||
931 | push eax |
- | |
932 | mov edx, [ebp] |
888 | push eax |
933 | sendFTP "150 Here it comes.." |
889 | sendFTP "150 Here it comes.." |
Line 934... | Line 890... | ||
934 | pop ebx |
890 | pop ebx |
935 | - | ||
936 | .read_more: |
891 | |
937 | mov edx, [ebp] |
892 | .read_more: |
Line 938... | Line 893... | ||
938 | test [edx + thread_data.permissions], ABORT |
893 | test [ebp + thread_data.permissions], ABORT |
939 | jnz abort_transfer |
894 | jnz abort_transfer |
940 | 895 | ||
941 | lea eax, [edx + thread_data.buffer] ; FIXME: use another buffer!! if we receive something on control connection now, we screw up! |
896 | lea eax, [ebp + thread_data.buffer] ; FIXME: use another buffer!! if we receive something on control connection now, we screw up! |
Line 942... | Line 897... | ||
942 | invoke file.read, ebx, eax, BUFFERSIZE |
897 | invoke file.read, ebx, eax, BUFFERSIZE |
943 | cmp eax, -1 |
898 | cmp eax, -1 |
944 | je .cannot_open ; FIXME: this is not the correct error |
899 | je .cannot_open ; FIXME: this is not the correct error |
945 | 900 | ||
946 | push eax ebx |
901 | push eax ebx |
947 | mov esi, eax |
902 | mov esi, eax |
948 | mov ecx, [edx + thread_data.datasocketnum] |
903 | mov ecx, [ebp + thread_data.datasocketnum] |
949 | lea edx, [edx + thread_data.buffer] |
904 | lea edx, [ebp + thread_data.buffer] |
950 | xor esi, esi |
905 | xor edi, edi |
Line 951... | Line 906... | ||
951 | mcall send |
906 | mcall send |
952 | pop ebx ecx |
907 | pop ebx ecx |
Line 953... | Line 908... | ||
953 | cmp eax, -1 |
908 | cmp eax, -1 |
954 | je socketerror |
909 | je socketerror ; FIXME: not the correct error |
Line 955... | Line 910... | ||
955 | 910 | ||
Line 956... | Line -... | ||
956 | ; cmp eax, ecx |
- | |
957 | ; jne not_all_byes_sent ; TODO |
911 | ; cmp eax, ecx |
958 | 912 | ; jne not_all_byes_sent ; TODO |
|
Line 959... | Line -... | ||
959 | cmp ecx, BUFFERSIZE |
- | |
960 | je .read_more |
913 | |
961 | 914 | cmp ecx, BUFFERSIZE |
|
Line 962... | Line 915... | ||
962 | invoke file.close, ebx |
915 | je .read_more |
963 | 916 | ||
Line 989... | Line 942... | ||
989 | align 4 |
942 | align 4 |
990 | cmdSTOR: |
943 | cmdSTOR: |
991 | 944 | ||
992 | test [edx + thread_data.permissions], PERMISSION_WRITE |
945 | test [ebp + thread_data.permissions], PERMISSION_WRITE |
Line 993... | Line 946... | ||
993 | jz permission_denied |
946 | jz permission_denied |
994 | 947 | ||
Line 995... | Line 948... | ||
995 | 948 | ||
996 | ;;;; |
949 | ;;;; |
997 | test [edx + thread_data.permissions], ABORT |
950 | test [ebp + thread_data.permissions], ABORT |
Line 998... | Line 951... | ||
998 | jnz abort_transfer |
951 | jnz abort_transfer |
Line 999... | Line 952... | ||
999 | 952 | ||
Line 1040... | Line 993... | ||
1040 | jmp parse_cmd.error |
993 | jmp parse_cmd.error |
Line 1041... | Line 994... | ||
1041 | 994 | ||
Line 1042... | Line 995... | ||
1042 | .ascii: |
995 | .ascii: |
1043 | mov [edx + thread_data.type], TYPE_ASCII |
996 | mov [ebp + thread_data.type], TYPE_ASCII |
1044 | jmp .subtype |
997 | jmp .subtype |
Line 1045... | Line 998... | ||
1045 | 998 | ||
1046 | .ebdic: |
999 | .ebdic: |
Line 1047... | Line 1000... | ||
1047 | mov [edx + thread_data.type], TYPE_EBDIC |
1000 | mov [ebp + thread_data.type], TYPE_EBDIC |
1048 | 1001 | ||
1049 | .subtype: |
1002 | .subtype: |
Line 1063... | Line 1016... | ||
1063 | jmp parse_cmd.error |
1016 | jmp parse_cmd.error |
Line 1064... | Line 1017... | ||
1064 | 1017 | ||
Line 1065... | Line 1018... | ||
1065 | .non_print: |
1018 | .non_print: |
1066 | or [edx + thread_data.type], TYPE_NP |
1019 | or [ebp + thread_data.type], TYPE_NP |
1067 | jmp .ok |
1020 | jmp .ok |
Line 1068... | Line 1021... | ||
1068 | 1021 | ||
1069 | .telnet: |
1022 | .telnet: |
1070 | or [edx + thread_data.type], TYPE_TELNET |
1023 | or [ebp + thread_data.type], TYPE_TELNET |
Line 1071... | Line 1024... | ||
1071 | jmp .ok |
1024 | jmp .ok |
1072 | 1025 | ||
1073 | .asacc: |
1026 | .asacc: |
Line 1074... | Line 1027... | ||
1074 | or [edx + thread_data.type], TYPE_ASA |
1027 | or [ebp + thread_data.type], TYPE_ASA |
1075 | jmp .ok |
1028 | jmp .ok |
1076 | 1029 | ||
Line 1077... | Line 1030... | ||
1077 | .image: |
1030 | .image: |
1078 | mov [edx + thread_data.type], TYPE_IMAGE |
1031 | mov [ebp + thread_data.type], TYPE_IMAGE |
1079 | jmp .ok |
1032 | jmp .ok |
Line 1088... | Line 1041... | ||
1088 | cmp al, 9 |
1041 | cmp al, 9 |
1089 | ja parse_cmd.error ; FIXME |
1042 | ja parse_cmd.error ; FIXME |
1090 | or al, TYPE_LOCAL |
1043 | or al, TYPE_LOCAL |
1091 | mov [edx + thread_data.type], al |
1044 | mov [ebp + thread_data.type], al |
1092 | 1045 | ||
1093 | .ok: |
1046 | .ok: |
Line 1094... | Line 1047... | ||
1094 | sendFTP "200 Command ok" |
1047 | sendFTP "200 Command ok" |
1095 | ret |
1048 | ret |
1096 | 1049 | ||
Line 1104... | Line 1057... | ||
1104 | cmdUSER: |
1057 | cmdUSER: |
1105 | 1058 | ||
1106 | lea esi, [esi + 5] |
1059 | lea esi, [esi + 5] |
Line 1107... | Line 1060... | ||
1107 | lea edi, [edx + thread_data.fpath] ; temp buffer for username |
1060 | lea edi, [ebp + thread_data.fpath] ; temp buffer for username |
1108 | .loop: |
1061 | .loop: |
1109 | lodsb |
1062 | lodsb |
1110 | stosb |
1063 | stosb |
1111 | cmp al, 0x20 |
1064 | cmp al, 0x20 |
1112 | jae .loop |
1065 | jae .loop |
1113 | mov byte [edi-1], 0 |
1066 | mov byte [edi-1], 0 |
1114 | 1067 | ||
Line 1115... | Line 1068... | ||
1115 | lea esi, [edx + thread_data.fpath] |
1068 | lea esi, [ebp + thread_data.fpath] |
1116 | lea eax, [edx + thread_data.home_dir] |
1069 | lea eax, [ebp + thread_data.home_dir] |
1117 | invoke ini.get_str, path2, esi, str_home, eax, 1024, str_infinity |
1070 | invoke ini.get_str, path2, esi, str_home, eax, 1024, str_infinity |
1118 | cmp eax, -1 |
1071 | cmp eax, -1 |
1119 | je .login_fail |
1072 | je .login_fail |
1120 | cmp dword [esi], -1 |
1073 | cmp dword [esi], -1 |
1121 | je .login_fail |
1074 | je .login_fail |
Line 1122... | Line 1075... | ||
1122 | 1075 | ||
Line 1123... | Line 1076... | ||
1123 | mov word [edx + thread_data.work_dir], "/" ; "/", 0 |
1076 | mov word [ebp + thread_data.work_dir], "/" ; "/", 0 |
1124 | 1077 | ||
1125 | invoke con_write_asciiz, str_logged_in |
1078 | invoke con_write_asciiz, str_logged_in |
1126 | mov [edx + thread_data.state], STATE_LOGIN |
1079 | mov [ebp + thread_data.state], STATE_LOGIN |
1127 | .sendstr: |
1080 | .sendstr: |
Line 1128... | Line 1081... | ||
1128 | sendFTP "331 Please specify the password" |
1081 | sendFTP "331 Please specify the password" |
1129 | ret |
1082 | ret |
1130 | 1083 | ||
1131 | .login_fail: |
1084 | .login_fail: |
Line 1132... | Line 1085... | ||
1132 | invoke con_write_asciiz, str_login_invalid |
1085 | invoke con_write_asciiz, str_login_invalid |
1133 | mov [edx + thread_data.state], STATE_LOGIN_FAIL |
1086 | mov [ebp + thread_data.state], STATE_LOGIN_FAIL |
1134 | jmp .sendstr |
1087 | jmp .sendstr |