Subversion Repositories Kolibri OS

Rev

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

Rev 2598 Rev 2602
Line 89... Line 89...
89
        dd 'ABOR'
89
        dd 'ABOR'
Line 90... Line 90...
90
        dd login_first, login_first, login_first, cmdABOR
90
        dd login_first, login_first, login_first, cmdABOR
91
;        dd 'ACCT
91
;        dd 'ACCT
92
;        dd login_fitst, login_first, login_first, cmd_ACCT
92
;        dd login_first, login_first, login_first, cmd_ACCT
93
;        dd 'APPE'
93
;        dd 'APPE'
94
;        dd login_fitst, login_first, login_first, cmd_APPE
94
;        dd login_first, login_first, login_first, cmd_APPE
95
        dd 'CDUP'
95
        dd 'CDUP'
96
        dd login_first, login_first, login_first, cmdCDUP
96
        dd login_first, login_first, login_first, cmdCDUP
97
        dd 'CWD'
97
        dd 'CWD'
98
        dd login_first, login_first, login_first, cmdCWD
98
        dd login_first, login_first, login_first, cmdCWD
99
        dd 'DELE'
99
        dd 'DELE'
100
        dd login_first, login_first, login_first, cmdDELE
100
        dd login_first, login_first, login_first, cmdDELE
101
;        dd 'HELP'
101
;        dd 'HELP'
102
;        dd login_fitst, login_first, login_first, cmd_HELP
102
;        dd login_first, login_first, login_first, cmd_HELP
103
        dd 'LIST'
103
        dd 'LIST'
104
        dd login_first, login_first, login_first, cmdLIST
104
        dd login_first, login_first, login_first, cmdLIST
105
;        dd 'MDTM'
105
;        dd 'MDTM'
106
;        dd login_fitst, login_first, login_first, cmd_MDTM
106
;        dd login_first, login_first, login_first, cmd_MDTM
107
;        dd 'MKD'
107
;        dd 'MKD'
108
;        dd login_fitst, login_first, login_first, cmd_MKD
108
;        dd login_first, login_first, login_first, cmd_MKD
109
;        dd 'MODE'
109
;        dd 'MODE'
110
;        dd login_fitst, login_first, login_first, cmd_MODE
110
;        dd login_first, login_first, login_first, cmd_MODE
111
        dd 'NLST'
111
        dd 'NLST'
112
        dd login_first, login_first, login_first, cmdNLST
112
        dd login_first, login_first, login_first, cmdNLST
113
        dd 'NOOP'
113
        dd 'NOOP'
114
        dd login_first, login_first, login_first, cmdNOOP
114
        dd login_first, login_first, login_first, cmdNOOP
115
        dd 'PASS'
115
        dd 'PASS'
116
        dd cmdPASS.0,   cmdPASS    , cmdPASS.2,   cmdPASS.3
116
        dd cmdPASS.0,   cmdPASS    , cmdPASS.2,   cmdPASS.3
Line 123... Line 123...
123
        dd 'QUIT'
123
        dd 'QUIT'
124
        dd cmdQUIT,     cmdQUIT,     cmdQUIT,     cmdQUIT
124
        dd cmdQUIT,     cmdQUIT,     cmdQUIT,     cmdQUIT
125
;        dd 'REIN'
125
;        dd 'REIN'
126
;        dd login_fitst, login_first, login_first, cmd_REIN
126
;        dd login_first, login_first, login_first, cmd_REIN
127
;        dd 'REST'
127
;        dd 'REST'
128
;        dd login_fitst, login_first, login_first, cmd_REST
128
;        dd login_first, login_first, login_first, cmd_REST
129
        dd 'RETR'
129
        dd 'RETR'
130
        dd login_first, login_first, login_first, cmdRETR
130
        dd login_first, login_first, login_first, cmdRETR
131
;        dd 'RMD'
131
;        dd 'RMD'
132
;        dd login_fitst, login_first, login_first, cmd_RMD
132
;        dd login_first, login_first, login_first, cmd_RMD
133
;        dd 'RNFR'
133
;        dd 'RNFR'
134
;        dd login_fitst, login_first, login_first, cmd_RNFR
134
;        dd login_first, login_first, login_first, cmd_RNFR
135
;        dd 'RNTO'
135
;        dd 'RNTO'
136
;        dd login_fitst, login_first, login_first, cmd_RNTO
136
;        dd login_first, login_first, login_first, cmd_RNTO
137
;        dd 'SITE'
137
;        dd 'SITE'
138
;        dd login_fitst, login_first, login_first, cmd_SITE
138
;        dd login_first, login_first, login_first, cmd_SITE
139
;        dd 'SIZE'
139
;        dd 'SIZE'
140
;        dd login_fitst, login_first, login_first, cmd_SIZE
140
;        dd login_first, login_first, login_first, cmd_SIZE
141
;        dd 'STAT'
141
;        dd 'STAT'
142
;        dd login_fitst, login_first, login_first, cmd_STAT
142
;        dd login_first, login_first, login_first, cmd_STAT
143
        dd 'STOR'
143
        dd 'STOR'
144
        dd login_first, login_first, login_first, cmdSTOR
144
        dd login_first, login_first, login_first, cmdSTOR
145
;        dd 'STOU'
145
;        dd 'STOU'
146
;        dd login_fitst, login_first, login_first, cmd_STOU
146
;        dd login_first, login_first, login_first, cmd_STOU
147
;        dd 'STRU'
147
;        dd 'STRU'
148
;        dd login_fitst, login_first, login_first, cmd_STRU
148
;        dd login_first, login_first, login_first, cmd_STRU
149
        dd 'SYST'
149
        dd 'SYST'
150
        dd login_first, login_first, login_first, cmdSYST
150
        dd login_first, login_first, login_first, cmdSYST
151
        dd 'TYPE'
151
        dd 'TYPE'
152
        dd login_first, login_first, login_first, cmdTYPE
152
        dd login_first, login_first, login_first, cmdTYPE
153
        dd 'USER'
153
        dd 'USER'
154
        dd cmdUSER,     cmdUSER,     cmdUSER,     cmdUSER.2
154
        dd cmdUSER,     cmdUSER,     cmdUSER,     cmdUSER.2
155
        db 0                                                    ; end marker
155
        db 0                                                    ; end marker
Line 166... Line 166...
166
 
166
 
167
align 4
167
align 4
Line 168... Line 168...
168
socketerror:
168
socketerror:
169
        pushd   0x0c
169
        invoke  con_set_flags, 0x0c
170
        call    [con_set_flags]
-
 
171
        push    str_sockerr
170
        invoke  con_write_asciiz, str_sockerr
172
        call    [con_write_asciiz]
-
 
173
        pushd   0x07
171
        invoke  con_set_flags, 0x07
174
        call    [con_set_flags]
-
 
175
 
172
 
Line 176... Line -...
176
        mov     edx, [ebp]
-
 
177
        sendFTP "425 Can't open data connection"
173
        sendFTP "425 Can't open data connection"
178
        ret
174
        ret
Line 179... Line 175...
179
 
175
 
180
align 4
176
align 4
181
abort_transfer:
177
abort_transfer:
182
        and     [edx + thread_data.permissions], not ABORT
178
        and     [edx + thread_data.permissions], not ABORT
183
        mov     [edx + thread_data.mode], MODE_NOTREADY
-
 
184
        push    ebx
179
        mov     [edx + thread_data.mode], MODE_NOTREADY
185
        call    [file.close]
180
        invoke  file.close, ebx
-
 
181
        mcall   close, [edx + thread_data.datasocketnum]
186
        mcall   close, [edx + thread_data.datasocketnum]
182
 
187
        mov     edx, [ebp]
183
        mov     edx, [ebp]
188
        sendFTP "530 Transfer aborted"
184
        sendFTP "530 Transfer aborted"
Line 189... Line 185...
189
        ret
185
        ret
190
 
186
 
Line 191... Line 187...
191
align 4
187
align 4
192
ip_to_dword:    ; esi = ptr to str, cl = separator ('.', ',')
188
ip_to_dword:    ; esi = ptr to str, cl = separator ('.', ',')
193
 
189
 
194
        call    ascii_to_byte
190
        call    ascii_to_byte
-
 
191
        mov     bl, al
Line 195... Line 192...
195
        mov     bh, al
192
        cmp     byte [esi], cl
196
        cmp     byte [esi], cl
193
        jne     .err
197
        jne     .err
194
        inc     esi
198
 
195
 
-
 
196
        call    ascii_to_byte
-
 
197
        mov     bh, al
199
        call    ascii_to_byte
198
        cmp     byte [esi], cl
Line 200... Line 199...
200
        mov     bh, al
199
        jne     .err
201
        cmp     byte [esi], cl
200
        inc     esi
202
        jne     .err
201
 
203
        shl     ebx, 16
202
        shl     ebx, 16
-
 
203
 
Line 204... Line 204...
204
 
204
        call    ascii_to_byte
205
        call    ascii_to_byte
205
        mov     bl, al
Line 206... Line 206...
206
        mov     bh, al
206
        cmp     byte [esi], cl
Line 274... Line 274...
274
        mov     ecx, 1024
274
        mov     ecx, 1024
275
  .loop1:
275
  .loop1:
276
        lodsb
276
        lodsb
277
        or      al, al
277
        cmp     al, 0x20
278
        jz      .next
278
        jb      .next
279
        stosb
279
        stosb
280
        loop    .loop1
280
        loop    .loop1
281
  .next:
281
  .next:
282
 
282
 
283
        cmp     byte[edi-1], '/'
283
        cmp     byte[edi-1], '/'
Line 284... Line 284...
284
        jne     @f
284
        jne     @f
Line 289... Line 289...
289
        mov     ecx, 1024
289
        mov     ecx, 1024
290
  .loop2:
290
  .loop2:
291
        lodsb
291
        lodsb
292
        or      al, al
292
        cmp     al, 0x20
293
        jz      .done
293
        jb      .done
294
        stosb
294
        stosb
295
        loop    .loop2
295
        loop    .loop2
296
 
296
 
Line 297... Line 297...
297
  .done:
297
  .done:
-
 
298
        xor     al, al
298
        stosb
299
        stosb
299
        ret
300
        ret
Line 300... Line 301...
300
 
301
 
301
;------------------------------------------------
302
;------------------------------------------------
Line 463... Line 464...
463
        cmp     eax, -1
464
        cmp     eax, -1
464
        je      socketerror
465
        je      socketerror
465
  @@:
466
  @@:
466
 
467
        mov     edx, [ebp]
467
; Create fpath from home_dir and work_dir
468
 
-
 
469
; Create fpath from home_dir and work_dir
Line 468... Line 470...
468
        call    create_path
470
        call    create_path
469
 
471
 
Line 470... Line 472...
470
        lea     eax, [edx + thread_data.fpath]
472
        lea     ebx, [edx + thread_data.fpath]
471
        push    eax
-
 
472
        call    [con_write_asciiz]
473
        invoke  con_write_asciiz, ebx
473
        push    str_newline
-
 
474
        call    [con_write_asciiz]
474
        invoke  con_write_asciiz, str_newline
Line 475... Line -...
475
 
-
 
476
; Start the search
-
 
477
        mov     edx, [ebp]
-
 
478
        push    FA_ANY
-
 
479
        push    str_mask
-
 
480
        lea     eax, [edx + thread_data.fpath]
-
 
481
        push    eax
-
 
Line -... Line 475...
-
 
475
 
-
 
476
 
-
 
477
        mov     edx, [ebp]                        ;;;
-
 
478
        lea     ebx, [edx + thread_data.fpath]       ;;;;
482
        call    [file.find.first]
479
; Start the search
483
 
480
        invoke  file.find.first, ebx, str_mask, FA_ANY
Line 484... Line 481...
484
        test    eax, eax
481
        test    eax, eax
485
        jz      .nosuchdir
482
        jz      .nosuchdir
486
 
-
 
487
        mov     edx, [ebp]
483
 
488
        lea     edi, [edx + thread_data.buffer]
484
        mov     edx, [ebp]                        ;;;
489
 
485
        lea     edi, [edx + thread_data.buffer]
490
  .parse_file:
486
  .parse_file:
Line 532... Line 528...
532
; now the filesize in ascii
528
; now the filesize in ascii
Line 533... Line 529...
533
        mov     eax, [ebx + FileInfoA.FileSizeLow]
529
        mov     eax, [ebx + FileInfoA.FileSizeLow]
534
        call    dword_to_ascii
530
        call    dword_to_ascii
535
 
531
        mov     al, ' '
536
        mov     al, ' '
-
 
537
        stosb
532
        stosb
538
 
533
 
Line 539... Line 534...
539
; then date (month/day/year)
534
; then date (month/day/year)
540
        movzx   eax, [ebx + FileInfoA.DateModify + FileDateTime.month]
535
        movzx   eax, [ebx + FileInfoA.DateModify + FileDateTime.month]
-
 
536
        cmp     eax, 12
-
 
537
        ja      @f
541
        mov     eax, [months + 4*eax]
538
        mov     eax, [months - 4 + 4*eax]
542
        stosd
539
        stosd
-
 
540
       @@:
Line 543... Line 541...
543
 
541
 
544
        movzx   eax, [ebx + FileInfoA.DateModify + FileDateTime.day]
542
        movzx   eax, [ebx + FileInfoA.DateModify + FileDateTime.day]
545
        call    dword_to_ascii
-
 
546
 
543
        call    dword_to_ascii
547
        mov     al, ' '
544
        mov     al, ' '
Line 548... Line 545...
548
        stosb
545
        stosb
549
 
546
 
550
        movzx   eax, [ebx + FileInfoA.DateModify + FileDateTime.year]
-
 
551
        call    dword_to_ascii
547
        movzx   eax, [ebx + FileInfoA.DateModify + FileDateTime.year]
552
 
548
        call    dword_to_ascii
Line 553... Line 549...
553
        mov     al, ' '
549
        mov     al, ' '
554
        stosb
550
        stosb
Line 568... Line 564...
568
        mov     ax, 0x0a0d
564
        mov     ax, 0x0a0d
569
        stosw
565
        stosw
570
 
566
 
571
        test    [edx + thread_data.permissions], ABORT
567
        test    [edx + thread_data.permissions], ABORT          ; Did we receive ABOR command from client?
Line 572... Line 568...
572
;;;        jnz     .abort
568
;;;        jnz     .abort                                         ; TODO
573
 
569
 
Line 574... Line 570...
574
; check next file
570
; check next file
575
        push    ebx
571
;;;        invoke  file.find.next, ebx
576
        call    [file.find.next]
572
;;;        jmp     .parse_file
577
        jmp     .parse_file
573
        mov     eax, ebx        ;;;;;
Line 578... Line 574...
578
 
574
 
579
; close file desc
575
; close file desc
580
  .done:
576
  .done:
581
        push    eax                             ; file discriptor is still in eax at this point!
-
 
Line 582... Line 577...
582
        call    [file.find.close]
577
        invoke  file.find.close, eax                            ; file discriptor is still in eax at this point!
583
 
578
 
584
; append the string with a 0
579
; append the string with a 0
Line 585... Line 580...
585
        xor     al, al
580
        xor     al, al
586
        stosb
-
 
587
 
581
        stosb
-
 
582
 
588
; Warn the client we're about to send the data
583
; Warn the client we're about to send the data
589
        mov     edx, [ebp]
584
        push    edi
Line 590... Line 585...
590
        push    edi
585
        mov     edx, [ebp]              ;;;;;;;
591
        sendFTP "150 Here it comes.."
586
        sendFTP "150 Here it comes.."
Line 601... Line 596...
601
 
596
 
602
; close the data socket..
597
; close the data socket..
Line 603... Line 598...
603
        mov     edx, [ebp]                                      ; thread_data pointer
598
        mov     edx, [ebp]                                      ; thread_data pointer
604
        mcall   close, [edx + thread_data.datasocketnum]
599
        mov     [edx + thread_data.mode], MODE_NOTREADY
605
        mov     [edx + thread_data.mode], MODE_NOTREADY
-
 
606
 
600
        mcall   close, [edx + thread_data.datasocketnum]
-
 
601
 
Line 607... Line 602...
607
        sendFTP "226 Transfer OK"
602
        sendFTP "226 Transfer OK"
608
        ret
603
        ret
Line 609... Line 604...
609
 
604
 
Line 636... Line 631...
636
align 4
631
align 4
637
cmdNOOP:
632
cmdNOOP:
638
 
633
 
639
        ret
634
        sendFTP "200 Command OK"
Line -... Line 635...
-
 
635
        ret
640
 
636
 
Line 641... Line 637...
641
;------------------------------------------------
637
;------------------------------------------------
642
; "PASS"
638
; "PASS"
643
;
639
;
Line 647... Line 643...
647
align 4
643
align 4
648
cmdPASS:
644
cmdPASS:
649
        lea     esi, [esi + 5]
645
        lea     esi, [esi + 5]
650
        lea     edi, [edx + thread_data.buffer + 512]           ; temp pass
646
 
651
        lea     eax, [edx + thread_data.fpath]                  ; temp username
647
; read the password from users.ini
-
 
648
        lea     edi, [edx + thread_data.buffer + 512]           ; temp pass
-
 
649
        lea     ebx, [edx + thread_data.fpath]                  ; temp username
652
        invoke  ini.get_str, path2, eax, str_pass, edi, 512
650
        invoke  ini.get_str, path2, ebx, str_pass, edi, 512, str_infinity
653
        test    eax, eax
651
        test    eax, eax
654
        jnz     .incorrect
652
        jnz     .incorrect
655
 
653
        cmp     dword [edi], -1
656
        repe    cmpsb
654
        je      .incorrect
-
 
655
        cmp     byte[edi], 0
-
 
656
        je      .pass_ok
-
 
657
 
-
 
658
; compare with received password
Line -... Line 659...
-
 
659
        repe    cmpsb
657
 
660
        cmp     byte [esi], 0x20
658
        cmp     byte [esi], 0x20
-
 
659
        jae     .incorrect
661
        jae     .incorrect
660
 
662
        cmp     byte [edi], 0
661
        cmp     byte [edi], 0
-
 
662
        jne     .incorrect
663
        jne     .incorrect
663
 
664
 
Line 664... Line 665...
664
  .pass_ok:
665
  .pass_ok:
665
        lea     eax, [edx + thread_data.fpath]
-
 
666
        invoke  ini.get_int, path2, eax, str_mode, 0
666
        invoke  ini.get_int, path2, ebx, str_mode, 0
-
 
667
        mov     edx, [ebp]                                      ; because libini destroys edx!
667
        mov     [edx + thread_data.permissions], eax
668
        mov     [edx + thread_data.permissions], eax
Line 668... Line -...
668
 
-
 
669
        push    str_pass_ok
669
 
670
        call    [con_write_asciiz]
-
 
671
 
-
 
672
        mov     edx, [ebp]                                      ; thread_data pointer
670
        invoke  con_write_asciiz, str_pass_ok
673
        mov     [edx + thread_data.state], STATE_ACTIVE
671
        mov     [edx + thread_data.state], STATE_ACTIVE
674
        sendFTP "230 You are now logged in"
672
        sendFTP "230 You are now logged in"
Line 675... Line 673...
675
        ret
673
        ret
Line 716... Line 714...
716
        mov     esi, sizeof.thread_data.datasock
714
        mov     esi, sizeof.thread_data.datasock
717
        mcall   bind
715
        mcall   bind
718
        cmp     eax, -1
716
        cmp     eax, -1
719
;        je      bind_err
717
;        je      bind_err       ; TODO
720
 
718
 
721
; And set it to listen!
719
; And set it to listen!
Line 722... Line 720...
722
        mcall   listen, , 1
720
        mcall   listen, , 1
723
        cmp     eax, -1
721
        cmp     eax, -1
724
;        je      listen_err
722
;        je      listen_err     ; TODO
725
 
723
 
Line 726... Line 724...
726
; Tell our thread we are ready to accept incoming calls
724
; Tell our thread we are ready to accept incoming calls
727
        mov     edx, [ebp]                                      ; thread_data pointer
725
        mov     edx, [ebp]                                      ; thread_data pointer
728
        mov     [edx + thread_data.mode], MODE_PASSIVE_WAIT
726
        mov     [edx + thread_data.mode], MODE_PASSIVE_WAIT
Line 769... Line 767...
769
        sub     esi, edx
767
        sub     esi, edx
770
        mov     ecx, [edx + thread_data.socketnum]
768
        mov     ecx, [edx + thread_data.socketnum]
771
        lea     edx, [edx + thread_data.buffer]
769
        lea     edx, [edx + thread_data.buffer]
772
        xor     esi, esi
770
        xor     edi, edi
773
        mcall   send
771
        mcall   send
774
 
772
 
Line 775... Line 773...
775
        ret
773
        ret
Line 776... Line 774...
776
 
774
 
Line 809... Line 807...
809
        mov     edx, [ebp]
807
        mov     edx, [ebp]
Line 810... Line 808...
810
; Print the new working dir on the console
808
; Print the new working dir on the console
811
        lea     eax, [edx + thread_data.work_dir]
809
        lea     eax, [edx + thread_data.work_dir]
812
        push    eax
810
        invoke  con_write_asciiz, eax
813
        call    [con_write_asciiz]
-
 
814
        push    str_newline
811
        invoke  con_write_asciiz, str_newline
815
        call    [con_write_asciiz]
-
 
816
 
812
 
Line 817... Line 813...
817
        ret
813
        ret
Line 818... Line 814...
818
 
814
 
819
;------------------------------------------------
815
;------------------------------------------------
Line 833... Line 829...
833
        mov     cl, ','
829
        mov     cl, ','
834
        call    ip_to_dword
830
        call    ip_to_dword
835
; And put it in datasock
831
; And put it in datasock
836
        mov     edx, [ebp]
832
;;;        mov     edx, [ebp]
837
        mov     [edx + thread_data.datasock.sin_addr], ebx
833
        mov     [edx + thread_data.datasock.sin_addr], ebx
838
 
834
 
839
; Now the same with portnumber
835
; Now the same with portnumber
Line 840... Line 836...
840
        call    ascii_to_byte
836
        inc     esi
-
 
837
        call    ascii_to_byte
841
        mov     bh, al
838
        mov     bh, al
842
        inc     esi
839
        inc     esi
843
        call    ascii_to_byte
840
        call    ascii_to_byte
844
        mov     bl, al
841
        mov     bl, al
845
 
842
 
Line 868... Line 865...
868
align 4
865
align 4
869
cmdQUIT:
866
cmdQUIT:
870
 
867
 
871
        mcall   close, [edx + thread_data.datasocketnum]
868
        sendFTP "221 Bye!"
Line 872... Line -...
872
 
-
 
873
        sendFTP "221 Bye!"
-
 
874
        mcall   close, [edx + thread_data.socketnum]
869
        mov     edx, [ebp]
-
 
870
        mcall   close, [edx + thread_data.datasocketnum]
-
 
871
        mcall   close, [edx + thread_data.socketnum]
875
 
872
 
Line 876... Line 873...
876
        add     esp, 4          ; get rid of call return address
873
        add     esp, 4          ; get rid of call return address
877
        jmp     thread_exit     ; now close this thread
874
        jmp     thread_exit     ; now close this thread
Line 889... Line 886...
889
        test    [edx + thread_data.permissions], PERMISSION_READ
886
        test    [edx + thread_data.permissions], PERMISSION_READ
Line 890... Line 887...
890
        jz      permission_denied
887
        jz      permission_denied
891
 
888
 
Line -... Line 889...
-
 
889
        cmp     ecx, 1024 + 5
-
 
890
        jae     .cannot_open
-
 
891
 
892
        sub     ecx, 5
892
        sub     ecx, 5
893
        jb      .cannot_open
893
        jb      .cannot_open
Line 894... Line 894...
894
 
894
 
895
        cmp     [edx + thread_data.mode], MODE_ACTIVE
895
        cmp     [edx + thread_data.mode], MODE_ACTIVE
896
        jne     @f
896
        jne     @f
897
        push    esi
897
        push    ecx esi
898
        mov     ecx, [edx + thread_data.datasocketnum]
898
        mov     ecx, [edx + thread_data.datasocketnum]
899
        lea     edx, [edx + thread_data.datasock]
899
        lea     edx, [edx + thread_data.datasock]
900
        mov     esi, sizeof.thread_data.datasock
900
        mov     esi, sizeof.thread_data.datasock
901
        mcall   connect
901
        mcall   connect
902
        pop     esi
902
        pop     esi ecx
903
        cmp     eax, -1
903
        cmp     eax, -1
904
        je      socketerror
904
        je      socketerror
Line 905... Line 905...
905
  @@:
905
  @@:
906
 
906
 
907
        push    esi
907
        push    ecx esi
908
        call    create_path
908
        call    create_path
909
        pop     esi
909
        pop     esi ecx
910
        dec     edi
-
 
-
 
910
        dec     edi
911
        add     esi, 5
911
        add     esi, 5
912
        mov     ecx, 1024
912
 
913
  .loop:
913
  .loop:
914
        lodsb
914
        lodsb
915
        cmp     al, 0x20
915
        cmp     al, 0x20
916
        jl      .done
916
        jl      .done
917
        stosb
917
        stosb
918
        loop    .loop
918
        loop    .loop
919
  .done:
919
  .done:
Line 920... Line 920...
920
        xor     al, al
920
        xor     al, al
921
        stosb
-
 
922
 
921
        stosb
923
        lea     eax, [edx + thread_data.fpath]
-
 
924
        push    eax
922
 
Line 925... Line -...
925
        call    [con_write_asciiz]
-
 
926
        push    str_newline
-
 
927
        call    [con_write_asciiz]
-
 
928
 
-
 
929
        mov     edx, [ebp]
923
        lea     ebx, [edx + thread_data.fpath]
930
        push    O_READ
924
        invoke  con_write_asciiz, ebx
931
        lea     eax, [edx + thread_data.fpath]
925
        invoke  con_write_asciiz, str_newline
Line 932... Line -...
932
        push    eax
-
 
933
        call    [file.open]
926
 
-
 
927
        invoke  file.open, ebx, O_READ
934
        test    eax, eax
928
        test    eax, eax
935
        jz      .cannot_open
929
        jz      .cannot_open
Line 936... Line 930...
936
 
930
 
937
        mov     edx, [ebp]
931
        push    eax
938
        push    eax
932
        mov     edx, [ebp]
939
        sendFTP "150 Here it comes.."
933
        sendFTP "150 Here it comes.."
Line 940... Line -...
940
        pop     ebx
-
 
941
 
934
        pop     ebx
942
  .read_more:
-
 
943
        mov     edx, [ebp]
-
 
944
        test    [edx + thread_data.permissions], ABORT
935
 
945
        jnz     abort_transfer
936
  .read_more:
946
 
937
        mov     edx, [ebp]
Line 947... Line -...
947
        push    BUFFERSIZE
-
 
948
        lea     eax, [edx + thread_data.buffer]
938
        test    [edx + thread_data.permissions], ABORT
949
        push    eax
939
        jnz     abort_transfer
950
        push    ebx
940
 
951
        call    [file.read]
941
        lea     eax, [edx + thread_data.buffer]                 ; FIXME: use another buffer!! if we receive something on control connection now, we screw up!
952
        cmp     eax, -1
942
        invoke  file.read, ebx, eax, BUFFERSIZE
953
        je      .cannot_open    ; fixme: this is not the correct error
943
        cmp     eax, -1
954
 
944
        je      .cannot_open                                    ; FIXME: this is not the correct error
955
        mov     edx, [ebp]
-
 
956
        push    eax ebx
945
 
957
        mov     esi, eax
946
        push    eax ebx
Line -... Line 947...
-
 
947
        mov     esi, eax
-
 
948
        mov     ecx, [edx + thread_data.datasocketnum]
-
 
949
        lea     edx, [edx + thread_data.buffer]
958
        mov     ecx, [edx + thread_data.datasocketnum]
950
        xor     esi, esi
959
        lea     edx, [edx + thread_data.buffer]
951
        mcall   send
Line 960... Line -...
960
        xor     esi, esi
-
 
961
        mcall   send
952
        pop     ebx ecx
Line 962... Line 953...
962
        pop     ebx ecx
953
        cmp     eax, -1
-
 
954
        je      socketerror
963
        mov     edx, [ebp]                                      ; thread_data pointer
955
 
Line -... Line 956...
-
 
956
;        cmp     eax, ecx
964
        cmp     eax, -1
957
;        jne     not_all_byes_sent                               ; TODO
965
        je      socketerror
958
 
Line 966... Line 959...
966
 
959
        cmp     ecx, BUFFERSIZE
967
        cmp     ecx, BUFFERSIZE
-
 
968
        je      .read_more
960
        je      .read_more
969
 
-
 
970
        mcall   close, [edx + thread_data.datasocketnum]
961
 
971
        mov     [edx + thread_data.mode], MODE_NOTREADY
-
 
972
 
962
        invoke  file.close, ebx
Line 973... Line 963...
973
        push    ebx
963
 
974
        call    [file.close]
964
        mov     edx, [ebp]
975
 
965
        mov     [edx + thread_data.mode], MODE_NOTREADY
Line 1094... Line 1084...
1094
 
1084
 
1095
        mov     al, byte[esi+7]
1085
        mov     al, byte[esi+7]
Line 1096... Line 1086...
1096
        sub     al, '0'
1086
        sub     al, '0'
1097
        jb      parse_cmd.error
1087
        jb      parse_cmd.error                         ; FIXME: this is not the correct errormessage
1098
        cmp     al, 9
1088
        cmp     al, 9
1099
        ja      parse_cmd.error
1089
        ja      parse_cmd.error                         ; FIXME
1100
        or      al, TYPE_LOCAL
1090
        or      al, TYPE_LOCAL
1101
        mov     [edx + thread_data.type], al
1091
        mov     [edx + thread_data.type], al
1102
 
1092
 
Line 1103... Line 1093...
1103
  .ok:
1093
  .ok:
1104
        sendFTP "200 Command ok"
1094
        sendFTP "200 Command ok"
1105
        ret
1095
        ret
Line 1106... Line 1096...
1106
 
1096
 
1107
;------------------------------------------------
1097
;------------------------------------------------
1108
; "USER"
1098
; "USER"
1109
;
1099
;
1110
; Login to the server, step one of two.
1100
; Login to the server, step one of two.                         ;;; TODO: prevent buffer overflow!
1111
;
1101
;
1112
;------------------------------------------------
1102
;------------------------------------------------
1113
align 4
1103
align 4
Line 1114... Line 1104...
1114
cmdUSER:
1104
cmdUSER:
1115
 
1105
 
1116
        lea     esi, [esi + 5]
1106
        lea     esi, [esi + 5]
1117
        lea     edi, [edx + thread_data.fpath]
1107
        lea     edi, [edx + thread_data.fpath]                  ; temp buffer for username
1118
  .loop:                                         ;;; TODO: prevent buffer overflow!
1108
  .loop:
1119
        lodsb
1109
        lodsb
1120
        stosb
1110
        stosb
1121
        cmp     al, 0x20
1111
        cmp     al, 0x20
Line 1122... Line 1112...
1122
        jae     .loop
1112
        jae     .loop
1123
        mov     byte [edi-1], 0
1113
        mov     byte [edi-1], 0
1124
 
1114
 
1125
        lea     esi, [edx + thread_data.fpath]
1115
        lea     esi, [edx + thread_data.fpath]
1126
        lea     eax, [edx + thread_data.home_dir]
1116
        lea     eax, [edx + thread_data.home_dir]
-
 
1117
        invoke  ini.get_str, path2, esi, str_home, eax, 1024, str_infinity
-
 
1118
        cmp     eax, -1
Line 1127... Line 1119...
1127
        invoke  ini.get_str, path2, esi, str_home, eax, 1024
1119
        je      .login_fail
Line 1128... Line -...
1128
        cmp     eax, -1
-
 
1129
        je      .login_fail
1120
        cmp     dword [esi], -1
1130
 
-
 
1131
        mov     word [edx + thread_data.work_dir], "/"          ; "/", 0
-
 
1132
 
1121
        je      .login_fail
1133
        push    str_logged_in
1122
 
1134
        call    [con_write_asciiz]
1123
        mov     word [edx + thread_data.work_dir], "/"          ; "/", 0
1135
 
1124
 
Line 1136... Line 1125...
1136
        mov     edx, [ebp]
1125
        invoke  con_write_asciiz, str_logged_in
1137
        mov     [edx + thread_data.state], STATE_LOGIN
1126
        mov     [edx + thread_data.state], STATE_LOGIN
1138
  .sendstr:
-
 
1139
        sendFTP "331 Please specify the password"
-
 
1140
        ret
-
 
1141
 
1127
  .sendstr:
1142
  .login_fail:
1128
        sendFTP "331 Please specify the password"
Line 1143... Line 1129...
1143
        push    str_login_invalid
1129
        ret
1144
        call    [con_write_asciiz]
1130