]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Squashed commit of the following:
authorRuss Combs <rucombs@cisco.com>
Fri, 7 Aug 2015 14:40:36 +0000 (10:40 -0400)
committerRuss Combs <rucombs@cisco.com>
Fri, 7 Aug 2015 14:40:36 +0000 (10:40 -0400)
commit cea192a5ee82ad5de3d06163d32e7c8740b72c54
Author: Russ Combs <rucombs@cisco.com>
Date:   Fri Aug 7 10:21:23 2015 -0400

    fix parameter range for those depending on loaded plugins
    reported by Siti Farhana Binti Lokman <sitifarhana.lokman@postgrad.manchester.ac.uk>

doc/params.txt
src/framework/parameter.cc
src/framework/parameter.h
src/main/help.cc
src/main/modules.cc
src/main/snort_module.cc
src/managers/module_manager.cc
src/managers/plugin_manager.cc
src/managers/plugin_manager.h

index 641b90bad3ab97acfa3b486bb7a4104a0fecef86..aeadcd94af991aa7db93ede059e70ebc8ad53b8a 100644 (file)
@@ -9,6 +9,7 @@ The following types are used:
 * *bit_list*: a list of consecutive integer values from 1 to the range
   maximum
 * *bool*: true or false
+* *dynamic*: a select type determined by loaded plugins
 * *enum*: a string selected from the given range
 * *implied*: an IPS rule option that takes no value but means true
 * *int*: a whole number in the given range
index ca03785eac1cf3551859f1c06f786ef70912df63..eb4ee7c0b4b593fb085d810da9c35c7b26596ab6 100644 (file)
@@ -371,6 +371,8 @@ bool Parameter::validate(Value& v) const
         return valid_multi(v, (const char*)range);
     case PT_ENUM:
         return valid_enum(v, (const char*)range);
+    case PT_DYNAMIC:
+        return valid_select(v, ((RangeQuery)range)());
 
     // address values
     case PT_MAC:
@@ -396,7 +398,7 @@ bool Parameter::validate(Value& v) const
 
 static const char* const pt2str[Parameter::PT_MAX] =
 {
-    "table", "list",
+    "table", "list", "dynamic",
     "bool", "int", "real", "port",
     "string", "select", "multi", "enum",
     "mac", "ip4", "addr",
@@ -409,6 +411,23 @@ const char* Parameter::get_type() const
     return pt2str[type];
 }
 
+const char* Parameter::get_range() const
+{
+    switch ( type )
+    {
+    case PT_TABLE:
+    case PT_LIST:
+        return nullptr;
+
+    case PT_DYNAMIC:
+        return ((RangeQuery)range)();
+
+    default:
+        break;
+    }
+    return (char*)range;
+}
+
 bool Parameter::get_bool() const
 {
     if ( !deflt )
index a3c24742c74936e01262b16e5c30813300a2e901..26e174d99799a3067b77b674f04ecc026653b463 100644 (file)
 
 struct SO_PUBLIC Parameter
 {
+    typedef const char* (*RangeQuery)();
+
     enum Type
     {
         PT_TABLE,      // range is Parameter*, no default
         PT_LIST,       // range is Parameter*, no default
+        PT_DYNAMIC,    // range is RangeQuery function ptr
         PT_BOOL,       // if you are reading this, get more coffee
         PT_INT,        // signed 64 bits or less determined by range
         PT_REAL,       // double
@@ -55,11 +58,12 @@ struct SO_PUBLIC Parameter
     };
     const char* name;
     Type type;
-    const void* range;  // nullptr|const char*|const Parameter*
+    const void* range;  // nullptr|const char*|RangeQuery|const Parameter*
     const char* deflt;
     const char* help;
 
     const char* get_type() const;
+    const char* get_range() const;
 
     bool validate(class Value&) const;
 
@@ -75,9 +79,6 @@ struct SO_PUBLIC Parameter
     bool is_quoted() const
     { return ( type > PT_PORT ); }
 
-    bool has_text_range() const
-    { return !is_table() and range != nullptr; }
-
     bool get_bool() const;
     double get_number() const;
     const char* get_string() const;
index ed2f4671e74441d985d90f916342f3131ca0ea41..8613d8262bf45399603802f5faf9e5737af61963 100644 (file)
@@ -102,12 +102,12 @@ void help_args(const char* pfx)
 
             cout << " " << Markup::escape(p->help);
 
-            if ( p->has_text_range() )
+            if ( const char* r = p->get_range() )
             {
-                if ( *((char*)p->range) == '(' )
-                    cout << " " << (char*)p->range;
+                if ( *r == '(' )
+                    cout << " " << r;
                 else
-                    cout << " (" << (char*)p->range << ")";
+                    cout << " (" << r << ")";
             }
             cout << endl;
         }
index a099593552fb6e47ee25bf7e2fa8acd2bb33f806..9834246e9d6e5e5d83814fa4559583e675fc77db 100644 (file)
@@ -32,6 +32,7 @@ using namespace std;
 
 #include "framework/module.h"
 #include "managers/module_manager.h"
+#include "managers/plugin_manager.h"
 #include "main.h"
 #include "main/snort.h"
 #include "main/snort_config.h"
@@ -177,10 +178,8 @@ bool EventQueueModule::set(const char*, Value& v, SnortConfig* sc)
 // search engine module
 //-------------------------------------------------------------------------
 
-// FIXIT-L valid search methods should be obtained from available mpse plugins
-#define SEARCH_METHODS \
-    "ac_banded | ac_bnfa | ac_bnfa_q | ac_full | ac_full_q | " \
-    "ac_sparse | ac_sparse_bands | ac_std"
+static const char* get_search_methods()
+{ return PluginManager::get_available_plugins(PT_SEARCH_ENGINE); }
 
 static const Parameter search_engine_params[] =
 {
@@ -220,7 +219,7 @@ static const Parameter search_engine_params[] =
     { "inspect_stream_inserts", Parameter::PT_BOOL, nullptr, "false",
       "inspect reassembled payload - disabling is good for performance, bad for detection" },
 
-    { "search_method", Parameter::PT_SELECT, SEARCH_METHODS, "ac_bnfa_q",
+    { "search_method", Parameter::PT_DYNAMIC, (void*)get_search_methods, "ac_bnfa_q",
       "set fast pattern algorithm - choose available search engine" },
 
     { "split_any_any", Parameter::PT_BOOL, nullptr, "false",
index d186cacfb0a72436c3a4f23961ecaacafb3e4d07..6176a080465ebe1372c2e0cbfb8354a86cc044e9 100644 (file)
@@ -35,9 +35,11 @@ using namespace std;
 #include "help.h"
 #include "shell.h"
 #include "detection/detect.h"
+#include "framework/base_api.h"
 #include "framework/module.h"
 #include "framework/parameter.h"
 #include "managers/module_manager.h"
+#include "managers/plugin_manager.h"
 #include "parser/config_file.h"
 #include "parser/parser.h"
 #include "parser/parse_utils.h"
@@ -117,12 +119,15 @@ static void x2s(const char* s)
 // help as well.
 //-------------------------------------------------------------------------
 
+static const char* get_alert_mode()
+{ return PluginManager::get_available_plugins(PT_LOGGER); }
+
 static const Parameter s_params[] =
 {
     { "-?", Parameter::PT_STRING, "(optional)", nullptr,
       "<option prefix> output matching command line option quick help (same as --help-options)" },
 
-    { "-A", Parameter::PT_STRING, nullptr, nullptr,
+    { "-A", Parameter::PT_DYNAMIC, (void*)get_alert_mode, nullptr,
       "<mode> set alert mode: none, cmg, or alert_*" },
 
     { "-B", Parameter::PT_IMPLIED, nullptr, nullptr,
index ae16b02064ab74ec9f0c0ee65b16db3f49e06c6f..8b3633cde51906d6bf04dd6398d44ead38110c17 100644 (file)
@@ -194,12 +194,12 @@ static void dump_field_std(const string& key, const Parameter* p)
     cout << " " << Markup::emphasis(Markup::escape(key));
 
     if ( p->deflt )
-        cout << " = " << Markup::escape((char*)p->deflt);
+        cout << " = " << Markup::escape(p->deflt);
 
     cout << ": " << p->help;
 
-    if ( p->range )
-        cout << " { " << Markup::escape((char*)p->range) << " }";
+    if ( const char* r = p->get_range() )
+        cout << " { " << Markup::escape(r) << " }";
 
     cout << endl;
 }
@@ -211,14 +211,14 @@ static void dump_field_tab(const string& key, const Parameter* p)
     cout << "\t" << Markup::emphasis(Markup::escape(key));
 
     if ( p->deflt )
-        cout << "\t" << Markup::escape((char*)p->deflt);
+        cout << "\t" << Markup::escape(p->deflt);
     else
         cout << "\t";
 
     cout << "\t" << p->help;
 
-    if ( p->range )
-        cout << "\t" << Markup::escape((char*)p->range);
+    if ( const char* r = p->get_range() )
+        cout << "\t" << Markup::escape(r);
     else
         cout << "\t";
 
index ede30cd6f373ebcf844b459deb851f4beaaa9e3a..66100171b0363af670a670a51f07f6679ecab815 100644 (file)
@@ -548,3 +548,23 @@ void PluginManager::instantiate(
         assert(false);
 }
 
+const char* PluginManager::get_available_plugins(PlugType t)
+{
+    static std::string s;
+    s.clear();
+
+    for ( auto it = plug_map.begin(); it != plug_map.end(); ++it )
+    {
+        const auto* api = it->second.api;
+
+        if ( t != api->type )
+            continue;
+
+        if ( !s.empty() )
+            s += " | ";
+
+        s += api->name;
+    }
+    return s.c_str();
+}
+
index 384db6e86f683aee9ec1d3161cb0e5fd4de5a84a..e7b9320f3170bf40ade4d0ed1c966a83c0235910 100644 (file)
@@ -60,6 +60,8 @@ public:
 
     static void instantiate(const BaseApi*, Module*, SnortConfig*);
     static void instantiate(const BaseApi*, Module*, SnortConfig*, const char* name);
+
+    static const char* get_available_plugins(PlugType);
 };
 
 #endif