From: Russ Combs Date: Sun, 10 Aug 2014 15:16:05 +0000 (-0400) Subject: fixed luajit option X-Git-Tag: 3.0.0-233~1426^2~26 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=275f0cbf72ccef503d44f0abf14aa7d41d303476;p=thirdparty%2Fsnort3.git fixed luajit option --- diff --git a/extra/src/ips_options/find.lua b/extra/src/ips_options/find.lua index 591987bca..187674109 100755 --- a/extra/src/ips_options/find.lua +++ b/extra/src/ips_options/find.lua @@ -15,8 +15,8 @@ -- -- alert tcp any any -> any 80 ( \ -- msg:"luajit example"; sid:1; \ --- content:"GET /"; \ --- find:pat "GET .+ HTTP/1.1"; ) +-- content:"GET"; \ +-- find:"pat='HTTP/1%.%d'"; ) -- -- the arg string is (in general) optional -- if present, it will be put in a table named args, eg: @@ -24,6 +24,8 @@ -- args { pat='GET .+ HTTP/1.1' } -- -- this table is defined before init is called +-- the args string, if present, must be valid lua code like +-- name1 = value1, name2 = 'value2'. -- ---------------------------------------------------------- -- this pulls in snort bindings with ffi @@ -51,7 +53,7 @@ function eval () -- see snort.lua for available buffers -- buf is a luajit cdata - local buf = ffi.C.get_cursor() + local buf = ffi.C.get_buffer() -- str is a lua string local str = ffi.string(buf.data, buf.len) diff --git a/src/ips_options/ips_luajit.cc b/src/ips_options/ips_luajit.cc index 5f9a1dea1..cfed49d44 100644 --- a/src/ips_options/ips_luajit.cc +++ b/src/ips_options/ips_luajit.cc @@ -110,13 +110,8 @@ static void init_lua( ParseError("%s luajit failed to init chunk %s", name, lua_tostring(L, -1)); - // create an args table with any rule options - string table("args = {"); - table += args; - table += "}"; - // load the args table - if ( luaL_loadstring(L, table.c_str()) ) + if ( luaL_loadstring(L, args.c_str()) ) ParseError("%s luajit failed to load args %s", name, lua_tostring(L, -1)); @@ -162,13 +157,13 @@ static void term_lua(lua_State*& L) static const Parameter luajit_params[] = { - { "*", Parameter::PT_STRING, nullptr, nullptr, + { "~", Parameter::PT_STRING, nullptr, nullptr, "luajit arguments" }, { nullptr, Parameter::PT_MAX, nullptr, nullptr, nullptr } }; -LuaJitModule::LuaJitModule() : Module("luajit", luajit_params) +LuaJitModule::LuaJitModule(const char* name) : Module(name, luajit_params) { } ProfileStats* LuaJitModule::get_profile() const @@ -194,7 +189,21 @@ LuaJitOption::LuaJitOption( const char* name, string& chunk, LuaJitModule* mod) : IpsOption(name) { - config = mod->args; + string args = mod->args; + + // if args not empty, it has to be a quoted string + // so remove enclosing quotes + if ( args.size() > 1 ) + { + args.erase(0, 1); + args.erase(args.size()-1); + } + + // create an args table with any rule options + config = "args = { "; + config += args; + config += "}"; + unsigned max = get_instance_max(); lua = new lua_State*[max]; diff --git a/src/ips_options/ips_luajit.h b/src/ips_options/ips_luajit.h index 82b58949b..3c8b6671e 100644 --- a/src/ips_options/ips_luajit.h +++ b/src/ips_options/ips_luajit.h @@ -28,7 +28,7 @@ class LuaJitModule : public Module { public: - LuaJitModule(); + LuaJitModule(const char* name); bool begin(const char*, int, SnortConfig*); bool set(const char*, Value&, SnortConfig*); diff --git a/src/managers/ips_manager.cc b/src/managers/ips_manager.cc index 73b021cd8..b18ee4708 100644 --- a/src/managers/ips_manager.cc +++ b/src/managers/ips_manager.cc @@ -247,7 +247,6 @@ bool IpsManager::option_end( #endif Module* mod = current_module; - current_keyword = nullptr; current_module = nullptr; current_params = nullptr; @@ -255,6 +254,7 @@ bool IpsManager::option_end( { ErrorMessage("ERROR can't finalize %s\n", key); s_errors++; + current_keyword = nullptr; return false; } @@ -264,6 +264,7 @@ bool IpsManager::option_end( // FIXIT need to error out in the end if any errors IpsOption* ips = opt->api->ctor(mod, otn); type = opt->api->type; + current_keyword = nullptr; if ( !ips ) return ( type == OPT_TYPE_META ); diff --git a/src/managers/plugin_manager.cc b/src/managers/plugin_manager.cc index 49be3f092..ed9e4ebce 100644 --- a/src/managers/plugin_manager.cc +++ b/src/managers/plugin_manager.cc @@ -100,6 +100,11 @@ const char* PluginManager::get_type_name(PlugType pt) return symbols[pt].name; } +static const char* current_plugin = nullptr; + +const char* PluginManager::get_current_plugin() +{ return current_plugin; } + struct Plugin { string key; @@ -214,6 +219,7 @@ static void add_plugin(Plugin& p) { if ( p.api->mod_ctor ) { + current_plugin = p.api->name; Module* m = p.api->mod_ctor(); ModuleManager::add_module(m, p.api); } diff --git a/src/managers/plugin_manager.h b/src/managers/plugin_manager.h index 73d573b4c..a9dc8da3d 100644 --- a/src/managers/plugin_manager.h +++ b/src/managers/plugin_manager.h @@ -52,6 +52,7 @@ public: static const BaseApi* get_api(PlugType, const char* name); static void instantiate(const BaseApi*, Module*, SnortConfig*); static const char* get_type_name(PlugType); + static const char* get_current_plugin(); }; #endif diff --git a/src/managers/script_manager.cc b/src/managers/script_manager.cc index 1d3535eaf..e08da752d 100644 --- a/src/managers/script_manager.cc +++ b/src/managers/script_manager.cc @@ -27,6 +27,7 @@ #include "ips_manager.h" #include "framework/ips_option.h" +#include "managers/plugin_manager.h" #include "ips_options/ips_luajit.h" #include "parser/parser.h" #include "helpers/directory.h" @@ -62,7 +63,8 @@ static vector ips_options; static Module* mod_ctor() { - return new LuaJitModule; + const char* key = PluginManager::get_current_plugin(); + return new LuaJitModule(key); } static void mod_dtor(Module* m) @@ -88,7 +90,7 @@ static IpsOption* ctor(Module* m, struct OptTreeNode*) return nullptr; LuaJitModule* mod = (LuaJitModule*)m; - return new LuaJitOption(api->name.c_str(), api->chunk, mod); + return new LuaJitOption(key, api->chunk, mod); } static void dtor(IpsOption* p)