Commit graph

101 commits

Author SHA1 Message Date
Johanna Amann
c8e1a39758 Input: Further small changes to error handling
Calling Error() in an input reader now automatically will disable the
reader and return a failure in the Update/Heartbeat calls.

Also adds more tests.

Addresses BIT-1181
2016-07-25 15:35:46 -07:00
Johanna Amann
6b9abe85a7 Add error events to input framework.
This change introduces error events for Table and Event readers. Users
can now specify an event that is called when an info, warning, or error
is emitted by their input reader. This can, e.g., be used to raise
notices in case errors occur when reading an important input stream.

Example:

event error_event(desc: Input::TableDescription, msg: string, level: Reporter::Level)
	{
	...
	}

event bro_init()
	{
	Input::add_table([$source="a", $error_ev=error_event, ...]);
	}

For the moment, this converts all errors in the Asciiformatter into
warnings (to show that they are non-fatal) - the Reader itself also has
to throw an Error to show that a fatal error occurred and processing
will be abort.

It might be nicer to change this and require readers to mark fatal
errors as such when throwing them.

Addresses BIT-1181
2016-07-22 19:45:28 -07:00
Johanna Amann
efab728876 Merge branch 'topic/jgras/input-default' of https://github.com/J-Gras/bro
* 'topic/jgras/input-default' of https://github.com/J-Gras/bro:
  Fixed &default values ignored by input framework.

BIT-1623 #merged
2016-06-15 17:32:50 -07:00
Jan Grashoefer
8d853872a4 Fixed &default values ignored by input framework.
Reading into a record, the input framework will no longer reset a
&default value in case there is no value to read.
2016-06-16 01:02:51 +02:00
Johanna Amann
e8418ad5b0 Ascii Input: Accept dos/windows newlines.
The ascii reader now accepts \r\n newlines without complaining.
Furthermore, the reader was slightly rewritten in a more c++11-y way,
removing all raw pointers from the class.

Addresses BIT-1198
2016-06-01 11:21:44 -07:00
Johanna Amann
a052dc4e35 Fix offset=-1 (eof) for raw reader
Addresses BIT-1479
2015-09-16 15:16:04 -07:00
Johanna Amann
cbba73ab12 add seeking functionality to raw reader.
one can now add an option "offset" to the config map. Positive offsets
are interpreted to be from the beginning of the file, negative from the
end of the file (-1 is end of file).

Only works for raw reader in streaming or manual mode. Does not work
with executables.

Addresses BIT-985
2015-04-17 11:19:12 -07:00
Johanna Amann
f79b5adc08 Merge remote-tracking branch 'origin/topic/vladg/ssh'
I replaced a few strcmps with either calls to std::str.compare
or with the == operator of BroString.

Also changed two of the input framework tests that did not pass
anymore after the merge. The new SSH analyzer no longer loads the
scripts that let network time run, hence those tests failed because
updates were not propagated from the threads (that took a while
to find.)

* origin/topic/vladg/ssh: (25 commits)
  SSH: Register analyzer for 22/tcp.
  SSH: Add 22/tcp to likely_server_ports
  SSH: Ignore encrypted packets by default.
  SSH: Fix some edge-cases which created BinPAC exceptions
  SSH: Add memleak btest
  SSH: Update baselines
  SSH: Added some more events for SSH2
  SSH: Intel framework integration (PUBKEY_HASH)
  Update baselines for new SSH analyzer.
  Update SSH policy scripts with new events.
  SSH: Add documentation
  Refactoring ssh-protocol.pac:
  SSH: Use the compression_algorithms const in another place.
  Some cleanup and refactoring on SSH main.bro.
  SSH: A bit of code cleanup.
  Move SSH constants to consts.pac
  SSH: Cleanup code style.
  SSH: Fix some memleaks.
  Refactored the SSH analyzer. Added supported for algorithm detection and more key exchange message types.
  Add host key support for SSH1.
  Add support for SSH1
  Move SSH analyzer to new plugin architecture.
  ...

Conflicts:
  scripts/base/protocols/ssh/main.bro
  testing/btest/Baseline/core.print-bpf-filters/output2
  testing/btest/Baseline/plugins.hooks/output

BIT-1344: #merged
2015-03-25 11:04:26 -07:00
Johanna Amann
c27848fc32 Change the way the input framework deals with values it cannot convert
into BroVals (especially enums)

Not we do not force an internal error anymore. Instead, we raise an
normal error and set an error flag that signals to the top-level
functions that the value could not be converted and should not be
propagated to the Bro core. This sadly makes the already messy code even
more messy - but since errors can happen in deeply nested data
structures, the alternative (catching the error at every possible
location and then trying to clean up there instead of recursively
deleting the data that cannot be used later) is much worse.

Addresses BIT-1199
2015-03-19 14:58:38 -07:00
Robin Sommer
5dea09b7c1 Baseline updates for the addition of local_resp.
That patch is a strong contender for the smallest ever ratio of
lines-of-code-changed to lines-of-baselines-updated. :-)
2015-02-23 16:25:11 -08:00
Bernhard Amann
3c59aa9459 Several fixes for input manager error handling.
- First:
Due to architectural constraints, it is very hard for the
input framework to handle optional records. For an optional record,
either the whole record has to be missing, or all non-optional elements
of the record have to be defined. This information is not available
to input readers after the records have been unrolled into the threading
types.

Behavior so far was to treat optional records like they are non-optional,
without warning. The patch changes this behavior to emit an error on stream-
creation (during type-checking) and refusing to open the file. I think this
is a better idea - the behavior so far was undocumented and unintuitive.

- Second:
For table and event streams, reader backend creation was done very early,
before actually checking if all arguments are valid. Initialization is moved
after the checks now - this makes a number of delete statements unnecessary.
Also - I suspect threads of failed input reader instances were not deleted
until shutdown

- Third:
Add a couple more consistency checks, e.g. checking if the destination value
of a table has the same type as we need. We did not check everything in all
instances, instead we just assigned the things without caring (which works,
but is not really desirable).

This change also exposed a few bugs in other testcases where table definitions
were wrong (did not respect $want_record)

- Fourth:
Improve error messages and write testcases for all error messages (I think).
2013-12-05 15:53:12 -08:00
Bernhard Amann
363cfb8506 rename the dbname configuration option to tablename.
Sorry for this - I noticed that I named this option quite unfortunately
while writing the documentation.

The patch also removes the dbname configuration option from the sqlite
input reader - it was not used there at all anymore (and I did not notice
that).
2013-10-17 12:24:40 -07:00
Daniel Thayer
1d23f055ba Add check for sqlite3 command to tests that require it 2013-10-14 15:05:06 -05:00
Jon Siwek
e202500f5f Fix a unit test. 2013-08-15 15:53:00 -05:00
Jon Siwek
4198414118 Add a diff canonifier to a test in need of it. 2013-08-14 15:10:47 -05:00
Jon Siwek
85084f2493 Input framework unit test adjustments.
- Generally increased the time allowed before they timeout.

- For tests w/ a clear termination condition (most of them), made
  timeouts result in a test failure.

- Seemed to be a race in some cases between tests generating output and
  the input reader stream getting removed/closed, so moved stream removal
  closer to termination time, when all output should be available.
2013-08-14 14:10:04 -05:00
Jon Siwek
d3dad31bdc Raw input reader command execution "fixes".
- Primarily working around an issue that occurs when threads
  concurrently create pipes and fork a child process.  See comment in
  code...

- Other minor cleanup of the code:  making sure the child process calls
  _exit() versus exit(), limits itself to few select system calls before
  the exec(), and closes more unused file descriptors.
2013-08-14 11:37:30 -05:00
Jon Siwek
1531980f3d Exec module and raw input reader fixes.
- Do stream mode for commands done by exec module, it seems important
  in some cases (e.g. ensure requested stdin is fully written).

- For cases where the raw input reader knows the child process has been
  reaped, set the childpid member to a sentinel value to indicate such
  so we don't later think we should kill it or wait on it anymore.

- More error checking on dup2/close calls.  Set sentinel values when
  closing ends of pipes to prevent double closing a fd.

- Signal flag not set when raw input reader's child exits as a result
  of a signal.  Left out a test for this -- might be portability issues
  (e.g. Ubuntu seems to do things different regarding the exit code and
  also is printing "Killed" to stderr where other platforms don't).
2013-08-02 17:27:10 -05:00
Bernhard Amann
f1745ff488 fix stderr test. ls behaves differently on errors on linux... 2013-05-27 23:07:37 -07:00
Bernhard Amann
08656c976b small fixes. 2013-05-27 22:59:27 -07:00
Bernhard Amann
3719524a6a Merge remote branch 'origin/master' into topic/bernhard/input-update 2013-05-27 20:32:50 -07:00
Bernhard Amann
2b009939f5 and there is no has-reader. 2013-05-14 22:12:23 -07:00
Bernhard Amann
2ad67643c0 make sqlite3 executable required and add test-cases for errors
logging: table does not contain all required columns (when extending
data structures)

input: table does not contain all required columns (when extending
data structure), wrong sql statement
2013-05-14 22:09:46 -07:00
Bernhard Amann
8f7619971f fix bug in input-manager regarding enums that a writer reads without
0-terminating the string
2013-05-13 20:26:41 -07:00
Bernhard Amann
6c99df508c actually make sqlite work again (tests passed because the writer
was not actually defined because of the define.)
2013-05-13 19:27:11 -07:00
Bernhard Amann
8875953751 A bunch of more changes for the raw reader
* send end_of_data event for all kind of streams
* send process_finished event containing exit code of child process for executed programs
* move raw-tests to separate directory
* expose name of input stream to readers
* better handling of some error cases in raw reader
* new force_kill option for raw reader which SIGKILLs progesses on exit

The ordering of events how they arrive in the main loop is a bit peculiar at the moment.
The process_finished event arrives in scriptland before all of the other events, even though
it should be sent last. I have not yet fully figured that out.
2013-03-18 21:49:16 -07:00
Bernhard Amann
6fef99ee03 make reading from stdout and stderr simultaneously work.
Needs a few test-cases - but seems ok...
2013-03-16 09:54:48 -07:00
Bernhard Amann
3aeec7ec14 allow sending data to stdin of child process 2013-03-15 15:47:20 -07:00
Bernhard Amann
fc42c71dfa Streaming reads from external commands work without blocking anything. 2013-03-15 13:58:41 -07:00
Bernhard Amann
fdc8de7596 add sqlite tests and fix small vector/set escaping bugs 2013-03-11 14:22:35 -07:00
Bernhard Amann
8cb91de93a Merge remote-tracking branch 'origin/master' into topic/bernhard/sqlite
Conflicts:
	src/threading/AsciiFormatter.cc
2013-03-11 11:47:10 -07:00
Bernhard Amann
1fb05da9cd Fix race-condition in table-event test.
Event depended on the input manager receiving all lines from the reader
before the first input event was processed by the scripting layer.
2013-03-07 20:28:18 -08:00
Bernhard Amann
dd24d7af83 update input tests to use exit_only_after_terminate 2013-02-01 15:45:21 -08:00
Jon Siwek
acafcfafd2 Revert "Trick for parallelizing input framework unit tests."
This reverts commit 43ed437daa.

The old way of doing the tests seems more reliable for now.
2013-01-18 13:15:34 -06:00
Bernhard Amann
0fcc3db9a0 start adding a different text for empty records for the sqlite writer.
Sadly there also seems to be another deadlock issue which I am currently
not really able to figure out - on shutdown sometimes (too often) the main
thread + all sqlite threads wait for semaphores or mutexes.
2013-01-16 18:13:39 -08:00
Bernhard Amann
3415b5fcbe make sqlite support more or less work for logging and input
* add support for &type_column for reading
* add basic tests for logging & input
* clean up a bit
* add support for tables for reading (untested)
2013-01-15 16:01:30 -08:00
Jon Siwek
43ed437daa Trick for parallelizing input framework unit tests.
Instead of loading listen.bro to block until files are read, just read
a pcap file in pseudo-realtime.  Seems to work well.
2012-12-11 17:06:54 -06:00
Bernhard Amann
d367e227c1 ok, this one is a bit... embarrassing.
Delete the correct entry in case of error. Fixes a segfault when the faulty
data is of type string and not the last field of the input...
2012-12-05 12:40:00 -08:00
Bernhard Amann
a6d87fcab7 rename the update_finished event to end_of_data and make it fire in
more cases.

It will now not only fire after table-reads have been completed,
but also after the last event of a whole-file-read (or whole-db-read, etc.).

The interface also has been extended a bit to allow readers to
directly fire the event should they so choose. This allows the
event to be fired in direct table-setting/event-sending modes,
which was previously not possible.
2012-10-10 11:51:20 -07:00
Bernhard Amann
4cbf4e3caf Small but important fix for the input framework. BroStrings were constructed
without a final \0 - which means that strings read by the input framework are
unusable by basically all internal functions (like to_count).

the basic test now also checks this.

Thanks at Sheharbano for noticing this.
2012-10-01 13:04:40 -07:00
Robin Sommer
20c71cac51 Merge remote-tracking branch 'remotes/origin/topic/bernhard/input-warn-on-invalid-numbers'
* remotes/origin/topic/bernhard/input-warn-on-invalid-numbers:
  ...and another small change to error handling -> now errors in single lines do not kill processing, but simply ignore the line, log it, and continue.
  Ok, this one was a little bit sneaky.
  ok, this one might really be a bit too big for 2.1
2012-08-27 12:43:36 -07:00
Robin Sommer
48c6bdf467 Merge remote-tracking branch 'origin/fastpath'
* origin/fastpath:
  fix handline of sets only containing a zero-length string.

Conflicts:
	src/input/readers/Ascii.cc
2012-08-27 12:27:24 -07:00
Bernhard Amann
56fa56ffa9 ...and another small change to error handling -> now errors in single lines
do not kill processing, but simply ignore the line, log it, and continue.
2012-08-27 11:38:20 -07:00
Bernhard Amann
a4ca5b0d82 fix handline of sets only containing a zero-length string.
Thank you Robin...
2012-08-27 09:50:51 -07:00
Robin Sommer
352d4bd5e2 Merge remote-tracking branch 'origin/fastpath'
* origin/fastpath:
  Ok, this one is not really necessary for 2.1 and more of a nice-to-have
  another small bug found while searching for something else...
  Fix two little bugs:
  sorry. the patch for the set_separator.
  make set_separators different from , work for input framework.
  Bug found bei Keith & Seth: input framework was not handling counts and ints out of 32-bit-range correctly.
2012-08-27 09:31:17 -07:00
Bernhard Amann
f133e8808a ok, this one might really be a bit too big for 2.1
Give all kinds of errors when encountering invalid numbers (like out-of-range-warnings, etc).
2012-08-26 22:00:37 -07:00
Bernhard Amann
7e46936728 Ok, this one is not really necessary for 2.1 and more of a nice-to-have
Before this patch, empty values were not hashed at all. Which had the unfortunate side-effect
that e.g. the lines

TEST	-
and
-	TEST

have the same hash values. On re-reads that means that the change will
be ignored.

This is probably pretty academic, but this patch changes it and adds a testcase.

Output of the reread test changes due to re-ordering of the output (probably
due to the fact that the internal hash values are changed and thus transferred
in a different order)
2012-08-26 20:49:21 -07:00
Bernhard Amann
a9e6d9ae81 Fix two little bugs:
Escaped ,'s in sets and vectors were unescaped before tokenization

Handling of zero-length-strings as last element in a set was broken (sets ending with a ,).

Hashing of lines just containing zero-length-strings was broken (now a \0 is appended to each
string before it is hashed - giving us a hash of something for a line just consisting of \0s.
This also allows to differentiate between vectors with varying numbers of zero-length-strings).
2012-08-26 19:17:21 -07:00
Bernhard Amann
977c1d7c5a make set_separators different from , work for input framework.
1-line-patch + test.
2012-08-26 17:52:07 -07:00
Bernhard Amann
124c985d7a Bug found bei Keith & Seth: input framework was not handling counts and ints out of 32-bit-range correctly.
Note - another bugfix will be coming later (problem reading sets containing zero-length-strings & un-escaping-bug in sets)
2012-08-26 14:49:37 -07:00