mirror of
https://github.com/zeek/zeek.git
synced 2025-10-07 17:18:20 +00:00
Re-instantiate providing location information to LoadFile
hooks.
#1835 subtly changed the semantics of the `LoadFile` plugin hook to no longer have the current script location available for signature files being loaded through `@load-sigs`. This was undocumented behavior, so it's technically not a regression, but since at least one external plugin is depending on it, this change restores the old behavior.
This commit is contained in:
parent
d29160e9de
commit
fccb9ccab0
8 changed files with 66 additions and 11 deletions
|
@ -26,9 +26,15 @@ std::pair<int, std::optional<std::string>> Plugin::HookLoadFileExtended(const Lo
|
|||
const std::string& file,
|
||||
const std::string& resolved)
|
||||
{
|
||||
// Zeek implicitly provides the location where the current '@load'
|
||||
// originated. If no location is available, filename will be a nullptr.
|
||||
auto src = zeek::detail::GetCurrentLocation().filename;
|
||||
if ( ! src )
|
||||
src = "n/a";
|
||||
|
||||
if ( type == LoadType::SCRIPT && file == "xxx" )
|
||||
{
|
||||
printf("HookLoadExtended/script: file=|%s| resolved=|%s|\n", file.c_str(), resolved.c_str());
|
||||
printf("HookLoadExtended/script: file=|%s| resolved=|%s| srcloc=|%s|\n", file.c_str(), resolved.c_str(), src);
|
||||
|
||||
return std::make_pair(1, R"(
|
||||
event zeek_init() {
|
||||
|
@ -41,9 +47,16 @@ std::pair<int, std::optional<std::string>> Plugin::HookLoadFileExtended(const Lo
|
|||
)");
|
||||
}
|
||||
|
||||
if ( type == LoadType::SCRIPT && file == "xxx3" )
|
||||
{
|
||||
printf("HookLoadExtended/script: file=|%s| resolved=|%s| srcloc=|%s|\n", file.c_str(), resolved.c_str(), src);
|
||||
// We don't replace this one.
|
||||
return std::make_pair(-1, std::nullopt);
|
||||
}
|
||||
|
||||
if ( type == LoadType::SCRIPT && file == "yyy" )
|
||||
{
|
||||
printf("HookLoadExtended/script: file=|%s| resolved=|%s|\n", file.c_str(), resolved.c_str());
|
||||
printf("HookLoadExtended/script: file=|%s| resolved=|%s| srcloc=|%s|\n", file.c_str(), resolved.c_str(), src);
|
||||
|
||||
return std::make_pair(1, R"(
|
||||
event zeek_init() {
|
||||
|
@ -54,7 +67,7 @@ std::pair<int, std::optional<std::string>> Plugin::HookLoadFileExtended(const Lo
|
|||
|
||||
if ( type == LoadType::SIGNATURES && file == "abc.sig" )
|
||||
{
|
||||
printf("HookLoadExtended/signature: file=|%s| resolved=|%s|\n", file.c_str(), resolved.c_str());
|
||||
printf("HookLoadExtended/signature: file=|%s| resolved=|%s| srcloc=|%s|\n", file.c_str(), resolved.c_str(), src);
|
||||
|
||||
return std::make_pair(1, R"(
|
||||
signature my-sig {
|
||||
|
@ -65,6 +78,13 @@ std::pair<int, std::optional<std::string>> Plugin::HookLoadFileExtended(const Lo
|
|||
)");
|
||||
}
|
||||
|
||||
if ( type == LoadType::SIGNATURES && file == "def.sig" )
|
||||
{
|
||||
printf("HookLoadExtended/signature: file=|%s| resolved=|%s| srcloc=|%s|\n", file.c_str(), resolved.c_str(), src);
|
||||
// We don't replace this one.
|
||||
return std::make_pair(-1, std::nullopt);
|
||||
}
|
||||
|
||||
return std::make_pair(-1, std::nullopt);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue