Commit Graph

17 Commits

Author SHA1 Message Date
Soner Tari
d877b9a635 Fix and improve get_name_value() and unit tests
Fix possible segfault if name has leading white space
Pass the name param to get_name_value() as char *, so it cannot be
modified ever

Improve unit tests for get_name_value and proxyspec_parse
2021-09-22 15:29:09 +03:00
Soner Tari
206734e4b6 Return -1 on error from all configuration functions, never exit()
And use all those return values.

Since we support include files now, we should be able to report in which
include file the error has occured. This is not possible if functions
just bail out calling exit(), because the user has to scroll back stderr
lines to find which include file has failed loading (a line starting
with 'Conf: ').

Plus, calling exit() on errors reduces unit testability of functions.

Also, handle all possible out of memory conditions in opts.c.
2021-09-22 00:51:36 +03:00
Soner Tari
446cc29f5f Don't change log action if not specified, and obey the order of filtering rules
Filtering rules can enable/disable or don't change logging. If a rule
does not mention a log action, its logging should not change. So, binary
log action fields were not enough to represent those 3 possibilities,
hence we have increased the size of those fields to 2-bits.

We should obey the order of rules as they are written in the conf file,
because latter rules should be able to override the log actions of
earlier rules. So, keep the order.
2021-09-19 16:24:35 +03:00
Soner Tari
cc7bd4a332 Add precedence to filtering rules
Now we assign precedence to each filtering rule. More specific rules
have higher precedence. So, filtering rules at lower precedence cannot
override the actions applied to a conn by filtering rules at higher
precedence.
The other precedence rules still apply.
2021-09-18 16:58:42 +03:00
Soner Tari
0c9fe83bb5 Update unit tests with master and cert log actions 2021-09-18 01:01:47 +03:00
Soner Tari
f0c2ca6819 Add Match action and connect|content|pcap|mirror log actions in filtering rules
- Match action is added to be used with log actions only, the other
filter actions can specify log actions too
- Log actions do not configure any loggers. Global loggers for
respective log actions should have been configured for those log actions
to have any effect.
- If no filter rules are defined for a proxyspec, all log actions are
enabled. Otherwise, all log actions are disabled, and filtering rules
should enable them specifically.
- Fix max number of tokens in proxyspec and filter parsers
- Fix issues with rejecting unknown args in filter rule parser
- Do not use filter_rules field of proxyspec after config finished, it
is used for filter configuration and freed afterwards
2021-09-16 21:34:23 +03:00
Soner Tari
37f82aa84e Simplify get_name_value() 2021-09-15 03:07:04 +03:00
Soner Tari
42fecffb70 Silence error message issued for Divert option non-yes|no value
If the value for the Divert option is not yes|no, it is assumed to be a
Divert filtering rule. So the parser for filtering rules should issue
any errors.
2021-09-14 18:32:57 +03:00
Soner Tari
9c8e56d5df Fix unit tests for proxyspec parser caused by tmp global opts change
Pass a non-NULL tmp global opts arg to proxyspec_parse() for its global
split flag accessed in the function.
2021-09-14 13:30:59 +03:00
Soner Tari
475a7ebcda Add Divert|Split|Pass|Block filtering rules
(Divert|Split|Pass|Block)
  ([from (
        user (username|*) [desc keyword]|
        ip (clientaddr|*)|
        *)]
    [to (
        sni (servername[*]|*)|
        cn (commonname[*]|*)|
        host (host[*]|*)|
        uri (uri[*]|*)|
        ip (serveraddr|*)|
        *)]
  |*)

Also, fix a couple of issues with filter rule handling
Clean up
2021-09-12 15:08:59 +03:00
Soner Tari
85fb1bd214 Add new data structure for general filtering rules
Now PassSite rules are considered as pass rule and added to the new data
structure. PassSite option will be deprecated in the future.
2021-09-10 22:53:08 +03:00
Soner Tari
6a4a70bb06 Avoid strdup() and simplify passsite search
Also, improve code, tests, and documentation
2021-09-08 00:21:52 +03:00
Soner Tari
982880ccfe Restructure passsite filter data structure
Now we don't go over all of the passsite rules in a linked list trying
to apply passsite to the sni or common names of a conn. Instead, we now
have user+keyword, keyword, ip, and all lists. For example, if we find
the conn user in the user+keyword list and a passsite in that list
matches, we don't look into other lists.

This change is expected to improve the performance of passsite
processing considerably, because in the earlier implementation we had to
go over all of the passsite rules trying to match passsite.

And this solution uses a correct data structure, even if not the best.
For example, each user or keyword in passsite rules is strdup()'ed only
once.

Note that a better solution could use, say, a hash table for users,
instead of a linked list. But hash tables are not suitable for keywords
or sites, because we search for substring matches with them, not exact
matches.

Also, this fixes passsite rules without any filters defined, i.e. to be
applied to all connections.

Also, now e2e tests error exit if WITHOUT_USERAUTH is enabled. E2e tests
require UserAuth enabled.
2021-09-07 18:52:52 +03:00
Soner Tari
6f5a7ceeb1 Add WITHOUT_USERAUTH switch 2020-08-25 23:32:32 +03:00
Soner Tari
3fe0e5f1eb Move tmp global opts vars to new tmp struct
The global opts strings in this new tmp struct are used while cloning
global opts into proxyspec opts. A var of this type is passed around as
a flag to indicate if these opts are global (if non-NULL), so should be
stored in that struct and used as such, or proxyspec specific (if NULL),
so should not be used as global. This var is temporary, hence freed
immediately after configuration is complete.
Also improve and clean up.
2020-05-15 19:18:13 +03:00
Soner Tari
01577657fd Clean up DOCKER directives 2020-05-12 12:02:53 +03:00
Soner Tari
8eab8d1da8 Restructure source tree, create src and tests folders, move files accordingly
Remove docker
2020-03-27 14:28:08 +03:00