From: russ Date: Mon, 25 Jul 2022 20:20:26 +0000 (-0400) Subject: ffi: add get_module_version(name, type) for conditional config X-Git-Tag: 3.1.40.0~12 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c62681b4d00fb26bdea4795375c643b763978921;p=thirdparty%2Fsnort3.git ffi: add get_module_version(name, type) for conditional config --- diff --git a/src/main/bootstrap.lua b/src/main/bootstrap.lua index c3b498405..ed3a5a00b 100644 --- a/src/main/bootstrap.lua +++ b/src/main/bootstrap.lua @@ -28,6 +28,7 @@ const char* push_include_path(const char*); void pop_include_path(); void snort_whitelist_append(const char*); void snort_whitelist_add_prefix(const char*); +int get_module_version(const char* name, const char* type); ]] function whitelist_append(list, is_prefix) @@ -63,6 +64,10 @@ function initialize_whitelist(tab) end end +function get_module_version(name, type) + return ffi.C.get_module_version(name, type) +end + --------------------------------------------------------------------------- -- path magic for includes --------------------------------------------------------------------------- @@ -149,6 +154,7 @@ function create_sandbox_env() SNORT_MINOR_VERSION = SNORT_MINOR_VERSION, SNORT_PATCH_VERSION = SNORT_PATCH_VERSION, SNORT_SUBLEVEL_VERSION = SNORT_SUBLEVEL_VERSION, + get_module_version = get_module_version, tweaks = tweaks, } diff --git a/src/managers/module_manager.cc b/src/managers/module_manager.cc index 02fa5c99f..0c9ffbae8 100644 --- a/src/managers/module_manager.cc +++ b/src/managers/module_manager.cc @@ -106,6 +106,8 @@ extern "C" void snort_whitelist_append(const char*); void snort_whitelist_add_prefix(const char*); + + int get_module_version(const char* name, const char* type); } //------------------------------------------------------------------------- @@ -741,6 +743,25 @@ SO_PUBLIC bool set_includer(const char* fqn, const char* s) return true; } +// cppcheck-suppress unusedFunction +SO_PUBLIC int get_module_version(const char* name, const char* type) +{ + // not all modules are plugins + // not all plugins have modules + ModHook* h = get_hook(name); + + if ( !h ) + { + if ( !type ) + return -1; + + PlugType pt = PluginManager::get_type(type); + return PluginManager::get_api(pt, name) ? 0 : -1; + } + + return h->api ? (int)h->api->version : 0; +} + //------------------------------------------------------------------------- // ffi methods - also called internally so no cppcheck suppressions //-------------------------------------------------------------------------