Fix and extend behavior of HookLoadFile

This commit fixes and extends the behavior of HookLoadFile. Before this
change, HookLoadFile appended ".bro" to each path that was @loaded, even
if the path specified directory names. Furthermore it only gave the path
of the file as it was specified in the Bro script without revealing the
final path of the file that it was going to load.

This patch changes this behavior - in addition to giving the unmodified
path given in the @load command, the hook now returns the resolved path
of the file or directory it is going to load (if found). The hook is
furthermore raises for @load-sigs and @load-plugin; a enum specifies the
kind of load that is happening.
This commit is contained in:
Johanna Amann 2017-11-16 12:04:11 -08:00
parent bde4404b5e
commit 91dcefe104
8 changed files with 978 additions and 643 deletions

View file

@ -403,6 +403,13 @@ public:
typedef std::list<BifItem> bif_item_list;
typedef std::list<std::pair<HookType, int> > hook_list;
/**
* The different types of @loads supported by HookLoadFile.
*/
enum LoadType {
SCRIPT, SIGNATURES, PLUGIN
};
/**
* Constructor.
*/
@ -611,10 +618,15 @@ protected:
* script directives. The hook can take over the file, in which case
* Bro will not further process it otherwise.
*
* @param file The filename to be loaded, including extension.
* @param type The type of load encountered: script load, signatures load,
* or plugin load.
*
* @param ext The extension of the filename. This is provided
* separately just for convenience. The dot is excluded.
* @param file The filename that was passed to @load. Only includes
* an extension if it was given in @load.
*
* @param resolved The file or directory name Bro resolved from
* the given path and is going to load. Empty string
* if Bro was not able to resolve a path.
*
* @return 1 if the plugin took over the file and loaded it
* successfully; 0 if the plugin took over the file but had trouble
@ -622,7 +634,7 @@ protected:
* have printed an error message); and -1 if the plugin wasn't
* interested in the file at all.
*/
virtual int HookLoadFile(const std::string& file, const std::string& ext);
virtual int HookLoadFile(const LoadType type, const std::string& file, const std::string& resolved);
/**
* Hook into executing a script-level function/event/hook. Whenever