]> source.dussan.org Git - rspamd.git/commitdiff
[Fix] Rspamadm grep: Disable Lua patterns in string search by default
authorAndrew Lewis <nerf@judo.za.org>
Tue, 25 Apr 2017 14:36:34 +0000 (16:36 +0200)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 1 May 2017 13:03:04 +0000 (14:03 +0100)
src/rspamadm/grep.c
src/rspamadm/grep.lua

index b88347a8bd321f9b4d3ca23e8c0a0a6459670d90..9665b40e86ade0714e7a3a34e0e96a75a39fceed 100644 (file)
@@ -25,6 +25,7 @@ static gchar **inputs = NULL;
 static gboolean sensitive = FALSE;
 static gboolean orphans = FALSE;
 static gboolean partial = FALSE;
+static gboolean luapat = FALSE;
 
 static void rspamadm_grep (gint argc, gchar **argv);
 static const char *rspamadm_grep_help (gboolean full_help);
@@ -39,6 +40,8 @@ struct rspamadm_command grep_command = {
 static GOptionEntry entries[] = {
                {"string", 's', 0, G_OPTION_ARG_STRING, &string,
                                "Plain string to search (case-insensitive)", NULL},
+               {"lua", 'l', 0, G_OPTION_ARG_NONE, &luapat,
+                               "Use Lua patterns in string search", NULL},
                {"pattern", 'p', 0, G_OPTION_ARG_STRING, &pattern,
                                "Pattern to search for (regex)", NULL},
                 {"input", 'i', 0, G_OPTION_ARG_STRING_ARRAY, &inputs,
@@ -63,6 +66,7 @@ rspamadm_grep_help (gboolean full_help)
                                "Usage: rspamadm grep <-s string | -p pattern> [-i input1 -i input2 -S -o -P]\n"
                                "Where options are:\n\n"
                                "-s: Plain string to search (case-insensitive)\n"
+                               "-l: Use Lua patterns in string search\n"
                                "-p: Pattern to search for (regex)\n"
                                "-i: Process specified inputs (stdin if unspecified)\n"
                                "-S: Enable case-sensitivity in string search\n"
@@ -137,6 +141,8 @@ rspamadm_grep (gint argc, gchar **argv)
                        "orphans", 0, false);
        ucl_object_insert_key (obj, ucl_object_frombool (partial),
                        "partial", 0, false);
+       ucl_object_insert_key (obj, ucl_object_frombool (luapat),
+                       "luapat", 0, false);
 
        rspamadm_execute_lua_ucl_subr (L,
                        argc,
index 68dc2a92c06e0006df6c8dc6824478fef35f00c0..a9d4b084a04dcf39c20da59fb89d04320de8dd95 100644 (file)
@@ -15,6 +15,10 @@ return function(_, res)
     end
   end
 
+  local plainm = true
+  if res['luapat'] then
+    plainm = false
+  end
   local orphans = res['orphans']
   local search_str = res['string']
   local sensitive = res['sensitive']
@@ -63,10 +67,10 @@ return function(_, res)
         if re then
           ismatch = re:match(line)
         elseif sensitive and search_str then
-          ismatch = string.find(line, search_str)
+          ismatch = string.find(line, search_str, 1, plainm)
         elseif search_str then
           local lwr = string.lower(line)
-          ismatch = string.find(lwr, search_str)
+          ismatch = string.find(lwr, search_str, 1, plainm)
         end
         if ismatch then
           if not hash then