1 /* @(#) $Id: rules.h,v 1.41 2009/06/24 17:06:22 dcid Exp $ */
3 /* Copyright (C) 2009 Trend Micro Inc.
6 * This program is a free software; you can redistribute it
7 * and/or modify it under the terms of the GNU General Public
8 * License (version 3) as published by the FSF - Free Software
17 #define MAX_LAST_EVENTS 11
20 #include "active-response.h"
22 /* Event context - stored on a uint8 */
23 #define SAME_USER 0x001 /* 1 */
24 #define SAME_SRCIP 0x002 /* 2 */
25 #define SAME_ID 0x004 /* 4 */
26 #define SAME_LOCATION 0x008 /* 8 */
27 #define DIFFERENT_URL 0x010 /* */
28 #define SAME_SRCPORT 0x020
29 #define SAME_DSTPORT 0x040
30 #define NOT_SAME_USER 0xffe /* 0xfff - 0x001 */
31 #define NOT_SAME_SRCIP 0xffd /* 0xfff - 0x002 */
32 #define NOT_SAME_ID 0xffb /* 0xfff - 0x004 */
33 #define NOT_SAME_AGENT 0xff7 /* 0xfff - 0x008 */
35 /* Alert options - store on a uint8 */
37 #define DO_MAILALERT 0x002
38 #define DO_LOGALERT 0x004
39 #define NO_ALERT 0x010
40 #define DO_OVERWRITE 0x020
41 #define DO_PACKETINFO 0x040
42 #define DO_EXTRAINFO 0x100
43 #define SAME_EXTRAINFO 0x200
46 typedef struct _RuleInfo
48 int sigid; /* id attribute -- required*/
49 int level; /* level attribute --required */
54 u_int8_t context; /* Not an user option */
56 int firedtimes; /* Not an user option */
57 int time_ignored; /* Not an user option */
61 int group_prev_matched_sz;
67 /* Not an option in the rule */
71 u_int16_t context_opts;
79 /* List of previously matched events */
80 OSList *sid_prev_matched;
82 /* Pointer to a list (points to sid_prev_matched of if_matched_sid */
85 /* List of previously matched events in this group.
86 * Every rule that has if_matched_group will have this
87 * list. Every rule that matches this group, it going to
88 * have a pointer to it (group_search).
90 OSList **group_prev_matched;
92 /* Pointer to group_prev_matched */
95 /* Function pointer to the event_search. */
96 void *(*event_search)(void *lf, void *rule);
103 /* Policy-based rules */
116 OSMatch *program_name;
120 char *comment; /* description in the xml */
128 OSRegex *if_matched_regex;
129 OSMatch *if_matched_group;
132 void *(*compiled_rule)(void *lf);
133 active_response **ar;
138 typedef struct _RuleNode
141 struct _RuleNode *next;
142 struct _RuleNode *child;
146 RuleInfo *currently_rule; /* */
148 /* RuleInfo functions */
149 RuleInfo *zerorulemember(int id,
159 /** Rule_list Functions **/
161 /* create the rule list */
162 void OS_CreateRuleList();
164 /* Add rule information to the list */
165 int OS_AddRule(RuleInfo *read_rule);
167 /* Add rule information as a child */
168 int OS_AddChild(RuleInfo *read_rule);
170 /* Add an overwrite rule */
171 int OS_AddRuleInfo(RuleNode *r_node, RuleInfo *newrule, int sid);
173 /* Mark groups (if_matched_group) */
174 int OS_MarkGroup(RuleNode *r_node, RuleInfo *orig_rule);
176 /* Mark IDs (if_matched_sid) */
177 int OS_MarkID(RuleNode *r_node, RuleInfo *orig_rule);
181 RuleNode *OS_GetFirstRule();
184 /** Defition of the internal rule IDS **
185 ** These SIGIDs cannot be used **
188 #define STATS_MODULE 11
189 #define FTS_MODULE 12
190 #define SYSCHECK_MODULE 13
191 #define HOSTINFO_MODULE 15
194 #define ROOTCHECK_MOD "rootcheck"
195 #define HOSTINFO_NEW "hostinfo_new"
196 #define HOSTINFO_MOD "hostinfo_modified"
197 #define SYSCHECK_MOD "syscheck_integrity_changed"
198 #define SYSCHECK_MOD2 "syscheck_integrity_changed_2nd"
199 #define SYSCHECK_MOD3 "syscheck_integrity_changed_3rd"
200 #define SYSCHECK_NEW "syscheck_new_entry"
201 #define SYSCHECK_DEL "syscheck_deleted"
204 #endif /* _OS_RULES */