From: Andrew Lewis Date: Tue, 25 Apr 2017 14:36:34 +0000 (+0200) Subject: [Fix] Rspamadm grep: Disable Lua patterns in string search by default X-Git-Tag: 1.5.7~12 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=396fc8458a3d4c21ed2f3a690adb1f3b9bddb8ec;p=rspamd.git [Fix] Rspamadm grep: Disable Lua patterns in string search by default --- diff --git a/src/rspamadm/grep.c b/src/rspamadm/grep.c index b88347a8b..9665b40e8 100644 --- a/src/rspamadm/grep.c +++ b/src/rspamadm/grep.c @@ -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, diff --git a/src/rspamadm/grep.lua b/src/rspamadm/grep.lua index 68dc2a92c..a9d4b084a 100644 --- a/src/rspamadm/grep.lua +++ b/src/rspamadm/grep.lua @@ -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