Subversion Repositories Kolibri OS

Rev

Rev 2562 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2554 hidnplayr 1
 
2
 
3
 
4
        cmp     byte [esi+3], 0x20
5
        jae     @f
6
 
2557 hidnplayr 7
       @@:
8
9
        mov     eax, [esi]
10
        and     eax, not 0x20202020     ; convert to upper case
11
 
2554 hidnplayr 12
        mov     edi, commands           ; list of commands to scan
13
  .scanloop:
14
        cmp     eax, [edi]
15
        jne     .try_next
16
17
        jmp     dword [edi+4]
2557 hidnplayr 18
2554 hidnplayr 19
 
20
        add     edi, 8
21
 
22
        jne     .scanloop
23
24
  .error:
25
        mcall   send, [socketnum2], str500, str500.length, 0
26
 
27
        ret
2557 hidnplayr 28
29
 
2554 hidnplayr 30
align 4
31
 
32
 
33
        db 'ABOR'
2562 hidnplayr 34
        dd cmdABOR
2554 hidnplayr 35
 
36
        dd cmdCWD
37
        db 'DELE'
38
        dd cmdDELE
39
        db 'LIST'
40
        dd cmdLIST
41
        db 'NLST'
42
        dd cmdNLST
43
        db 'NOOP'
44
        dd cmdNOOP
45
        db 'PASS'
46
        dd cmdPASS
47
        db 'PASV'
2557 hidnplayr 48
        dd cmdPASV
49
        db 'PWD', 0
2562 hidnplayr 50
        dd cmdPWD
51
        db 'PORT'
2563 hidnplayr 52
        dd cmdPORT
2554 hidnplayr 53
        db 'QUIT'
54
        dd cmdQUIT
55
        db 'RETR'
56
        dd cmdRETR
57
        db 'STOR'
58
        dd cmdSTOR
59
        db 'SYST'
60
        dd cmdSYST
61
        db 'TYPE'
62
        dd cmdTYPE
63
        db 'USER'
64
        dd cmdUSER
65
        db 'XPWD'
66
        dd cmdPWD
67
        db 0            ; end marker
68
69
2562 hidnplayr 70
align 4
2554 hidnplayr 71
 
72
 
73
        ret
74
75
 
76
cmdCWD:                 ; Change Working Directory
77
 
78
        sub     ecx, 4
2563 hidnplayr 79
        jb      .err
2554 hidnplayr 80
 
2563 hidnplayr 81
        mov     edi, work_dir + 1
82
83
        cmp     byte [esi], '/'
84
        jne     @f
85
 
86
        dec     ecx
87
        jz      .done
88
       @@:
89
90
  .loop:
91
        lodsb
92
 
93
        jb      .done
94
        stosb
95
        loop    .loop
96
  .done:
97
        cmp     byte [edi-1], '/'
98
        je      @f
99
        mov     byte [edi], '/'
100
        inc     edi
101
       @@:
102
        mov     byte [edi], 0
103
104
        mcall   send, [socketnum2], str250, str250.length, 0
105
106
 
107
108
 
2554 hidnplayr 109
110
 
2563 hidnplayr 111
112
 
113
cmdDELE:
114
 
2554 hidnplayr 115
        ret
116
117
 
118
cmdLIST:
119
 
120
; If we are in active mode, it's time to open a data socket..
121
        cmp     [mode], MODE_ACTIVE
122
 
2563 hidnplayr 123
        mcall   connect, [datasocketnum], datasock, datasock.length
2562 hidnplayr 124
        cmp     eax, -1
125
        je      .err
126
  @@:
127
128
; Warn the client we're about to send the data
129
        mcall   send, [socketnum2], str150, str150.length, 0    ; here it comes..
130
 
2563 hidnplayr 131
; Create fpath from home_dir and work_dir
2562 hidnplayr 132
        call    create_path
133
 
2563 hidnplayr 134
; Start the search
135
        push    FA_READONLY + FA_FOLDER
136
 
137
        push    fpath
2562 hidnplayr 138
        call    [file.find.first]
139
2563 hidnplayr 140
        mov     edi, buffer
2562 hidnplayr 141
  .parse_file:
142
 
143
        jz      .done
144
2563 hidnplayr 145
        mov     edx, eax        ; yes, save the descripter
2562 hidnplayr 146
147
 
2563 hidnplayr 148
        test    [edx + FileInfoA.Attributes], FA_FOLDER
2562 hidnplayr 149
 
150
2563 hidnplayr 151
        test    [edx + FileInfoA.Attributes], FA_READONLY
2562 hidnplayr 152
        jnz     .readonly
153
 
2563 hidnplayr 154
        mov     eax, '-rw-'
2562 hidnplayr 155
        stosd
156
 
157
158
  .folder:
159
        mov     eax, 'drwx'
160
 
161
        jmp     .attr
162
2563 hidnplayr 163
  .readonly:
2562 hidnplayr 164
        mov     eax, '-r--'
165
 
166
167
  .attr:
168
        mov     eax, 'rw-r'
169
 
170
        mov     ax, 'w-'
171
        stosw
172
        mov     al, ' '
173
        stosb
174
175
; now..
176
        mov     ax, '1 '
177
 
178
179
; now write owner, everything is owned by FTP, woohoo!
180
        mov     eax, 'FTP '
181
 
182
        stosd
183
184
; now the filesize in ascii
185
        mov     ebx, [edx + FileInfoA.FileSizeLow]
186
 
187
2563 hidnplayr 188
        mov     al, ' '
2562 hidnplayr 189
        stosb
190
 
191
; then date (month/day/year)
192
        movzx   ebx, [edx + FileInfoA.DateModify + FileDateTime.month]
193
 
194
        stosd
195
196
        movzx   ebx, [edx + FileInfoA.DateModify + FileDateTime.day]
197
        call    dword_to_ascii
198
 
199
        mov     al, ' '
200
        stosb
201
 
202
        movzx   ebx, [edx + FileInfoA.DateModify + FileDateTime.year]
203
        call    dword_to_ascii
204
 
205
        mov     al, ' '
206
        stosb
207
 
208
; and last but not least, filename
209
        lea     esi, [edx + FileInfoA.FileName]
210
 
211
  .nameloop:
212
        lodsb
213
        test    al, al
214
        jz      .namedone
215
        stosb
216
        loop    .nameloop
217
218
; insert a cr lf
219
  .namedone:
220
 
2563 hidnplayr 221
        stosw
2562 hidnplayr 222
223
; check next file
224
        push    edx
225
 
2563 hidnplayr 226
        jmp     .parse_file
227
228
; close file desc
229
  .done:
230
 
231
        call    [file.find.close]
2562 hidnplayr 232
233
; append the string with a 0
234
        xor     al, al
235
 
2563 hidnplayr 236
2562 hidnplayr 237
; print everything on the console
238
        push    buffer
239
 
2563 hidnplayr 240
2562 hidnplayr 241
; and send it to the client
242
        lea     esi, [edi - buffer]
243
 
2563 hidnplayr 244
2562 hidnplayr 245
; close the data socket..
246
        mcall   close, [datasocketnum]
247
 
2563 hidnplayr 248
        cmp     [mode], MODE_PASSIVE_OK
2562 hidnplayr 249
        jne     @f
250
 
251
      @@:
252
253
; And send "transfer ok" on the base connection
254
        mcall   send, [socketnum2], str226, str226.length, 0
255
 
2563 hidnplayr 256
        ret
257
2562 hidnplayr 258
 
2554 hidnplayr 259
        pushd   0x0c
260
 
2562 hidnplayr 261
262
        push    str_err1
263
        call    [con_write_asciiz]
264
 
265
        pushd   0x07
266
        call    [con_set_flags]
267
 
268
        ret
269
270
 
271
cmdNLST:
272
 
2554 hidnplayr 273
        ret
274
275
 
276
cmdNOOP:
277
 
278
        ret
279
280
 
281
cmdPASS:
282
 
283
        mcall   send, [socketnum2], str230, str230.length, 0
2557 hidnplayr 284
285
 
286
        call    [con_write_asciiz]
2560 hidnplayr 287
 
288
        mov     [state], STATE_ACTIVE
289
290
 
2557 hidnplayr 291
292
 
293
cmdPASV:
294
 
295
; 227 Entering Passive Mode (a1,a2,a3,a4,p1,p2)
2560 hidnplayr 296
; where a1.a2.a3.a4 is the IP address and p1*256+p2 is the port number.
297
 
298
        mcall   socket, AF_INET4, SOCK_STREAM, 0
299
        cmp     eax, -1
300
 
2562 hidnplayr 301
        mov     [passivesocknum], eax
302
303
        mov     [datasock.port], 2000
304
        mov     [datasock.ip], 0
305
 
306
        mcall   bind, [passivesocknum], datasock, datasock.length
307
        cmp     eax, -1
308
 
309
310
        mcall   listen, [passivesocknum], 1
311
312
 
313
314
 
315
        mov     eax, '227 '     ; FIXME (now hardcoded to 127.0.0.1:2000)
316
 
317
        mov     eax, '(127'
318
        stosd
319
        mov     eax, ',0,0'
320
        stosd
321
        mov     eax, ',1,7'
322
        stosd
323
        mov     eax, ',208'
324
        stosd
325
        mov     al, ')'
326
        stosb
327
        mov     ax, 0x0d0a
328
        stosw
329
        xor     al, al
330
        stosb
331
332
        lea     esi, [edi - buffer]
333
334
 
335
336
 
337
338
 
2560 hidnplayr 339
cmdPWD:         ; Print Working Directory
340
 
341
        mov     dword[buffer], '257 '
2563 hidnplayr 342
        mov     byte[buffer+4], '"'
2554 hidnplayr 343
 
2560 hidnplayr 344
        lea     edi, [buffer+5]
345
        mov     esi, work_dir
346
 
347
  .loop:
348
        lodsb
349
        or      al, al
350
        jz      .ok
351
        stosb
352
        dec     ecx
353
        jnz     .loop
354
355
  .ok:
356
        mov     dword[edi], '"' + 0x000a0d00    ; '"',13,10,0
357
 
358
359
        mcall   send, [socketnum2], buffer, , 0
360
361
 
362
;        push    str_pwd
363
 
2562 hidnplayr 364
365
        ret
366
367
 
2554 hidnplayr 368
cmdPORT:
369
 
370
; PORT a1,a2,a3,a4,p1,p2
371
; IP address a1.a2.a3.a4, port p1*256+p2
372
 
2560 hidnplayr 373
        mov     [mode], MODE_ACTIVE
374
375
 
376
        xor     edx, edx
377
 
378
        call    ascii_to_byte
379
        mov     dh, bl
380
 
381
        call    ascii_to_byte
382
        mov     dl, bl
383
        shl     edx, 16
384
        inc     esi
385
        call    ascii_to_byte
386
        mov     dh, bl
387
        inc     esi
388
        call    ascii_to_byte
389
        mov     dl, bl
390
        inc     esi
391
392
        mov     [datasock.ip], edx
393
394
 
395
        mov     dh, bl
396
 
397
        call    ascii_to_byte
398
        mov     dl, bl
399
400
        mov     [datasock.port], dx
401
402
 
403
        cmp     eax, -1
404
 
2562 hidnplayr 405
        mov     [datasocketnum], eax
2560 hidnplayr 406
407
        mcall   send, [socketnum2], str225, str225.length, 0
408
        ret
409
 
410
  .err:
2554 hidnplayr 411
412
 
2560 hidnplayr 413
        ret
414
 
415
align 4
416
cmdQUIT:
417
 
2554 hidnplayr 418
        mcall   send, [socketnum2], str221, str221.length, 0
419
        mcall   close, [socketnum2]
420
 
2557 hidnplayr 421
        ret
422
423
 
2554 hidnplayr 424
cmdRETR:
425
 
426
        cmp     [mode], MODE_ACTIVE
427
        jne     @f
428
 
2563 hidnplayr 429
;        cmp     eax, -1
430
;        je      .err
431
  @@:
2562 hidnplayr 432
433
        mcall   send, [socketnum2], str150, str150.length, 0    ; here it comes..
2563 hidnplayr 434
2562 hidnplayr 435
 
2563 hidnplayr 436
        push    home_dir
437
 
438
;        test    eax, eax
439
;        jz      .cannot_open
440
2562 hidnplayr 441
        mov     ebx, eax
442
2563 hidnplayr 443
 
444
        push    BUFFERSIZE
445
 
446
        push    ebx
447
        call    [file.read]
448
;        cmp     eax, -1
449
;        je      .cannot_open
450
2562 hidnplayr 451
        push    eax
2563 hidnplayr 452
        push    ebx
2562 hidnplayr 453
 
2563 hidnplayr 454
        mcall   send, [datasocketnum], buffer, , 0
455
        pop     ebx
456
        pop     ecx
457
;        cmp     eax, -1
458
;        je      .socketerr
459
460
        cmp     ecx, BUFFERSIZE
461
        je      .read_more
462
 
463
        mcall   close, [datasocketnum]
464
465
 
466
        jne     @f
467
 
468
      @@:
469
470
        mcall   send, [socketnum2], str226, str226.length, 0    ; transfer ok
471
472
 
473
474
 
2554 hidnplayr 475
cmdSTOR:
476
 
477
        ret
478
479
 
480
cmdSYST:
481
 
482
        mcall   send, [socketnum2], str215, str215.length, 0
483
484
 
2557 hidnplayr 485
486
 
2554 hidnplayr 487
cmdTYPE:
488
 
489
490
        cmp     ecx, 6
491
 
2560 hidnplayr 492
 
493
        mov     al, byte[esi+5]
494
        and     al, not 0x20
495
 
496
        cmp     al, 'A'
497
        je      .ascii
498
 
499
        je      .ebdic
500
        cmp     al, 'I'
501
        je      .image
502
        cmp     al, 'L'
503
        je      .local
504
505
        jmp     parse_cmd.error
506
507
 
508
        mov     [type], TYPE_ASCII
509
 
510
511
  .ebdic:
512
        mov     [type], TYPE_EBDIC
513
 
514
  .subtype:
515
516
 
517
        jb      .non_print
518
 
519
        mov     al, byte[esi+7]
520
        and     al, not 0x20
521
 
522
        cmp     al, 'N'
523
        je      .non_print
524
 
525
        je      .telnet
526
        cmp     al, 'C'
527
        je      .asacc
528
529
        jmp     parse_cmd.error
530
531
 
532
        or      [type], TYPE_NP
533
 
534
535
  .telnet:
536
        or      [type], TYPE_TELNET
537
 
538
539
  .asacc:
540
        or      [type], TYPE_ASA
541
 
542
543
  .image:
544
        mov     [type], TYPE_IMAGE
545
 
546
547
  .local:
548
        cmp     ecx, 8
549
 
550
551
        mov     al, byte[esi+7]
552
        sub     al, '0'
553
 
554
        cmp     al, 9
555
        ja      parse_cmd.error
556
        or      al, TYPE_LOCAL
557
        mov     [type], al
558
559
  .ok:
560
        mcall   send, [socketnum2], str200, str200.length, 0
561
 
562
        ret
563
564
 
2554 hidnplayr 565
cmdUSER:
566
 
567
        mcall   send, [socketnum2], str331, str331.length, 0
568
        mov     [state], STATE_LOGIN
569
 
2557 hidnplayr 570
        mov     byte [work_dir], "/"
571
        mov     byte [work_dir+1], 0
572
 
2560 hidnplayr 573
        push    str_logged_in
574
        call    [con_write_asciiz]
575
 
576
        ret
577
578
 
2554 hidnplayr 579
580
 
581
 
582
 
2560 hidnplayr 583
 
584
 
585
 
586
 
587
        xor     ebx, ebx
588
589
 
590
591
 
592
        sub     al, '0'
593
 
594
        cmp     al, 9
595
        ja      .done
596
        lea     ebx, [ebx*4 + ebx]
597
        shl     ebx, 1
598
        add     ebx, eax
599
        inc     esi
600
601
        jmp     .loop
602
603
 
604
        ret
605
 
606
align 4
607
dword_to_ascii: ; edi = ptr where to write, ebx is number
608
 
2562 hidnplayr 609
        mov     eax, '1'
610
        stosb
2560 hidnplayr 611
 
2562 hidnplayr 612
        ret
613
2560 hidnplayr 614
 
2562 hidnplayr 615
create_path:            ; combine home_dir and work_dir strings into fpath
2560 hidnplayr 616
 
2563 hidnplayr 617
        mov     esi, home_dir
618
        mov     ecx, 1024
619
620
  .loop1:
621
        lodsb
2560 hidnplayr 622
 
2563 hidnplayr 623
        jz      .next
624
        stosb
625
        loop    .loop1
626
  .next:
627
628
        cmp     byte[edi-1], '/'
629
        jne     @f
2562 hidnplayr 630
 
2563 hidnplayr 631
       @@:
632
633
        mov     esi, work_dir
634
        mov     ecx, 1024
2562 hidnplayr 635
 
2563 hidnplayr 636
  .loop2:
637
        lodsb
2562 hidnplayr 638
 
2563 hidnplayr 639
        jz      .done
640
        stosb
641
        loop    .loop2
642
643
  .done:
644
        stosb
645
 
646
        ret
647
648
 
649
650
 
651
 
652
 
653
 
654
 
655
 
2554 hidnplayr 656
.length = $ - str200
2562 hidnplayr 657
str215  db '215 UNIX type: L8', 13, 10
2554 hidnplayr 658
.length = $ - str215
2560 hidnplayr 659
str220  db '220 KolibriOS FTP Daemon 1.0', 13, 10
2554 hidnplayr 660
.length = $ - str220
2557 hidnplayr 661
str221  db '221 Bye!', 13, 10
2554 hidnplayr 662
.length = $ - str221
663
str225  db '225 Data connection open', 13, 10
664
.length = $ - str225
2557 hidnplayr 665
str226  db '226 Transfer OK, Closing connection', 13, 10
2560 hidnplayr 666
.length = $ - str226
667
str230  db '230 You are now logged in.', 13, 10
2554 hidnplayr 668
.length = $ - str230
2562 hidnplayr 669
str250  db '250 command successful', 13, 10
2554 hidnplayr 670
.length = $ - str250
2557 hidnplayr 671
str331  db '331 Please specify the password.', 13, 10
2554 hidnplayr 672
.length = $ - str331
2563 hidnplayr 673
str421  db '421 Timeout!', 13, 10
2554 hidnplayr 674
.length = $ - str421
2557 hidnplayr 675
str425  db '425 Cant open data connection.', 13, 10
2560 hidnplayr 676
.length = $ - str425
677
str500  db '500 Unsupported command', 13, 10
678
.length = $ - str500
679
str550  db '550 No such file', 13, 10
2554 hidnplayr 680
.length = $ - str550
2557 hidnplayr 681