• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src-rt/router/vsftpd/

Lines Matching refs:p_sess

60 static void handle_pwd(struct vsf_session* p_sess);
61 static void handle_cwd(struct vsf_session* p_sess);
62 static void handle_pasv(struct vsf_session* p_sess, int is_epsv);
63 static void handle_retr(struct vsf_session* p_sess);
64 static void handle_cdup(struct vsf_session* p_sess);
65 static void handle_list(struct vsf_session* p_sess);
66 static void handle_type(struct vsf_session* p_sess);
67 static void handle_port(struct vsf_session* p_sess);
68 static void handle_stor(struct vsf_session* p_sess);
69 static void handle_mkd(struct vsf_session* p_sess);
70 static void handle_rmd(struct vsf_session* p_sess);
71 static void handle_dele(struct vsf_session* p_sess);
72 static void handle_rest(struct vsf_session* p_sess);
73 static void handle_rnfr(struct vsf_session* p_sess);
74 static void handle_rnto(struct vsf_session* p_sess);
75 static void handle_nlst(struct vsf_session* p_sess);
76 static void handle_size(struct vsf_session* p_sess);
77 static void handle_site(struct vsf_session* p_sess);
78 static void handle_appe(struct vsf_session* p_sess);
79 static void handle_mdtm(struct vsf_session* p_sess);
80 static void handle_site_chmod(struct vsf_session* p_sess,
82 static void handle_site_umask(struct vsf_session* p_sess,
84 static void handle_eprt(struct vsf_session* p_sess);
85 static void handle_help(struct vsf_session* p_sess);
86 static void handle_stou(struct vsf_session* p_sess);
87 static void handle_stat(struct vsf_session* p_sess);
88 static void handle_stat_file(struct vsf_session* p_sess);
90 static int pasv_active(struct vsf_session* p_sess);
91 static int port_active(struct vsf_session* p_sess);
92 static void pasv_cleanup(struct vsf_session* p_sess);
93 static void port_cleanup(struct vsf_session* p_sess);
94 static void handle_dir_common(struct vsf_session* p_sess, int full_details,
97 static int get_remote_transfer_fd(struct vsf_session* p_sess,
99 static void check_abor(struct vsf_session* p_sess);
101 static void handle_upload_common(struct vsf_session* p_sess, int is_append,
105 static int data_transfer_checks_ok(struct vsf_session* p_sess);
106 static void resolve_tilde(struct mystr* p_str, struct vsf_session* p_sess);
109 process_post_login(struct vsf_session* p_sess)
111 str_getcwd(&p_sess->home_str);
112 if (p_sess->is_anonymous)
115 p_sess->bw_rate_max = tunable_anon_max_rate;
120 p_sess->bw_rate_max = tunable_local_max_rate;
124 vsf_sysutil_install_sighandler(kVSFSysUtilSigURG, handle_sigurg, p_sess);
128 vsf_banner_dir_changed(p_sess, FTP_LOGINOK);
129 vsf_cmdio_write(p_sess, FTP_LOGINOK, "Login successful.");
139 vsf_cmdio_get_cmd_and_arg(p_sess, &p_sess->ftp_cmd_str,
140 &p_sess->ftp_arg_str, 1);
144 str_copy(&proctitle_str, &p_sess->ftp_cmd_str);
145 if (!str_isempty(&p_sess->ftp_arg_str))
148 str_append_str(&proctitle_str, &p_sess->ftp_arg_str);
169 else if (str_equal(&s_src_str, &p_sess->ftp_cmd_str))
218 if(str_equal_text(&p_sess->ftp_cmd_str, *target_cmd)){
226 if(str_equal_text(&p_sess->ftp_cmd_str, *target_cmd)){
234 if(str_equal_text(&p_sess->ftp_cmd_str, *target_cmd)){
242 if(str_equal_text(&p_sess->ftp_cmd_str, *target_cmd)){
250 if(str_equal_text(&p_sess->ftp_cmd_str, *target_cmd)){
260 arg_buf = (char *)str_getbuf(&p_sess->ftp_arg_str);
262 if(str_getlen(&p_sess->ftp_arg_str) > 0 && arg_buf[0] == '/'){
263 str_alloc_text(&p_sess->full_path, POOL_MOUNT_ROOT);
264 if(str_getlen(&p_sess->ftp_arg_str) != 1)
265 str_append_text(&p_sess->full_path, arg_buf);
269 if(str_getlen(&p_sess->ftp_arg_str) == 0){
270 str_alloc_text(&p_sess->full_path, fullpath);
279 str_alloc_text(&p_sess->ftp_arg_str, fullpath+strlen(POOL_MOUNT_ROOT));
281 str_alloc_text(&p_sess->ftp_arg_str, "/");
284 str_alloc_text(&p_sess->full_path, fullpath);
285 str_append_text(&p_sess->full_path, "/");
286 str_append_str(&p_sess->full_path, &p_sess->ftp_arg_str);
289 realpath(str_getbuf(&p_sess->full_path), fullpath);
290 str_alloc_text(&p_sess->full_path, fullpath);
293 strncpy(fullpath, str_getbuf(&p_sess->full_path), PATH_MAX);
295 str_split_text(&p_sess->full_path, &p_sess->ftp_arg_str, POOL_MOUNT_ROOT);
297 str_alloc_text(&p_sess->full_path, fullpath);
301 // remove the char '/' in the end of p_sess->ftp_arg_str.
302 arg_buf = (char *)str_getbuf(&p_sess->ftp_arg_str);
303 len = str_getlen(&p_sess->ftp_arg_str);
307 str_alloc_text(&p_sess->ftp_arg_str, fullpath);
310 // remove the char '/' in the end of p_sess->full_path.
311 arg_buf = (char *)str_getbuf(&p_sess->full_path);
312 len = str_getlen(&p_sess->full_path);
314 str_trunc(&p_sess->full_path, len-1);
319 layer = how_many_layer(str_getbuf(&p_sess->full_path), &mount_path, &share_name);
321 if(str_equal_text(&p_sess->ftp_cmd_str, "CDUP") || str_equal_text(&p_sess->ftp_cmd_str, "XCUP"))
334 p_sess->layer = layer;
336 if(layer == SHARE_LAYER && p_sess->is_anonymous){
338 if(str_equal_text(&p_sess->ftp_cmd_str, *target_cmd))
344 if(str_equal_text(&p_sess->ftp_cmd_str, *target_cmd)){
345 if(layer >= SHARE_LAYER && !p_sess->is_anonymous){
346 user_right = get_permission(str_getbuf(&p_sess->user_str), mount_path, share_name, "ftp");
356 if(str_equal_text(&p_sess->ftp_cmd_str, *target_cmd)){
359 else if(!p_sess->is_anonymous){
360 user_right = get_permission(str_getbuf(&p_sess->user_str), mount_path, share_name, "ftp");
370 if(str_equal_text(&p_sess->ftp_cmd_str, *target_cmd)){
374 else if(!p_sess->is_anonymous){
375 user_right = get_permission(str_getbuf(&p_sess->user_str), mount_path, share_name, "ftp");
385 if(str_equal_text(&p_sess->ftp_cmd_str, *target_cmd)){
386 if(layer >= SHARE_LAYER && !p_sess->is_anonymous){
387 user_right = get_permission(str_getbuf(&p_sess->user_str), mount_path, share_name, "ftp");
414 vsf_cmdio_write(p_sess, FTP_NOPERM, "Permission denied (restricted operation).");
416 else if (str_equal_text(&p_sess->ftp_cmd_str, "QUIT"))
418 vsf_cmdio_write(p_sess, FTP_GOODBYE, "Goodbye.");
421 else if (str_equal_text(&p_sess->ftp_cmd_str, "PWD") ||
422 str_equal_text(&p_sess->ftp_cmd_str, "XPWD"))
424 handle_pwd(p_sess);
426 else if (str_equal_text(&p_sess->ftp_cmd_str, "ICNV")) // Jiahao
428 str_upper(&p_sess->ftp_arg_str);
429 if (str_equal_text(&p_sess->ftp_arg_str, "ON"))
432 vsf_cmdio_write(p_sess, FTP_CWDOK, "enable iconv().");
434 else if (str_equal_text(&p_sess->ftp_arg_str, "OFF"))
437 vsf_cmdio_write(p_sess, FTP_CWDOK, "disable iconv().");
441 vsf_cmdio_write(p_sess, FTP_CWDOK, "iconv() enabled.");
445 vsf_cmdio_write(p_sess, FTP_CWDOK, "iconv() disabled.");
449 else if (str_equal_text(&p_sess->ftp_cmd_str, "CWD") ||
450 str_equal_text(&p_sess->ftp_cmd_str, "XCWD"))
452 handle_cwd(p_sess);
454 else if (str_equal_text(&p_sess->ftp_cmd_str, "CDUP") ||
455 str_equal_text(&p_sess->ftp_cmd_str, "XCUP"))
457 handle_cdup(p_sess);
460 !p_sess->epsv_all &&
461 (str_equal_text(&p_sess->ftp_cmd_str, "PASV") ||
462 str_equal_text(&p_sess->ftp_cmd_str, "P@SW")))
464 handle_pasv(p_sess, 0);
467 str_equal_text(&p_sess->ftp_cmd_str, "EPSV"))
469 handle_pasv(p_sess, 1);
472 str_equal_text(&p_sess->ftp_cmd_str, "RETR"))
474 handle_retr(p_sess);
476 else if (str_equal_text(&p_sess->ftp_cmd_str, "NOOP"))
478 vsf_cmdio_write(p_sess, FTP_NOOPOK, "NOOP ok.");
480 else if (str_equal_text(&p_sess->ftp_cmd_str, "SYST"))
482 vsf_cmdio_write(p_sess, FTP_SYSTOK, "UNIX Type: L8");
484 else if (str_equal_text(&p_sess->ftp_cmd_str, "HELP"))
486 handle_help(p_sess);
489 str_equal_text(&p_sess->ftp_cmd_str, "LIST"))
491 handle_list(p_sess);
493 else if (str_equal_text(&p_sess->ftp_cmd_str, "TYPE"))
495 handle_type(p_sess);
498 !p_sess->epsv_all &&
499 str_equal_text(&p_sess->ftp_cmd_str, "PORT"))
501 handle_port(p_sess);
504 (tunable_anon_upload_enable || !p_sess->is_anonymous) &&
505 str_equal_text(&p_sess->ftp_cmd_str, "STOR"))
507 handle_stor(p_sess);
510 (tunable_anon_mkdir_write_enable || !p_sess->is_anonymous) &&
511 (str_equal_text(&p_sess->ftp_cmd_str, "MKD") ||
512 str_equal_text(&p_sess->ftp_cmd_str, "XMKD")))
514 handle_mkd(p_sess);
517 (tunable_anon_other_write_enable || !p_sess->is_anonymous) &&
518 (str_equal_text(&p_sess->ftp_cmd_str, "RMD") ||
519 str_equal_text(&p_sess->ftp_cmd_str, "XRMD")))
521 handle_rmd(p_sess);
524 (tunable_anon_other_write_enable || !p_sess->is_anonymous) &&
525 str_equal_text(&p_sess->ftp_cmd_str, "DELE"))
527 handle_dele(p_sess);
529 else if (str_equal_text(&p_sess->ftp_cmd_str, "REST"))
531 handle_rest(p_sess);
534 (tunable_anon_other_write_enable || !p_sess->is_anonymous) &&
535 str_equal_text(&p_sess->ftp_cmd_str, "RNFR"))
537 handle_rnfr(p_sess);
540 (tunable_anon_other_write_enable || !p_sess->is_anonymous) &&
541 str_equal_text(&p_sess->ftp_cmd_str, "RNTO"))
543 handle_rnto(p_sess);
546 str_equal_text(&p_sess->ftp_cmd_str, "NLST"))
548 handle_nlst(p_sess);
550 else if (str_equal_text(&p_sess->ftp_cmd_str, "SIZE"))
552 handle_size(p_sess);
554 else if (!p_sess->is_anonymous &&
555 str_equal_text(&p_sess->ftp_cmd_str, "SITE"))
557 handle_site(p_sess);
562 else if (str_equal_text(&p_sess->ftp_cmd_str, "ABOR") ||
563 str_equal_text(&p_sess->ftp_cmd_str, "\377\364\377\362ABOR"))
565 vsf_cmdio_write(p_sess, FTP_ABOR_NOCONN, "No transfer to ABOR.");
568 (tunable_anon_other_write_enable || !p_sess->is_anonymous) &&
569 str_equal_text(&p_sess->ftp_cmd_str, "APPE"))
571 handle_appe(p_sess);
573 else if (str_equal_text(&p_sess->ftp_cmd_str, "MDTM"))
575 handle_mdtm(p_sess);
578 str_equal_text(&p_sess->ftp_cmd_str, "EPRT"))
580 handle_eprt(p_sess);
582 else if (str_equal_text(&p_sess->ftp_cmd_str, "STRU"))
584 str_upper(&p_sess->ftp_arg_str);
585 if (str_equal_text(&p_sess->ftp_arg_str, "F"))
587 vsf_cmdio_write(p_sess, FTP_STRUOK, "Structure set to F.");
591 vsf_cmdio_write(p_sess, FTP_BADSTRU, "Bad STRU command.");
594 else if (str_equal_text(&p_sess->ftp_cmd_str, "MODE"))
596 str_upper(&p_sess->ftp_arg_str);
597 if (str_equal_text(&p_sess->ftp_arg_str, "S"))
599 vsf_cmdio_write(p_sess, FTP_MODEOK, "Mode set to S.");
603 vsf_cmdio_write(p_sess, FTP_BADMODE, "Bad MODE command.");
606 else if (str_equal_text(&p_sess->ftp_cmd_str, "STOU"))
608 handle_stou(p_sess);
610 else if (str_equal_text(&p_sess->ftp_cmd_str, "ALLO"))
612 vsf_cmdio_write(p_sess, FTP_ALLOOK, "ALLO command ignored.");
614 else if (str_equal_text(&p_sess->ftp_cmd_str, "REIN"))
616 vsf_cmdio_write(p_sess, FTP_COMMANDNOTIMPL, "REIN not implemented.");
618 else if (str_equal_text(&p_sess->ftp_cmd_str, "ACCT"))
620 vsf_cmdio_write(p_sess, FTP_COMMANDNOTIMPL, "ACCT not implemented.");
622 else if (str_equal_text(&p_sess->ftp_cmd_str, "SMNT"))
624 vsf_cmdio_write(p_sess, FTP_COMMANDNOTIMPL, "SMNT not implemented.");
626 else if (str_equal_text(&p_sess->ftp_cmd_str, "FEAT"))
628 handle_feat(p_sess);
630 else if (str_equal_text(&p_sess->ftp_cmd_str, "OPTS"))
632 handle_opts(p_sess);
634 else if (str_equal_text(&p_sess->ftp_cmd_str, "STAT") &&
635 str_isempty(&p_sess->ftp_arg_str))
637 handle_stat(p_sess);
640 str_equal_text(&p_sess->ftp_cmd_str, "STAT"))
642 handle_stat_file(p_sess);
644 else if (tunable_ssl_enable && str_equal_text(&p_sess->ftp_cmd_str, "PBSZ"))
646 handle_pbsz(p_sess);
648 else if (tunable_ssl_enable && str_equal_text(&p_sess->ftp_cmd_str, "PROT"))
650 handle_prot(p_sess);
652 else if (str_equal_text(&p_sess->ftp_cmd_str, "PASV") ||
653 str_equal_text(&p_sess->ftp_cmd_str, "PORT") ||
654 str_equal_text(&p_sess->ftp_cmd_str, "STOR") ||
655 str_equal_text(&p_sess->ftp_cmd_str, "MKD") ||
656 str_equal_text(&p_sess->ftp_cmd_str, "XMKD") ||
657 str_equal_text(&p_sess->ftp_cmd_str, "RMD") ||
658 str_equal_text(&p_sess->ftp_cmd_str, "XRMD") ||
659 str_equal_text(&p_sess->ftp_cmd_str, "DELE") ||
660 str_equal_text(&p_sess->ftp_cmd_str, "RNFR") ||
661 str_equal_text(&p_sess->ftp_cmd_str, "RNTO") ||
662 str_equal_text(&p_sess->ftp_cmd_str, "SITE") ||
663 str_equal_text(&p_sess->ftp_cmd_str, "APPE") ||
664 str_equal_text(&p_sess->ftp_cmd_str, "EPSV") ||
665 str_equal_text(&p_sess->ftp_cmd_str, "EPRT") ||
666 str_equal_text(&p_sess->ftp_cmd_str, "RETR") ||
667 str_equal_text(&p_sess->ftp_cmd_str, "LIST") ||
668 str_equal_text(&p_sess->ftp_cmd_str, "NLST") ||
669 str_equal_text(&p_sess->ftp_cmd_str, "STOU") ||
670 str_equal_text(&p_sess->ftp_cmd_str, "ALLO") ||
671 str_equal_text(&p_sess->ftp_cmd_str, "REIN") ||
672 str_equal_text(&p_sess->ftp_cmd_str, "ACCT") ||
673 str_equal_text(&p_sess->ftp_cmd_str, "SMNT") ||
674 str_equal_text(&p_sess->ftp_cmd_str, "FEAT") ||
675 str_equal_text(&p_sess->ftp_cmd_str, "OPTS") ||
676 str_equal_text(&p_sess->ftp_cmd_str, "STAT") ||
677 str_equal_text(&p_sess->ftp_cmd_str, "PBSZ") ||
678 str_equal_text(&p_sess->ftp_cmd_str, "PROT"))
680 vsf_cmdio_write(p_sess, FTP_NOPERM, "Permission denied.");
684 vsf_cmdio_write(p_sess, FTP_BADCMD, "Unknown command.");
686 if (vsf_log_entry_pending(p_sess))
688 vsf_log_do_log(p_sess, 0);
692 str_free(&p_sess->full_path);
696 handle_pwd(struct vsf_session* p_sess)
745 vsf_cmdio_write_str(p_sess, FTP_PWDOK, &s_pwd_res_str);
749 handle_cwd(struct vsf_session* p_sess)
752 resolve_tilde(&p_sess->full_path, p_sess);
753 if (!vsf_access_check_file(&p_sess->full_path))
755 vsf_cmdio_write(p_sess, FTP_NOPERM, "Permission denied.");
758 retval = str_chdir(&p_sess->full_path);
762 vsf_banner_dir_changed(p_sess, FTP_CWDOK);
763 vsf_cmdio_write(p_sess, FTP_CWDOK, "Directory successfully changed.");
770 tmp_str = local2remote(str_getbuf(&p_sess->full_path));
773 str_empty(&p_sess->full_path);
774 str_append_text(&p_sess->full_path, tmp_str);
777 retval = str_chdir(&p_sess->full_path);
781 vsf_banner_dir_changed(p_sess, FTP_CWDOK);
782 vsf_cmdio_write(p_sess, FTP_CWDOK, "Directory successfully changed.");
787 vsf_cmdio_write(p_sess, FTP_FILEFAIL, "Failed to change directory.");
792 handle_cdup(struct vsf_session* p_sess)
794 char *ptr = rindex(str_getbuf(&p_sess->full_path), '/');
797 vsf_cmdio_write(p_sess, FTP_FILEFAIL, "Failed to change the upper directory.");
803 handle_cwd(p_sess);
807 port_active(struct vsf_session* p_sess)
810 if (p_sess->p_port_sockaddr != 0)
813 if (pasv_active(p_sess))
822 pasv_active(struct vsf_session* p_sess)
825 if (p_sess->pasv_listen_fd != -1)
828 if (port_active(p_sess))
837 port_cleanup(struct vsf_session* p_sess)
839 vsf_sysutil_sockaddr_clear(&p_sess->p_port_sockaddr);
843 pasv_cleanup(struct vsf_session* p_sess)
845 if (p_sess->pasv_listen_fd != -1)
847 vsf_sysutil_close(p_sess->pasv_listen_fd);
848 p_sess->pasv_listen_fd = -1;
853 handle_pasv(struct vsf_session* p_sess, int is_epsv)
859 int is_ipv6 = vsf_sysutil_sockaddr_is_ipv6(p_sess->p_local_addr);
860 if (is_epsv && !str_isempty(&p_sess->ftp_arg_str))
863 str_upper(&p_sess->ftp_arg_str);
864 if (str_equal_text(&p_sess->ftp_arg_str, "ALL"))
866 p_sess->epsv_all = 1;
867 vsf_cmdio_write(p_sess, FTP_EPSVALLOK, "EPSV ALL ok.");
870 argval = vsf_sysutil_atoi(str_getbuf(&p_sess->ftp_arg_str));
873 vsf_cmdio_write(p_sess, FTP_EPSVBAD, "Bad network protocol.");
877 pasv_cleanup(p_sess);
878 port_cleanup(p_sess);
881 p_sess->pasv_listen_fd = vsf_sysutil_get_ipv6_sock();
885 p_sess->pasv_listen_fd = vsf_sysutil_get_ipv4_sock();
887 vsf_sysutil_activate_reuseaddr(p_sess->pasv_listen_fd);
910 vsf_sysutil_sockaddr_clone(&s_p_sockaddr, p_sess->p_local_addr);
912 retval = vsf_sysutil_bind(p_sess->pasv_listen_fd, s_p_sockaddr);
927 vsf_sysutil_listen(p_sess->pasv_listen_fd, 1);
933 vsf_cmdio_write_str(p_sess, FTP_EPSVOK, &s_pasv_res_str);
967 vsf_cmdio_write_str(p_sess, FTP_PASVOK, &s_pasv_res_str);
971 handle_retr(struct vsf_session* p_sess)
981 filesize_t offset = p_sess->restart_pos;
982 p_sess->restart_pos = 0;
983 if (!data_transfer_checks_ok(p_sess))
987 if (p_sess->is_ascii && offset != 0)
989 vsf_cmdio_write(p_sess, FTP_FILEFAIL, "No support for resume of ASCII transfer.");
992 resolve_tilde(&p_sess->full_path, p_sess);
993 vsf_log_start_entry(p_sess, kVSFLogEntryDownload);
994 str_copy(&p_sess->log_str, &p_sess->full_path);
995 prepend_path_to_filename(&p_sess->log_str);
996 if (!vsf_access_check_file(&p_sess->full_path))
998 vsf_cmdio_write(p_sess, FTP_NOPERM, "Permission denied.");
1001 opened_file = str_open(&p_sess->full_path, kVSFSysStrOpenReadOnly);
1004 // vsf_cmdio_write(p_sess, FTP_FILEFAIL, "Failed to open file."); // Jiahao
1009 tmp_str = local2remote(str_getbuf(&p_sess->full_path));
1011 str_empty(&p_sess->full_path);
1012 str_append_text(&p_sess->full_path, tmp_str);
1014 opened_file = str_open(&p_sess->full_path, kVSFSysStrOpenReadOnly);
1016 vsf_cmdio_write(p_sess, FTP_FILEFAIL, "Failed to open file.");
1021 vsf_cmdio_write(p_sess, FTP_FILEFAIL, "Failed to open file.");
1026 vsf_cmdio_write(p_sess, FTP_FILEFAIL, "Failed to open file.");
1042 vsf_cmdio_write(p_sess, FTP_FILEFAIL, "Failed to open file.");
1047 if (p_sess->is_anonymous && tunable_anon_world_readable_only &&
1050 vsf_cmdio_write(p_sess, FTP_FILEFAIL, "Failed to open file.");
1061 if (tunable_ascii_download_enable && p_sess->is_ascii)
1071 // str_append_str(&s_mark_str, &p_sess->full_path); // Jiahao
1072 tmp_filename = local2remote(str_getbuf(&p_sess->full_path));
1074 str_append_str(&s_mark_str, &p_sess->full_path);
1084 remote_fd = get_remote_transfer_fd(p_sess, str_getbuf(&s_mark_str));
1089 trans_ret = vsf_ftpdataio_transfer_file(p_sess, remote_fd,
1091 vsf_ftpdataio_dispose_transfer_fd(p_sess);
1092 p_sess->transfer_size = trans_ret.transferred;
1096 vsf_log_do_log(p_sess, 1);
1104 vsf_cmdio_write(p_sess, FTP_BADSENDFILE, "Failure reading local file.");
1108 vsf_cmdio_write(p_sess, FTP_BADSENDNET, "Failure writing network stream.");
1112 vsf_cmdio_write(p_sess, FTP_TRANSFEROK, "File send OK.");
1114 check_abor(p_sess);
1116 port_cleanup(p_sess);
1117 pasv_cleanup(p_sess);
1123 handle_list(struct vsf_session* p_sess)
1125 handle_dir_common(p_sess, 1, 0);
1129 handle_dir_common(struct vsf_session* p_sess, int full_details, int stat_cmd)
1144 if (!stat_cmd && !data_transfer_checks_ok(p_sess))
1151 if (!str_isempty(&p_sess->ftp_arg_str) &&
1152 str_get_char_at(&p_sess->ftp_arg_str, 0) == '-')
1155 str_mid_to_end(&p_sess->ftp_arg_str, &s_option_str, 1);
1162 //str_copy(&s_filter_str, &p_sess->ftp_arg_str);
1163 str_append_str(&s_filter_str, &p_sess->full_path);
1168 resolve_tilde(&s_filter_str, p_sess);
1171 vsf_cmdio_write(p_sess, FTP_NOPERM, "Permission denied.");
1213 vsf_cmdio_write_hyphen(p_sess, FTP_STATFILE_OK, "Status follows:");
1217 int remote_fd = get_remote_transfer_fd(p_sess, "Here comes the directory listing.");
1224 if (p_sess->is_anonymous && p_dir && tunable_anon_world_readable_only)
1235 retval = vsf_ftpdataio_transfer_dir(p_sess, use_control, p_dir,
1242 vsf_cmdio_write(p_sess, FTP_STATFILE_OK, "End of status");
1246 vsf_ftpdataio_dispose_transfer_fd(p_sess);
1251 vsf_cmdio_write(p_sess, FTP_TRANSFEROK, "Transfer done (but failed to open directory).");
1255 vsf_cmdio_write(p_sess, FTP_TRANSFEROK, "Directory send OK.");
1259 vsf_cmdio_write(p_sess, FTP_BADSENDNET, "Failure writing network stream.");
1262 check_abor(p_sess);
1272 port_cleanup(p_sess);
1273 pasv_cleanup(p_sess);
1278 handle_type(struct vsf_session* p_sess)
1280 str_upper(&p_sess->ftp_arg_str);
1281 if (str_equal_text(&p_sess->ftp_arg_str, "I") ||
1282 str_equal_text(&p_sess->ftp_arg_str, "L8") ||
1283 str_equal_text(&p_sess->ftp_arg_str, "L 8"))
1285 p_sess->is_ascii = 0;
1286 vsf_cmdio_write(p_sess, FTP_TYPEOK, "Switching to Binary mode.");
1288 else if (str_equal_text(&p_sess->ftp_arg_str, "A") ||
1289 str_equal_text(&p_sess->ftp_arg_str, "A N"))
1291 p_sess->is_ascii = 1;
1292 vsf_cmdio_write(p_sess, FTP_TYPEOK, "Switching to ASCII mode.");
1296 vsf_cmdio_write(p_sess, FTP_BADCMD, "Unrecognised TYPE command.");
1301 handle_port(struct vsf_session* p_sess)
1306 pasv_cleanup(p_sess);
1307 port_cleanup(p_sess);
1308 p_raw = vsf_sysutil_parse_uchar_string_sep(&p_sess->ftp_arg_str, ',', vals,
1312 vsf_cmdio_write(p_sess, FTP_BADCMD, "Illegal PORT command.");
1317 vsf_sysutil_sockaddr_clone(&p_sess->p_port_sockaddr, p_sess->p_local_addr);
1318 vsf_sysutil_sockaddr_set_ipv4addr(p_sess->p_port_sockaddr, vals);
1319 vsf_sysutil_sockaddr_set_port(p_sess->p_port_sockaddr, the_port);
1326 if (!vsf_sysutil_sockaddr_addr_equal(p_sess->p_remote_addr,
1327 p_sess->p_port_sockaddr) ||
1330 vsf_cmdio_write(p_sess, FTP_BADCMD, "Illegal PORT command.");
1331 port_cleanup(p_sess);
1335 vsf_cmdio_write(p_sess, FTP_PORTOK,
1340 handle_stor(struct vsf_session* p_sess)
1342 handle_upload_common(p_sess, 0, 0);
1346 handle_upload_common(struct vsf_session* p_sess, int is_append, int is_unique)
1354 filesize_t offset = p_sess->restart_pos;
1355 p_sess->restart_pos = 0;
1356 if (!data_transfer_checks_ok(p_sess))
1360 resolve_tilde(&p_sess->full_path, p_sess);
1361 p_filename = &p_sess->full_path;
1367 vsf_log_start_entry(p_sess, kVSFLogEntryUpload);
1368 str_copy(&p_sess->log_str, &p_sess->full_path);
1369 prepend_path_to_filename(&p_sess->log_str);
1372 vsf_cmdio_write(p_sess, FTP_NOPERM, "Permission denied.");
1376 if (p_sess->write_enable==0) // Jiahao
1378 vsf_cmdio_write(p_sess, FTP_NOPERM, "Permission denied.");
1386 if (is_unique || (p_sess->is_anonymous && !tunable_anon_other_write_enable))
1406 vsf_cmdio_write(p_sess, FTP_UPLOADFAIL, "Could not create file.");
1411 if (p_sess->is_anonymous && tunable_chown_uploads)
1416 vsf_one_process_chown_upload(p_sess, new_file_fd);
1420 vsf_two_process_chown_upload(p_sess, new_file_fd);
1441 vsf_cmdio_write_str(p_sess, FTP_DATACONN, &resp_str);
1442 remote_fd = get_remote_transfer_fd(p_sess, str_getbuf(&resp_str));
1447 remote_fd = get_remote_transfer_fd(p_sess, "Ok to send data.");
1455 if (tunable_ascii_upload_enable && p_sess->is_ascii)
1457 trans_ret = vsf_ftpdataio_transfer_file(p_sess, remote_fd,
1462 trans_ret = vsf_ftpdataio_transfer_file(p_sess, remote_fd,
1465 vsf_ftpdataio_dispose_transfer_fd(p_sess);
1466 p_sess->transfer_size = trans_ret.transferred;
1470 vsf_log_do_log(p_sess, 1);
1475 vsf_cmdio_write(p_sess, FTP_BADSENDFILE, "Failure writing to local file.");
1479 vsf_cmdio_write(p_sess, FTP_BADSENDNET, "Failure reading network stream.");
1483 vsf_cmdio_write(p_sess, FTP_TRANSFEROK, "File receive OK.");
1485 check_abor(p_sess);
1487 port_cleanup(p_sess);
1488 pasv_cleanup(p_sess);
1493 handle_mkd(struct vsf_session* p_sess)
1497 resolve_tilde(&p_sess->full_path, p_sess);
1498 vsf_log_start_entry(p_sess, kVSFLogEntryMkdir);
1499 str_copy(&p_sess->log_str, &p_sess->full_path);
1500 prepend_path_to_filename(&p_sess->log_str);
1502 if (!vsf_access_check_file(&p_sess->full_path))
1504 vsf_cmdio_write(p_sess, FTP_NOPERM, "Permission denied.");
1507 if (p_sess->write_enable==0) // Jiahao
1509 vsf_cmdio_write(p_sess, FTP_NOPERM, "Permission denied.");
1515 if(p_sess->layer != SHARE_LAYER || !p_sess->is_anonymous){
1516 retval = str_mkdir(&p_sess->full_path, 0777);
1521 mount_path = (char *)str_getbuf(&p_sess->full_path);
1523 new_folder = rindex(str_getbuf(&p_sess->full_path), '/');
1525 vsf_cmdio_write(p_sess, FTP_FILEFAIL, "1. Create directory operation failed.");
1540 vsf_cmdio_write(p_sess, FTP_FILEFAIL, "2. Create directory operation failed.");
1543 vsf_log_do_log(p_sess, 1);
1547 str_copy(&s_tmp_str, &p_sess->full_path);
1567 vsf_cmdio_write_str(p_sess, FTP_MKDIROK, &s_mkd_res);
1572 handle_rmd(struct vsf_session* p_sess)
1576 resolve_tilde(&p_sess->full_path, p_sess);
1577 vsf_log_start_entry(p_sess, kVSFLogEntryRmdir);
1578 str_copy(&p_sess->log_str, &p_sess->full_path);
1579 prepend_path_to_filename(&p_sess->log_str);
1580 if (!vsf_access_check_file(&p_sess->full_path))
1582 vsf_cmdio_write(p_sess, FTP_NOPERM, "Permission denied.");
1585 if (p_sess->write_enable==0) // Jiahao
1587 vsf_cmdio_write(p_sess, FTP_NOPERM, "Permission denied.");
1592 if(p_sess->layer != SHARE_LAYER || !p_sess->is_anonymous){
1593 retval = str_rmdir(&p_sess->full_path);
1598 mount_path = (char *)str_getbuf(&p_sess->full_path);
1602 vsf_cmdio_write(p_sess, FTP_FILEFAIL, "Remove directory operation failed (001).");
1617 vsf_cmdio_write(p_sess, FTP_FILEFAIL,
1622 vsf_log_do_log(p_sess, 1);
1623 vsf_cmdio_write(p_sess, FTP_RMDIROK,
1629 handle_dele(struct vsf_session* p_sess)
1632 resolve_tilde(&p_sess->full_path, p_sess);
1633 vsf_log_start_entry(p_sess, kVSFLogEntryDelete);
1634 str_copy(&p_sess->log_str, &p_sess->full_path);
1635 prepend_path_to_filename(&p_sess->log_str);
1637 if (!vsf_access_check_file(&p_sess->full_path))
1639 vsf_cmdio_write(p_sess, FTP_NOPERM, "Permission denied.");
1643 if (p_sess->write_enable==0) // Jiahao
1645 vsf_cmdio_write(p_sess, FTP_NOPERM, "Permission denied.");
1648 retval = str_unlink(&p_sess->full_path);
1651 vsf_cmdio_write(p_sess, FTP_FILEFAIL, "Delete operation failed.");
1655 vsf_log_do_log(p_sess, 1);
1656 vsf_cmdio_write(p_sess, FTP_DELEOK, "Delete operation successful.");
1661 handle_rest(struct vsf_session* p_sess)
1664 filesize_t val = str_a_to_filesize_t(&p_sess->ftp_arg_str);
1669 p_sess->restart_pos = val;
1673 vsf_cmdio_write_str(p_sess, FTP_RESTOK, &s_rest_str);
1677 handle_rnfr(struct vsf_session* p_sess)
1683 str_free(&p_sess->rnfr_filename_str);
1684 resolve_tilde(&p_sess->full_path, p_sess);
1689 len = str_getlen(&p_sess->full_path);
1691 if (!vsf_access_check_file(&p_sess->full_path))
1694 vsf_log_start_entry(p_sess, kVSFLogEntryRename);
1695 str_copy(&p_sess->log_str, &p_sess->full_path);
1696 prepend_path_to_filename(&p_sess->log_str);
1697 vsf_cmdio_write(p_sess, FTP_NOPERM, "Permission denied.");
1700 if (p_sess->write_enable==0) // Jiahao
1702 vsf_cmdio_write(p_sess, FTP_NOPERM, "Permission denied.");
1707 retval = str_stat(&p_sess->full_path, &p_statbuf);
1712 str_copy(&p_sess->rnfr_filename_str, &p_sess->full_path);
1713 vsf_cmdio_write(p_sess, FTP_RNFROK, "Ready for RNTO.");
1717 vsf_log_start_entry(p_sess, kVSFLogEntryRename);
1718 str_copy(&p_sess->log_str, &p_sess->full_path);
1719 prepend_path_to_filename(&p_sess->log_str);
1720 vsf_cmdio_write(p_sess, FTP_FILEFAIL, "RNFR command failed.");
1725 handle_rnto(struct vsf_session* p_sess)
1731 if (str_isempty(&p_sess->rnfr_filename_str))
1733 vsf_cmdio_write(p_sess, FTP_NEEDRNFR,
1737 resolve_tilde(&p_sess->full_path, p_sess);
1738 vsf_log_start_entry(p_sess, kVSFLogEntryRename);
1739 str_copy(&p_sess->log_str, &p_sess->rnfr_filename_str);
1740 prepend_path_to_filename(&p_sess->log_str);
1741 str_append_char(&p_sess->log_str, ' ');
1742 str_copy(&s_tmp_str, &p_sess->full_path);
1744 str_append_str(&p_sess->log_str, &s_tmp_str);
1745 if (!vsf_access_check_file(&p_sess->full_path))
1747 vsf_cmdio_write(p_sess, FTP_NOPERM, "Permission denied.");
1750 if (p_sess->write_enable==0) // Jiahao
1752 vsf_cmdio_write(p_sess, FTP_NOPERM, "Permission denied.");
1760 if(p_sess->layer != SHARE_LAYER || !p_sess->is_anonymous){
1761 retval = str_rename(&p_sess->rnfr_filename_str, &p_sess->full_path);
1767 mount_path = (char *)str_getbuf(&p_sess->rnfr_filename_str);
1769 new_folder = rindex(str_getbuf(&p_sess->full_path), '/');
1771 str_free(&p_sess->rnfr_filename_str);
1772 vsf_cmdio_write(p_sess, FTP_FILEFAIL, "Rename failed 1.");
1778 str_free(&p_sess->rnfr_filename_str);
1779 vsf_cmdio_write(p_sess, FTP_FILEFAIL, "Rename failed 2.");
1793 str_free(&p_sess->rnfr_filename_str);
1796 vsf_log_do_log(p_sess, 1);
1797 vsf_cmdio_write(p_sess, FTP_RENAMEOK, "Rename successful.");
1801 vsf_cmdio_write(p_sess, FTP_FILEFAIL, "Rename failed.");
1806 handle_nlst(struct vsf_session* p_sess)
1808 handle_dir_common(p_sess, 0, 0);
1841 struct vsf_session* p_sess = (struct vsf_session*) p_private;
1843 if (p_sess->data_fd == -1)
1848 vsf_cmdio_get_cmd_and_arg(p_sess, &async_cmd_str, &async_arg_str, 0);
1860 p_sess->abor_received = 1;
1865 vsf_sysutil_shutdown_failok(p_sess->data_fd);
1870 vsf_cmdio_write(p_sess, FTP_BADCMD, "Unknown command.");
1878 get_remote_transfer_fd(struct vsf_session* p_sess, const char* p_status_msg)
1881 if (!pasv_active(p_sess) && !port_active(p_sess))
1885 p_sess->abor_received = 0;
1886 if (pasv_active(p_sess))
1888 remote_fd = vsf_ftpdataio_get_pasv_fd(p_sess);
1892 remote_fd = vsf_ftpdataio_get_port_fd(p_sess);
1898 vsf_cmdio_write(p_sess, FTP_DATACONN, p_status_msg);
1899 if (vsf_ftpdataio_post_mark_connect(p_sess) != 1)
1901 vsf_ftpdataio_dispose_transfer_fd(p_sess);
1908 check_abor(struct vsf_session* p_sess)
1911 if (p_sess->abor_received)
1913 p_sess->abor_received = 0;
1914 vsf_cmdio_write(p_sess, FTP_ABOROK, "ABOR successful.");
1919 handle_size(struct vsf_session* p_sess)
1928 resolve_tilde(&p_sess->ftp_arg_str, p_sess);
1929 if (!vsf_access_check_file(&p_sess->ftp_arg_str))
1931 vsf_cmdio_write(p_sess, FTP_NOPERM, "Permission denied.");
1934 retval = str_stat(&p_sess->ftp_arg_str, &s_p_statbuf);
1937 vsf_cmdio_write(p_sess, FTP_FILEFAIL, "Could not get file size.");
1944 vsf_cmdio_write_str(p_sess, FTP_SIZEOK, &s_size_res_str);
1949 handle_site(struct vsf_session* p_sess)
1953 str_split_char(&p_sess->ftp_arg_str, &s_site_args_str, ' ');
1954 str_upper(&p_sess->ftp_arg_str);
1957 str_equal_text(&p_sess->ftp_arg_str, "CHMOD"))
1959 handle_site_chmod(p_sess, &s_site_args_str);
1961 else if (str_equal_text(&p_sess->ftp_arg_str, "UMASK"))
1963 handle_site_umask(p_sess, &s_site_args_str);
1965 else if (str_equal_text(&p_sess->ftp_arg_str, "HELP"))
1967 vsf_cmdio_write(p_sess, FTP_SITEHELP, "CHMOD UMASK HELP");
1971 vsf_cmdio_write(p_sess, FTP_BADCMD, "Unknown SITE command.");
1976 handle_site_chmod(struct vsf_session* p_sess, struct mystr* p_arg_str)
1983 vsf_cmdio_write(p_sess, FTP_BADCMD, "SITE CHMOD needs 2 arguments.");
1989 vsf_cmdio_write(p_sess, FTP_BADCMD, "SITE CHMOD needs 2 arguments.");
1992 resolve_tilde(&s_chmod_file_str, p_sess);
1993 vsf_log_start_entry(p_sess, kVSFLogEntryChmod);
1994 str_copy(&p_sess->log_str, &s_chmod_file_str);
1995 prepend_path_to_filename(&p_sess->log_str);
1996 str_append_char(&p_sess->log_str, ' ');
1997 str_append_str(&p_sess->log_str, p_arg_str);
2000 vsf_cmdio_write(p_sess, FTP_NOPERM, "Permission denied.");
2003 if (p_sess->write_enable==0) // Jiahao
2005 vsf_cmdio_write(p_sess, FTP_NOPERM, "Permission denied.");
2013 vsf_cmdio_write(p_sess, FTP_FILEFAIL, "SITE CHMOD command failed.");
2017 vsf_log_do_log(p_sess, 1);
2018 vsf_cmdio_write(p_sess, FTP_CHMODOK, "SITE CHMOD command ok.");
2023 handle_site_umask(struct vsf_session* p_sess, struct mystr* p_arg_str)
2045 vsf_cmdio_write_str(p_sess, FTP_UMASKOK, &s_umask_resp_str);
2049 handle_appe(struct vsf_session* p_sess)
2051 handle_upload_common(p_sess, 1, 0);
2055 handle_mdtm(struct vsf_session* p_sess)
2061 struct str_locate_result loc = str_locate_char(&p_sess->ftp_arg_str, ' ');
2062 int retval = str_stat(&p_sess->ftp_arg_str, &s_p_statbuf);
2064 vsf_sysutil_isdigit(str_get_char_at(&p_sess->ftp_arg_str, 0)))
2067 (loc.index > 15 && str_get_char_at(&p_sess->ftp_arg_str, 14) == '.'))
2074 str_split_char(&p_sess->ftp_arg_str, &s_filename_str, ' ');
2075 modtime = vsf_sysutil_parse_time(str_getbuf(&p_sess->ftp_arg_str));
2076 str_copy(&p_sess->ftp_arg_str, &s_filename_str);
2078 resolve_tilde(&p_sess->ftp_arg_str, p_sess);
2079 if (!vsf_access_check_file(&p_sess->ftp_arg_str))
2081 vsf_cmdio_write(p_sess, FTP_NOPERM, "Permission denied.");
2085 (tunable_anon_other_write_enable || !p_sess->is_anonymous))
2087 if (p_sess->write_enable==0) // Jiahao
2089 vsf_cmdio_write(p_sess, FTP_NOPERM, "Permission denied.");
2092 retval = str_stat(&p_sess->ftp_arg_str, &s_p_statbuf);
2095 vsf_cmdio_write(p_sess, FTP_FILEFAIL,
2101 str_getbuf(&p_sess->ftp_arg_str), modtime, tunable_use_localtime);
2104 vsf_cmdio_write(p_sess, FTP_FILEFAIL,
2109 vsf_cmdio_write(p_sess, FTP_MDTMOK,
2118 vsf_cmdio_write(p_sess, FTP_FILEFAIL,
2127 vsf_cmdio_write_str(p_sess, FTP_MDTMOK, &s_mdtm_res_str);
2133 handle_eprt(struct vsf_session* p_sess)
2140 int is_ipv6 = vsf_sysutil_sockaddr_is_ipv6(p_sess->p_local_addr);
2142 port_cleanup(p_sess);
2143 pasv_cleanup(p_sess);
2144 str_copy(&s_part1_str, &p_sess->ftp_arg_str);
2155 vsf_cmdio_write(p_sess, FTP_BADCMD, "Bad EPRT protocol.");
2183 vsf_sysutil_sockaddr_clone(&p_sess->p_port_sockaddr, p_sess->p_local_addr);
2186 vsf_sysutil_sockaddr_set_ipv6addr(p_sess->p_port_sockaddr, p_raw_addr);
2190 vsf_sysutil_sockaddr_set_ipv4addr(p_sess->p_port_sockaddr, p_raw_addr);
2192 vsf_sysutil_sockaddr_set_port(p_sess->p_port_sockaddr, (unsigned short) port);
2199 if (!vsf_sysutil_sockaddr_addr_equal(p_sess->p_remote_addr,
2200 p_sess->p_port_sockaddr) ||
2203 vsf_cmdio_write(p_sess, FTP_BADCMD, "Illegal EPRT command.");
2204 port_cleanup(p_sess);
2208 vsf_cmdio_write(p_sess, FTP_EPRTOK,
2212 vsf_cmdio_write(p_sess, FTP_BADCMD, "Bad EPRT command.");
2217 handle_help(struct vsf_session* p_sess)
2219 vsf_cmdio_write_hyphen(p_sess, FTP_HELP,
2221 vsf_cmdio_write_raw(p_sess,
2223 vsf_cmdio_write_raw(p_sess,
2225 vsf_cmdio_write_raw(p_sess,
2227 vsf_cmdio_write_raw(p_sess,
2230 vsf_cmdio_write(p_sess, FTP_HELP, "Help OK.");
2234 handle_stou(struct vsf_session* p_sess)
2236 handle_upload_common(p_sess, 0, 1);
2261 handle_stat(struct vsf_session* p_sess)
2263 vsf_cmdio_write_hyphen(p_sess, FTP_STATOK, "FTP server status:");
2264 vsf_cmdio_write_raw(p_sess, " Connected to ");
2265 vsf_cmdio_write_raw(p_sess, str_getbuf(&p_sess->remote_ip_str));
2266 vsf_cmdio_write_raw(p_sess, "\r\n");
2267 vsf_cmdio_write_raw(p_sess, " Logged in as ");
2268 vsf_cmdio_write_raw(p_sess, str_getbuf(&p_sess->user_str));
2269 vsf_cmdio_write_raw(p_sess, "\r\n");
2270 vsf_cmdio_write_raw(p_sess, " TYPE: ");
2271 if (p_sess->is_ascii)
2273 vsf_cmdio_write_raw(p_sess, "ASCII\r\n");
2277 vsf_cmdio_write_raw(p_sess, "BINARY\r\n");
2279 if (p_sess->bw_rate_max == 0)
2281 vsf_cmdio_write_raw(p_sess, " No session bandwidth limit\r\n");
2285 vsf_cmdio_write_raw(p_sess, " Session bandwidth limit in byte/s is ");
2286 vsf_cmdio_write_raw(p_sess, vsf_sysutil_ulong_to_str(p_sess->bw_rate_max));
2287 vsf_cmdio_write_raw(p_sess, "\r\n");
2291 vsf_cmdio_write_raw(p_sess, " No session timeout\r\n");
2295 vsf_cmdio_write_raw(p_sess, " Session timeout in seconds is ");
2296 vsf_cmdio_write_raw(p_sess,
2298 vsf_cmdio_write_raw(p_sess, "\r\n");
2300 if (p_sess->control_use_ssl)
2302 vsf_cmdio_write_raw(p_sess, " Control connection is encrypted\r\n");
2306 vsf_cmdio_write_raw(p_sess, " Control connection is plain text\r\n");
2308 if (p_sess->data_use_ssl)
2310 vsf_cmdio_write_raw(p_sess, " Data connections will be encrypted\r\n");
2314 vsf_cmdio_write_raw(p_sess, " Data connections will be plain text\r\n");
2316 if (p_sess->num_clients > 0)
2318 vsf_cmdio_write_raw(p_sess, " At session startup, client count was ");
2319 vsf_cmdio_write_raw(p_sess, vsf_sysutil_ulong_to_str(p_sess->num_clients));
2320 vsf_cmdio_write_raw(p_sess, "\r\n");
2322 vsf_cmdio_write_raw(p_sess,
2324 vsf_cmdio_write(p_sess, FTP_STATOK, "End of status");
2328 handle_stat_file(struct vsf_session* p_sess)
2330 handle_dir_common(p_sess, 1, 1);
2334 data_transfer_checks_ok(struct vsf_session* p_sess)
2336 if (!pasv_active(p_sess) && !port_active(p_sess))
2338 vsf_cmdio_write(p_sess, FTP_BADSENDCONN, "Use PORT or PASV first.");
2341 if (tunable_ssl_enable && !p_sess->data_use_ssl &&
2342 ((tunable_force_local_data_ssl && !p_sess->is_anonymous) ||
2343 (tunable_force_anon_data_ssl && p_sess->is_anonymous)))
2346 p_sess, FTP_NEEDENCRYPT, "Data connections must be encrypted.");
2353 resolve_tilde(struct mystr* p_str, struct vsf_session* p_sess)
2362 str_copy(p_str, &p_sess->home_str);