Subversion Repositories Kolibri OS

Rev

Rev 2557 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1.  
  2.  
  3.  
  4. align 4
  5. parse_cmd:                              ; esi must point to command
  6.  
  7.         cmp     byte [esi+3], 0x20
  8.         jae     @f
  9.         mov     byte [esi+3], 0
  10.        @@:
  11.  
  12.         mov     eax, [esi]
  13.         and     eax, not 0x20202020     ; convert to upper case
  14.                                         ; (also convert spaces to null)
  15.         mov     edi, commands           ; list of commands to scan
  16.   .scanloop:
  17.         cmp     eax, [edi]
  18.         jne     .try_next
  19.  
  20.         jmp     dword [edi+4]
  21.  
  22.   .try_next:
  23.         add     edi, 8
  24.         cmp     byte [edi], 0
  25.         jne     .scanloop
  26.  
  27.   .error:
  28.         mcall   send, [socketnum2], str500, str500.length, 0
  29.  
  30.         ret
  31.  
  32.  
  33. align 4
  34. commands:                               ; all commands must be in uppercase
  35.  
  36.         db 'ABOR'
  37.         dd cmdABOR
  38.  
  39.         db 'CWD', 0
  40.         dd cmdCWD
  41.  
  42.         db 'DELE'
  43.         dd cmdDELE
  44.  
  45.         db 'LIST'
  46.         dd cmdLIST
  47.  
  48.         db 'NLST'
  49.         dd cmdNLST
  50.  
  51.         db 'NOOP'
  52.         dd cmdNOOP
  53.  
  54.         db 'PASS'
  55.         dd cmdPASS
  56.  
  57.         db 'PWD', 0     ; Print Working Directory
  58.         dd cmdPWD
  59.  
  60.         db 'PORT'
  61.         dd cmdPORT
  62.  
  63.         db 'QUIT'
  64.         dd cmdQUIT
  65.  
  66.         db 'RETR'
  67.         dd cmdRETR
  68.  
  69.         db 'STOR'
  70.         dd cmdSTOR
  71.  
  72.         db 'SYST'
  73.         dd cmdSYST
  74.  
  75.         db 'TYPE'
  76.         dd cmdTYPE
  77.  
  78.         db 'USER'
  79.         dd cmdUSER
  80.  
  81.         db 'XPWD'
  82.         dd cmdPWD
  83.  
  84.         db 0                    ; end marker
  85.  
  86.  
  87. align 4
  88. cmdABOR:
  89.  
  90.         ret
  91.  
  92. align 4
  93. cmdCWD:
  94.  
  95.         ret
  96.  
  97. align 4
  98. cmdDELE:
  99.  
  100.         ret
  101.  
  102. align 4
  103. cmdLIST:
  104.  
  105.         ret
  106.  
  107. align 4
  108. cmdNLST:
  109.  
  110.         ret
  111.  
  112. align 4
  113. cmdNOOP:
  114.  
  115.         ret
  116.  
  117. align 4
  118. cmdPASS:
  119.  
  120.         mcall   send, [socketnum2], str230, str230.length, 0
  121.  
  122.         push    str_pass_ok
  123.         call    [con_write_asciiz]
  124.  
  125.         mov     [state], STATE_ACTIVE
  126.  
  127.         ret
  128.  
  129. align 4
  130. cmdPASV:
  131.  
  132.         mov     [mode], MODE_PASSIVE
  133.  
  134. ; TODO: open the UDP socket and return our IP + port
  135.  
  136. ; 227 Entering Passive Mode (a1,a2,a3,a4,p1,p2)
  137. ; where a1.a2.a3.a4 is the IP address and p1*256+p2 is the port number.
  138.  
  139.         ret
  140.  
  141. align 4
  142. cmdPWD:
  143.  
  144.         mov     dword[buffer], '257 '
  145.         mov     byte[buffer+4], '"'
  146.  
  147.         lea     edi, [buffer+5]
  148.         mov     esi, work_dir
  149.         mov     ecx, 1024
  150.   .loop:
  151.         lodsb
  152.         or      al, al
  153.         jz      .ok
  154.         stosb
  155.         dec     ecx
  156.         jnz     .loop
  157.  
  158.   .ok:
  159.         mov     dword[edi], '"' + 0x000a0d00    ; '"',13,10,0
  160.         lea     esi, [edi - buffer + 4]
  161.  
  162.         mcall   send, [socketnum2], buffer, , 0
  163.  
  164.         ret
  165.  
  166. align 4
  167. cmdPORT:
  168.  
  169. ; PORT a1,a2,a3,a4,p1,p2
  170. ; IP address a1.a2.a3.a4, port p1*256+p2
  171.  
  172.         mov     [mode], MODE_ACTIVE
  173.  
  174.         lea     esi, [esi+5]
  175.         xor     edx, edx
  176.  
  177.         call    ascii_to_byte
  178.         mov     dh, bl
  179.         inc     esi
  180.         call    ascii_to_byte
  181.         mov     dl, bl
  182.         shl     edx, 16
  183.         inc     esi
  184.         call    ascii_to_byte
  185.         mov     dh, bl
  186.         inc     esi
  187.         call    ascii_to_byte
  188.         mov     dl, bl
  189.         inc     esi
  190.  
  191.         mov     [datasock.ip], edx
  192.  
  193.         call    ascii_to_byte
  194.         mov     dh, bl
  195.         inc     esi
  196.         call    ascii_to_byte
  197.         mov     dl, bl
  198.  
  199.         mov     [datasock.port], dx
  200.  
  201.         mcall   socket, AF_INET4, SOCK_DGRAM, 0
  202.         cmp     eax, -1
  203.         je      .err
  204.         mov     [datasocketnum], eax
  205.  
  206.         mcall   connect, [datasocketnum], datasock, datasock.length
  207.         cmp     eax, -1
  208.         je      .err
  209.  
  210.         mcall   send, [socketnum2], str225, str225.length, 0
  211.         ret
  212.  
  213.   .err:
  214.  
  215.         mcall   send, [socketnum2], str425, str425.length, 0
  216.         ret
  217.  
  218. align 4
  219. cmdQUIT:
  220.  
  221.         mcall   send, [socketnum2], str221, str221.length, 0
  222.         mcall   close, [socketnum2]
  223.  
  224.         ret
  225.  
  226. align 4
  227. cmdRETR:
  228.  
  229.         ret
  230.  
  231. align 4
  232. cmdSTOR:
  233.  
  234.         ret
  235.  
  236. align 4
  237. cmdSYST:
  238.  
  239.         mcall   send, [socketnum2], str215, str215.length, 0
  240.  
  241.         ret
  242.  
  243. align 4
  244. cmdTYPE:
  245.  
  246.  
  247.         cmp     ecx, 6
  248.         jb      parse_cmd.error
  249.  
  250.         mov     al, byte[esi+5]
  251.         and     al, not 0x20
  252.  
  253.         cmp     al, 'A'
  254.         je      .ascii
  255.         cmp     al, 'E'
  256.         je      .ebdic
  257.         cmp     al, 'I'
  258.         je      .image
  259.         cmp     al, 'L'
  260.         je      .local
  261.  
  262.         jmp     parse_cmd.error
  263.  
  264.   .ascii:
  265.         mov     [type], TYPE_ASCII
  266.         jmp     .subtype
  267.  
  268.   .ebdic:
  269.         mov     [type], TYPE_EBDIC
  270.  
  271.   .subtype:
  272.  
  273.         cmp     ecx, 8
  274.         jb      .non_print
  275.  
  276.         mov     al, byte[esi+7]
  277.         and     al, not 0x20
  278.  
  279.         cmp     al, 'N'
  280.         je      .non_print
  281.         cmp     al, 'T'
  282.         je      .telnet
  283.         cmp     al, 'C'
  284.         je      .asacc
  285.  
  286.         jmp     parse_cmd.error
  287.  
  288.   .non_print:
  289.         or      [type], TYPE_NP
  290.         jmp     .ok
  291.  
  292.   .telnet:
  293.         or      [type], TYPE_TELNET
  294.         jmp     .ok
  295.  
  296.   .asacc:
  297.         or      [type], TYPE_ASA
  298.         jmp     .ok
  299.  
  300.   .image:
  301.         mov     [type], TYPE_IMAGE
  302.         jmp     .ok
  303.  
  304.   .local:
  305.         cmp     ecx, 8
  306.         jb      parse_cmd.error
  307.  
  308.         mov     al, byte[esi+7]
  309.         sub     al, '0'
  310.         jb      parse_cmd.error
  311.         cmp     al, 9
  312.         ja      parse_cmd.error
  313.         or      al, TYPE_LOCAL
  314.         mov     [type], al
  315.  
  316.   .ok:
  317.         mcall   send, [socketnum2], str200, str200.length, 0
  318.  
  319.         ret
  320.  
  321. align 4
  322. cmdUSER:
  323.  
  324.         mcall   send, [socketnum2], str331, str331.length, 0
  325.         mov     [state], STATE_LOGIN
  326.  
  327.         mov     byte [work_dir], "/"
  328.         mov     byte [work_dir+1], 0
  329.  
  330.         push    str_logged_in
  331.         call    [con_write_asciiz]
  332.  
  333.         ret
  334.  
  335.  
  336.  
  337.  
  338.  
  339.  
  340.  
  341. align 4         ; esi = ptr to str
  342. ascii_to_byte:
  343.  
  344.         xor     ebx, ebx
  345.  
  346.   .loop:
  347.  
  348.         movzx   eax, byte[esi]
  349.         sub     al, '0'
  350.         jb      .done
  351.         cmp     al, 9
  352.         ja      .done
  353.         lea     ebx, [ebx*4 + ebx]
  354.         shl     ebx, 1
  355.         add     ebx, eax
  356.         inc     esi
  357.  
  358.         jmp     .loop
  359.  
  360.   .done:
  361.         ret
  362.  
  363.  
  364.  
  365.  
  366.  
  367. str150  db '150 Here it comes...', 13, 10
  368. str200  db '200 Command OK.', 13, 10
  369. .length = $ - str200
  370. str215  db '215 UNIX type: L8', 13, 10
  371. .length = $ - str215
  372. str220  db '220 KolibriOS FTP Daemon 1.0', 13, 10
  373. .length = $ - str220
  374. str221  db '221 Bye!', 13, 10
  375. .length = $ - str221
  376. str225  db '225 Data connection open', 13, 10
  377. .length = $ - str225
  378. str226  db '226 Transfer OK, Closing connection', 13, 10
  379. str230  db '230 You are now logged in.', 13, 10
  380. .length = $ - str230
  381. str250  db '250 command successful', 13, 10
  382. ;str257  db '257 "'
  383. ;.length = $ - str257
  384. ;str257b db '"', 13, 10
  385. ;.length = $ - str257b
  386. str331  db '331 Please specify the password.', 13, 10
  387. .length = $ - str331
  388. str421  db '421 Timeout!', 13, 10
  389. .length = $ - str421
  390. str425  db '425 Cant open data connection.', 13, 10
  391. .length = $ - str425
  392. str500  db '500 Unsupported command', 13, 10
  393. .length = $ - str500
  394. str550  db '550 No such file', 13, 10