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)
//------------------------------------------------------
// 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);
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);
#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" },
#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);
#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"
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());
+ }
}
}