]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Merge pull request #1832 in SNORT/snort3 from ~BRASTULT/snort3:plugin_path_fix to...
authorRuss Combs (rucombs) <rucombs@cisco.com>
Mon, 18 Nov 2019 23:46:03 +0000 (23:46 +0000)
committerRuss Combs (rucombs) <rucombs@cisco.com>
Mon, 18 Nov 2019 23:46:03 +0000 (23:46 +0000)
Squashed commit of the following:

commit 9b38272cd911699b161dfdc4f9aaf15411c5e401
Author: Brandon Stultz <brastult@cisco.com>
Date:   Thu Oct 31 22:11:42 2019 -0400

    plugin_manager: allow loading individual plugin files in plugin-path

src/main/snort_config.cc
src/main/snort_config.h
src/main/snort_module.cc
src/managers/plugin_manager.cc

index 7447f8d335d26a13ca0d91d2623c9b6bae176912..f72881101eafcb5a1169e48c19a88f50f5d1e3ba 100644 (file)
@@ -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)
index f38db416621844b40941a1022a383d27f4f6c489..9cb93dbeb9d8189e5b714943a1b8664e911a65d7 100644 (file)
@@ -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);
index 99539355518fd815c0fa5b9ff39aadfc64819f77..2611a2c63546d05161d781608f40a01cbc99c3de 100644 (file)
@@ -466,7 +466,7 @@ static const Parameter s_params[] =
 #endif
 
     { "--plugin-path", Parameter::PT_STRING, nullptr, nullptr,
-      "<path> where to find plugins" },
+      "<path> 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);
index 8abb108e676a316f4e7036259b44ebe36aaf75bd..68b0a04923c40f16c3072ed703d1245b86084085 100644 (file)
 #include "plugin_manager.h"
 
 #include <dlfcn.h>
-#include <sys/stat.h>
-
 #include <iostream>
 #include <map>
+#include <sstream>
+#include <sys/stat.h>
 
 #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<char> buf(t, t+strlen(t)+1);
-    char* last;
+    struct stat sb;
+    stringstream paths_stream(paths);
+    string segment;
+    vector<string> 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());
+        }
     }
 }