]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
fixed luajit option
authorRuss Combs <rucombs@cisco.com>
Sun, 10 Aug 2014 15:16:05 +0000 (11:16 -0400)
committerRuss Combs <rucombs@cisco.com>
Sun, 10 Aug 2014 15:16:05 +0000 (11:16 -0400)
extra/src/ips_options/find.lua
src/ips_options/ips_luajit.cc
src/ips_options/ips_luajit.h
src/managers/ips_manager.cc
src/managers/plugin_manager.cc
src/managers/plugin_manager.h
src/managers/script_manager.cc

index 591987bcaf12a0895e4d1f915d03db2b426fe4de..187674109c794355291b95a90a157e17055e4091 100755 (executable)
@@ -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)
index 5f9a1dea101abae5adc8194d50561ed1057d58c4..cfed49d44b740d38bf5ddbe05cddc8f0bfdf0125 100644 (file)
@@ -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];
index 82b58949b65f1875cd9eea9abb99c35813412234..3c8b6671e2d968b3355c359400a92b0321641c46 100644 (file)
@@ -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*);
index 73b021cd856e79df34471c89282fce1a8f4fbf4e..b18ee470878d3c7bfc88cd8ae24c3a3c8469c7f5 100644 (file)
@@ -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 );
index 49be3f0923c2e3ee1bcffb834382bd28dbdf0968..ed9e4ebcef3870fda3f048e6102f945463c9f9f8 100644 (file)
@@ -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);
     }
index 73d573b4c36125bbde5833718061d20088ba4947..a9dc8da3d7fd560065279d3087b6c07c84b24877 100644 (file)
@@ -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
index 1d3535eaf4fb07f16e030f430afd440b856a3a04..e08da752d66aa023344134f94beba5b63b570499 100644 (file)
@@ -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<LuaIpsApi*> 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)