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 2) as published by the FSF - Free Software
11 * License details at the LICENSE file included with OSSEC or
12 * online at: http://www.ossec.net/en/licensing.html
15 /* Common API for dealing with directory trees */
24 /* Event context - stored on a uint8 */
25 #define SAME_USER 0x001 /* 1 */
26 #define SAME_SRCIP 0x002 /* 2 */
27 #define SAME_ID 0x004 /* 4 */
28 #define SAME_LOCATION 0x008 /* 8 */
29 #define DIFFERENT_URL 0x010 /* */
30 #define SAME_SRCPORT 0x020
31 #define SAME_DSTPORT 0x040
32 #define SAME_DODIFF 0x100
33 #define NOT_SAME_USER 0xffe /* 0xfff - 0x001 */
34 #define NOT_SAME_SRCIP 0xffd /* 0xfff - 0x002 */
35 #define NOT_SAME_ID 0xffb /* 0xfff - 0x004 */
36 #define NOT_SAME_AGENT 0xff7 /* 0xfff - 0x008 */
39 /* Alert options - store on a uint8 */
41 #define DO_MAILALERT 0x002
42 #define DO_LOGALERT 0x004
44 #define NO_ALERT 0x010
45 #define DO_OVERWRITE 0x020
46 #define DO_PACKETINFO 0x040
47 #define DO_EXTRAINFO 0x100
48 #define SAME_EXTRAINFO 0x200
51 /** Types of events (from decoders) **/
52 #define UNKNOWN 0 /* Unkown */
53 #define SYSLOG 1 /* syslog messages */
54 #define IDS 2 /* IDS alerts */
55 #define FIREWALL 3 /* Firewall events */
56 #define WEBLOG 7 /* Apache logs */
57 #define SQUID 8 /* Squid logs */
58 #define WINDOWS 9 /* Windows logs */
59 #define HOST_INFO 10 /* Host information logs (from nmap or similar) */
60 #define OSSEC_RL 11 /* Ossec rules */
63 /* FTS allowed values */
64 #define FTS_NAME 001000
65 #define FTS_USER 002000
66 #define FTS_DSTUSER 004000
67 #define FTS_SRCIP 000100
68 #define FTS_DSTIP 000200
69 #define FTS_LOCATION 000400
71 #define FTS_DATA 000020
72 #define FTS_SYSTEMNAME 000040
77 typedef struct _RuleInfo
79 int sigid; /* id attribute -- required*/
80 int level; /* level attribute --required */
85 u_int8_t context; /* Not an user option */
87 int firedtimes; /* Not an user option */
88 int time_ignored; /* Not an user option */
92 int group_prev_matched_sz;
98 /* Not an option in the rule */
101 /* Context options */
102 u_int16_t context_opts;
108 u_int16_t decoded_as;
110 /* List of previously matched events */
111 OSList *sid_prev_matched;
113 /* Pointer to a list (points to sid_prev_matched of if_matched_sid */
116 /* List of previously matched events in this group.
117 * Every rule that has if_matched_group will have this
118 * list. Every rule that matches this group, it going to
119 * have a pointer to it (group_search).
121 OSList **group_prev_matched;
123 /* Pointer to group_prev_matched */
124 OSList *group_search;
126 /* Function pointer to the event_search. */
127 void *(*event_search)(void *lf, void *rule);
134 /* Policy-based rules */
147 OSMatch *program_name;
151 char *comment; /* description in the xml */
159 OSRegex *if_matched_regex;
160 OSMatch *if_matched_group;
169 int OS_ReadXMLRules(char *rulefile,
170 void *(*ruleact_function)(RuleInfo *rule, void *data),