Branch data Line data Source code
1 : : // $Id: RuleAction.cc 5906 2008-07-03 19:52:50Z vern $
2 : :
3 : : #include <string>
4 : : using std::string;
5 : :
6 : : #include "config.h"
7 : :
8 : : #include "RuleAction.h"
9 : : #include "RuleMatcher.h"
10 : : #include "Conn.h"
11 : : #include "Event.h"
12 : : #include "NetVar.h"
13 : : #include "DPM.h"
14 : : #include "PIA.h"
15 : :
16 : : void RuleActionEvent::DoAction(const Rule* parent, RuleEndpointState* state,
17 : 0 : const u_char* data, int len)
18 : : {
19 [ # # ]: 0 : if ( signature_match )
20 : : {
21 : 0 : val_list* vl = new val_list;
22 : 0 : vl->append(rule_matcher->BuildRuleStateValue(parent, state));
23 : 0 : vl->append(new StringVal(msg));
24 : :
25 [ # # ]: 0 : if ( data )
26 : 0 : vl->append(new StringVal(len, (const char*)data));
27 : : else
28 : 0 : vl->append(new StringVal(""));
29 : :
30 : 0 : mgr.QueueEvent(signature_match, vl);
31 : : }
32 : 0 : }
33 : :
34 : 0 : void RuleActionEvent::PrintDebug()
35 : : {
36 : 0 : fprintf(stderr, " RuleActionEvent: |%s|\n", msg);
37 : 0 : }
38 : :
39 : 11 : RuleActionDPM::RuleActionDPM(const char* arg_analyzer)
40 : : {
41 : 11 : string str(arg_analyzer);
42 : 11 : string::size_type pos = str.find(':');
43 : 11 : string arg = str.substr(0, pos);
44 : 11 : analyzer = Analyzer::GetTag(arg.c_str());
45 : :
46 [ # # - + ]: 11 : if ( pos != string::npos )
47 : : {
48 : 0 : arg = str.substr(pos + 1);
49 : 0 : child_analyzer = Analyzer::GetTag(arg.c_str());
50 : : }
51 : : else
52 : 11 : child_analyzer = AnalyzerTag::Error;
53 : :
54 [ # # ][ + - ]: 11 : if ( analyzer != AnalyzerTag::Error )
55 : 11 : dpm->ActivateSigs();
56 : 11 : }
57 : :
58 : 0 : void RuleActionDPM::PrintDebug()
59 : : {
60 [ # # ]: 0 : if ( child_analyzer == AnalyzerTag::Error )
61 : 0 : fprintf(stderr, "|%s|\n", Analyzer::GetTagName(analyzer));
62 : : else
63 : : fprintf(stderr, "|%s:%s|\n",
64 : : Analyzer::GetTagName(analyzer),
65 : 0 : Analyzer::GetTagName(child_analyzer));
66 : 0 : }
67 : :
68 : :
69 : : void RuleActionEnable::DoAction(const Rule* parent, RuleEndpointState* state,
70 : 0 : const u_char* data, int len)
71 : : {
72 [ # # ]: 0 : if ( ChildAnalyzer() == AnalyzerTag::Error )
73 : : {
74 [ # # ]: 0 : if ( ! Analyzer::IsAvailable(Analyzer()) )
75 : 0 : return;
76 : :
77 [ # # ]: 0 : if ( state->PIA() )
78 : 0 : state->PIA()->ActivateAnalyzer(Analyzer(), parent);
79 : : }
80 : : else
81 : : {
82 [ # # ]: 0 : if ( ! Analyzer::IsAvailable(ChildAnalyzer()) )
83 : 0 : return;
84 : :
85 : : // This is ugly and works only if there exists only one
86 : : // analyzer of each type.
87 : : state->PIA()->AsAnalyzer()->Conn()->FindAnalyzer(Analyzer())
88 : 0 : ->AddChildAnalyzer(ChildAnalyzer());
89 : : }
90 : : }
91 : :
92 : 0 : void RuleActionEnable::PrintDebug()
93 : : {
94 : 0 : fprintf(stderr, " RuleActionEnable: ");
95 : 0 : RuleActionDPM::PrintDebug();
96 : 0 : }
97 : :
98 : : void RuleActionDisable::DoAction(const Rule* parent, RuleEndpointState* state,
99 : 0 : const u_char* data, int len)
100 : : {
101 [ # # ]: 0 : if ( ChildAnalyzer() == AnalyzerTag::Error )
102 : : {
103 [ # # ]: 0 : if ( state->PIA() )
104 : 0 : state->PIA()->DeactivateAnalyzer(Analyzer());
105 : : }
106 : : else
107 : : state->GetAnalyzer()->AddChildAnalyzer(
108 : 0 : state->GetAnalyzer()->FindChild(ChildAnalyzer()));
109 : 0 : }
110 : :
111 : 0 : void RuleActionDisable::PrintDebug()
112 : : {
113 : 0 : fprintf(stderr, " RuleActionDisable: ");
114 : 0 : RuleActionDPM::PrintDebug();
115 [ + - ][ + - ]: 6 : }
|