diff --git a/src/input/Manager.cc b/src/input/Manager.cc index ad52edfa06..68964dd121 100644 --- a/src/input/Manager.cc +++ b/src/input/Manager.cc @@ -2536,8 +2536,31 @@ Val* Manager::ValueToVal(const Stream* i, const Value* val, bool& have_error) co if ( stag == TYPE_VOID ) TypeTag stag = val->val.set_val.vals[0]->type; - set_index = new TypeList(base_type(stag)->Ref()); - set_index->Append(base_type(stag)->Ref()); + BroType* index_type; + + if ( stag == TYPE_ENUM ) + { + // Enums are not a base-type, so need to look it up. + const auto& sv = val->val.set_val.vals[0]->val.string_val; + std::string enum_name(sv.data, sv.length); + auto enum_id = global_scope()->Lookup(enum_name); + + if ( ! enum_id ) + { + Warning(i, "Value '%s' for stream '%s' is not a valid enum.", + enum_name.data(), i->name.c_str()); + + have_error = true; + return nullptr; + } + + index_type = enum_id->Type()->AsEnumType(); + } + else + index_type = base_type_no_ref(stag); + + set_index = new TypeList(index_type); + set_index->Append(index_type->Ref()); } SetType* s = new SetType(set_index, 0); diff --git a/testing/btest/Baseline/scripts.base.frameworks.input.config.enum-set/zeek..stdout b/testing/btest/Baseline/scripts.base.frameworks.input.config.enum-set/zeek..stdout new file mode 100644 index 0000000000..c38913d6aa --- /dev/null +++ b/testing/btest/Baseline/scripts.base.frameworks.input.config.enum-set/zeek..stdout @@ -0,0 +1,12 @@ +DPD::ignore_violations, { + +} +--- +{ +Analyzer::ANALYZER_SYSLOG +} +--- +DPD::ignore_violations, { +Analyzer::ANALYZER_SYSLOG +} +--- diff --git a/testing/btest/Baseline/scripts.base.frameworks.input.config.enum-set/zeek.config.log b/testing/btest/Baseline/scripts.base.frameworks.input.config.enum-set/zeek.config.log new file mode 100644 index 0000000000..732d185efa --- /dev/null +++ b/testing/btest/Baseline/scripts.base.frameworks.input.config.enum-set/zeek.config.log @@ -0,0 +1,10 @@ +#separator \x09 +#set_separator , +#empty_field (empty) +#unset_field - +#path config +#open 2019-10-03-04-02-02 +#fields ts id old_value new_value location +#types time string string string string +1570075321.966826 DPD::ignore_violations (empty) Analyzer::ANALYZER_SYSLOG - +#close 2019-10-03-04-02-02 diff --git a/testing/btest/scripts/base/frameworks/input/config/enum-set.zeek b/testing/btest/scripts/base/frameworks/input/config/enum-set.zeek new file mode 100644 index 0000000000..1bfd964202 --- /dev/null +++ b/testing/btest/scripts/base/frameworks/input/config/enum-set.zeek @@ -0,0 +1,46 @@ +# @TEST-EXEC: btest-bg-run zeek zeek -b %INPUT +# @TEST-EXEC: btest-bg-wait 10 +# @TEST-EXEC: btest-diff zeek/.stdout +# @TEST-EXEC: btest-diff zeek/config.log + +@TEST-START-FILE configfile4 +DPD::ignore_violations Analyzer::ANALYZER_SYSLOG +@TEST-END-FILE + +@load base/frameworks/config +@load base/frameworks/dpd + +redef exit_only_after_terminate = T; +redef InputConfig::empty_field = "EMPTY"; +redef InputConfig::set_separator = "\t"; + +type Idx: record { + option_name: string; +}; + +type Val: record { + option_val: string; +}; + +global currconfig: table[string] of string = table(); + +event InputConfig::new_value(name: string, source: string, id: string, value: any) + { + print id, lookup_ID(id); + print "---"; + print value; + print "---"; + Config::set_value(id, value); + print id, lookup_ID(id); + print "---"; + } + +event Input::end_of_data(name: string, source:string) + { + terminate(); + } + +event zeek_init() + { + Input::add_table([$reader=Input::READER_CONFIG, $source="../configfile4", $name="configuration", $idx=Idx, $val=Val, $destination=currconfig, $want_record=F]); + }