From: Russ Combs (rucombs) Date: Mon, 18 Nov 2019 23:46:03 +0000 (+0000) Subject: Merge pull request #1832 in SNORT/snort3 from ~BRASTULT/snort3:plugin_path_fix to... X-Git-Tag: 3.0.0-265~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=590f603fe432742e2a8b893e1e143aa03cfd8344;p=thirdparty%2Fsnort3.git Merge pull request #1832 in SNORT/snort3 from ~BRASTULT/snort3:plugin_path_fix to master Squashed commit of the following: commit 9b38272cd911699b161dfdc4f9aaf15411c5e401 Author: Brandon Stultz Date: Thu Oct 31 22:11:42 2019 -0400 plugin_manager: allow loading individual plugin files in plugin-path --- diff --git a/src/main/snort_config.cc b/src/main/snort_config.cc index 7447f8d33..f72881101 100644 --- a/src/main/snort_config.cc +++ b/src/main/snort_config.cc @@ -990,12 +990,15 @@ void SnortConfig::set_include_path(const char* path) include_path.clear(); } -void SnortConfig::set_plugin_path(const char* path) +void SnortConfig::add_plugin_path(const char* path) { - if (path) - plugin_path = path; + if (!path) + return; + + if (!plugin_path.empty()) + plugin_path += ":" + std::string(path); else - plugin_path.clear(); + plugin_path = path; } void SnortConfig::set_tweaks(const char* t) diff --git a/src/main/snort_config.h b/src/main/snort_config.h index f38db4166..9cb93dbeb 100644 --- a/src/main/snort_config.h +++ b/src/main/snort_config.h @@ -425,6 +425,7 @@ public: //------------------------------------------------------ // Non-static mutator methods + void add_plugin_path(const char*); void add_script_path(const char*); void enable_syslog(); void set_alert_before_pass(bool); @@ -445,7 +446,6 @@ public: void set_obfuscate(bool); void set_obfuscation_mask(const char*); void set_include_path(const char*); - void set_plugin_path(const char*); void set_process_all_events(bool); void set_quiet(bool); void set_show_year(bool); diff --git a/src/main/snort_module.cc b/src/main/snort_module.cc index 995393555..2611a2c63 100644 --- a/src/main/snort_module.cc +++ b/src/main/snort_module.cc @@ -466,7 +466,7 @@ static const Parameter s_params[] = #endif { "--plugin-path", Parameter::PT_STRING, nullptr, nullptr, - " where to find plugins" }, + " a colon separated list of directories or plugin libraries" }, { "--process-all-events", Parameter::PT_IMPLIED, nullptr, nullptr, "process all action groups" }, @@ -946,7 +946,7 @@ bool SnortModule::set(const char*, Value& v, SnortConfig* sc) #endif else if ( v.is("--plugin-path") ) - sc->set_plugin_path(v.get_string()); + sc->add_plugin_path(v.get_string()); else if ( v.is("--process-all-events") ) sc->set_process_all_events(true); diff --git a/src/managers/plugin_manager.cc b/src/managers/plugin_manager.cc index 8abb108e6..68b0a0492 100644 --- a/src/managers/plugin_manager.cc +++ b/src/managers/plugin_manager.cc @@ -24,10 +24,10 @@ #include "plugin_manager.h" #include -#include - #include #include +#include +#include #include "framework/codec.h" #include "framework/connector.h" @@ -339,21 +339,34 @@ static void add_plugin(Plugin& p) static void load_plugins(const std::string& paths) { - const char* t = paths.c_str(); - vector buf(t, t+strlen(t)+1); - char* last; + struct stat sb; + stringstream paths_stream(paths); + string segment; + vector path_list; - char* s = strtok_r(&buf[0], ":", &last); + while ( getline(paths_stream, segment, ':') ) + if ( segment.length() > 0 ) + path_list.push_back(segment); - while ( s ) + for ( auto& path : path_list ) { - Directory d(s, lib_pattern); - const char* f; + if ( stat(path.c_str(), &sb) ) + continue; + + if ( sb.st_mode & S_IFDIR ) + { + Directory d(path.c_str(), lib_pattern); - while ( (f = d.next()) ) - load_lib(f); + while ( const char* f = d.next() ) + load_lib(f); + } + else + { + if ( path.find("/") == string::npos ) + path = "./" + path; - s = strtok_r(nullptr, ":", &last); + load_lib(path.c_str()); + } } }