Blame SOURCES/vsftpd-2.3.4-sqb.patch

bd78b8
diff -up vsftpd-2.3.4/ls.c.sqb vsftpd-2.3.4/ls.c
bd78b8
--- vsftpd-2.3.4/ls.c.sqb	2011-09-13 10:37:05.222089078 +0200
bd78b8
+++ vsftpd-2.3.4/ls.c	2011-09-13 10:59:19.550508941 +0200
bd78b8
@@ -245,7 +245,7 @@ vsf_filename_passes_filter(const struct 
bd78b8
   int ret = 0;
bd78b8
   char last_token = 0;
bd78b8
   int must_match_at_current_pos = 1;
bd78b8
-  
bd78b8
+  int matched = 0;
bd78b8
   
bd78b8
   str_copy(&filter_remain_str, p_filter_str);
bd78b8
   
bd78b8
@@ -275,7 +275,7 @@ vsf_filename_passes_filter(const struct 
bd78b8
     static struct mystr s_match_needed_str;
bd78b8
     /* Locate next special token */
bd78b8
     struct str_locate_result locate_result =
bd78b8
-      str_locate_chars(&filter_remain_str, "*?{");
bd78b8
+      str_locate_chars(&filter_remain_str, "*?{[");
bd78b8
     (*iters)++;
bd78b8
     /* Isolate text leading up to token (if any) - needs to be matched */
bd78b8
     if (locate_result.found)
bd78b8
@@ -293,94 +293,170 @@ vsf_filename_passes_filter(const struct 
bd78b8
       str_empty(&filter_remain_str);
bd78b8
       last_token = 0;
bd78b8
     }
bd78b8
-    if (!str_isempty(&s_match_needed_str))
bd78b8
-    {
bd78b8
-      /* Need to match something.. could be a match which has to start at
bd78b8
-       * current position, or we could allow it to start anywhere
bd78b8
-       */
bd78b8
-      unsigned int indexx;
bd78b8
-      locate_result = str_locate_str(&name_remain_str, &s_match_needed_str);
bd78b8
-      if (!locate_result.found)
bd78b8
-      {
bd78b8
-        /* Fail */
bd78b8
-        goto out;
bd78b8
-      }
bd78b8
-      indexx = locate_result.index;
bd78b8
-      if (must_match_at_current_pos && indexx > 0)
bd78b8
-      {
bd78b8
-        goto out;
bd78b8
-      }
bd78b8
-      if (!must_match_at_current_pos && last_token == 0)
bd78b8
-      {
bd78b8
-        struct mystr last_str = INIT_MYSTR;
bd78b8
-        str_mid_to_end(&name_remain_str, &last_str,
bd78b8
-          str_getlen(&name_remain_str) - str_getlen(&s_match_needed_str));
bd78b8
-        locate_result = str_locate_str(&last_str, &s_match_needed_str);
bd78b8
-        str_free(&last_str);
bd78b8
 
bd78b8
-        if (locate_result.found)
bd78b8
+    matched = 0;
bd78b8
+    do {
bd78b8
+      if (!str_isempty(&s_match_needed_str))
bd78b8
+      {
bd78b8
+        if (!matched)
bd78b8
+        {
bd78b8
+          matched = 1;
bd78b8
+        }
bd78b8
+        /* Need to match something.. could be a match which has to start at
bd78b8
+         * current position, or we could allow it to start anywhere
bd78b8
+         */
bd78b8
+        unsigned int indexx;
bd78b8
+        locate_result = str_locate_str(&name_remain_str, &s_match_needed_str);
bd78b8
+        if (!locate_result.found)
bd78b8
+        {
bd78b8
+          /* Fail */
bd78b8
+          goto out;
bd78b8
+        }
bd78b8
+        indexx = locate_result.index;
bd78b8
+        if (must_match_at_current_pos && indexx > 0)
bd78b8
         {
bd78b8
-          ret = 1;
bd78b8
+          goto out;
bd78b8
         }
bd78b8
-        goto out;
bd78b8
+        if (!must_match_at_current_pos && last_token == 0)
bd78b8
+        {
bd78b8
+          struct mystr last_str = INIT_MYSTR;
bd78b8
+          str_mid_to_end(&name_remain_str, &last_str,
bd78b8
+            str_getlen(&name_remain_str) - str_getlen(&s_match_needed_str));
bd78b8
+          locate_result = str_locate_str(&last_str, &s_match_needed_str);
bd78b8
+          str_free(&last_str);
bd78b8
+
bd78b8
+          if (locate_result.found)
bd78b8
+          {
bd78b8
+            ret = 1;
bd78b8
+          }
bd78b8
+          goto out;
bd78b8
+        }
bd78b8
+        /* Chop matched string out of remainder */
bd78b8
+        str_mid_to_end(&name_remain_str, &temp_str,
bd78b8
+                       indexx + str_getlen(&s_match_needed_str));
bd78b8
+        str_copy(&name_remain_str, &temp_str);
bd78b8
       }
bd78b8
-      /* Chop matched string out of remainder */
bd78b8
-      str_mid_to_end(&name_remain_str, &temp_str,
bd78b8
-                     indexx + str_getlen(&s_match_needed_str));
bd78b8
-      str_copy(&name_remain_str, &temp_str);
bd78b8
-    }
bd78b8
-    if (last_token == '?')
bd78b8
-    {
bd78b8
-      if (str_isempty(&name_remain_str))
bd78b8
+      if (last_token == '?')
bd78b8
       {
bd78b8
-        goto out;
bd78b8
+        if (str_isempty(&name_remain_str))
bd78b8
+        {
bd78b8
+          goto out;
bd78b8
+        }
bd78b8
+        str_right(&name_remain_str, &temp_str, str_getlen(&name_remain_str) - 1);
bd78b8
+        str_copy(&name_remain_str, &temp_str);
bd78b8
+        must_match_at_current_pos = 1;
bd78b8
       }
bd78b8
-      str_right(&name_remain_str, &temp_str, str_getlen(&name_remain_str) - 1);
bd78b8
-      str_copy(&name_remain_str, &temp_str);
bd78b8
-      must_match_at_current_pos = 1;
bd78b8
-    }
bd78b8
-    else if (last_token == '{')
bd78b8
-    {
bd78b8
-      struct str_locate_result end_brace =
bd78b8
-        str_locate_char(&filter_remain_str, '}');
bd78b8
-      must_match_at_current_pos = 1;
bd78b8
-      if (end_brace.found)
bd78b8
+      else if (last_token == '{')
bd78b8
       {
bd78b8
-        str_split_char(&filter_remain_str, &temp_str, '}');
bd78b8
-        str_copy(&brace_list_str, &filter_remain_str);
bd78b8
-        str_copy(&filter_remain_str, &temp_str);
bd78b8
-        str_split_char(&brace_list_str, &temp_str, ',');
bd78b8
-        while (!str_isempty(&brace_list_str))
bd78b8
-        {
bd78b8
-          str_copy(&new_filter_str, &brace_list_str);
bd78b8
-          str_append_str(&new_filter_str, &filter_remain_str);
bd78b8
-          if (vsf_filename_passes_filter(&name_remain_str, &new_filter_str,
bd78b8
-                                         iters))
bd78b8
+        struct str_locate_result end_brace =
bd78b8
+          str_locate_char(&filter_remain_str, '}');
bd78b8
+        must_match_at_current_pos = 1;
bd78b8
+        if (end_brace.found)
bd78b8
+        {
bd78b8
+          str_split_char(&filter_remain_str, &temp_str, '}');
bd78b8
+          str_copy(&brace_list_str, &filter_remain_str);
bd78b8
+          str_copy(&filter_remain_str, &temp_str);
bd78b8
+          str_split_char(&brace_list_str, &temp_str, ',');
bd78b8
+          while (!str_isempty(&brace_list_str))
bd78b8
           {
bd78b8
-            ret = 1;
bd78b8
-            goto out;
bd78b8
+            str_empty(&new_filter_str);
bd78b8
+            if (!matched)
bd78b8
+            {
bd78b8
+              str_append_char(&new_filter_str, '*');
bd78b8
+            }
bd78b8
+            str_append_str(&new_filter_str, &brace_list_str);
bd78b8
+            str_append_str(&new_filter_str, &filter_remain_str);
bd78b8
+            if (vsf_filename_passes_filter(&name_remain_str, &new_filter_str,
bd78b8
+                                           iters))
bd78b8
+            {
bd78b8
+              ret = 1;
bd78b8
+              goto out;
bd78b8
+            }
bd78b8
+            str_copy(&brace_list_str, &temp_str);
bd78b8
+            str_split_char(&brace_list_str, &temp_str, ',');
bd78b8
           }
bd78b8
-          str_copy(&brace_list_str, &temp_str);
bd78b8
-          str_split_char(&brace_list_str, &temp_str, ',');
bd78b8
+          goto out;
bd78b8
+        }
bd78b8
+        else if (str_isempty(&name_remain_str) ||
bd78b8
+                 str_get_char_at(&name_remain_str, 0) != '{')
bd78b8
+        {
bd78b8
+          goto out;
bd78b8
+        }
bd78b8
+        else
bd78b8
+        {
bd78b8
+          str_right(&name_remain_str, &temp_str,
bd78b8
+                    str_getlen(&name_remain_str) - 1);
bd78b8
+          str_copy(&name_remain_str, &temp_str);
bd78b8
         }
bd78b8
-        goto out;
bd78b8
       }
bd78b8
-      else if (str_isempty(&name_remain_str) ||
bd78b8
-               str_get_char_at(&name_remain_str, 0) != '{')
bd78b8
+      else if (last_token == '[')
bd78b8
       {
bd78b8
-        goto out;
bd78b8
+        struct str_locate_result end_sqb =
bd78b8
+          str_locate_char(&filter_remain_str, ']');
bd78b8
+        must_match_at_current_pos = 1;
bd78b8
+        if (end_sqb.found)
bd78b8
+        {
bd78b8
+          unsigned int cur_pos;
bd78b8
+          char stch, ench;
bd78b8
+          const char *p_brace;
bd78b8
+
bd78b8
+          str_split_char(&filter_remain_str, &temp_str, ']');
bd78b8
+          str_copy(&brace_list_str, &filter_remain_str);
bd78b8
+          str_copy(&filter_remain_str, &temp_str);
bd78b8
+          p_brace = str_getbuf(&brace_list_str);
bd78b8
+          for (cur_pos = 0; cur_pos < str_getlen(&brace_list_str);)
bd78b8
+          {
bd78b8
+            stch = p_brace[cur_pos];
bd78b8
+            // char vers. range
bd78b8
+            if (cur_pos + 2 < str_getlen(&brace_list_str) &&
bd78b8
+                p_brace[cur_pos+1] == '-')
bd78b8
+            {
bd78b8
+              ench = p_brace[cur_pos+2];
bd78b8
+              cur_pos += 3;
bd78b8
+            }
bd78b8
+            else
bd78b8
+            {
bd78b8
+              ench = stch;
bd78b8
+              cur_pos++;
bd78b8
+            }
bd78b8
+            // expand char[s]
bd78b8
+            for (;stch <= ench && !str_isempty(&brace_list_str); stch++)
bd78b8
+            {
bd78b8
+              str_empty(&new_filter_str);
bd78b8
+              if (!matched)
bd78b8
+              {
bd78b8
+                str_append_char(&new_filter_str, '*');
bd78b8
+              }
bd78b8
+              str_append_char(&new_filter_str, stch);
bd78b8
+              str_append_str(&new_filter_str, &filter_remain_str);
bd78b8
+              if (vsf_filename_passes_filter(&name_remain_str, &new_filter_str,
bd78b8
+                                             iters))
bd78b8
+              {
bd78b8
+                ret = 1;
bd78b8
+                goto out;
bd78b8
+              }
bd78b8
+            }
bd78b8
+          }
bd78b8
+          goto out;
bd78b8
+        }
bd78b8
+        else if (str_isempty(&name_remain_str) ||
bd78b8
+                 str_get_char_at(&name_remain_str, 0) != '[')
bd78b8
+        {
bd78b8
+          goto out;
bd78b8
+        }
bd78b8
+        else
bd78b8
+        {
bd78b8
+          str_right(&name_remain_str, &temp_str,
bd78b8
+                    str_getlen(&name_remain_str) - 1);
bd78b8
+          str_copy(&name_remain_str, &temp_str);
bd78b8
+        }
bd78b8
       }
bd78b8
       else
bd78b8
       {
bd78b8
-        str_right(&name_remain_str, &temp_str,
bd78b8
-                  str_getlen(&name_remain_str) - 1);
bd78b8
-        str_copy(&name_remain_str, &temp_str);
bd78b8
+        must_match_at_current_pos = 0;
bd78b8
       }
bd78b8
-    }
bd78b8
-    else
bd78b8
-    {
bd78b8
-      must_match_at_current_pos = 0;
bd78b8
-    }
bd78b8
+    } while (locate_result.found &&
bd78b8
+             str_getlen(&name_remain_str) > 0 && last_token != '*');
bd78b8
   }
bd78b8
   /* Any incoming string left means no match unless we ended on the correct
bd78b8
    * type of wildcard.