|
1 | 1 | #!/usr/bin/perl -w |
2 | 2 | # |
3 | | -# SEC (Simple Event Correlator) 2.8.1 - sec |
4 | | -# Copyright (C) 2000-2018 Risto Vaarandi |
| 3 | +# SEC (Simple Event Correlator) 2.8.2 - sec |
| 4 | +# Copyright (C) 2000-2019 Risto Vaarandi |
5 | 5 | # |
6 | 6 | # This program is free software; you can redistribute it and/or |
7 | 7 | # modify it under the terms of the GNU General Public License |
@@ -179,8 +179,8 @@ $WIN32 = ($^O =~ /win/i && $^O !~ /cygwin/i && $^O !~ /darwin/i); |
179 | 179 |
|
180 | 180 | # set version and usage variables |
181 | 181 |
|
182 | | -$SEC_VERSION = "SEC (Simple Event Correlator) 2.8.1"; |
183 | | -$SEC_COPYRIGHT = "Copyright (C) 2000-2018 Risto Vaarandi"; |
| 182 | +$SEC_VERSION = "SEC (Simple Event Correlator) 2.8.2"; |
| 183 | +$SEC_COPYRIGHT = "Copyright (C) 2000-2019 Risto Vaarandi"; |
184 | 184 |
|
185 | 185 | $SEC_USAGE = qq!Usage: $0 [options] |
186 | 186 |
|
@@ -325,6 +325,7 @@ use constant REWRITE => 51; |
325 | 325 | use constant ADDINPUT => 52; |
326 | 326 | use constant DROPINPUT => 53; |
327 | 327 | use constant SIGEMUL => 54; |
| 328 | +use constant VARIABLESET => 55; |
328 | 329 | use constant IF => 100; |
329 | 330 | use constant WHILE => 101; |
330 | 331 | use constant BREAK => 102; |
@@ -867,7 +868,7 @@ sub analyze_action { |
867 | 868 | my($actionlist, @action); |
868 | 869 | my($actionlist2, @action2); |
869 | 870 | my($createafter, $event, $timestamp); |
870 | | - my($lifetime, $context, $alias); |
| 871 | + my($lifetime, $context, $alias, $entry); |
871 | 872 | my($variable, $value, $code, $codeptr, $params, $evalok, $op); |
872 | 873 |
|
873 | 874 | if ($action =~ /^none$/i) { return NONE; } |
@@ -1559,6 +1560,28 @@ sub analyze_action { |
1559 | 1560 | return (SIGEMUL, $signal); |
1560 | 1561 | } |
1561 | 1562 |
|
| 1563 | + elsif ($action =~ /^varset\s+(\S+)\s+(\S+)$/i) { |
| 1564 | + |
| 1565 | + $variable = $1; |
| 1566 | + $entry = $2; |
| 1567 | + process_action_parens($entry); |
| 1568 | + |
| 1569 | + if ($variable !~ /^%[[:alpha:]]\w*$/) { |
| 1570 | + log_msg(LOG_ERR, "Rule in $conffile at line $lineno:", |
| 1571 | + "Variable $variable does not have the form", |
| 1572 | + "%<letter>[<letter>|<digit>|<underscore>]..."); |
| 1573 | + return INVALIDVALUE; |
| 1574 | + } |
| 1575 | + |
| 1576 | + if (!length($entry)) { |
| 1577 | + log_msg(LOG_ERR, "Rule in $conffile at line $lineno:", |
| 1578 | + "Empty pattern match cache entry name given for varset action"); |
| 1579 | + return INVALIDVALUE; |
| 1580 | + } |
| 1581 | + |
| 1582 | + return (VARIABLESET, substr($variable, 1), $entry); |
| 1583 | + } |
| 1584 | + |
1562 | 1585 | elsif ($action =~ /^if\s/i) { |
1563 | 1586 |
|
1564 | 1587 | $value = EXPRSYMBOL; |
@@ -6439,6 +6462,27 @@ sub execute_sigemul_action { |
6439 | 6462 | return 2; |
6440 | 6463 | } |
6441 | 6464 |
|
| 6465 | +sub execute_varset_action { |
| 6466 | + |
| 6467 | + my($actionlist, $text, $i) = @_; |
| 6468 | + my($entry, $variable, $value); |
| 6469 | + |
| 6470 | + $variable = $actionlist->[$i+1]; |
| 6471 | + $entry = $actionlist->[$i+2]; |
| 6472 | + |
| 6473 | + substitute_actionlist_var($entry, $text); |
| 6474 | + |
| 6475 | + log_msg(LOG_DEBUG, |
| 6476 | + "Checking the presence of pattern match cache entry '$entry'"); |
| 6477 | + |
| 6478 | + $value = (exists($pmatch_cache{$entry}))?1:0; |
| 6479 | + $variables{$variable} = $value; |
| 6480 | + |
| 6481 | + log_msg(LOG_DEBUG, "Variable '%$variable' set to '$value'"); |
| 6482 | + |
| 6483 | + return 3; |
| 6484 | +} |
| 6485 | + |
6442 | 6486 | sub execute_if_action { |
6443 | 6487 |
|
6444 | 6488 | my($actionlist, $text, $i) = @_; |
@@ -7442,12 +7486,16 @@ sub subst_string { |
7442 | 7486 |
|
7443 | 7487 | } else { |
7444 | 7488 |
|
| 7489 | + # calling defined($pmatch_cache{$4}->{$+}) will create $pmatch_cache{$4} |
| 7490 | + # if it doesn't exist, thus exists($pmatch_cache{$4}) is called first |
| 7491 | + |
7445 | 7492 | $msg =~ s/$token2(?:$token2|([0-9]+)|\{([0-9]+)\}| |
7446 | 7493 | \+\{([[:alpha:]_][\w!]*|[0-9]+)\}| |
7447 | 7494 | :\{([[:alpha:]]\w*):([[:alpha:]_][\w!]*|[0-9]+)\})/ |
7448 | 7495 | !defined($+)?$token: |
7449 | | - (!defined($4)?(defined($subst_ref->{$+})?$subst_ref->{$+}:"") |
7450 | | - :(defined($pmatch_cache{$4}->{$+})?$pmatch_cache{$4}->{$+}:""))/egx; |
| 7496 | + (!defined($4)?(defined($subst_ref->{$+})?$subst_ref->{$+}:""): |
| 7497 | + ((exists($pmatch_cache{$4}) && defined($pmatch_cache{$4}->{$+}))? |
| 7498 | + $pmatch_cache{$4}->{$+}:""))/egx; |
7451 | 7499 | } |
7452 | 7500 | } |
7453 | 7501 |
|
@@ -9565,6 +9613,11 @@ sub actionlist2str { |
9565 | 9613 | $i += 2; |
9566 | 9614 | } |
9567 | 9615 |
|
| 9616 | + elsif ($actionlist->[$i] == VARIABLESET) { |
| 9617 | + $result .= "varset %" . $actionlist->[$i+1] . " " . $actionlist->[$i+2]; |
| 9618 | + $i += 3; |
| 9619 | + } |
| 9620 | + |
9568 | 9621 | elsif ($actionlist->[$i] == IF) { |
9569 | 9622 | $result .= "if %" . $actionlist->[$i+1] . " ("; |
9570 | 9623 | if (scalar(@{$actionlist->[$i+2]})) { |
@@ -13386,6 +13439,7 @@ $actioncopyfunc[REWRITE] = \©_three_elem_action; |
13386 | 13439 | $actioncopyfunc[ADDINPUT] = \©_four_elem_action; |
13387 | 13440 | $actioncopyfunc[DROPINPUT] = \©_two_elem_action; |
13388 | 13441 | $actioncopyfunc[SIGEMUL] = \©_two_elem_action; |
| 13442 | +$actioncopyfunc[VARIABLESET] = \©_three_elem_action; |
13389 | 13443 | $actioncopyfunc[IF] = \©_if_action; |
13390 | 13444 | $actioncopyfunc[WHILE] = \©_while_action; |
13391 | 13445 | $actioncopyfunc[BREAK] = \©_one_elem_action; |
@@ -13446,6 +13500,7 @@ $actionsubstfunc[REWRITE] = \&subst_three_elem_action; |
13446 | 13500 | $actionsubstfunc[ADDINPUT] = \&subst_four_elem_action; |
13447 | 13501 | $actionsubstfunc[DROPINPUT] = \&subst_two_elem_action; |
13448 | 13502 | $actionsubstfunc[SIGEMUL] = \&subst_two_elem_action; |
| 13503 | +$actionsubstfunc[VARIABLESET] = \&subst_event_assign_etc_action; |
13449 | 13504 | $actionsubstfunc[IF] = \&subst_if_action; |
13450 | 13505 | $actionsubstfunc[WHILE] = \&subst_while_action; |
13451 | 13506 | $actionsubstfunc[BREAK] = \&subst_none_break_continue; |
@@ -13506,6 +13561,7 @@ $execactionfunc[REWRITE] = \&execute_rewrite_action; |
13506 | 13561 | $execactionfunc[ADDINPUT] = \&execute_addinput_action; |
13507 | 13562 | $execactionfunc[DROPINPUT] = \&execute_dropinput_action; |
13508 | 13563 | $execactionfunc[SIGEMUL] = \&execute_sigemul_action; |
| 13564 | +$execactionfunc[VARIABLESET] = \&execute_varset_action; |
13509 | 13565 | $execactionfunc[IF] = \&execute_if_action; |
13510 | 13566 | $execactionfunc[WHILE] = \&execute_while_action; |
13511 | 13567 | $execactionfunc[BREAK] = \&execute_break_action; |
|
0 commit comments