1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
| static void handle_mdtm(struct vsf_session* p_sess) { static struct mystr s_filename_str; static struct vsf_sysutil_statbuf* s_p_statbuf; int do_write = 0; long modtime = 0; struct str_locate_result loc = str_locate_char(&p_sess->ftp_arg_str, ' '); int retval = str_stat(&p_sess->ftp_arg_str, &s_p_statbuf); if (tunable_mdtm_write && retval != 0 && loc.found && vsf_sysutil_isdigit(str_get_char_at(&p_sess->ftp_arg_str, 0))) { if (loc.index == 8 || loc.index == 14 || (loc.index > 15 && str_get_char_at(&p_sess->ftp_arg_str, 14) == '.')) { do_write = 1; } } if (do_write != 0) { str_split_char(&p_sess->ftp_arg_str, &s_filename_str, ' '); modtime = vsf_sysutil_parse_time(str_getbuf(&p_sess->ftp_arg_str)); str_copy(&p_sess->ftp_arg_str, &s_filename_str); } resolve_tilde(&p_sess->ftp_arg_str, p_sess); if (!vsf_access_check_file(&p_sess->ftp_arg_str)) { vsf_cmdio_write(p_sess, FTP_NOPERM, "Permission denied."); return; } if (do_write && tunable_write_enable && (tunable_anon_other_write_enable || !p_sess->is_anonymous)) { retval = str_stat(&p_sess->ftp_arg_str, &s_p_statbuf); if (retval != 0 || !vsf_sysutil_statbuf_is_regfile(s_p_statbuf)) { vsf_cmdio_write(p_sess, FTP_FILEFAIL, "Could not set file modification time."); } else { retval = vsf_sysutil_setmodtime( str_getbuf(&p_sess->ftp_arg_str), modtime, tunable_use_localtime); if (retval != 0) { vsf_cmdio_write(p_sess, FTP_FILEFAIL, "Could not set file modification time."); } else { vsf_cmdio_write(p_sess, FTP_MDTMOK, "File modification time set."); } } } else { if (retval != 0 || !vsf_sysutil_statbuf_is_regfile(s_p_statbuf)) { vsf_cmdio_write(p_sess, FTP_FILEFAIL, "Could not get file modification time."); } else { static struct mystr s_mdtm_res_str; str_alloc_text(&s_mdtm_res_str, vsf_sysutil_statbuf_get_numeric_date( s_p_statbuf, tunable_use_localtime)); vsf_cmdio_write_str(p_sess, FTP_MDTMOK, &s_mdtm_res_str); } } }
|