Index: vsftpd-3.0.2/ls.c =================================================================== --- vsftpd-3.0.2.orig/ls.c +++ vsftpd-3.0.2/ls.c @@ -117,16 +117,6 @@ vsf_ls_populate_dir_list(struct mystr_li { continue; } - /* If we have an ls option which is a filter, apply it */ - if (!str_isempty(p_filter_str)) - { - unsigned int iters = 0; - if (!vsf_filename_passes_filter(&s_next_filename_str, p_filter_str, - &iters)) - { - continue; - } - } /* Calculate the full path (relative to CWD) for lstat() and * output purposes */ @@ -144,6 +134,16 @@ vsf_ls_populate_dir_list(struct mystr_li continue; } } + /* If we have an ls option which is a filter, apply it */ + if (!str_isempty(p_filter_str)) + { + unsigned int iters = 0; + if (!vsf_filename_passes_filter(&s_next_path_and_filename_str, p_filter_str, + &iters)) + { + continue; + } + } if (is_verbose) { static struct mystr s_final_file_str; @@ -246,8 +246,30 @@ vsf_filename_passes_filter(const struct int ret = 0; char last_token = 0; int must_match_at_current_pos = 1; + + str_copy(&filter_remain_str, p_filter_str); - str_copy(&name_remain_str, p_filename_str); + + if (!str_isempty (&filter_remain_str) && !str_isempty(p_filename_str)) { + if (str_get_char_at(p_filter_str, 0) == '/') { + if (str_get_char_at(p_filename_str, 0) != '/') { + str_getcwd (&name_remain_str); + + if (str_getlen(&name_remain_str) > 1) /* cwd != root dir */ + str_append_char (&name_remain_str, '/'); + + str_append_str (&name_remain_str, p_filename_str); + } + else + str_copy (&name_remain_str, p_filename_str); + } else { + if (str_get_char_at(p_filter_str, 0) != '{') + str_basename (&name_remain_str, p_filename_str); + else + str_copy (&name_remain_str, p_filename_str); + } + } else + str_copy(&name_remain_str, p_filename_str); while (!str_isempty(&filter_remain_str) && *iters < VSFTP_MATCHITERS_MAX) { Index: vsftpd-3.0.2/str.c =================================================================== --- vsftpd-3.0.2.orig/str.c +++ vsftpd-3.0.2/str.c @@ -770,3 +770,14 @@ str_replace_unprintable(struct mystr* p_ } } +void +str_basename (struct mystr* d_str, const struct mystr* path) +{ + static struct mystr tmp; + + str_copy (&tmp, path); + str_split_char_reverse(&tmp, d_str, '/'); + + if (str_isempty(d_str)) + str_copy (d_str, path); +} Index: vsftpd-3.0.2/str.h =================================================================== --- vsftpd-3.0.2.orig/str.h +++ vsftpd-3.0.2/str.h @@ -101,6 +101,7 @@ void str_replace_unprintable(struct myst int str_atoi(const struct mystr* p_str); filesize_t str_a_to_filesize_t(const struct mystr* p_str); unsigned int str_octal_to_uint(const struct mystr* p_str); +void str_basename (struct mystr* d_str, const struct mystr* path); /* PURPOSE: Extract a line of text (delimited by \n or EOF) from a string * buffer, starting at character position 'p_pos'. The extracted line will