1 /* @(#) $Id: ./src/analysisd/decoders/decoder.c, 2011/09/08 dcid Exp $
4 /* Copyright (C) 2009 Trend Micro Inc.
7 * This program is a free software; you can redistribute it
8 * and/or modify it under the terms of the GNU General Public
9 * License (version 2) as published by the FSF - Free Software
12 * License details at the LICENSE file included with OSSEC or
13 * online at: http://www.ossec.net/en/licensing.html
18 #include "os_regex/os_regex.h"
19 #include "os_xml/os_xml.h"
22 #include "eventinfo.h"
28 * Will use the osdecoders to decode the received event.
30 void DecodeEvent(Eventinfo *lf)
33 OSDecoderNode *child_node;
39 char *regex_prev = NULL;
42 node = OS_GetFirstOSDecoder(lf->program_name);
45 /* Return if no node...
46 * This shouldn't happen here anyways.
55 print_out("\n**Phase 2: Completed decoding.");
61 nnode = node->osdecoder;
64 /* First checking program name */
67 if(!OSMatch_Execute(lf->program_name, lf->p_name_size,
76 /* If prematch fails, go to the next osdecoder in the list */
79 if(!(pmatch = OSRegex_Execute(lf->log, nnode->prematch)))
91 if(!alert_only)print_out(" decoder: '%s'", nnode->name);
95 lf->decoder_info = nnode;
98 child_node = node->child;
101 /* If no child node is set, set the child node
102 * as if it were the child (ugh)
111 /* Check if we have any child osdecoder */
114 nnode = child_node->osdecoder;
117 /* If we have a pre match and it matches, keep
118 * going. If we don't have a prematch, stop
119 * and go for the regexes.
125 /* If we have an offset set, use it */
126 if(nnode->prematch_offset & AFTER_PARENT)
135 if((cmatch = OSRegex_Execute(llog, nnode->prematch)))
140 lf->decoder_info = nnode;
152 /* If we have multiple regex-only childs,
153 * do not attempt to go any further with them.
155 if(child_node->osdecoder->get_next)
159 child_node = child_node->next;
160 }while(child_node && child_node->osdecoder->get_next);
165 child_node = child_node->next;
170 child_node = child_node->next;
177 /* Nothing matched */
182 /* If we have a external decoder, execute it */
183 if(nnode->plugindecoder)
185 nnode->plugindecoder(lf);
190 /* Getting the regex */
197 /* With regex we have multiple options
198 * regarding the offset:
199 * after the prematch,
201 * after some previous regex,
204 if(nnode->regex_offset)
206 if(nnode->regex_offset & AFTER_PARENT)
210 else if(nnode->regex_offset & AFTER_PREMATCH)
214 else if(nnode->regex_offset & AFTER_PREVREGEX)
227 /* If Regex does not match, return */
228 if(!(regex_prev = OSRegex_Execute(llog, nnode->regex)))
232 child_node = child_node->next;
233 nnode = child_node->osdecoder;
240 /* Fixing next pointer */
241 if(*regex_prev != '\0')
244 while(nnode->regex->sub_strings[i])
248 nnode->order[i](lf, nnode->regex->sub_strings[i]);
249 nnode->regex->sub_strings[i] = NULL;
254 /* We do not free any memory used above */
255 os_free(nnode->regex->sub_strings[i]);
256 nnode->regex->sub_strings[i] = NULL;
260 /* If we have a next regex, try getting it */
263 child_node = child_node->next;
264 nnode = child_node->osdecoder;
271 /* If we don't have a regex, we may leave now */
277 }while((node=node->next) != NULL);
282 print_out(" No decoder matched.");
289 /*** Event decoders ****/
290 void *DstUser_FP(Eventinfo *lf, char *field)
293 if(!alert_only)print_out(" dstuser: '%s'", field);
299 void *SrcUser_FP(Eventinfo *lf, char *field)
302 if(!alert_only)print_out(" srcuser: '%s'", field);
308 void *SrcIP_FP(Eventinfo *lf, char *field)
311 if(!alert_only)print_out(" srcip: '%s'", field);
317 void *DstIP_FP(Eventinfo *lf, char *field)
320 if(!alert_only)print_out(" dstip: '%s'", field);
326 void *SrcPort_FP(Eventinfo *lf, char *field)
329 if(!alert_only)print_out(" srcport: '%s'", field);
335 void *DstPort_FP(Eventinfo *lf, char *field)
338 if(!alert_only)print_out(" dstport: '%s'", field);
344 void *Protocol_FP(Eventinfo *lf, char *field)
347 if(!alert_only)print_out(" proto: '%s'", field);
350 lf->protocol = field;
353 void *Action_FP(Eventinfo *lf, char *field)
356 if(!alert_only)print_out(" action: '%s'", field);
362 void *ID_FP(Eventinfo *lf, char *field)
365 if(!alert_only)print_out(" id: '%s'", field);
371 void *Url_FP(Eventinfo *lf, char *field)
374 if(!alert_only)print_out(" url: '%s'", field);
380 void *Data_FP(Eventinfo *lf, char *field)
383 if(!alert_only)print_out(" extra_data: '%s'", field);
389 void *Status_FP(Eventinfo *lf, char *field)
392 if(!alert_only)print_out(" status: '%s'", field);
398 void *SystemName_FP(Eventinfo *lf, char *field)
401 if(!alert_only)print_out(" system_name: '%s'", field);
404 lf->systemname = field;
407 void *None_FP(Eventinfo *lf, char *field)