1 /* @(#) $Id: ./src/analysisd/decoders/decoders_list.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
21 #include "headers/debug_op.h"
24 #include "error_messages/error_messages.h"
27 /* We have two internal lists. One with the program_name
28 * and one without. This is going to improve greatly the
29 * performance of our decoder matching.
31 OSDecoderNode *osdecodernode_forpname;
32 OSDecoderNode *osdecodernode_nopname;
35 /* Create the Event List */
36 void OS_CreateOSDecoderList()
38 osdecodernode_forpname = NULL;
39 osdecodernode_nopname = NULL;
45 /* Get first osdecoder */
46 OSDecoderNode *OS_GetFirstOSDecoder(char *p_name)
48 /* If program name is set, we return the forpname list.
52 return(osdecodernode_forpname);
55 return(osdecodernode_nopname);
59 /* Add a osdecoder to the list */
60 OSDecoderNode *_OS_AddOSDecoder(OSDecoderNode *s_node, OSDecoderInfo *pi)
62 OSDecoderNode *tmp_node = s_node;
67 OSDecoderNode *new_node;
69 new_node = (OSDecoderNode *)calloc(1,sizeof(OSDecoderNode));
72 merror(MEM_ERROR,ARGV0);
76 /* Going to the last node */
79 /* Checking for common names */
80 if((strcmp(tmp_node->osdecoder->name,pi->name) == 0) &&
83 if((tmp_node->osdecoder->prematch ||
84 tmp_node->osdecoder->regex) && pi->regex_offset)
89 /* Multi-regexes patterns cannot have prematch */
92 merror(PDUP_INV, ARGV0,pi->name);
96 /* Multi-regex patterns cannot have fts set */
99 merror(PDUPFTS_INV, ARGV0,pi->name);
103 if(tmp_node->osdecoder->regex && pi->regex)
105 tmp_node->osdecoder->get_next = 1;
109 merror(DUP_INV, ARGV0,pi->name);
114 }while(tmp_node->next && (tmp_node = tmp_node->next));
117 /* Must have a prematch set */
118 if(!rm_f && (pi->regex_offset & AFTER_PREVREGEX))
120 merror(INV_OFFSET, ARGV0, pi->name);
124 tmp_node->next = new_node;
126 new_node->next = NULL;
127 new_node->osdecoder = pi;
128 new_node->child = NULL;
133 /* Must not have a previous regex set */
134 if(pi->regex_offset & AFTER_PREVREGEX)
136 merror(INV_OFFSET, ARGV0, pi->name);
140 tmp_node = (OSDecoderNode *)calloc(1, sizeof(OSDecoderNode));
144 ErrorExit(MEM_ERROR,ARGV0);
147 tmp_node->child = NULL;
148 tmp_node->next = NULL;
149 tmp_node->osdecoder = pi;
158 int OS_AddOSDecoder(OSDecoderInfo *pi)
161 OSDecoderNode *osdecodernode;
164 /* We can actually have two lists. One with program
165 * name and the other without.
169 osdecodernode = osdecodernode_forpname;
173 osdecodernode = osdecodernode_nopname;
177 /* Search for parent on both lists */
180 OSDecoderNode *tmp_node = osdecodernode_forpname;
182 /* List with p_name */
185 if(strcmp(tmp_node->osdecoder->name, pi->parent) == 0)
187 tmp_node->child = _OS_AddOSDecoder(tmp_node->child, pi);
190 merror(DEC_PLUGIN_ERR, ARGV0);
195 tmp_node = tmp_node->next;
199 /* List without p name */
200 tmp_node = osdecodernode_nopname;
203 if(strcmp(tmp_node->osdecoder->name, pi->parent) == 0)
205 tmp_node->child = _OS_AddOSDecoder(tmp_node->child, pi);
208 merror(DEC_PLUGIN_ERR, ARGV0);
213 tmp_node = tmp_node->next;
217 /* OSDecoder was added correctly */
223 merror(PPLUGIN_INV, ARGV0, pi->parent);
228 osdecodernode = _OS_AddOSDecoder(osdecodernode, pi);
231 merror(DEC_PLUGIN_ERR, ARGV0);
235 /* Updating global decoders pointers */
238 osdecodernode_forpname = osdecodernode;
242 osdecodernode_nopname = osdecodernode;