Rev 2560 | 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 ; Print Working Directory |
||
2562 | hidnplayr | 50 | dd cmdPWD |
51 | db 'PORT' |
||
2560 | 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: |
||
77 | |||
78 | ret |
||
79 | |||
80 | |||
81 | cmdDELE: |
||
82 | |||
83 | ret |
||
84 | |||
85 | |||
86 | cmdLIST: |
||
87 | |||
88 | cmp [mode], MODE_ACTIVE |
||
89 | jne @f |
||
90 | |||
2562 | hidnplayr | 91 | cmp eax, -1 |
92 | je .err |
||
93 | @@: |
||
94 | |||
95 | mcall send, [socketnum2], str150, str150.length, 0 ; here it comes.. |
||
96 | |||
97 | |||
98 | push str_mask |
||
99 | |||
100 | call [file.find.first] |
||
101 | |||
102 | mov edi, buffer |
||
103 | jmp .parse_file |
||
104 | |||
105 | .checknextfile: |
||
106 | push edx |
||
107 | |||
108 | |||
109 | .parse_file: |
||
110 | test eax, eax |
||
111 | |||
112 | |||
113 | mov edx, eax |
||
114 | |||
115 | |||
116 | test [eax + FileInfoA.Attributes], FA_FOLDER |
||
117 | |||
118 | |||
119 | test [eax + FileInfoA.Attributes], FA_READONLY |
||
120 | jnz .readonly |
||
121 | |||
122 | mov eax, '-rw-' |
||
123 | stosd |
||
124 | |||
125 | |||
126 | .folder: |
||
127 | mov eax, 'drwx' |
||
128 | |||
129 | jmp .attr |
||
130 | |||
131 | .readonly: |
||
132 | mov eax, '-r--' |
||
133 | |||
134 | |||
135 | .attr: |
||
136 | mov eax, 'rw-r' |
||
137 | |||
138 | mov ax, 'w-' |
||
139 | stosw |
||
140 | mov al, ' ' |
||
141 | stosb |
||
142 | |||
143 | ; now.. |
||
144 | mov ax, '1 ' |
||
145 | |||
146 | |||
147 | ; now write owner, everything is owned by FTP, woohoo! |
||
148 | mov eax, 'FTP ' |
||
149 | |||
150 | stosd |
||
151 | |||
152 | ; now the filesize in ascii |
||
153 | mov ebx, dword [edx + FileInfoA.FileSize] |
||
154 | |||
155 | |||
156 | mov al, ' ' |
||
157 | stosb |
||
158 | |||
159 | ; then date (month/day/year) |
||
160 | movzx ebx, [edx + FileInfoA.DateModify + FileDateTime.month] |
||
161 | |||
162 | stosd |
||
163 | |||
164 | movzx ebx, [edx + FileInfoA.DateModify + FileDateTime.day] |
||
165 | call dword_to_ascii |
||
166 | |||
167 | mov al, ' ' |
||
168 | stosb |
||
169 | |||
170 | movzx ebx, [edx + FileInfoA.DateModify + FileDateTime.year] |
||
171 | call dword_to_ascii |
||
172 | |||
173 | mov al, ' ' |
||
174 | stosb |
||
175 | |||
176 | ; and last but not least, filename |
||
177 | lea esi, [edx + FileInfoA.FileName] |
||
178 | |||
179 | .nameloop: |
||
180 | lodsb |
||
181 | test al, al |
||
182 | jz .namedone |
||
183 | stosb |
||
184 | loop .nameloop |
||
185 | |||
186 | .namedone: |
||
187 | mov ax, 0x0d0a |
||
188 | |||
189 | jmp .checknextfile |
||
190 | |||
191 | .done: |
||
192 | push edx |
||
193 | |||
194 | |||
195 | xor al, al |
||
196 | stosb |
||
197 | |||
198 | push buffer |
||
199 | call [con_write_asciiz] |
||
200 | |||
201 | lea esi, [edi - buffer] |
||
202 | mcall send, [datasocketnum], buffer, , 0 |
||
203 | |||
204 | mcall close, [datasocketnum] |
||
205 | |||
206 | |||
207 | jne @f |
||
208 | |||
209 | @@: |
||
210 | |||
211 | mcall send, [socketnum2], str226, str226.length, 0 ; transfer ok |
||
212 | |||
213 | |||
214 | |||
215 | |||
2554 | hidnplayr | 216 | pushd 0x0c |
217 | |||
2562 | hidnplayr | 218 | |
219 | push str_err1 |
||
220 | call [con_write_asciiz] |
||
221 | |||
222 | pushd 0x07 |
||
223 | call [con_set_flags] |
||
224 | |||
225 | ret |
||
226 | |||
227 | |||
228 | cmdNLST: |
||
229 | |||
2554 | hidnplayr | 230 | ret |
231 | |||
232 | |||
233 | cmdNOOP: |
||
234 | |||
235 | ret |
||
236 | |||
237 | |||
238 | cmdPASS: |
||
239 | |||
240 | mcall send, [socketnum2], str230, str230.length, 0 |
||
2557 | hidnplayr | 241 | |
242 | |||
243 | call [con_write_asciiz] |
||
2560 | hidnplayr | 244 | |
245 | mov [state], STATE_ACTIVE |
||
246 | |||
247 | |||
2557 | hidnplayr | 248 | |
249 | |||
250 | cmdPASV: |
||
251 | |||
252 | ; 227 Entering Passive Mode (a1,a2,a3,a4,p1,p2) |
||
2560 | hidnplayr | 253 | ; where a1.a2.a3.a4 is the IP address and p1*256+p2 is the port number. |
254 | |||
255 | mcall socket, AF_INET4, SOCK_STREAM, 0 |
||
256 | cmp eax, -1 |
||
257 | |||
2562 | hidnplayr | 258 | mov [passivesocknum], eax |
259 | |||
260 | mov [datasock.port], 2000 |
||
261 | mov [datasock.ip], 0 |
||
262 | |||
263 | mcall bind, [passivesocknum], datasock, datasock.length |
||
264 | cmp eax, -1 |
||
265 | |||
266 | |||
267 | mcall listen, [passivesocknum], 1 |
||
268 | |||
269 | |||
270 | |||
271 | |||
272 | mov eax, '227 ' ; FIXME (now hardcoded to 127.0.0.1:2000) |
||
273 | |||
274 | mov eax, '(127' |
||
275 | stosd |
||
276 | mov eax, ',0,0' |
||
277 | stosd |
||
278 | mov eax, ',1,7' |
||
279 | stosd |
||
280 | mov eax, ',208' |
||
281 | stosd |
||
282 | mov al, ')' |
||
283 | stosb |
||
284 | mov ax, 0x0d0a |
||
285 | stosw |
||
286 | xor al, al |
||
287 | stosb |
||
288 | |||
289 | lea esi, [edi - buffer] |
||
290 | |||
291 | |||
292 | |||
293 | |||
294 | |||
295 | |||
2560 | hidnplayr | 296 | cmdPWD: |
297 | |||
298 | mov dword[buffer], '257 ' |
||
2554 | hidnplayr | 299 | mov byte[buffer+4], '"' |
300 | |||
2560 | hidnplayr | 301 | lea edi, [buffer+5] |
302 | mov esi, work_dir |
||
303 | |||
304 | .loop: |
||
305 | lodsb |
||
306 | or al, al |
||
307 | jz .ok |
||
308 | stosb |
||
309 | dec ecx |
||
310 | jnz .loop |
||
311 | |||
312 | .ok: |
||
313 | mov dword[edi], '"' + 0x000a0d00 ; '"',13,10,0 |
||
314 | |||
315 | |||
316 | mcall send, [socketnum2], buffer, , 0 |
||
317 | |||
318 | |||
319 | ; push str_pwd |
||
320 | |||
2562 | hidnplayr | 321 | |
322 | ret |
||
323 | |||
324 | |||
2554 | hidnplayr | 325 | cmdPORT: |
326 | |||
327 | ; PORT a1,a2,a3,a4,p1,p2 |
||
328 | ; IP address a1.a2.a3.a4, port p1*256+p2 |
||
329 | |||
2560 | hidnplayr | 330 | mov [mode], MODE_ACTIVE |
331 | |||
332 | |||
333 | xor edx, edx |
||
334 | |||
335 | call ascii_to_byte |
||
336 | mov dh, bl |
||
337 | |||
338 | call ascii_to_byte |
||
339 | mov dl, bl |
||
340 | shl edx, 16 |
||
341 | inc esi |
||
342 | call ascii_to_byte |
||
343 | mov dh, bl |
||
344 | inc esi |
||
345 | call ascii_to_byte |
||
346 | mov dl, bl |
||
347 | inc esi |
||
348 | |||
349 | mov [datasock.ip], edx |
||
350 | |||
351 | |||
352 | mov dh, bl |
||
353 | |||
354 | call ascii_to_byte |
||
355 | mov dl, bl |
||
356 | |||
357 | mov [datasock.port], dx |
||
358 | |||
359 | |||
360 | cmp eax, -1 |
||
361 | |||
2562 | hidnplayr | 362 | mov [datasocketnum], eax |
2560 | hidnplayr | 363 | |
364 | mcall send, [socketnum2], str225, str225.length, 0 |
||
365 | ret |
||
366 | |||
367 | .err: |
||
2554 | hidnplayr | 368 | |
369 | |||
2560 | hidnplayr | 370 | ret |
371 | |||
372 | align 4 |
||
373 | cmdQUIT: |
||
374 | |||
2554 | hidnplayr | 375 | mcall send, [socketnum2], str221, str221.length, 0 |
376 | mcall close, [socketnum2] |
||
377 | |||
2557 | hidnplayr | 378 | ret |
379 | |||
380 | |||
2554 | hidnplayr | 381 | cmdRETR: |
382 | |||
383 | ; mcall connect, [datasocketnum], datasock, datasock.length |
||
384 | ; cmp eax, -1 |
||
385 | |||
2562 | hidnplayr | 386 | |
387 | ; push O_READ |
||
388 | ; push home_dir |
||
389 | |||
390 | ; test eax, eax |
||
391 | ; jz .cannot_open |
||
392 | ; |
||
393 | ; push BUFFERSIZE |
||
394 | ; push buffer |
||
395 | ; push eax |
||
396 | ; call [file.read] |
||
397 | ; cmp eax, -1 |
||
398 | ; jz .cannot_open |
||
399 | |||
400 | ret |
||
401 | |||
402 | |||
2554 | hidnplayr | 403 | cmdSTOR: |
404 | |||
405 | ret |
||
406 | |||
407 | |||
408 | cmdSYST: |
||
409 | |||
410 | mcall send, [socketnum2], str215, str215.length, 0 |
||
411 | |||
412 | |||
2557 | hidnplayr | 413 | |
414 | |||
2554 | hidnplayr | 415 | cmdTYPE: |
416 | |||
417 | |||
418 | cmp ecx, 6 |
||
419 | |||
2560 | hidnplayr | 420 | |
421 | mov al, byte[esi+5] |
||
422 | and al, not 0x20 |
||
423 | |||
424 | cmp al, 'A' |
||
425 | je .ascii |
||
426 | |||
427 | je .ebdic |
||
428 | cmp al, 'I' |
||
429 | je .image |
||
430 | cmp al, 'L' |
||
431 | je .local |
||
432 | |||
433 | jmp parse_cmd.error |
||
434 | |||
435 | |||
436 | mov [type], TYPE_ASCII |
||
437 | |||
438 | |||
439 | .ebdic: |
||
440 | mov [type], TYPE_EBDIC |
||
441 | |||
442 | .subtype: |
||
443 | |||
444 | |||
445 | jb .non_print |
||
446 | |||
447 | mov al, byte[esi+7] |
||
448 | and al, not 0x20 |
||
449 | |||
450 | cmp al, 'N' |
||
451 | je .non_print |
||
452 | |||
453 | je .telnet |
||
454 | cmp al, 'C' |
||
455 | je .asacc |
||
456 | |||
457 | jmp parse_cmd.error |
||
458 | |||
459 | |||
460 | or [type], TYPE_NP |
||
461 | |||
462 | |||
463 | .telnet: |
||
464 | or [type], TYPE_TELNET |
||
465 | |||
466 | |||
467 | .asacc: |
||
468 | or [type], TYPE_ASA |
||
469 | |||
470 | |||
471 | .image: |
||
472 | mov [type], TYPE_IMAGE |
||
473 | |||
474 | |||
475 | .local: |
||
476 | cmp ecx, 8 |
||
477 | |||
478 | |||
479 | mov al, byte[esi+7] |
||
480 | sub al, '0' |
||
481 | |||
482 | cmp al, 9 |
||
483 | ja parse_cmd.error |
||
484 | or al, TYPE_LOCAL |
||
485 | mov [type], al |
||
486 | |||
487 | .ok: |
||
488 | mcall send, [socketnum2], str200, str200.length, 0 |
||
489 | |||
490 | ret |
||
491 | |||
492 | |||
2554 | hidnplayr | 493 | cmdUSER: |
494 | |||
495 | mcall send, [socketnum2], str331, str331.length, 0 |
||
496 | mov [state], STATE_LOGIN |
||
497 | |||
2557 | hidnplayr | 498 | mov byte [work_dir], "/" |
499 | mov byte [work_dir+1], 0 |
||
500 | |||
2560 | hidnplayr | 501 | push str_logged_in |
502 | call [con_write_asciiz] |
||
503 | |||
504 | ret |
||
505 | |||
506 | |||
2554 | hidnplayr | 507 | |
508 | |||
509 | |||
510 | |||
2560 | hidnplayr | 511 | |
512 | |||
513 | |||
514 | |||
515 | xor ebx, ebx |
||
516 | |||
517 | |||
518 | |||
519 | |||
520 | sub al, '0' |
||
521 | |||
522 | cmp al, 9 |
||
523 | ja .done |
||
524 | lea ebx, [ebx*4 + ebx] |
||
525 | shl ebx, 1 |
||
526 | add ebx, eax |
||
527 | inc esi |
||
528 | |||
529 | jmp .loop |
||
530 | |||
531 | |||
532 | ret |
||
533 | |||
534 | align 4 |
||
535 | dword_to_ascii: ; edi = ptr where to write, ebx is number |
||
536 | |||
2562 | hidnplayr | 537 | mov eax, '1' |
538 | stosb |
||
2560 | hidnplayr | 539 | |
2562 | hidnplayr | 540 | ret |
541 | |||
2560 | hidnplayr | 542 | |
2562 | hidnplayr | 543 | |
2560 | hidnplayr | 544 | |
545 | |||
2562 | hidnplayr | 546 | |
547 | |||
548 | |||
2554 | hidnplayr | 549 | .length = $ - str200 |
2562 | hidnplayr | 550 | str215 db '215 UNIX type: L8', 13, 10 |
2554 | hidnplayr | 551 | .length = $ - str215 |
2560 | hidnplayr | 552 | str220 db '220 KolibriOS FTP Daemon 1.0', 13, 10 |
2554 | hidnplayr | 553 | .length = $ - str220 |
2557 | hidnplayr | 554 | str221 db '221 Bye!', 13, 10 |
2554 | hidnplayr | 555 | .length = $ - str221 |
556 | str225 db '225 Data connection open', 13, 10 |
||
557 | .length = $ - str225 |
||
2557 | hidnplayr | 558 | str226 db '226 Transfer OK, Closing connection', 13, 10 |
2560 | hidnplayr | 559 | .length = $ - str226 |
560 | str230 db '230 You are now logged in.', 13, 10 |
||
2554 | hidnplayr | 561 | .length = $ - str230 |
2562 | hidnplayr | 562 | str250 db '250 command successful', 13, 10 |
2554 | hidnplayr | 563 | ;str257 db '257 "' |
2557 | hidnplayr | 564 | ;.length = $ - str257 |
2554 | hidnplayr | 565 | ;str257b db '"', 13, 10 |
2560 | hidnplayr | 566 | ;.length = $ - str257b |
567 | str331 db '331 Please specify the password.', 13, 10 |
||
568 | .length = $ - str331 |
||
569 | str421 db '421 Timeout!', 13, 10 |
||
2554 | hidnplayr | 570 | .length = $ - str421 |
2557 | hidnplayr | 571 | str425 db '425 Cant open data connection.', 13, 10 |
2560 | hidnplayr | 572 | .length = $ - str425 |
573 | str500 db '500 Unsupported command', 13, 10 |
||
574 | .length = $ - str500 |
||
575 | str550 db '550 No such file', 13, 10 |
||
2554 | hidnplayr | 576 |